Re: Reading memory from inferior at given pointer

Tom Tromey <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
>>>>> ">" == weller  <[email protected]> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.