Does ADDR2LINE report the line number whose number is 1 number?

I am using ADDR2LINE on Linux and have the following code that generated a segmentation error specifically for testing

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

Line 82 above is the one that does "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, not 82?

Am I missing something? Does ADDR2Line indicate a NEXT string?

Thanks for helo

Linton

+4
source share
1 answer

ADDR2LINE gives the line number where it crashed, not the next one. Try adding this code to the nearest main () to get backtrack 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 right reason / explanation for this is yes, it leads to a crash in a free function. But with the return value and, therefore, this means the end of line 82 and the beginning of line 83.

+1
source

All Articles