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:
+8
-3
@@ -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
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user