]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
show minimal backtrace if gdb is not installed
authorAlain Spineux <alain@baculasystems.com>
Mon, 5 Feb 2024 15:21:16 +0000 (16:21 +0100)
committerEric Bollengier <eric@baculasystems.com>
Wed, 4 Dec 2024 08:14:25 +0000 (09:14 +0100)
- here is a sample, lines in the stack trace are doubled
  with and witout demanglind/addr2line

Attempt to dump locks
threadid=0x7ffaa63fe640 max=2 current=-1
threadid=0x7ffaa53fc640 max=3 current=-1
threadid=0x7ffaa5bfd640 max=0 current=-1
threadid=0x7ffaa6bff640 max=0 current=-1
threadid=0x7ffaa7a2a080 max=0 current=-1
Attempt to dump current JCRs. njcrs=1
threadid=0x7ffaa53fc640 JobId=2 JobStatus=R jcr=0x7ffa98025728 name=RestoreFiles.2024-02-07_19.45.34_04
        use_count=1 killable=1
        JobType=R JobLevel=F
        sched_time=07-Feb-2024 19:45 start_time=07-Feb-2024 19:45
        end_time=01-Jan-1970 01:00 wait_time=01-Jan-1970 01:00
        db=(nil) db_batch=(nil) batch_started=0
        dcr=0x7ffa98000908 volumename=TestVolume001 dev=0x7ffa9800bbe8 newvol=0 reserved=1 locked=0
List plugins. Hook count=0
    /home/bac/workspace/bee/regress/bin/libbacsd-18.0.0.so(_Z12read_recordsP3DCRPFbS0_P10DEV_RECORDEPFbS0_E+0x11b) [0x7ffaa806b275]
    /home/bac/workspace/bee/regress/bin/libbacsd-18.0.0.so:read_records(DCR*, bool (*)(DCR*, DEV_RECORD*), bool (*)(DCR*))
    /home/bac/workspace/bee/regress/bin/libbacsd-18.0.0.so(_Z12do_read_dataP3JCR+0x43c) [0x7ffaa80695f4]
    /home/bac/workspace/bee/regress/bin/libbacsd-18.0.0.so:do_read_data(JCR*)
    /home/bac/workspace/bee/regress/bin/bacula-sd(+0x234a7) [0x5558cd5db4a7]
    /home/bac/workspace/bee/regress/build/src/stored/fd_cmds.c:431
    /home/bac/workspace/bee/regress/bin/bacula-sd(+0x2281a) [0x5558cd5da81a]
    /home/bac/workspace/bee/regress/build/src/stored/fd_cmds.c:234
    /home/bac/workspace/bee/regress/bin/bacula-sd(+0x22473) [0x5558cd5da473]
    /home/bac/workspace/bee/regress/build/src/stored/fd_cmds.c:176
    /home/bac/workspace/bee/regress/bin/bacula-sd(+0x25025) [0x5558cd5dd025]
    /home/bac/workspace/bee/regress/build/src/stored/job.c:252
    /home/bac/workspace/bee/regress/bin/bacula-sd(+0x17f53) [0x5558cd5cff53]
    /home/bac/workspace/bee/regress/build/src/stored/dircmd.c:255
    /home/bac/workspace/bee/regress/bin/libbac-18.0.0.so(workq_server+0x45f) [0x7ffaa7f9e0fe]
    /home/bac/workspace/bee/regress/bin/libbac-18.0.0.so:workq_server()
    /home/bac/workspace/bee/regress/bin/libbac-18.0.0.so(lmgr_thread_launcher+0xf7) [0x7ffaa7faa2b4]
    /home/bac/workspace/bee/regress/bin/libbac-18.0.0.so:lmgr_thread_launcher()
    /lib/x86_64-linux-gnu/libc.so.6(+0x94ac3) [0x7ffaa7894ac3]
    ./nptl/pthread_create.c:442
    /lib/x86_64-linux-gnu/libc.so.6(+0x126850) [0x7ffaa7926850]
    ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:83

Please install GDB.

bacula/src/lib/bsys.c
bacula/src/lib/protos.h
bacula/src/lib/signal.c

index c708164510103c5144596c8a463955c01fa3cde2..f7ec1397ffd9326208ddba63293240fc231b3edd 100644 (file)
@@ -1082,7 +1082,7 @@ char * unescape_filename_pathsep(const char* fname, char *buf, int len)
  */
 #include <cxxabi.h>
 #include <execinfo.h>
-void stack_trace()
+void stack_trace(FILE *file)
 {
    const size_t max_depth = 100;
    size_t stack_depth;
@@ -1108,9 +1108,12 @@ void stack_trace()
             final = j;
          }
       }
+      if (file) {
+         fprintf(file, "    %s\n", stack_strings[i]);
+      }
       ok = false;
       if (begin && end && end>(begin+1)) {
-         /* /home/bac/workspace2/bee/regress/bin/bacula-dir(+0x3c400) */
+         /* we have a function name ./prog(myfunc+0x21) [0x8048894] */
          char *function = (char *)actuallymalloc(sz);
          *begin++ = '\0';
          *end = '\0';
@@ -1126,7 +1129,11 @@ void stack_trace()
             bstrncpy(function, begin, sz);
             bstrncat(function, "()", sz);
          }
-         Pmsg2(000, "    %s:%s\n", stack_strings[i], function);
+         if (file) {
+            fprintf(file, "    %s:%s\n", stack_strings[i], function);
+         } else {
+            Pmsg2(000, "    %s:%s\n", stack_strings[i], function);
+         }
          actuallyfree(function);
          ok = true;
       } else if (begin) {
@@ -1142,7 +1149,11 @@ void stack_trace()
                char buf[1000];
                *buf = '\0';
                while (fgets(buf, sizeof(buf), bpipe->rfd)) {
-                  Pmsg1(000, "    %s", buf);
+                  if (file) {
+                     fprintf(file, "    %s", buf);
+                  } else {
+                     Pmsg1(000, "    %s", buf);
+                  }
                }
                if (close_bpipe(bpipe) == 0) {
                   ok = true;
@@ -1152,7 +1163,11 @@ void stack_trace()
       }
       if (!ok) {
          /* didn't find the mangled name, just print the whole line */
-         Pmsg1(000, "    %s\n", stack_strings[i]);
+         if (file) {
+            fprintf(file, "    %s\n", stack_strings[i]);
+         } else {
+            Pmsg1(000, "    %s\n", stack_strings[i]);
+         }
       }
    }
    actuallyfree(stack_strings); /* malloc()ed by backtrace_symbols */
@@ -1285,7 +1300,7 @@ bail_out:
 }
 
 #else /* HAVE_BACKTRACE && HAVE_GCC */
-void stack_trace() {}
+void stack_trace(FILE *file) { (void)file; }
 void gdb_stack_trace() {}
 void gdb_print_local(int level) {}
 #endif /* HAVE_BACKTRACE && HAVE_GCC */
index ad2689171ecc3b375032523b36f3e79a73c6199f..25ec42399600cafc49b410c807fa8fe3e274e277 100644 (file)
@@ -132,7 +132,7 @@ char     *escape_filename_pathsep(const char *fname, char *buf, int len);
 char     *unescape_filename_pathsep(const char *fname, char *buf, int len);
 int       Zdeflate(char *in, int in_len, char *out, int &out_len);
 int       Zinflate(char *in, int in_len, char *out, int &out_len);
-void      stack_trace();
+void      stack_trace(FILE *file = NULL);
 void      gdb_stack_trace();
 void      gdb_traceback();
 void      gdb_print_local(int level);
index af47350891d86b03c9a8fef79b9249799d1ce0c2..382b6877c19725c394624bef3cd2aa9e5e0a1bff 100644 (file)
@@ -232,11 +232,16 @@ extern "C" void signal_handler(int sig)
          Dmsg0(500, "Doing sleep\n");
          bmicrosleep(30, 0);
       }
-      if (WEXITSTATUS(chld_status) == 0) {
+      if (WIFEXITED(chld_status) && WEXITSTATUS(chld_status) == 0) {
          fprintf(stderr, "%s", _("It looks like the traceback worked...\n"));
       } else {
          fprintf(stderr, _("The btraceback call returned %d\n"),
                            WEXITSTATUS(chld_status));
+         FILE *fd;
+         fd = bfopen(buf, "a+");
+         stack_trace(fd);
+         fprintf(fd, _("\nPlease install GDB.\n"));
+         fclose(fd);
       }
 
 #ifndef DEVELOPER /* When DEVELOPER set, this is done above */