gdb不停收到sigtrap信号
2014-11-25 16:25
369 查看
源:http://my.oschina.net/mavericsoung/blog/132993
main()
{
char c='x';
read(0,&c,1);
printf("go\n");
printf("come\n");
}
编译生成a.out后,运行gdb a.out
(gdb) b main
Breakpoint 1 at 0x80483e5: file gdb.c, line 3.
(gdb) r
Starting program: /tmp/tx
Breakpoint 1, main () at gdb.c:3
3 char c='x';
(gdb) set $foo=&c
(gdb) watch *$foo //对c所在的地址设置一个观察点
Hardware watchpoint 2: *$foo
(gdb) del 1
(gdb) c
Continuing.
Hardware watchpoint 2: *$foo
Old value = 0 '\0'
New value = 120 'x'
main () at gdb.c:4
4 read(0,&c,1);
(gdb) c
Continuing. //输入回车
Hardware watchpoint 2: *$foo
Old value = 120 'x'
New value = 10 '\n'
0x00ae3402 in __kernel_vsyscall ()
(gdb)
Continuing.
Program received signal SIGTRAP, Trace/breakpoint trap. //此后,gdb不停收到sigtrap信号,不知何故
0x009f23f3 in __read_nocancel () from /lib/libc.so.6
(gdb)
Continuing.
Program received signal SIGTRAP, Trace/breakpoint trap.
0x009f23f4 in __read_nocancel () from /lib/libc.so.6
(gdb)
Continuing.
Program received signal SIGTRAP, Trace/breakpoint trap.
0x009f23f9 in __read_nocancel () from /lib/libc.so.6
(gdb)
但如果把代码改成
main()
{
char c='x';
printf("go\n");
c++;
printf("come\n");
}
sigtrap就不会发生。第一个程序,c的值是在kernel里面被改的,第二个程序,c是在用户空间被改的。为什么在kernel里修改观察点的值,就会不断收到sigtrap呢?
=====================================================================解决办法
=====================================================================
main()
{
char c='x';
read(0,&c,1);
printf("go\n");
printf("come\n");
}
编译生成a.out后,运行gdb a.out
(gdb) b main
Breakpoint 1 at 0x80483e5: file gdb.c, line 3.
(gdb) r
Starting program: /tmp/tx
Breakpoint 1, main () at gdb.c:3
3 char c='x';
(gdb) set $foo=&c
(gdb) watch *$foo //对c所在的地址设置一个观察点
Hardware watchpoint 2: *$foo
(gdb) del 1
(gdb) c
Continuing.
Hardware watchpoint 2: *$foo
Old value = 0 '\0'
New value = 120 'x'
main () at gdb.c:4
4 read(0,&c,1);
(gdb) c
Continuing. //输入回车
Hardware watchpoint 2: *$foo
Old value = 120 'x'
New value = 10 '\n'
0x00ae3402 in __kernel_vsyscall ()
(gdb)
Continuing.
Program received signal SIGTRAP, Trace/breakpoint trap. //此后,gdb不停收到sigtrap信号,不知何故
0x009f23f3 in __read_nocancel () from /lib/libc.so.6
(gdb)
Continuing.
Program received signal SIGTRAP, Trace/breakpoint trap.
0x009f23f4 in __read_nocancel () from /lib/libc.so.6
(gdb)
Continuing.
Program received signal SIGTRAP, Trace/breakpoint trap.
0x009f23f9 in __read_nocancel () from /lib/libc.so.6
(gdb)
但如果把代码改成
main()
{
char c='x';
printf("go\n");
c++;
printf("come\n");
}
sigtrap就不会发生。第一个程序,c的值是在kernel里面被改的,第二个程序,c是在用户空间被改的。为什么在kernel里修改观察点的值,就会不断收到sigtrap呢?
=====================================================================解决办法
=====================================================================
本帖最后由 cjog 于 2012-01-17 17:29 编辑 找到解决问题的办法了 在kernel mode改写了watchpoint的值以后,cpu把eflags的TF位置1了,照理说gdb应该清0这一位,但由于未知原因,gdb没清0该位, (gdb) info registers eax 0x1 1 ecx 0xbfa4fc93 -1079706477 edx 0x1 1 ebx 0x0 0 esp 0xbfa4fc64 0xbfa4fc64 ebp 0xbfa4fc98 0xbfa4fc98 esi 0x92dca0 9624736 edi 0x0 0 eip 0x978402 0x978402 <__kernel_vsyscall+2> eflags 0x200346 [ PF ZF TF IF ID ] cs 0x73 115 ss 0x7b 123 ds 0x7b 123 es 0x7b 123 fs 0x0 0 gs 0x33 51 (gdb) 只需手动清楚该位即可: (gdb) set $ps&=~(1<<8) 【on x86-based machines $ps is an alias for the eflags register,TF is the 9th bit of eflags】 (gdb) info registers eax 0x1 1 ecx 0xbf90f353 -1081019565 edx 0x1 1 ebx 0x0 0 esp 0xbf90f324 0xbf90f324 ebp 0xbf90f358 0xbf90f358 esi 0x92dca0 9624736 edi 0x0 0 eip 0xe66402 0xe66402 <__kernel_vsyscall+2> eflags 0x200246 [ PF ZF IF ID ] cs 0x73 115 ss 0x7b 123 ds 0x7b 123 es 0x7b 123 fs 0x0 0 gs 0x33 51 (gdb) 再continue,gdb就不会不停收到SIGTRAP了 |
相关文章推荐
- gdb不停收到sigtrap信号
- gdb时发出SIGTRAP信号的处理
- gdb 收到SIGPIPE信号
- TRAP 收到信号后不立即执行的问题
- GDB在调试运行过程中会由于收到信号而停止
- 使用gdb调试网络程序时,收到SIGPIPE信号异常退出问题
- gdb启动时,进程收到中断信号造成无法正常启动的解决办法
- gdb中忽略信号处理
- linux trap 捕捉信号
- Linux 操作系统 SIGTERM等信号意义
- 嵌入式 UNIX SIGTERM等信号意义一览文档
- shell脚本trap信号和服务器跳板机,mysql自动化脚本,检测主从复制
- shell学习五十三天----捕获信号trap
- Linux查找是发送SIGKILL信号的进程
- 进程通信:信号通信之SIGSTOP和SIGCONT测试
- SIGCHLD信号与SIG_IGN处理的使用
- gdb中调试signal信号
- GDB调试信号、多线程、多进程
- 【转贴】gdb中的信号(signal)相关调试技巧
- 我使用过的Linux命令之trap - 在脚本中处理信号