开发者

ADDR2LINE reports line number that is 1 number out?

I am using ADDR2L开发者_StackOverflowINE on Linux and have the following code that generated a segmentation fault purposely for testing

79 free(var1);
80
81 printf("Thread end...\n");
82 free(var1);
83 }

Line 82 above is the one that does the "double free" and the one that causes the dump.....however when I use ADDR2LINE on the command line it reports the line number that caused the error as 83 and not 82?

Am I missing something here? Does ADDR2Line mention the NEXT line?

Thanks for the helo

Lynton


ADDR2LINE does give the line number where it crashed and not the next. Try adding this code at near main() to get the backtrace of the last addresses and pass them to addr2line.. see what you get.

void sig_segv(int signo)
{
// Generate backtrace
void *addresses[40];
char **strings;
int c = backtrace(addresses, 40);
strings = backtrace_symbols(addresses,c);
printf("backtrace returned: %d\n", c); 
for (int i = 0; i < c; i++) {
    std::cout << strings[i] << std::endl;
}   
exit(1);
}

inside main()

signal(SIGSEGV, sig_segv);

The only correct reason/explanation for that is yes it does crash at the free function. But at the return value and hence that means the end of line 82 and start of line 83.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜