Commit 4ef7737d authored by Dave Gosselin's avatar Dave Gosselin Committed by Dave Gosselin

MDEV-33616 Show correct function names in safemalloc backtrace

Fix safemalloc's backtrace functionality to work on macOS.
parent 450040e0
...@@ -224,6 +224,11 @@ static void print_stack(void **frame) ...@@ -224,6 +224,11 @@ static void print_stack(void **frame)
{ {
const char *err; const char *err;
int i; int i;
#ifdef __APPLE__
char** strptr= 0;
#else
my_addr_loc loc;
#endif
if ((err= my_addr_resolve_init())) if ((err= my_addr_resolve_init()))
{ {
...@@ -231,18 +236,29 @@ static void print_stack(void **frame) ...@@ -231,18 +236,29 @@ static void print_stack(void **frame)
return; return;
} }
#ifdef __APPLE__
for (i= 0; i < SF_REMEMBER_FRAMES && frame[i]; i++);
strptr= backtrace_symbols(frame, i);
#endif
for (i=0; i < SF_REMEMBER_FRAMES && frame[i]; i++) for (i=0; i < SF_REMEMBER_FRAMES && frame[i]; i++)
{ {
my_addr_loc loc;
if (i) if (i)
fprintf(stderr, ", "); fprintf(stderr, ", ");
#ifdef __APPLE__
fprintf(stderr, "%s", strptr[i]);
#else
if (my_addr_resolve(frame[i], &loc)) if (my_addr_resolve(frame[i], &loc))
fprintf(stderr, "%p", frame[i]); fprintf(stderr, "%p", frame[i]);
else else
fprintf(stderr, "%s:%u", loc.file, loc.line); fprintf(stderr, "%s:%u", loc.file, loc.line);
#endif
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
#ifdef __APPLE__
free(strptr);
#endif
} }
#else #else
#define print_stack(X) fprintf(stderr, "???\n") #define print_stack(X) fprintf(stderr, "???\n")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment