Skip to content
Snippets Groups Projects
Commit 315fe00d authored by Julien Signoles's avatar Julien Signoles
Browse files

Merge branch 'kostyantyn/bugfix/backtrace' into 'master'

Fix for backtrace

See merge request !127
parents 75d22798 72694e0d
No related branches found
No related tags found
No related merge requests found
...@@ -30,16 +30,47 @@ ...@@ -30,16 +30,47 @@
#include "e_acsl_shexec.h" #include "e_acsl_shexec.h"
# ifdef __GLIBC__ extern void *__libc_stack_end;
# include <execinfo.h>
# endif struct frame_layout {
void *next;
void *return_address;
};
/* The following implementation of malloc-free backtrace [native_backtrace]
is mostly taken from Glibc-2.22 (see file debug/backtrace.c) */
static int native_backtrace (void **array, int size) {
struct frame_layout *current;
void *top_frame,
*top_stack;
int cnt = 0;
top_frame = __builtin_frame_address(0);
/* Some notion of current stack. Need not be exactly the top of the stack,
just something somewhere in the current frame. */
top_stack = ({ char __csf; &__csf; });
/* We skip the call to this function, it makes no sense to record it. */
current = ((struct frame_layout *) top_frame);
while (cnt < size) {
/* Assume that the stack grows downwards */
if ((void *) current < top_stack || !((void *) current < __libc_stack_end))
/* This means the address is out of range. Note that for the
toplevel we see a frame pointer with value NULL which clearly is
out of range. */
break;
array[cnt++] = current->return_address;
current = ((struct frame_layout *) (current->next));
}
return cnt;
}
static void trace() { static void trace() {
# ifdef __GLIBC__ # ifdef __GLIBC__
# ifdef __linux__ # ifdef __linux__
int size = 24; int size = 24;
void **bb = native_malloc(sizeof(void*)*size); void **bb = native_malloc(sizeof(void*)*size);
backtrace(bb,size); native_backtrace(bb, size);
char executable [PATH_MAX]; char executable [PATH_MAX];
sprintf(executable, "/proc/%d/exe", getpid()); sprintf(executable, "/proc/%d/exe", getpid());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment