Commit c78f594b authored by Sergei Golubchik's avatar Sergei Golubchik

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.
parent 7ba2916c
......@@ -46,6 +46,7 @@
#cmakedefine HAVE_INTTYPES_H 1
#cmakedefine HAVE_KQUEUE 1
#cmakedefine HAVE_LIMITS_H 1
#cmakedefine HAVE_LINK_H 1
#cmakedefine HAVE_LINUX_UNISTD_H 1
#cmakedefine HAVE_LOCALE_H 1
#cmakedefine HAVE_MALLOC_H 1
......
......@@ -188,6 +188,7 @@ CHECK_INCLUDE_FILES (grp.h HAVE_GRP_H)
CHECK_INCLUDE_FILES (ieeefp.h HAVE_IEEEFP_H)
CHECK_INCLUDE_FILES (inttypes.h HAVE_INTTYPES_H)
CHECK_INCLUDE_FILES (langinfo.h HAVE_LANGINFO_H)
CHECK_INCLUDE_FILES (link.h HAVE_LINK_H)
CHECK_INCLUDE_FILES (linux/unistd.h HAVE_LINUX_UNISTD_H)
CHECK_INCLUDE_FILES (linux/falloc.h HAVE_LINUX_FALLOC_H)
CHECK_INCLUDE_FILES (limits.h HAVE_LIMITS_H)
......
......@@ -71,7 +71,7 @@ ENDIF()
ADD_CONVENIENCE_LIBRARY(mysys ${MYSYS_SOURCES})
TARGET_LINK_LIBRARIES(mysys dbug strings mysys_ssl ${ZLIB_LIBRARY}
${LIBNSL} ${LIBM} ${LIBRT} ${LIBSOCKET} ${LIBEXECINFO})
${LIBNSL} ${LIBM} ${LIBRT} ${LIBDL} ${LIBSOCKET} ${LIBEXECINFO})
DTRACE_INSTRUMENT(mysys)
IF(HAVE_BFD_H)
......
......@@ -126,12 +126,20 @@ const char *my_addr_resolve_init()
*/
#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)
......
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