更改环 0 中观察点的值会导致 gdb 出现奇怪的行为
src.c:
main()
{
char c='x';
read(0,&c,1);
printf("go\n");
printf("come\n");
}
gcc src.c -g,你得到一个可执行文件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 //set a watchpoint for the address in which c reside
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. **//type carrige return**
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. **//from now on,gdb receive SIGTRAP repeatedly,why?**
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");
}
那么一切都会顺利,没有有线行为。
在第一个程序中,在内核模式下修改了观察点的值,然后gdb收到SIGTRAP;在第二个程序中,在用户模式下修改了观察点,没有发生任何接线。有人能告诉我为什么吗?预先致谢。
src.c:
main()
{
char c='x';
read(0,&c,1);
printf("go\n");
printf("come\n");
}
gcc src.c -g, you get a executable a.out,then,
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 //set a watchpoint for the address in which c reside
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. **//type carrige return**
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. **//from now on,gdb receive SIGTRAP repeatedly,why?**
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)
however,if i modify the source code to:
main()
{
char c='x';
printf("go\n");
c++;
printf("come\n");
}
then everything goes well,no wired behavior.
In the 1st program,the value of the watchpoint is modified in kernel mode,then gdb receive SIGTRAP;In the 2nd program,watchpoint is modified in user mode,nothing wired happen.could anyone tell me why? Heaps of thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论