Bitfield support in decompiler
See original GitHub issueIs your feature request related to a problem? Please describe. Right now the decompiler shows bitfield access simply as shift and mask (in other words, it is unaware of bitfields).
For example, consider:
- a big-endian bitfield that is a byte long, and
- a member 3 bits long starting at the 2nd bit.
A member read might look like bitfield >> 3 & 0x7
, and a member write like bitfield = (bitfield & 0xc7) | (member << 3 & 0x38)
. This makes understanding decompiler output difficult.
The data type manager allows the declaration of bitfields only by importing them through the “Parse C Source” menu item (great if you have a header file for your platform), however the decompiler does not make use of this information.
Describe the solution you’d like
- Ability to declare bitfields in the data type manager
- Control over implementation-specific details like member allocation order
- Decompiler recognizes data/variables typed as a bitfield + shift-and-mask pcode matching defined offsets and lengths as a bitfield member access, and shows the member access instead of the shift and mask
The above example would then look like var1 = bitfield.member
and bitfield.member = var1
for the read and write cases.
Describe alternatives you’ve considered No real alternative besides the current situation of consulting datasheets and my own notes for bitfield layout.
- Bitfield layout will depend on architecture and endianness
- There is no definitive way for a function to access a bitfield member. It could shift first then mask, or mask then shift. Recognizing member access, even by pcode, might not be trivial.
Additional context This is mainly for embedded systems that pack many short parameters into registers.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:16
- Comments:16 (1 by maintainers)
The ability to represent bitfields within Structures has just been added to the master branch . Support for bitfields has been added to the CParser, PDB parser and DWARF. The PDB XML file format has changed for bitfields - any retained PDB XML files will need to be regenerated to benefit from the bitfield improvements (bitfield bit-offset information was missing from XML). Note that “aligned” bitfield packing support is currently to msb filled first for big-endian and lsb filled-first for little-endian data. These bitfield component definitions are currently not conveyed to the decompiler and there is currently no bitfield reference mechanism. Structure Data instances in memory will reflect bitfield data. See Structure Editor help content for some additional information.
This is something I’d really like to see implemented, both in the decompiler and just in the disassembly list view. I feel like a lot of good additions could be done to the enumerations feature. In addition to this, the ability to specify values within bitmasks within the enum would be great. Systems that use their own flag registers may group multiple independent sets into a single register each with a different mask.
Separating enumerations from the overall “data types” in some way would make navigating them easier as well.