无法在gdb中创建断点

时间:2013-01-23 13:50:47

标签: c++ gdb opensuse

我使用openSUSE作为我的操作系统和gdb 7.5。我想用gdb调试我的程序,带断点。但是当我创建一个断点,然后运行我的程序时,gdb通知我如下:

Error in re-setting breakpoint 1: malformed linespec error: unexpected string, ".cpp"

在我的所有课程中都是如此。此外,当运行到断点时,程序根本不会停止。谁能告诉我什么是错的?

我下载了最新的gdb并安装它,之前的消息消失了,但是当运行gdb时它告诉我:

warning: Could not load shared library symbols for linux-gate.so.1. Do you need "set solib-search-path" or "set sysroot"?

如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

  

我使用“b + linenumber”

这定义了相对于当前行的断点,请参阅als Specifying a Location。使用下面评论中的代码,以下内容可行:

$ gdb ./main
(gdb) b +5
Breakpoint 1 at 0x40139c: file main.cpp, line 6.
(gdb) run
[New Thread 1528.0x1930]

Breakpoint 1, main () at main.cpp:5
5           while(scanf("%d%d",&a,&b)!=EOF)

除非有充分理由指定相对行号,否则我建议您使用绝对行号或函数名称:

(gdb) b main
Breakpoint 1 at 0x401395: file main.cpp, line 3.
(gdb) b main.cpp:6
Breakpoint 1 at 0x40139c: file main.cpp, line 6.

答案 1 :(得分:0)

gdb 7.5中存在一个已知错误,当​​源文件名以十进制数字开头时,调试器无法解析linespec。有关详细信息,请参阅this message

尝试重命名文件并从分发存储库更新gdb。如果错误仍然存​​在,请向您的分发维护者提交错误。

查看提交给gdb bugzilla的bug report的示例会话。

(gdb) b 3
Breakpoint 1 at 0x4004c3: file 2.c, line 3.
(gdb) r
Starting program: /home/teawater/tmp/a.out 
Error in re-setting breakpoint 1: malformed linespec error: unexpected string, ".c"
Error in re-setting breakpoint 1: malformed linespec error: unexpected string, ".c"
Error in re-setting breakpoint 1: malformed linespec error: unexpected string, ".c"
Error in re-setting breakpoint 1: malformed linespec error: unexpected string, ".c"