|
@@ -115,13 +115,44 @@ void sdprintf (const char *format, ...)
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static void write_debug()
|
|
|
|
|
|
|
+static void write_debug(bool gdb_backtrace = 1)
|
|
|
{
|
|
{
|
|
|
putlog(LOG_MISC, "*", "** Paste to bryan:");
|
|
putlog(LOG_MISC, "*", "** Paste to bryan:");
|
|
|
const size_t cur_buf = (current_get_buf == 0) ? GET_BUFS - 1 : current_get_buf - 1;
|
|
const size_t cur_buf = (current_get_buf == 0) ? GET_BUFS - 1 : current_get_buf - 1;
|
|
|
for (size_t i = 0; i < GET_BUFS; i++)
|
|
for (size_t i = 0; i < GET_BUFS; i++)
|
|
|
putlog(LOG_MISC, "*", "%c %02zu: %s", i == cur_buf ? '*' : '_', i, get_buf[i]);
|
|
putlog(LOG_MISC, "*", "%c %02zu: %s", i == cur_buf ? '*' : '_', i, get_buf[i]);
|
|
|
putlog(LOG_MISC, "*", "** end");
|
|
putlog(LOG_MISC, "*", "** end");
|
|
|
|
|
+
|
|
|
|
|
+#ifdef DEBUG
|
|
|
|
|
+ if (gdb_backtrace) {
|
|
|
|
|
+ /* Write GDB backtrace */
|
|
|
|
|
+ char gdb[1024] = "", btfile[256] = "", std_in[101] = "", *out = NULL;
|
|
|
|
|
+ unsigned int core = 0;
|
|
|
|
|
+
|
|
|
|
|
+ simple_snprintf(btfile, sizeof(btfile), ".gdb-backtrace-%d", getpid());
|
|
|
|
|
+
|
|
|
|
|
+ FILE *f = fopen(btfile, "w");
|
|
|
|
|
+
|
|
|
|
|
+ if (f) {
|
|
|
|
|
+ strlcpy(std_in, "bt 100\nbt 100 full\ndetach\nquit\n", sizeof(stdin));
|
|
|
|
|
+ //simple_snprintf(stdin, sizeof(stdin), "detach\n");
|
|
|
|
|
+ //simple_snprintf(stdin, sizeof(stdin), "q\n");
|
|
|
|
|
+
|
|
|
|
|
+ simple_snprintf(gdb, sizeof(gdb), "gdb %s %d", binname, getpid());
|
|
|
|
|
+ shell_exec(gdb, std_in, &out, NULL);
|
|
|
|
|
+ fprintf(f, "%s\n", out);
|
|
|
|
|
+ fclose(f);
|
|
|
|
|
+ free(out);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //enabling core dumps
|
|
|
|
|
+ struct rlimit limit;
|
|
|
|
|
+ if (!getrlimit(RLIMIT_CORE, &limit)) {
|
|
|
|
|
+ limit.rlim_cur = limit.rlim_max;
|
|
|
|
|
+ if(!setrlimit(RLIMIT_CORE, &limit)) core = limit.rlim_cur;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#ifndef DEBUG
|
|
#ifndef DEBUG
|
|
@@ -152,32 +183,6 @@ static void got_segv(int z)
|
|
|
write_debug();
|
|
write_debug();
|
|
|
fatal("SEGMENT VIOLATION -- CRASHING!", 1);
|
|
fatal("SEGMENT VIOLATION -- CRASHING!", 1);
|
|
|
#ifdef DEBUG
|
|
#ifdef DEBUG
|
|
|
- char gdb[1024] = "", btfile[256] = "", std_in[101] = "", *out = NULL;
|
|
|
|
|
- unsigned int core = 0;
|
|
|
|
|
-
|
|
|
|
|
- simple_snprintf(btfile, sizeof(btfile), ".gdb-backtrace-%d", getpid());
|
|
|
|
|
-
|
|
|
|
|
- FILE *f = fopen(btfile, "w");
|
|
|
|
|
-
|
|
|
|
|
- if (f) {
|
|
|
|
|
- strlcpy(std_in, "bt 100\nbt 100 full\ndetach\nquit\n", sizeof(stdin));
|
|
|
|
|
-// simple_snprintf(stdin, sizeof(stdin), "detach\n");
|
|
|
|
|
-// simple_snprintf(stdin, sizeof(stdin), "q\n");
|
|
|
|
|
-
|
|
|
|
|
- simple_snprintf(gdb, sizeof(gdb), "gdb %s %d", binname, getpid());
|
|
|
|
|
- shell_exec(gdb, std_in, &out, NULL);
|
|
|
|
|
- fprintf(f, "%s\n", out);
|
|
|
|
|
- fclose(f);
|
|
|
|
|
- free(out);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //enabling core dumps
|
|
|
|
|
- struct rlimit limit;
|
|
|
|
|
- if (!getrlimit(RLIMIT_CORE, &limit)) {
|
|
|
|
|
- limit.rlim_cur = limit.rlim_max;
|
|
|
|
|
- if(!setrlimit(RLIMIT_CORE, &limit)) core = limit.rlim_cur;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
raise(SIGSEGV);
|
|
raise(SIGSEGV);
|
|
|
#else
|
|
#else
|
|
|
exit(1);
|
|
exit(1);
|
|
@@ -238,7 +243,7 @@ static void got_alarm(int z)
|
|
|
*/
|
|
*/
|
|
|
static void got_ill(int z)
|
|
static void got_ill(int z)
|
|
|
{
|
|
{
|
|
|
- write_debug();
|
|
|
|
|
|
|
+ write_debug(0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
static void
|