diff options
author | Michael Snyder <msnyder@vmware.com> | 2002-01-08 00:59:31 +0000 |
---|---|---|
committer | Michael Snyder <msnyder@vmware.com> | 2002-01-08 00:59:31 +0000 |
commit | 94cd915f48523bbcbe20f74835d7f5a9d0b3a916 (patch) | |
tree | dc78d55a6fc5d5e7ae9a34a443711986bb9b714d /gdb/infptrace.c | |
parent | 1dba4cb4baa4862670e9019c2bd1f718807b4b92 (diff) | |
download | gdb-94cd915f48523bbcbe20f74835d7f5a9d0b3a916.zip gdb-94cd915f48523bbcbe20f74835d7f5a9d0b3a916.tar.gz gdb-94cd915f48523bbcbe20f74835d7f5a9d0b3a916.tar.bz2 |
2002-01-07 Michael Snyder <msnyder@redhat.com>
* infptrace.c (GDB_MAX_ALLOCA): New define.
(child_xfer_memory): Use xmalloc/xfree instead of alloca if the
size of the buffer exceeds GDB_MAX_ALLOCA (default 1 megabyte,
can be overridden with whatever value is appropriate to the host).
* infttrace.c (child_xfer_memory): Add FIXME warning about use of
alloca to allocate potentially large buffer.
* rs6000-nat.c (child_xfer_memory): Ditto.
* symm-nat.c (child_xfer_memory): Ditto.
* x86-64-linux-nat.c (child_xfer_memory): Ditto.
Diffstat (limited to 'gdb/infptrace.c')
-rw-r--r-- | gdb/infptrace.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/gdb/infptrace.c b/gdb/infptrace.c index 9815e05..c39ca03 100644 --- a/gdb/infptrace.c +++ b/gdb/infptrace.c @@ -480,6 +480,11 @@ store_inferior_registers (int regno) #endif /* !defined (FETCH_INFERIOR_REGISTERS). */ +/* Set an upper limit on alloca. */ +#ifndef GDB_MAX_ALLOCA +#define GDB_MAX_ALLOCA 0x1000 +#endif + #if !defined (CHILD_XFER_MEMORY) /* NOTE! I tried using PTRACE_READDATA, etc., to read and write memory in the NEW_SUN_PTRACE case. It ought to be straightforward. But @@ -506,9 +511,20 @@ child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write, /* Round ending address up; get number of longwords that makes. */ int count = ((((memaddr + len) - addr) + sizeof (PTRACE_XFER_TYPE) - 1) / sizeof (PTRACE_XFER_TYPE)); + int alloc = count * sizeof (PTRACE_XFER_TYPE); + PTRACE_XFER_TYPE *buffer; + struct cleanup *old_chain = NULL; + /* Allocate buffer of that many longwords. */ - PTRACE_XFER_TYPE *buffer = - (PTRACE_XFER_TYPE *) alloca (count * sizeof (PTRACE_XFER_TYPE)); + if (len < GDB_MAX_ALLOCA) + { + buffer = (PTRACE_XFER_TYPE *) alloca (alloc); + } + else + { + buffer = (PTRACE_XFER_TYPE *) xmalloc (alloc); + old_chain = make_cleanup (xfree, buffer); + } if (write) { @@ -573,6 +589,8 @@ child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write, len); } + if (old_chain != NULL) + do_cleanups (old_chain); return len; } |