using namespace std;
using namespace GOOGLE_NAMESPACE;
-#if defined(HAVE_STACKTRACE) && defined(__ELF__)
+#if defined(HAVE_STACKTRACE)
#define always_inline
+// A wrapper function for Symbolize() to make the unit test simple.
+static const char *TrySymbolize(void *pc) {
+ static char symbol[4096];
+ if (Symbolize(pc, symbol, sizeof(symbol))) {
+ return symbol;
+ } else {
+ return NULL;
+ }
+}
+
+# if defined(__ELF__)
+
// This unit tests make sense only with GCC.
// Uses lots of GCC specific features.
#if defined(__GNUC__) && !defined(__OPENCC__)
# endif // defined(__i386__) || defined(__x86_64__)
#endif
-// A wrapper function for Symbolize() to make the unit test simple.
-static const char *TrySymbolize(void *pc) {
- static char symbol[4096];
- if (Symbolize(pc, symbol, sizeof(symbol))) {
- return symbol;
- } else {
- return NULL;
- }
-}
-
// Make them C linkage to avoid mangled names.
extern "C" {
void nonstatic_func() {
#endif
}
+# elif defined(OS_WINDOWS)
+
+#include <intrin.h>
+#pragma intrinsic(_ReturnAddress)
+
+struct Foo {
+ static void func(int x);
+};
+
+__declspec(noinline) void Foo::func(int x) {
+ volatile int a = x;
+ ++a;
+}
+
+TEST(Symbolize, SymbolizeWithDemangling) {
+ Foo::func(100);
+ const char* ret = TrySymbolize((void *)(&Foo::func));
+ EXPECT_STREQ("public: static void __cdecl Foo::func(int)", ret);
+}
+
+__declspec(noinline) void TestWithReturnAddress() {
+ void *return_address = _ReturnAddress();
+ const char *symbol = TrySymbolize(return_address);
+ CHECK(symbol != NULL);
+ CHECK_STREQ(symbol, "main");
+ cout << "Test case TestWithReturnAddress passed." << endl;
+}
+# endif // __ELF__
+#endif // HAVE_STACKTRACE
+
int main(int argc, char **argv) {
FLAGS_logtostderr = true;
InitGoogleLogging(argv[0]);
InitGoogleTest(&argc, argv);
-#ifdef HAVE_SYMBOLIZE
+#if defined(HAVE_SYMBOLIZE)
+# if defined(__ELF__)
// We don't want to get affected by the callback interface, that may be
// used to install some callback function at InitGoogle() time.
InstallSymbolizeCallback(NULL);
TestWithPCInsideNonInlineFunction();
TestWithReturnAddress();
return RUN_ALL_TESTS();
-#else
- return 0;
-#endif
-}
-
-#else
-int main() {
-#ifdef HAVE_SYMBOLIZE
+# elif defined(OS_WINDOWS)
+ TestWithReturnAddress();
+ return RUN_ALL_TESTS();
+# else // OS_WINDOWS
printf("PASS (no symbolize_unittest support)\n");
+ return 0;
+# endif // __ELF__
#else
printf("PASS (no symbolize support)\n");
-#endif
return 0;
+#endif // HAVE_SYMBOLIZE
}
-#endif // HAVE_STACKTRACE