I'm trying to determine address values and sizes using ARM .elf output in GDB. With the usual p& and print functions I can determine most of the addresses and and variable sizes, but I can't figure out if the variable is a bitValue or not.
To give an example:
typedef struct
{
bool_t start;
bool_t running :1;
bool_t objectpoolUsable :1;
bool_t ready :1;
bool_t test :1;
bool_t stop :1;
uint8_t defaultMachine;
}bitFieldTest;
bitFieldTest bitValues;
When asking GDB for the address of "bitValues.ready" or "bitValues.running" it will return the same address (since it uses the same address), but doesn't give me the bit position. Neither do I know if it really is a bitvalue or just a boolean taking the space of a uint8_t.
To clarify what I need to do: Give GDB only a single name, what might be a bitValue, and return me the right address and type. If this type is a bitValue, I need to find the bit position. For non-bitValues this works fine, bitValues are causing trouble for now.
Is GDB able to give some kind of output to solve this problem?
There's no way to get this information directly using the gdb expression API. There's no really deep reason for this -- certainly gdb knows the bit position -- but it is a consequence of the fact that gdb expressions mimic the language being debugged, plus just that nobody ever bothered to expose it. Since I've never heard of anyone wanting this before, I think it's safe to say that it is a rare request.
The information is available via gdb's Python API. In particular, if you iterate over the fields of a type, the Field object will have a bitpos member that has the bit offset of the data. Note that the offset is from the start of the enclosing struct.
It would be a relatively simple matter to write a new command in Python that prints this information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With