mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
MDEV-6479 stack traces in 10.1
Take into account that PIE binaries are loaded at some offset, so addresses cannot be directly resolved with addr2line. Find this offset and subtract it before resolving an address.
This commit is contained in:
@@ -126,12 +126,20 @@ err:
|
||||
*/
|
||||
#elif defined(MY_ADDR_RESOLVE_FORK)
|
||||
/*
|
||||
yet another - just execute addr2line or eu-addr2line, whatever available,
|
||||
pipe the addresses to it, and parse the output
|
||||
yet another - just execute addr2line pipe the addresses to it, and parse the
|
||||
output
|
||||
*/
|
||||
|
||||
#include <m_string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#if defined(HAVE_LINK_H) && defined(HAVE_DLOPEN)
|
||||
#include <link.h>
|
||||
static ElfW(Addr) offset= 0;
|
||||
#else
|
||||
#define offset 0
|
||||
#endif
|
||||
|
||||
static int in[2], out[2];
|
||||
static int initialized= 0;
|
||||
static char output[1024];
|
||||
@@ -140,7 +148,7 @@ int my_addr_resolve(void *ptr, my_addr_loc *loc)
|
||||
char input[32], *s;
|
||||
size_t len;
|
||||
|
||||
len= my_snprintf(input, sizeof(input), "%p\n", ptr);
|
||||
len= my_snprintf(input, sizeof(input), "%p\n", ptr - offset);
|
||||
if (write(in[1], input, len) <= 0)
|
||||
return 1;
|
||||
if (read(out[0], output, sizeof(output)) <= 0)
|
||||
@@ -172,6 +180,12 @@ const char *my_addr_resolve_init()
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
#if defined(HAVE_LINK_H) && defined(HAVE_DLOPEN)
|
||||
struct link_map *lm = (struct link_map*) dlopen(0, RTLD_NOW);
|
||||
if (lm)
|
||||
offset= lm->l_addr;
|
||||
#endif
|
||||
|
||||
if (pipe(in) < 0)
|
||||
return "pipe(in)";
|
||||
if (pipe(out) < 0)
|
||||
|
Reference in New Issue
Block a user