Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
0 segfault 0x0000000102b1a8c8 segfault + 2248
1 segfault 0x0000000102b1a9d0 segfault + 2512
2 libsystem_c.dylib 0x00007fff99b5dcfa _sigtramp + 26
3 ??? 0x0000040000000000 0x0 + 4398046511104
4 segfault 0x0000000102b1ac67 _ZN7Crasher11doSomethingEv + 71
5 segfault 0x0000000102b1ac1a _ZN7Crasher18doSomethingPrivateEv + 208
6 segfault 0x0000000102b1ac67 _ZN7Crasher11doSomethingEv + 71
7 segfault 0x0000000102b1a880 segfault + 2176
8 segfault 0x0000000102b1aac4 segfault + 2756
9 segfault 0x0000000102b1ab33 segfault + 2867
10 segfault 0x0000000102b1a854 segfault + 2132
$ strip segfault
$ ./segfault
That's a function!
That's a private function! myPrivateInteger == 1752392050
myPrivateDoubles[1] == 60993401604041306737928347282702617388988841504491171140800281285302442927306116721201046092641903128620672849302937378251940003901836219046866981678295779355600933772275817062376375849852470059862498765690530537583237171035779906888043337758015488.000000
myPrivateString == 0x63202c6f6c6c6548
That's a function!
0 segfault 0x0000000102b1a8c8 segfault + 2248
1 segfault 0x0000000102b1a9d0 segfault + 2512
2 libsystem_c.dylib 0x00007fff99b5dcfa _sigtramp + 26
3 ??? 0x0000040000000000 0x0 + 4398046511104
4 segfault 0x0000000102b1ac67 _ZN7Crasher11doSomethingEv + 71
5 segfault 0x0000000102b1ac1a _ZN7Crasher18doSomethingPrivateEv + 208
6 segfault 0x0000000102b1ac67 _ZN7Crasher11doSomethingEv + 71
7 segfault 0x0000000102b1a880 segfault + 2176
8 segfault 0x0000000102b1aac4 segfault + 2756
9 segfault 0x0000000102b1ab33 segfault + 2867
10 segfault 0x0000000102b1a854 segfault + 2132
pragma GCC visibility push(hidden)diff --git a/main.cpp b/main.cpp
index 9f89031..1e8ba47 100644
--- a/main.cpp
+++ b/main.cpp
@@ -3,6 +3,8 @@
#include <signal.h>
#include <execinfo.h>
+#pragma GCC visibility push(hidden)
+
#define P_DOUBLE_COUNT 10000
// if set to 1, cat is used instead of curl'ing file to server
--
0 segfault 0x0000000100000a7c 0x0 + 4294969980
1 segfault 0x0000000100000b19 0x0 + 4294970137
2 libSystem.B.dylib 0x00007fff831fd1ba _sigtramp + 26
3 ??? 0x3838383630393937 0x0 + 4051049670208207159
4 segfault 0x0000000100000c9b 0x0 + 4294970523
5 segfault 0x0000000100000c61 0x0 + 4294970465
6 segfault 0x0000000100000c9b 0x0 + 4294970523
7 segfault 0x0000000100000a59 0x0 + 4294969945
8 segfault 0x0000000100000b99 0x0 + 4294970265
9 segfault 0x0000000100000bd5 0x0 + 4294970325
10 segfault 0x0000000100000a34 0x0 + 4294969908
11 ??? 0x0000000000000001 0x0 + 1
LIBNAME_123 {
global:
# C++ functions
extern "C++" {
Foo::Bar::*;
};
# C functions
cfoo; cbar;
local: *;
extern "C++" {
Foo::Bar::private_stuff*;
};
};
static int inSigSegvHandler = 0;
static void sigsegvHandler(int sig) {
++inSigSegvHandler;
if(inSigSegvHandler > 1) { // защита от двойного попадания, сигнал ставлю sigaction + SA_RESTART
fprintf(stderr, "*** SIG %d TWICE ***\n", sig);
_exit(2);
}
invokeDebuggerToSelf();
_exit(1);
}
void invokeDebuggerToSelf() {
int pid = getpid();
char link[MAX_PATH];
char buf[MAX_PATH];
char bufexe[MAX_PATH];
char pidbuf[16];
char cmdline[MAX_PATH];
memset(bufexe, 0, sizeof(bufexe));
memset(link, 0, sizeof(link));
sprintf(link, "/proc/%d/exe", pid);
if(readlink(link, bufexe, MAX_PATH) <=0)
strcpy(bufexe, "где-там-оно-лежит"); // вдруг звезды сойдутся неудачно
sprintf(pidbuf, "%d", pid);
int wpid;
if((wpid=fork()) == 0) {
execlp("gdb", "gdb", "-batch", "-q", "-x", gdbFile, bufexe, pidbuf, NULL);
}
else if(wpid > 0) {
int status;
waitpid(wpid, &status, WUNTRACED);
_exit(0);
}
}
Краш-репорты в *nix: backtrace, SEGFAULT (и reinterpret_cast)