- 论坛徽章:
- 0
|
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呢? |
|