Reading memory from inferior at given pointer

Fri Apr 19 10:45:00 GMT 2013


I'm currently trying to implement a custom language in gdb and I am
unsure on how to proceed with reading memory from specific inferior pointers.

For example. I have added commands which call into inferior by using
call_function_by_hand. The return value from the runtime is a struct
which would look like this:

struct foo {
  enum lang_type type;
  size_t len;
  union {
    double d;
    long l;
    char *s;
  } data;

Now I can read the structure just fine like this (shortend):

struct value ret = call_function_by_hand("callthis", argc, argv);
CORE_ADDR addr = unpack_pointer(value_type(ret), value_contents(ret));
target_read_memory(addr, (void *)data, sizeof(struct foo));

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.


More information about the Gdb mailing list