GDB看不到源文件(GDB cannot see source file)

2019-10-24 01:07发布

虽然尝试调试代码,我试图把break语句通过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

Answer 1:

  1. 不要与使用文件名~字。 GDB不其拓展到你家的位置。
  2. 确保你的代码得到与编译-g标志。
  3. 尽量只使用文件名,如果不是暧昧,所以:

     break NewMaterial.C:166 
  4. 如果它是不明确的,请尝试使用相关的“编制根”的路径中使用它(例如项目的根,只是因为它是传递到编译器)。

  5. 作为最后的手段-使用完整路径(但字面上:完整路径,没有~字符)。


文章来源: GDB cannot see source file
标签: ubuntu gdb