This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Reading memory from inferior at given pointer
- From: Tom Tromey <tromey at redhat dot com>
- To: Weller <weller at bfw-online dot de>
- Cc: gdb at sourceware dot org
- Date: Fri, 26 Apr 2013 07:55:49 -0600
- Subject: Re: Reading memory from inferior at given pointer
- References: <20130419104524 dot GA32527 at bfw-online dot de> <87fvyhp0gh dot fsf at fleche dot redhat dot com> <20130426075240 dot GA14698 at bfw-online dot de>
>>>>> ">" == 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