This repository was archived by the owner on Jun 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Symbolizer support for mingw and cygwin #208
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
52f3c05
added dbghelp symbolizer support for mingw and cygwin
sergiud e44b536
fixed compiler errors in case <stdint.h> is not available
sergiud 47dae7a
use glog platform definitions
sergiud 8a428d5
cmake: check whether SymFromAddr actually works
sergiud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -844,18 +844,22 @@ static ATTRIBUTE_NOINLINE bool SymbolizeAndDemangle(void *pc, char *out, | |
|
|
||
| _END_GOOGLE_NAMESPACE_ | ||
|
|
||
| #elif defined(OS_WINDOWS) | ||
| #elif defined(OS_WINDOWS) || defined(OS_CYGWIN) | ||
|
|
||
| #include <windows.h> | ||
| #include <DbgHelp.h> | ||
|
|
||
| #ifdef _MSC_VER | ||
| #pragma comment(lib, "DbgHelp") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yup, the above makes sense now. |
||
| #endif | ||
|
|
||
| _START_GOOGLE_NAMESPACE_ | ||
|
|
||
| class SymInitializer { | ||
| public: | ||
| HANDLE process = NULL; | ||
| bool ready = false; | ||
| SymInitializer() { | ||
| HANDLE process; | ||
| bool ready; | ||
| SymInitializer() : process(NULL), ready(false) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| // Initialize the symbol handler. | ||
| // https://msdn.microsoft.com/en-us/library/windows/desktop/ms680344(v=vs.85).aspx | ||
| process = GetCurrentProcess(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -357,10 +357,12 @@ void ATTRIBUTE_NOINLINE TestWithReturnAddress() { | |
| #endif | ||
| } | ||
|
|
||
| # elif defined(OS_WINDOWS) | ||
| # elif defined(OS_WINDOWS) || defined(OS_CYGWIN) | ||
|
|
||
| #ifdef _MSC_VER | ||
| #include <intrin.h> | ||
| #pragma intrinsic(_ReturnAddress) | ||
| #endif | ||
|
|
||
| struct Foo { | ||
| static void func(int x); | ||
|
|
@@ -378,7 +380,13 @@ TEST(Symbolize, SymbolizeWithDemangling) { | |
| } | ||
|
|
||
| __declspec(noinline) void TestWithReturnAddress() { | ||
| void *return_address = _ReturnAddress(); | ||
| void *return_address = | ||
| #ifdef __GNUC__ // Cygwin and MinGW support | ||
| __builtin_return_address(0) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| #else | ||
| _ReturnAddress() | ||
| #endif | ||
| ; | ||
| const char *symbol = TrySymbolize(return_address); | ||
| CHECK(symbol != NULL); | ||
| CHECK_STREQ(symbol, "main"); | ||
|
|
@@ -401,7 +409,7 @@ int main(int argc, char **argv) { | |
| TestWithPCInsideNonInlineFunction(); | ||
| TestWithReturnAddress(); | ||
| return RUN_ALL_TESTS(); | ||
| # elif defined(OS_WINDOWS) | ||
| # elif defined(OS_WINDOWS) || defined(OS_CYGWIN) | ||
| TestWithReturnAddress(); | ||
| return RUN_ALL_TESTS(); | ||
| # else // OS_WINDOWS | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,6 +127,7 @@ | |
| # define HAVE_STACKTRACE | ||
| #endif | ||
|
|
||
| #ifndef HAVE_SYMBOLIZE | ||
| // defined by gcc | ||
| #if defined(__ELF__) && defined(OS_LINUX) | ||
| # define HAVE_SYMBOLIZE | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kind of wish we could move this check into configuration time, but then we'd need to do it in a couple build systems. Oh well. |
||
|
|
@@ -137,6 +138,7 @@ | |
| // Use DbgHelp to symbolize | ||
| # define HAVE_SYMBOLIZE | ||
| #endif | ||
| #endif // !defined(HAVE_SYMBOLIZE) | ||
|
|
||
| #ifndef ARRAYSIZE | ||
| // There is a better way, but this is good enough for our purpose. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least with MSVC, this isn't necessary due to
from here. But I'm guessing it's needed for MinGW / Cygwin? Let me get one installed and give it a whirl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup saw below, that must be the case.