File tree Expand file tree Collapse file tree
examples/crash_diagnostic/bad_plugins Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// Bad plugin #1: crashes during construction (inside allocator).
22// Simulates a library that segfaults when the app tries to instantiate it.
33
4+ // Bad plugin #1: crashes during construction (inside allocator).
5+ // Simulates a library that segfaults when the app tries to instantiate it.
6+
47#include < stdexcept>
58
9+ #if defined(_WIN32)
10+ #define BAD_EXPORT __declspec (dllexport)
11+ #else
12+ #define BAD_EXPORT __attribute__ ((visibility(" default" )))
13+ #endif
14+
615class CrashInConstructor {
716 public:
817 CrashInConstructor () {
@@ -11,9 +20,6 @@ class CrashInConstructor {
1120};
1221
1322extern " C" {
14- __attribute__ ((visibility(" default" )))
15- CrashInConstructor* allocator() { return new CrashInConstructor (); }
16-
17- __attribute__ ((visibility(" default" )))
18- void deallocator(CrashInConstructor* ptr) { delete ptr; }
23+ BAD_EXPORT CrashInConstructor* allocator () { return new CrashInConstructor (); }
24+ BAD_EXPORT void deallocator (CrashInConstructor* ptr) { delete ptr; }
1925}
Original file line number Diff line number Diff line change 22// A global/static constructor runs during library loading and fails.
33// This is the hardest to debug because it happens inside dlopen() itself.
44
5+ // Bad plugin #3: crashes at dlopen time, before any symbol is resolved.
6+ // A global/static constructor runs during library loading and fails.
7+
58#include < stdexcept>
69
10+ #if defined(_WIN32)
11+ #define BAD_EXPORT __declspec (dllexport)
12+ #else
13+ #define BAD_EXPORT __attribute__ ((visibility(" default" )))
14+ #endif
15+
716static int bad_init () {
817 throw std::runtime_error (" static init failed: cannot connect to server" );
918 return 0 ;
@@ -18,9 +27,6 @@ class CrashOnLoad {
1827};
1928
2029extern " C" {
21- __attribute__ ((visibility(" default" )))
22- CrashOnLoad* allocator() { return new CrashOnLoad (); }
23-
24- __attribute__ ((visibility(" default" )))
25- void deallocator(CrashOnLoad* ptr) { delete ptr; }
30+ BAD_EXPORT CrashOnLoad* allocator () { return new CrashOnLoad (); }
31+ BAD_EXPORT void deallocator (CrashOnLoad* ptr) { delete ptr; }
2632}
You can’t perform that action at this time.
0 commit comments