سؤال

the main structure is

struct my_struct 
{
   int x; 
   void* md_template;
   void* md_capture_buff;
   ....
};

When i am doing

(gdb) p ((struct my_struct *)dev_base->next->priv)

The output is like this

$1 = {
 x= 15 '\017'
 md_template = ,
 md_capture_buff =
}

And when i am doing it with p/x:

(gdb) p/x ((struct my_struct *)dev_base->next->priv)

The output is like this

$1 = {
 x= 0xf;
 md_template =0x410027001a50 ,
 md_capture_buff = 0x41002c0c5490
}

In gdb-python:

python val = gdb.parse_and_eval('((struct my_struct *)dev_base->next->priv)')

python print val

The output is:

$1 = {
 x= 15 '\017'
 md_template = ,
 md_capture_buff =
}  

So how to write equivalent to p/x in gdb-python? or how to get the address of 'md_capture_buff' in python script as python val = gdb.parse_and_eval('((struct my_struct *)dev_base->next->priv)').address is not prining the address?

هل كانت مفيدة؟

المحلول

You probably have "set print address" off. I wouldn't do this. It's arguably a bug that the str operator is respecting this setting.

There isn't a good way to reproduce "p/x" other than just invoking it directly. See gdb.execute.

You can get the value of any field using []. Like

val = something['fieldname']

It's usually better, IMO, to use the API rather than parse_and_eval. That is, you can cast, look up fields, etc, directly from Python.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top