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
2016-01-11 16:31:56 -08:00
parent c84f33f09d
commit 9f587fc8e6
2 changed files with 19 additions and 4 deletions
+8 -3
View File
@@ -38,6 +38,7 @@
#include <stdbool.h>
#include <stdio.h>
#include "compiler.h"
#include <execinfo.h>
#define THIS_MODULE VLM_backtrace
#include "vlog.h"
@@ -106,8 +107,9 @@ in_stack(void *p)
}
void
backtrace_capture(struct backtrace *backtrace)
backtrace_capture(struct backtrace *bt)
{
#ifdef OLD_BACKTRACE_CAPTURE
void **frame;
size_t n;
@@ -117,7 +119,10 @@ backtrace_capture(struct backtrace *backtrace)
&& n < BACKTRACE_MAX_FRAMES;
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 <signal.h>
#include "util.h"
#include <execinfo.h>
#include "vlog.h"
#define THIS_MODULE VLM_fault
@@ -59,12 +60,13 @@ fault_handler(int sig_nr)
void
log_backtrace(void)
{
#define STACK_DEPTH_LIMIT 128
#ifdef OLD_LOG_BACKTRACE
/* During the loop:
frame[0] points to the next frame.
frame[1] points to the return address. */
void **frame;
#define STACK_DEPTH_LIMIT 128
int stack_depth = 0;
for (frame = __builtin_frame_address(0);
frame != NULL && frame[0] != NULL
@@ -79,9 +81,17 @@ log_backtrace(void)
(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);
}
void
register_fault_handlers(void)
{