gdb";手表;无法通过glibc(读取)函数修改变量?
我想在修改gdb";手表;无法通过glibc(读取)函数修改变量?,c,linux,gdb,glibc,C,Linux,Gdb,Glibc,我想在修改ch时中断。我在gdb中使用了watch ch,它不起作用 类似于ch=1将中断。为什么read()不会中断 就是这样使用watch命令。或者read()函数是特殊的 对不起,我的英语,代码说所有的事情 文件1.c: #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h>
ch
时中断。我在gdb中使用了watch ch
,它不起作用
类似于ch=1代码>将中断。为什么read()
不会中断
就是这样使用watch
命令。或者read()
函数是特殊的
对不起,我的英语,代码说所有的事情
文件1.c:
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
const char *const filename = "/etc/passwd";
int main(void)
{
int fd;
int ch;
fd = open(filename, O_RDONLY);
read(fd, &ch, sizeof(int));
printf ("%d\n", ch);
close (fd);
return 0;
}
对于read()
的正常实现,对内存的写入将直接由内核执行,而不是由任何用户空间代码执行。调试器没有在内核中设置断点的机制,即使设置了断点,它也没有这样做的权限。对于read()
的正常实现,对内存的写入将直接由内核执行,而不是由任何用户空间代码执行。调试器没有在内核中设置断点的机制,即使设置了断点,它也没有这样做的权限。ch真的被读取了吗?检查读取结果。int ch=42代码>和if(读(fd,&ch,sizeof(int))==-1)perror(“读:”
我确信read()
成功了。并且ch
被更改了。ch真的被读取了吗?检查读取结果。int ch=42代码>和if(读(fd,&ch,sizeof(int))==-1)perror(“读:”
我确信read()
成功。并且ch
已更改。此外,内核(甚至硬件设备驱动程序本身,如果文件缓存被禁用)可能正在使用与用户空间VA不同的虚拟地址映射写入内存。x86调试寄存器只能监视虚拟地址,不是物理地址。是像read()
这样的其他函数不能watch
的地方。我想知道所有这类函数。或者你能给我一些参考文档吗?没有官方文档。形式上,read
可以是一个库函数,它使用内核读入临时缓冲区,然后memcpy
将其读入调用者的缓冲区。这将是低效但有效的。我猜这样的定义是:查看您的C库,它以内核直接将数据写入(或在使用awatch的情况下读取)的方式进行系统调用,以监视变量。此外,内核(甚至硬件设备驱动程序本身,如果文件缓存被禁用)可能正在使用与用户空间VA不同的虚拟地址映射写入内存。x86调试寄存器只能监视虚拟地址,而不能监视物理地址。其他函数如read()
不能观看
。我想知道所有这类功能。或者你能给我一些参考文档吗。没有官方文档。形式上,read
可以是一个库函数,它使用内核读入临时缓冲区,然后memcpy
将其读入调用者的缓冲区。这将是低效但有效的。我猜这样的定义是:查看您的C库,它以内核直接将数据写入(或在使用awatch的情况下读取)的方式进行系统调用,以监视变量。这将发生。
$ gdb a.out
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 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 "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/zodiac1111/tmp/a.out...done.
(gdb) b main
Breakpoint 1 at 0x80484b5: file 1.c, line 11.
(gdb) r
Starting program: /home/zodiac1111/tmp/a.out
Breakpoint 1, main () at 1.c:11
11 fd = open(filename, O_RDONLY);
(gdb) watch ch
Hardware watchpoint 2: ch
(gdb) c
Continuing.
1953460082
Watchpoint 2 deleted because the program has left the block in
which its expression is valid.
__libc_start_main (main=0x80484ac <main>, argc=1, ubp_av=0xbffff4c4,
init=0x8048530 <__libc_csu_init>, fini=0x8048520 <__libc_csu_fini>,
rtld_fini=0xb7ff0590, stack_end=0xbffff4bc) at libc-start.c:260
260 libc-start.c: No such dir...
(gdb) c
Continuing.
[Inferior 1 (process 9513) exited normally]