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]

Reading memory from inferior at given pointer


Hello,

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.

Lennart


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