Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cast type of gdb.value to int

Tags:

python

gdb

I want to cast in python code a gdb.value which is a complicated type variable to int (this is not general type, but defined in the our code - a kind of bitfield). When I promped in the gdb shell itself:

"p var"

it prints it as int, i.e. the gdb know how to cast that bitfield to int.

(Strange thing, in addition, I got when I try this command:

int(var.cast(i.type))

When "i" is gdb.value that its type is int. The var indeed becomes int, but its value become same as the value of i).

So is someone know how to cast this gdb.value by use the knowledge of the gdb. (Or by other way..)

Thanks. This is my first question in StackOverFlow, sorry on the confusion and my weak English.

like image 514
Yehezkel Avatar asked Feb 11 '15 10:02

Yehezkel


1 Answers

What you want is:

int(value.cast(gdb.lookup_type('long')))
like image 190
Zach Riggle Avatar answered Oct 09 '22 04:10

Zach Riggle