更改环 0 中观察点的值会导致 gdb 出现奇怪的行为

发布于 2024-12-27 14:46:39 字数 1472 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文