ADDR2LINE报告行号是1号吗?

时间:2023-01-15 01:29:36

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

我在Linux上使用ADDR2LINE,并有下面的代码专门为测试生成了一个分段错误。

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?

上面的第82行是做“双重免费”的那一行,而这一行则导致了你的过失。但是,当我在命令行上使用ADDR2LINE时,它会报告导致错误为83而不是82的行号?

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

我是不是漏掉了什么?ADDR2Line提到下一行了吗?

Thanks for the helo

谢谢你的直升机

Lynton

暗讽

1 个解决方案

#1


1  

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.

ADDR2LINE确实给出了崩溃处的行号,而不是下一个。尝试在near main()上添加这段代码,以获取最后地址的回溯,并将它们传递给addr2line。看到你得到的。

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()

在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.

唯一正确的原因/解释是它确实会在*函数上崩溃。但是在返回值,这意味着第82行结束,第83行开始。

#1


1  

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.

ADDR2LINE确实给出了崩溃处的行号,而不是下一个。尝试在near main()上添加这段代码,以获取最后地址的回溯,并将它们传递给addr2line。看到你得到的。

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()

在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.

唯一正确的原因/解释是它确实会在*函数上崩溃。但是在返回值,这意味着第82行结束,第83行开始。