gdb如何在Linux上访问另一个进程虚拟内存?全部通过/ proc完成吗?
在Linux上读取内存 :
1)如字节数来读取比更少
3 * sizeof(long)或文件系统
/proc不可用或从读取
/proc/PID/mem不成功则
ptrace使用具有
PTRACE_PEEKTEXT读取数据。
这些是函数中的这些条件
linux_proc_xfer_partial():
if (len < 3 * sizeof (long)) return 0; xsnprintf (filename, sizeof filename, "/proc/%d/mem", ptid_get_pid (inferior_ptid)); fd = gdb_open_cloexec (filename, O_RDonLY | O_LARGEFILE, 0); if (fd == -1) return 0;
2)如果要读取的字节数大于或等于3 *sizeof(long)并且
/proc可用,则使用
pread64或(
lseek()和
read()使用:
static LONGESTlinux_proc_xfer_partial (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULonGEST offset, LonGEST len){ ..... #ifdef HAVE_PREAD64 if (pread64 (fd, readbuf, len, offset) != len)#else if (lseek (fd, offset, SEEK_SET) == -1 || read (fd, readbuf, len) != len)#endif ret = 0; else ret = len; close (fd); return ret;}在Linux上写内存 :
1)
ptrace与
PTRACE_POKETEXT或一起
PTRACE_POKEDATA使用。
至于第二个问题:
在哪里可以找到有关…设置硬件观察点的信息
gdb,内部观察点:s
http://sourceware.org/gdb/wiki/Internals%20Watchpoints
参考:
- http://linux.die.net/man/2/ptrace
- http://www.alexonlinux.com/how-debugger-works



