- bugfix to harden the code that looks up line #'s from a stack trace
This commit is contained in:
parent
b24e1142f4
commit
d06b01e4e4
|
@ -297,33 +297,41 @@ public:
|
||||||
#if defined(__GNUC__) && !defined(__FreeBSD__) && !defined(BSD)
|
#if defined(__GNUC__) && !defined(__FreeBSD__) && !defined(BSD)
|
||||||
static int getFileAndLine(void *address, char *file, size_t flen) {
|
static int getFileAndLine(void *address, char *file, size_t flen) {
|
||||||
int line=-1;
|
int line=-1;
|
||||||
static char buf[256]="";
|
const int maxbufSize = 1024;
|
||||||
|
static char buf[maxbufSize+1]="";
|
||||||
char *p=NULL;
|
char *p=NULL;
|
||||||
|
|
||||||
// prepare command to be executed
|
// prepare command to be executed
|
||||||
// our program need to be passed after the -e parameter
|
// our program need to be passed after the -e parameter
|
||||||
//sprintf (buf, "/usr/bin/addr2line -C -e ./a.out -f -i %lx", addr);
|
//sprintf (buf, "/usr/bin/addr2line -C -e ./a.out -f -i %lx", addr);
|
||||||
sprintf (buf, "addr2line -C -e %s -f -i %p",application_binary.c_str(),address);
|
sprintf(buf, "addr2line -C -e %s -f -i %p",application_binary.c_str(),address);
|
||||||
|
|
||||||
FILE* f = popen (buf, "r");
|
FILE* f = popen (buf, "r");
|
||||||
|
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
perror (buf);
|
perror (buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get function name
|
// get function name
|
||||||
char *ret = fgets (buf, 256, f);
|
char *ret = fgets (buf, maxbufSize, f);
|
||||||
// get file and line
|
if(ret == NULL) {
|
||||||
ret = fgets (buf, 256, f);
|
pclose(f);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (buf[0] != '?') {
|
// get file and line
|
||||||
int l;
|
ret = fgets (buf, maxbufSize, f);
|
||||||
|
if(ret == NULL) {
|
||||||
|
pclose(f);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strlen(buf) > 0 && buf[0] != '?') {
|
||||||
|
//int l;
|
||||||
char *p = buf;
|
char *p = buf;
|
||||||
|
|
||||||
// file name is until ':'
|
// file name is until ':'
|
||||||
while (*p != ':')
|
while(*p != 0 && *p != ':') {
|
||||||
{
|
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +341,7 @@ public:
|
||||||
sscanf (p,"%d", &line);
|
sscanf (p,"%d", &line);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
strcpy (file,"unkown");
|
strcpy (file,"unknown");
|
||||||
line = 0;
|
line = 0;
|
||||||
}
|
}
|
||||||
pclose(f);
|
pclose(f);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user