Linux上gdb如何访问另一个进程的虚拟内存?都是通过/proc完成的吗?
在Linux上读取内存:
1) 如果要读取的字节数小于3 * sizeof (long)
或文件系统/proc
不可用或正在读取/proc/PID/mem
那么不成功ptrace
与使用PTRACE_PEEKTEXT
读取数据。
这些是函数中的条件linux_proc_xfer_partial()
:
/* Don't bother for one word. */
if (len < 3 * sizeof (long))
return 0;
/* We could keep this file open and cache it - possibly one per
thread. That requires some juggling, but is even faster. */
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
or (lseek()
and read()
使用:
static LONGEST
linux_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)
{
.....
/* If pread64 is available, use it. It's faster if the kernel
supports it (only one syscall), and it's 64-bit safe even on
32-bit platforms (for instance, SPARC debugging a SPARC64
application). */
#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
with PTRACE_POKETEXT
or PTRACE_POKEDATA
用来。
As for your second question:
我在哪里可以找到有关...设置硬件观察点的信息
gdb,内部观察点:shttp://sourceware.org/gdb/wiki/Internals%20Watchpoints http://sourceware.org/gdb/wiki/Internals%20Watchpoints
参考:
- http://linux.die.net/man/2/ptrace http://linux.die.net/man/2/ptrace
- http://www.alexonlinux.com/how-debugger-works http://www.alexonlinux.com/how-debugger-works