Reading memory from inferior at given pointer

Tom Tromey tromey@redhat.com
Fri Apr 26 13:55:00 GMT 2013


>>>>> ">" == weller  <weller@bfw-online.de> writes:

>> Thanks for taking the time to answer. My aim was to use
>> the actual string found at the given address in the target.

>> I know implemented it like this, which works fine so far:
>> target_read_string((CORE_ADDR)(data->data.s), &read, data->data_len, &errnop);

>> But I am not to sure about the cast to CORE_ADDR. Is there a prefered
>> way to get the CORE_ADDR so it e.g. doesn't break on different
>> architectures.

The target_read_memory call, from your earlier note:

>> target_read_memory(addr, (void *)data, sizeof(struct foo));

... is assuming that structure layout is the same between the gdb host
and the inferior.  However this is not necessarily true.

If you want this to work on any architecture, you should use the value
API.  If you can't assume that you have debuginfo for "struct foo" then
you can describe it in C code in gdb using the type API.

Then you can find the pointer using the value API, and then convert this
to a CORE_ADDR, also using the value API.

Tom



More information about the Gdb mailing list