mirror of
https://github.com/MariaDB/server.git
synced 2025-01-29 18:20:07 +01:00
fix stack traces when linking with libbfd
also, return different values for different errors in my_addr_resolve()
This commit is contained in:
parent
855f0b9b16
commit
e336fc07bd
1 changed files with 18 additions and 12 deletions
|
@ -34,6 +34,13 @@ static const char *strip_path(const char *s)
|
||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HAVE_LINK_H) && defined(HAVE_DLOPEN)
|
||||||
|
#include <link.h>
|
||||||
|
static ptrdiff_t offset= 0;
|
||||||
|
#else
|
||||||
|
#define offset 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The following is very much single-threaded code and it's only supposed
|
The following is very much single-threaded code and it's only supposed
|
||||||
to be used on shutdown or for a crash report
|
to be used on shutdown or for a crash report
|
||||||
|
@ -60,7 +67,7 @@ static asymbol **symtable= 0;
|
||||||
*/
|
*/
|
||||||
int my_addr_resolve(void *ptr, my_addr_loc *loc)
|
int my_addr_resolve(void *ptr, my_addr_loc *loc)
|
||||||
{
|
{
|
||||||
bfd_vma addr= (intptr)ptr;
|
bfd_vma addr= (intptr)ptr - offset;
|
||||||
asection *sec;
|
asection *sec;
|
||||||
|
|
||||||
for (sec= bfdh->sections; sec; sec= sec->next)
|
for (sec= bfdh->sections; sec; sec= sec->next)
|
||||||
|
@ -103,6 +110,12 @@ const char *my_addr_resolve_init()
|
||||||
uint unused;
|
uint unused;
|
||||||
char **matching;
|
char **matching;
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
bfdh= bfd_openr(my_progname, NULL);
|
bfdh= bfd_openr(my_progname, NULL);
|
||||||
if (!bfdh)
|
if (!bfdh)
|
||||||
goto err;
|
goto err;
|
||||||
|
@ -133,13 +146,6 @@ err:
|
||||||
#include <m_string.h>
|
#include <m_string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#if defined(HAVE_LINK_H) && defined(HAVE_DLOPEN)
|
|
||||||
#include <link.h>
|
|
||||||
static ptrdiff_t offset= 0;
|
|
||||||
#else
|
|
||||||
#define offset 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int in[2], out[2];
|
static int in[2], out[2];
|
||||||
static int initialized= 0;
|
static int initialized= 0;
|
||||||
static char output[1024];
|
static char output[1024];
|
||||||
|
@ -174,7 +180,7 @@ int my_addr_resolve(void *ptr, my_addr_loc *loc)
|
||||||
extra_bytes_read= read(out[0], output + total_bytes_read,
|
extra_bytes_read= read(out[0], output + total_bytes_read,
|
||||||
sizeof(output) - total_bytes_read);
|
sizeof(output) - total_bytes_read);
|
||||||
if (extra_bytes_read < 0)
|
if (extra_bytes_read < 0)
|
||||||
return 1;
|
return 2;
|
||||||
/* Timeout or max bytes read. */
|
/* Timeout or max bytes read. */
|
||||||
if (extra_bytes_read == 0)
|
if (extra_bytes_read == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -184,7 +190,7 @@ int my_addr_resolve(void *ptr, my_addr_loc *loc)
|
||||||
|
|
||||||
/* Failed starting addr2line. */
|
/* Failed starting addr2line. */
|
||||||
if (total_bytes_read == 0)
|
if (total_bytes_read == 0)
|
||||||
return 1;
|
return 3;
|
||||||
|
|
||||||
/* Go through the addr2line response and get the required data.
|
/* Go through the addr2line response and get the required data.
|
||||||
The response is structured in 2 lines. The first line contains the function
|
The response is structured in 2 lines. The first line contains the function
|
||||||
|
@ -205,14 +211,14 @@ int my_addr_resolve(void *ptr, my_addr_loc *loc)
|
||||||
}
|
}
|
||||||
/* Response is malformed. */
|
/* Response is malformed. */
|
||||||
if (filename_start == -1 || line_number_start == -1)
|
if (filename_start == -1 || line_number_start == -1)
|
||||||
return 1;
|
return 4;
|
||||||
|
|
||||||
loc->func= output;
|
loc->func= output;
|
||||||
loc->file= output + filename_start;
|
loc->file= output + filename_start;
|
||||||
|
|
||||||
/* Addr2line was unable to extract any meaningful information. */
|
/* Addr2line was unable to extract any meaningful information. */
|
||||||
if (strcmp(loc->file, "??") == 0)
|
if (strcmp(loc->file, "??") == 0)
|
||||||
return 1;
|
return 5;
|
||||||
|
|
||||||
loc->file= strip_path(loc->file);
|
loc->file= strip_path(loc->file);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue