gpt4 book ai didi

gcc - Recomile exe with debugging symbols,用于不带调试符号的exe生成的core dump

转载 作者:行者123 更新时间:2023-12-05 04:17:00 28 4
gpt4 key购买 nike

我有一个缺少调试信息的核心转储。转储是由一个不太可重现的错误引起的。

既然我确切地知道是哪个版本的源代码以及原始构建命令和优化级别,是否可以为这个可执行文件生成调试信息?

最佳答案

是的,这是可能的。这是一个相当详细的示例。

产生崩溃的程序(crash.c):

#include <stdio.h>                                                                             
#include <string.h>

int func(char *str){
char buff[32];
strcpy(buff,str);
return 0;
}

int main(int argc, char *argv[]){
func(argv[1]);
return 0;
}

编译没有调试符号的版本:

$ gcc crash.c -o crash

使用调试符号编译一个版本:

$ gcc -g crash.c -o crash_debug

使用二进制不带调试符号生成核心文件:

$ ./crash AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Segmentation fault (core dumped)

使用gdb 和二进制不带 调试符号查看内核:

$ gdb -q ./crash  core                                                                         

warning: ~/.gdbinit.local: No such file or directory
Reading symbols from ./crash...(no debugging symbols found)...done.

warning: exec file is newer than core file.
[New LWP 7768]
Core was generated by `./crash AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x000000000040052b in func ()

如我们所见,gdb 找不到任何调试符号。现在让我们尝试使用包含调试符号和 core 文件的二进制文件启动 gdb:

$ gdb -q ./crash_debug  core                                                                   

warning: ~/.gdbinit.local: No such file or directory
Reading symbols from ./crash_debug...done.

warning: core file may not match specified executable file.
[New LWP 7768]
Core was generated by `./crash AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x000000000040052b in func (str=0x7fff4bb66f73 'A' <repeats 52 times>) at crash.c:8
8 }

这行得通!

另一种方式,如@dbrank0建议,将使用 symbol-file 命令从不同的二进制文件加载符号:

$ gdb -q -c core                                                                               

warning: ~/.gdbinit.local: No such file or directory
[New LWP 7768]
Core was generated by `./crash AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x000000000040052b in ?? ()
gdb$ symbol-file crash_debug
Reading symbols from crash_debug...done.
gdb$ bt
#0 0x000000000040052b in func (str=0x7fff4bb66f73 'A' <repeats 52 times>) at crash.c:8
#1 0x4141414141414141 in ?? ()
#2 0x00007f0041414141 in ?? ()
#3 0x0000000200000000 in ?? ()
#4 0x0000000000000000 in ?? ()
gdb$

希望这对您有所帮助!

关于gcc - Recomile exe with debugging symbols,用于不带调试符号的exe生成的core dump,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25112636/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com