在Linux中访问另一个进程虚拟内存(调试)

时间:2014-07-23 19:26:48

标签: linux gdb

gdb如何在Linux上访问另一个进程虚拟内存?这一切都是通过/ proc完成的吗?

1 个答案:

答案 0 :(得分:10)

  

gdb如何在Linux上访问另一个进程虚拟内存?这一切都是通过/ proc完成的吗?

在Linux上阅读内存

1)如果要读取的字节数小于3 * sizeof (long)或文件系统/proc不可用或从/proc/PID/mem读取不成功,则ptrace与{一起使用} {1}}读取数据。

这些是函数PTRACE_PEEKTEXT中的条件:

linux_proc_xfer_partial()

2)如果要读取的字节数大于或等于3 * sizeof(long)且 /* 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; 可用,则/proc或(pread64lseek()使用:

read()

在Linux上编写内存

1)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; } 使用ptracePTRACE_POKETEXT

<小时/> 至于你的第二个问题:

  

在哪里可以找到有关...设置硬件观察点的信息

gdb,Internals Watchpoint:s http://sourceware.org/gdb/wiki/Internals%20Watchpoints

参考: