ubuntu - GDB 看不到源文件

标签 ubuntu gdb

在尝试调试代码时,我尝试通过 GDB 在代码中放置中断语句,但由于某些原因,GDB 看不到源文件,尽管它在那里。我是第一次使用 GDB,所以我不知道这是否是正确的方法。以下是终端消息:

~$ cd ~/projects/bison/sandbox/2D-RZ_rodlet_10pellets
~/projects/bison/sandbox/2D-RZ_rodlet_10pellets$ gdb ../../bison-dbg
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ../../bison-dbg...done.
(gdb) break ~/projects/bison/src/materials/NewMaterial.C:166
No source file named ~/projects/bison/src/materials/NewMaterial.C.
Make breakpoint pending on future shared library load? (y or [n])

我可以将源文件定位为:
~/projects/bison/src/materials$ ls | grep New
NewMaterial.C
NewMaterial.C~
NewMaterial.x86_64-unknown-linux-gnu.dbg.lo
NewMaterial.x86_64-unknown-linux-gnu.dbg.lo.d
NewMaterial.x86_64-unknown-linux-gnu.opt.lo
NewMaterial.x86_64-unknown-linux-gnu.opt.lo.d

最佳答案

  • 不要使用带有 ~ 的文件名特点。 GDB 不会将它们扩展到您的 HOME 位置。
  • 确保使用 -g 编译您的代码旗帜。
  • 尝试仅使用文件名,如果它不是模棱两可的,那么:
    break NewMaterial.C:166
    
  • 如果不明确,请尝试将其与“编译根”相关的路径(例如项目根,就像它传递给编译器一样)一起使用。
  • 作为最后的手段 - 使用完整路径(但字面意思是:完整路径,没有 ~ 字符)。
  • 关于ubuntu - GDB 看不到源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31543177/

    相关文章:

    android - IDEA和DDMS同时运行无法连接模拟器

    ubuntu - 如何为共享库调整 debian 包中的符号文件

    c++ - gdb 奇怪的行为( [next] 在 block 代码上跳回几行)

    Linux 内核在用户空间进程中支持 live-core 选项

    c - gdb 在调试程序行为中改变了什么 w.r.t. `accept()` 和 `close()`

    c - 了解二进制炸弹第二阶段的汇编代码

    ubuntu - 安装时选择puppet客户端版本-Ubuntu

    ubuntu - ettercap 过滤不起作用

    python - 如何使python程序 ".py"可执行?

    c++ - CentOS 上的 GDB 忽略 gdbinit 文件