Use glibc backtrace functions instead of our own

Our own functions don't seem to work with the latest gcc,
so it seems to make sense to use the glibc versions which
should be equivalent and maintained.
This commit is contained in:
Bob Lantz committed 2016-01-11 16:31:56 -08:00
1 parent c84f33f09d
commit 9f587fc8e6
2 files changed
+19 -4

No files matched your search

+8 -3
View File
@@ -38,6 +38,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include "compiler.h" #include "compiler.h"
#include <execinfo.h>
#define THIS_MODULE VLM_backtrace #define THIS_MODULE VLM_backtrace
#include "vlog.h" #include "vlog.h"
@@ -106,8 +107,9 @@ in_stack(void *p)
} }
void void
backtrace_capture(struct backtrace *backtrace) backtrace_capture(struct backtrace *bt)
{ {
#ifdef OLD_BACKTRACE_CAPTURE
void **frame; void **frame;
size_t n; size_t n;
@@ -117,7 +119,10 @@ backtrace_capture(struct backtrace *backtrace)
&& n < BACKTRACE_MAX_FRAMES; && n < BACKTRACE_MAX_FRAMES;
frame = frame[0]) frame = frame[0])
{ {
backtrace->frames[n++] = (uintptr_t) frame[1]; bt->frames[n++] = (uintptr_t) frame[1];
} }
backtrace->n_frames = n; bt->n_frames = n;
#else
bt->n_frames = backtrace(bt->frames, BACKTRACE_MAX_FRAMES);
#endif
} }
+11 -1
View File
@@ -40,6 +40,7 @@
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include "util.h" #include "util.h"
#include <execinfo.h>
#include "vlog.h" #include "vlog.h"
#define THIS_MODULE VLM_fault #define THIS_MODULE VLM_fault
@@ -59,12 +60,13 @@ fault_handler(int sig_nr)
void void
log_backtrace(void) log_backtrace(void)
{ {
#define STACK_DEPTH_LIMIT 128
#ifdef OLD_LOG_BACKTRACE
/* During the loop: /* During the loop:
frame[0] points to the next frame. frame[0] points to the next frame.
frame[1] points to the return address. */ frame[1] points to the return address. */
void **frame; void **frame;
#define STACK_DEPTH_LIMIT 128
int stack_depth = 0; int stack_depth = 0;
for (frame = __builtin_frame_address(0); for (frame = __builtin_frame_address(0);
frame != NULL && frame[0] != NULL frame != NULL && frame[0] != NULL
@@ -79,9 +81,17 @@ log_backtrace(void)
(char *) frame[1] - (char *) addrinfo.dli_saddr); (char *) frame[1] - (char *) addrinfo.dli_saddr);
} }
} }
#else
/* Use glibc functions to print backtrace */
void *buffer[STACK_DEPTH_LIMIT];
backtrace(buffer, STACK_DEPTH_LIMIT);
backtrace_symbols_fd(buffer, STACK_DEPTH_LIMIT, fileno(stderr));
#endif
fflush(stderr); fflush(stderr);
} }
void void
register_fault_handlers(void) register_fault_handlers(void)
{ {