简体   繁体   English

(gdb)p / x等价于gdb python脚本?

[英](gdb) p/x equivalent in gdb python script?

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: 当我用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: 在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? 那么如何在gdb-python中写与p / x等效的东西呢? 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? 还是如何在python脚本中以python val = gdb.parse_and_eval('((struct my_struct *)dev_base->next->priv)').address的地址获取'md_capture_buff'的地址?

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. str运算符遵守此设置可以说是一个错误。

There isn't a good way to reproduce "p/x" other than just invoking it directly. 除了直接调用“ p / x”之外,没有什么好方法可以复制它。 See gdb.execute. 请参阅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. IMO,通常最好使用API​​而不是parse_and_eval。 That is, you can cast, look up fields, etc, directly from Python. 也就是说,您可以直接从Python强制转换,查找字段等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM