*/
#include <cxxabi.h>
#include <execinfo.h>
-void stack_trace()
+void stack_trace(FILE *file)
{
const size_t max_depth = 100;
size_t stack_depth;
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';
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) {
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;
}
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 */
}
#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 */
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);
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 */