Elf symbols, little update
A little while ago I worked more on my little script to extract and expand the global symbols from an ELF file with debug (DWARF) informations. I keep it in my head all the time, so…
Here are the changes and some explanation for them.
- Small optimization in address handling. The script was constantly converting the address from integer to hexadecimal string and back on every operation where address was needed. That is now gone and the conversion is done only at printing.
- Resolve constant addresses. This one is kind of simple and it bothers me how I did not consider such a simple thing.
- Experimental support for bit offsets in structs. I am not sure if I am doing it right here, it seems to work with my examples, but I am still not super convinced especially because I totally ignore the program data structure and endian-ness. Maybe I am here for a world of hurt.
- Maximum array size handling. This one is a nice one. When the array is empty the maximum (all bits are ‘1’) value is set for the array size. The script was than trying to expand this infinite amount of elements and it would either crash all eat all the memory. So, I for not investigated and set a configurable guard to limit the number of array elements.
- Apply data from specification to the DIE. The DIE may not contain all the required information like size or the address, this information is instead stored in a separate DIE made specificaly to specify and add some information to the original DIE. To add support for this, I went with a barbaric way and go over all DIEs in the elf file before running the type resolution on variables. There is a noticable slow down together with the next point.
- Variable “normalization” by address. I call it “normalization” but the real thing is that I filter the DIEs with “0” as an address. The problem which I encountered is that in many CUs (Compile Units) the same variable is defined but the address is either not present and the data from specifications should be used to get it, or the address is zero on purpose, or the address is directly only on one DIE and all other ones are without it. And I did not found a good way to get rid of them all apart from filtering variables with zero address. This adds some time to process once again and slows the thing down. Well, it can also speed it up since the printing is the slowest part of the program.
All of the changes can be seen in the git logs.
Maybe one day I will write a nice proper introduction and description of this little script. There is still a lot of work and feature to do.