gdb无法看到源文件

时间:2015-07-21 15:18:51

标签: ubuntu gdb

在尝试调试代码时,我试图通过gdb在代码中添加break语句,但由于某些原因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

吉安

1 个答案:

答案 0 :(得分:1)

  1. 请勿使用~个字符的文件名。 Gdb不会将它们扩展到您的HOME位置。
  2. 确保您的代码使用-g标记进行编译。
  3. 尝试仅使用文件名,如果它不含糊,那么:
    break NewMaterial.C:166
  4. 如果不明确,请尝试将其与“编译根”相关的路径一起使用(例如,项目根目录,就像它传递给编译器一样)。
  5. 作为最后的手段 - 使用完整路径(但字面意思是:完整路径,没有~标志)。