This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFC PATCH] fix xfer from section that ends at max of CORE_ADDR
- From: Victor Kamensky <victor dot kamensky at linaro dot org>
- To: gdb-patches at sourceware dot org
- Cc: victor dot kamensky at linaro dot org
- Date: Tue, 21 Oct 2014 22:29:41 -0700
- Subject: [RFC PATCH] fix xfer from section that ends at max of CORE_ADDR
- Authentication-results: sourceware.org; auth=none
Fix section_table_xfer_memory_partial function to deals with
section entry that may have its endaddr at 0, because that
section ends at max of CORE_ADDR and address next after it
would be 0 once stored back to CORE_ADDR (overflow).
bigcore.exp test run into this issue while running in ARM
V7 rootfs on top of ARM V8 kernel (compat mode). In that
core file the following section existed (from readelf -a
execute on core file):
LOAD 0xffe23000 0xffff1000 0x00000000 0x0f000 0x0f000 RW 0x1000
and gdb could not read from it.
gdb/ChangeLog:
2014-10-21 Victor Kamensky <victor.kamensky@linaro.org>
* exec.c (section_table_xfer_memory_partial): Use ULONGEST
for section start and end addresses to handle section that
may has its end at max of CORE_ADDR and therefore such
section endaddr field would be 0.
---
gdb/exec.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/gdb/exec.c b/gdb/exec.c
index f32589b..7c9b4b6 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -697,11 +697,18 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
struct bfd_section *asect = p->the_bfd_section;
bfd *abfd = asect->owner;
+ /* To deals with possible overflow where p->endaddr is 0,
+ because of section ends on max of CORE_ADDR, copy section
+ addr and endaddr to ULONGEST type. Recover section length
+ first, and use it to determine section_endaddr. */
+ ULONGEST section_addr = p->addr;
+ ULONGEST section_endaddr = section_addr + (p->endaddr - p->addr);
+
if (section_name && strcmp (section_name, asect->name) != 0)
continue; /* not the section we need. */
- if (memaddr >= p->addr)
+ if (memaddr >= section_addr)
{
- if (memend <= p->endaddr)
+ if (memend <= section_endaddr)
{
/* Entire transfer is within this section. */
if (writebuf)
@@ -721,7 +728,7 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
else
return TARGET_XFER_EOF;
}
- else if (memaddr >= p->endaddr)
+ else if (memaddr >= section_endaddr)
{
/* This section ends before the transfer starts. */
continue;
--
1.8.1.4