GDB忽略我的断点 [英] GDB ignores my breakpoints

查看:300
本文介绍了GDB忽略我的断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的测试案例非常简单,我必须做一些非常愚蠢的事情。我写了一个简单的源文件 test.c

  #include< stdio.h中> 

int main(int argc,char * argv []){
printf(1 \\\
);
printf(2 \\\
);
printf(3 \\\
);
返回0;
}

我用 gcc -g test.c 并使用 gdb a.out 启动GDB。然后我用 break main main 中创建了一个断点,并使用 run (也试过用 start ) - 但GDB简单地忽略了我的断点!



这是shell我尝试编译 test.c 并运行GDB:

 版权所有(C)2013免费版(C)2013免费版本(g)免费版本(g) Software Foundation,Inc. 
许可证GPLv3 +:GNU GPL版本3或更高版本< http://gnu.org/licenses/gpl.html>
这是免费软件:您可以自由更改和重新分配它。
在法律允许的范围内,不存在任何担保。有关详细信息,请键入显示复制
和显示保修。
此GDB被配置为x86_64-unknown-linux-gnu。
有关错误报告的说明,请参阅:
< http://www.gnu.org/software/gdb/bugs/> ...
阅读/ home / idanarye中的符号/gdbtest/a.out...done。
(gdb)break main
在0x40050f处的断点1:file test.c,第4行。
(gdb)run
启动程序:/ home / idanarye / gdbtest / a。 out
1
2
3
在启动程序期间,程序正常退出。
(gdb)

我在这里做错了什么?



我正在运行64位Arch Linux。我的GCC版本是4.8.2。
$ b

UPDATE



结果如下 disas main

 函数main的汇编代码转储:
0x0000000000400500< + 0> ;: push%rbp
0x0000000000400501< + 1>:mov%rsp,%rbp
0x0000000000400504< + 4> ;: sub $ 0x10,%rsp
0x0000000000400508< + 8>:mov%edi,-0x4(%rbp)
0x000000000040050b< + 11> ;: mov%rsi,-0x10(%rbp)
0x000000000040050f< + 15> ;: mov $ 0x4005c4,%edi
0x0000000000400514< + 20> ;: callq 0x4003e0< puts @ plt>
0x0000000000400519< + 25> ;: mov $ 0x4005c6,%edi
0x000000000040051e< + 30> ;: callq 0x4003e0< puts @ plt>
0x0000000000400523< + 35> ;: mov $ 0x4005c8,%edi
0x0000000000400528< + 40> ;: callq 0x4003e0< puts @ plt>
0x000000000040052d< + 45>:mov $ 0x0,%eax
0x0000000000400532< + 50>:leaveq
0x0000000000400533< + 51>:retq
汇编程序转储结束。



更新



不知道如何或为何,但它现在有效。可能是一个系统更新修正了它...

解决方案

(策划来自评论)



你不会出现任何错误;它似乎是GDB的错。



消息在启动程序中退出正常。是异常的,正确的是程序正常退出。。它建议GDB无法在 main()中插入断点,或者追踪到的程序调用 ptrace(PT_TRACE_ME,0,0,0)失败。程序因此没有被停止运行,并且它在GDB只希望它启动并停在 exec()时退出。您可以在执行示例时运行 gdb ,并在 strace 下运行 grep strace 记录任何失败 ptrace 调用?



你可以使用 strace -f -o syscall.txt gdb ./a.out



截至目前,权宜之计似乎是以root身份运行GDB。

My test case is so simple that I must be doing something very stupid. I wrote a simple source file test.c:

#include<stdio.h>

int main(int argc,char* argv[]){
    printf("1\n");
    printf("2\n");
    printf("3\n");
    return 0;
}

I compiled it with gcc -g test.c and started GDB with gdb a.out. Then I created a breakpoint in main with break main and ran it with run(also tried with start) - but GDB simply ignored my breakpoint!

This is the shell session of me trying to compile test.c and run GDB:

[idanarye@idanarye_lg gdbtest]$ gcc -g test.c
[idanarye@idanarye_lg gdbtest]$ gdb a.out
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 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-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/idanarye/gdbtest/a.out...done.
(gdb) break main
Breakpoint 1 at 0x40050f: file test.c, line 4.
(gdb) run
Starting program: /home/idanarye/gdbtest/a.out 
1
2
3
During startup program exited normally.
(gdb) 

What in the world am I doing wrong here?

I'm running a 64bit Arch Linux. My GCC version is 4.8.2.

UPDATE

Here is the result of disas main:

Dump of assembler code for function main:
   0x0000000000400500 <+0>:     push   %rbp
   0x0000000000400501 <+1>:     mov    %rsp,%rbp
   0x0000000000400504 <+4>:     sub    $0x10,%rsp
   0x0000000000400508 <+8>:     mov    %edi,-0x4(%rbp)
   0x000000000040050b <+11>:    mov    %rsi,-0x10(%rbp)
   0x000000000040050f <+15>:    mov    $0x4005c4,%edi
   0x0000000000400514 <+20>:    callq  0x4003e0 <puts@plt>
   0x0000000000400519 <+25>:    mov    $0x4005c6,%edi
   0x000000000040051e <+30>:    callq  0x4003e0 <puts@plt>
   0x0000000000400523 <+35>:    mov    $0x4005c8,%edi
   0x0000000000400528 <+40>:    callq  0x4003e0 <puts@plt>
   0x000000000040052d <+45>:    mov    $0x0,%eax
   0x0000000000400532 <+50>:    leaveq 
   0x0000000000400533 <+51>:    retq   
End of assembler dump. 

UPDATE

No idea how or why, but it works now. Probably a system update fixed it...

解决方案

(curated from comments)

You do not appear do be doing anything wrong; It appears to be GDB's fault.

The message During startup program exited normally. is anomalous, the correct one being Program exited normally.. It suggests GDB failed to insert a breakpoint in main() or the traced program's call to ptrace(PT_TRACE_ME, 0, 0, 0) failed. The program thus ran without being stopped, and it exited while GDB was only expecting it to start up and stop at exec(). Can you run gdb under strace while doing your example and grep strace's log for any failed ptrace calls?

You would do so with strace -f -o syscall.txt gdb ./a.out.

As of right now a stop-gap measure appears to be to run GDB as root.

这篇关于GDB忽略我的断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆