This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Addition of a special memory reading command


Hello,

I am developing an Eclipse plugin for my virtual machine and I have
encountered some problems with displaying memory of the debuggee.
Address space of my debuggee can contain holes (which are not page
aligned and generally can have any size) and reading such a memory
causes troubles. For example, lets consider that the memory at
addresses 0x10000000-0x10000004 is valid and the neighbourhood is not
valid. Then gdb that is ordered to read 20 bytes of memory from
address 0x0ffffff0 will not show the last valid bytes.
So, if the programmer (or the gdb frontend) wants to get the real
memory contents in this case, he must read the memory for each
interested address until he find a valid memory block.

I can understand that my case is rather special, but it can happen in
usual C userspace application too. If the memory page at address
0x0010000 is mapped and the previous one is not mapped, reading 100
bytes from the address 0x000fffff fails. This issue can be illustrated
on the following source code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>

int main(void) {
	void* address = (void*) 0x00100000;

	char* allocated_address = (char*) mmap(address,
			4092,
			PROT_READ | PROT_WRITE,
			MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS,
			-1,
			0
			);

	strcpy(allocated_address, "testing string");
	return EXIT_SUCCESS;
}

I think that having a special memory command would solve this. The
command would ask the virtual machine about the next valid block of
memory from the provided address. If the programmer encounters "Cannot
access memory at address ..." during examining the memory, he can use
the proposed command to ensure that the memory really is not valid or
to find out that the valid memory begins from an address X. My VM can
provide such information to gdb and, for the userspace scenario, I can
imagine that an operating system would be able to get the info from
page tables.

Probably I will be able to write a patch to gdb that implements the
command. The patch would create the command and implement it in the
remote protocol - for other targets it would just print "not
supported". However, I doubt that the Eclipse CDT community would
accept changes related to the proposed command until the command is
accepted into gdb. And keeping the patches for both gdb and CDT does
not seem to be fortunate to me.

So, how do you like the proposed command? Might it be possible to
integrate it to the future version of gdb?

Regards,
Tomas


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]