diff options
author | Daniel Jacobowitz <drow@false.org> | 2002-11-26 01:23:46 +0000 |
---|---|---|
committer | Daniel Jacobowitz <drow@false.org> | 2002-11-26 01:23:46 +0000 |
commit | eb78484829c67075caaa4ac984dd8b50b5d750bc (patch) | |
tree | 5d1c675cdefdc0b97a2387453702bcb940af80f9 /gdb/linux-proc.c | |
parent | afbfa4076a55445d5e61f5c872b438d1ea997aeb (diff) | |
download | gdb-eb78484829c67075caaa4ac984dd8b50b5d750bc.zip gdb-eb78484829c67075caaa4ac984dd8b50b5d750bc.tar.gz gdb-eb78484829c67075caaa4ac984dd8b50b5d750bc.tar.bz2 |
* acconfig.h (HAVE_PREAD64): Add.
* configure.in: Check for pread64.
* config.in: Regenerated.
* configure: Regenerated.
* lin-lwp.c (lin_lwp_xfer_memory): Call linux_proc_xfer_memory.
* linux-proc.c (linux_proc_xfer_memory): New function.
* config/nm-linux.h (linux_proc_xfer_memory): Add prototype.
Diffstat (limited to 'gdb/linux-proc.c')
-rw-r--r-- | gdb/linux-proc.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/gdb/linux-proc.c b/gdb/linux-proc.c index f76def3..2f43ae6 100644 --- a/gdb/linux-proc.c +++ b/gdb/linux-proc.c @@ -25,6 +25,8 @@ #include <sys/procfs.h> /* for elf_gregset etc. */ #include <sys/stat.h> /* for struct stat */ #include <ctype.h> /* for isdigit */ +#include <unistd.h> /* for open, pread64 */ +#include <fcntl.h> /* for O_RDONLY */ #include "regcache.h" /* for registers_changed */ #include "gregset.h" /* for gregset */ #include "gdbcore.h" /* for get_exec_file */ @@ -33,6 +35,10 @@ #include "cli/cli-decode.h" /* for add_info */ #include "gdb_string.h" +#ifndef O_LARGEFILE +#define O_LARGEFILE 0 +#endif + /* Function: child_pid_to_exec_file * * Accepts an integer pid @@ -577,3 +583,46 @@ Specify any of the following keywords for detailed info:\n\ status -- list a different bunch of random process info.\n\ all -- list all available /proc info."); } + +int linux_proc_xfer_memory (CORE_ADDR addr, char *myaddr, int len, int write, + struct mem_attrib *attrib, + struct target_ops *target) +{ + int fd, ret; + char filename[64]; + + if (write) + return 0; + + /* 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. */ + sprintf (filename, "/proc/%d/mem", PIDGET (inferior_ptid)); + fd = open (filename, O_RDONLY | O_LARGEFILE); + if (fd == -1) + return 0; + + /* 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). + + We play some autoconf and CFLAGS games to get this declaration + exposed: -D_XOPEN_SOURCE=500 -D_LARGEFILE64_SOURCE. And then + a -D_BSD_SOURCE to counteract the defaults for _XOPEN_SOURCE. */ +#ifdef HAVE_PREAD64 + if (pread64 (fd, myaddr, len, addr) != len) +#else + if (lseek (fd, addr, SEEK_SET) == -1 + || read (fd, myaddr, len) != len) +#endif + ret = 0; + else + ret = len; + + close (fd); + return ret; +} |