summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergiu Deitsch <sergiud@users.noreply.github.com>2018-02-27 20:03:20 (GMT)
committerGitHub <noreply@github.com>2018-02-27 20:03:20 (GMT)
commita97d6b0e1ce34e4e1956c63de8ddd325ff164512 (patch)
tree8d3f6187d337bd8900d4f7990be91ebc6b39221b /src
parent1aec14edf48dac9c816a272981a399d69c0c652d (diff)
downloadglog-a97d6b0e1ce34e4e1956c63de8ddd325ff164512.zip
glog-a97d6b0e1ce34e4e1956c63de8ddd325ff164512.tar.gz
glog-a97d6b0e1ce34e4e1956c63de8ddd325ff164512.tar.bz2
Symbolizer support for mingw and cygwin (#208)HEADmaster
* added dbghelp symbolizer support for mingw and cygwin * fixed compiler errors in case <stdint.h> is not available * cmake: check whether SymFromAddr actually works
Diffstat (limited to 'src')
-rw-r--r--src/config.h.cmake.in3
-rw-r--r--src/symbolize.cc12
-rw-r--r--src/symbolize.h6
-rw-r--r--src/symbolize_unittest.cc14
-rw-r--r--src/utilities.h2
5 files changed, 27 insertions, 10 deletions
diff --git a/src/config.h.cmake.in b/src/config.h.cmake.in
index 9d87d37..e15c737 100644
--- a/src/config.h.cmake.in
+++ b/src/config.h.cmake.in
@@ -130,6 +130,9 @@
/* define if your compiler has __sync_val_compare_and_swap */
#cmakedefine HAVE___SYNC_VAL_COMPARE_AND_SWAP
+/* define if symbolize support is available */
+#cmakedefine HAVE_SYMBOLIZE
+
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#cmakedefine LT_OBJDIR
diff --git a/src/symbolize.cc b/src/symbolize.cc
index 98a754f..61fe2ff 100644
--- a/src/symbolize.cc
+++ b/src/symbolize.cc
@@ -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")
+#endif
_START_GOOGLE_NAMESPACE_
class SymInitializer {
public:
- HANDLE process = NULL;
- bool ready = false;
- SymInitializer() {
+ HANDLE process;
+ bool ready;
+ SymInitializer() : process(NULL), ready(false) {
// Initialize the symbol handler.
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680344(v=vs.85).aspx
process = GetCurrentProcess();
diff --git a/src/symbolize.h b/src/symbolize.h
index 86f0c79..9ff16c1 100644
--- a/src/symbolize.h
+++ b/src/symbolize.h
@@ -130,9 +130,9 @@ void InstallSymbolizeCallback(SymbolizeCallback callback);
// file is opened successfully, returns the file descriptor. Otherwise,
// returns -1. |out_file_name_size| is the size of the file name buffer
// (including the null-terminator).
-typedef int (*SymbolizeOpenObjectFileCallback)(uint64_t pc,
- uint64_t &start_address,
- uint64_t &base_address,
+typedef int (*SymbolizeOpenObjectFileCallback)(uint64 pc,
+ uint64 &start_address,
+ uint64 &base_address,
char *out_file_name,
int out_file_name_size);
void InstallSymbolizeOpenObjectFileCallback(
diff --git a/src/symbolize_unittest.cc b/src/symbolize_unittest.cc
index a0a9737..413161b 100644
--- a/src/symbolize_unittest.cc
+++ b/src/symbolize_unittest.cc
@@ -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)
+#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
diff --git a/src/utilities.h b/src/utilities.h
index be2cff4..ca21cfb 100644
--- a/src/utilities.h
+++ b/src/utilities.h
@@ -127,6 +127,7 @@
# define HAVE_STACKTRACE
#endif
+#ifndef HAVE_SYMBOLIZE
// defined by gcc
#if defined(__ELF__) && defined(OS_LINUX)
# define HAVE_SYMBOLIZE
@@ -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.