简体   繁体   English

GDB 不显示 function 名称

[英]GDB doesn't show function names

I am debugging from an embedded device using gdbserver:我正在使用 gdbserver 从嵌入式设备进行调试:

./gdbserver HOST:5000 /home/test_app

In my PC, I execute gdb in this way:在我的 PC 中,我以这种方式执行 gdb:

arm-none-linux-gnueabi-gdb test_app

Once the application is executing, I receive the Segfault I want to debug, but it's impossible to know what line produced it:应用程序执行后,我收到了要调试的段错误,但无法知道是哪一行产生的:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 715]
0x31303030 in ?? ()
(gdb) bt
#0  0x31303030 in ?? ()
#1  0x0000dff8 in ?? ()
#2  0x0000dff8 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

(I must say I'm totally new to GDB) (我必须说我是 GDB 的新手)

Ok this usually happens if debug symbols are missing... just to make sure run following commands好的,如果缺少调试符号,通常会发生这种情况......只是为了确保运行以下命令

file <your_executable>

you will get info on your binary like format, arch etc.. last part of the info describes if the binary is stripped or not.您将获得有关您的二进制文件的信息,如格式、架构等。信息的最后一部分描述了二进制文件是否被剥离。 For debugging in GDB the binary should not have been stripped.为了在 GDB 中进行调试,不应剥离二进制文件。

nm --debug-sym <your_executable> | grep debug

If you have some valid prints as below it means debug symbols are present.如果您有一些如下有效的打印件,则表示存在调试符号。

00000000 N .debug_abbrev
00000000 N .debug_aranges
00000000 N .debug_frame
00000000 N .debug_info
00000000 N .debug_line
00000000 N .debug_loc
00000000 N .debug_pubnames
00000000 N .debug_str

Further when you invoke GDB you should have follwing line此外,当您调用 GDB 时,您应该有以下行

Reading symbols from <your_executable>...done.

At this point you should be able to list sources with list command.此时,您应该能够使用list命令列出源。

Make sure both gdb and gdbserver have same versioninig.确保 gdb 和 gdbserver 具有相同的版本。

arm-none-linux-gnueabi-gdb --version
./gdbserver --version

If all the above are true, and you still don't get backtrace, there is something bad going on with your stack.如果上述所有情况都是正确的,而您仍然没有得到回溯,那么您的堆栈就会出现问题。 Try running some static analysis, valgrind on your code / newly added code.尝试在您的代码/新添加的代码上运行一些静态分析,valgrind。

You need to build your application with debug symbols enabled.您需要在启用调试符号的情况下构建应用程序。 The switch for gcc is -g gcc 的开关是-g

For others, if nm --debug-sym <your_executable> | grep debug对于其他人,如果nm --debug-sym <your_executable> | grep debug nm --debug-sym <your_executable> | grep debug prints the debug symbols but you do not get them in gdb, this might be because you are opening a core in gdb using a executable that is different from the one that generated the core. nm --debug-sym <your_executable> | grep debug打印调试符号,但您没有在 gdb 中获取它们,这可能是因为您在 gdb 中打开一个内核时使用的可执行文件与生成内核的可执行文件不同。

You will need to include -g for every translation unit, for example, if you have a bunch of object files that are linked to build your final executable you will need to include -g for each compilation command.您需要为每个翻译单元包含-g ,例如,如果您有一堆链接到构建最终可执行文件的目标文件,则需要为每个编译命令包含-g

g++ -g file1.cpp -c -o file1.o
g++ -g file2.cpp -c -o file2.o
...
g++ -g file1.o file2.o -o main

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM