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]

Re: Reading memory from inferior at given pointer


>>>>> ">" == 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


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