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: Weller <weller at bfw-online dot de>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: gdb at sourceware dot org
- Date: Fri, 26 Apr 2013 09:52:40 +0200
- 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>
On Tue, Apr 23, 2013 at 12:26:54PM -0600, Tom Tromey wrote:
> >>>>> ">" == Weller <weller@bfw-online.de> writes:
>
> >> Which allows me to read the long and double values just fine. But my
> >> hurdle is reading the char *. Which no matter which function I try
> >> always results in a bad address from which I can't read the correct
> >> string. I tried different functions mentioned in 9.3 of "GDB Internal"
> >> and also looked around in different language implementations. But I am
> >> clearly doing something wrong here.
>
> >> Which would be the correct way to read from this memory area from the
> >> inferior process? Any help would be appreciated.
>
> Are you trying to see the value of the pointer, or the pointed-to
> characters?
>
> To get the pointer I would use the various "value" APIs (see
> gdb/value.h) to extract the field from the value returned by
> call_function_by_hand.
>
> For the characters, you can use read_string.
>
> Tom
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.
Lennart