This is the mail archive of the
mailing list for the GDB project.
[RFC] problem with read_memory_string (reads 8 bytes at a time)
- From: Joel Brobecker <brobecker at adacore dot com>
- To: gdb-patches at sourceware dot org
- Date: Wed, 8 Apr 2009 11:26:51 -0700
- Subject: [RFC] problem with read_memory_string (reads 8 bytes at a time)
I did what I thought would be a nice cleanup in ada-lang.c last weekend,
by deleting a local function (extract_string), and replacing it by a call
to read_memory_string instead. This works fine most of the time, but
nightly testing did reveal a problem with that function on powerpc-elf.
Cannot access memory at address 0x1002e8
Here is what happens:
1. The "start" commands needs to know that the name of the "main"
program is. As a result, we call ada_main_name, which finds
the symbol that points us to the string containing that main
2. To read that name, we call read_memory_string now, and this
routine performs strings reads 8 bytes at a time.
The problem is that our string is at the end of our .rodata section.
The string is 8 bytes long, and sits at 0x1002e0. The .rodata section
ends at 0x001102ec. So here's what we end up doing:
a. Read 8 bytes from 0x1002e0 - no problem.
But we haven't read the \0 yet, so we keep going.
b. Read 8 bytes from 0x1002e0 + 8 = 0x1002e8:
i. The section ends at 0x001102ec, so bfd returns only 4 bytes read.
ii. We find out that only 4 bytes were read, so we still need to
read another 4 bytes for the 8byte read to be complete
iii. the next 4byte read doesn't find a section from which to
read the 4bytes, and so returns 0 signifying an error.
I don't really know how to fix this issue except by reading the string
one byte at a time :-(. Any suggestion?