Sometimes you handle software that have very conditional structures, especially in big embedded projects where space efficiency is critical.
You might be familiar with Dwarf, a very powerful debugging format that you have certainly used without knowing it.
Basicly, Dwarf infos are the sections in your execs, dlls, elf … that allows you to debug things with open-minded softwares.
For instance, if you can do step-by-step debugging in gdb, on your pc or with a remote target, it’s because gdb is able to read through Dwarf informations and know what to do with the low-level stuff.
You might be surprised to know what there is in the .debug_* sections of your favorite ‘objdump -x’: symbols, paths, sizes …
Directly from your compiler, served to you in a compact and smart way.
Lately, I faced huge embedded softwares, with problems such as shared memory compatibility, and where using Dwarf informations to understang how things are actually working could be interesting.
Well, I did not really found what I was looking for, thinks like dwarfdump are literaly dumping Dwarf informations with little control, and objdump is also too much.
So I wrote this little piece of C++ code which allows you to, mainly, find and dump symbols.
For instance, let’s say you have something like this somewhere in your software:
typedef struct MyStructTag { int x, y; unsigned int z; }MyStruct; #if A # define MYSTRUCT_ARR_SZ 21 #else # define MYSTRUCT_ARR_SZ 100 #endif typedef union AnUnionTag { MyStruct structArray[MYSTRUCT_ARR_SZ]; unsigned int someOtherStuff[10]; } AnUnion; |
Imagine thinks like this built and conditionnalized through hundreds of files.
What is the actual output ? What is the size ?
Simple enough:
./symbol-query ../TestProject/TextProject -o output.xml -q sym AnUnion |
It dumps the “AnUnion” symbol as a tree structure to output.xml, which is something like this:
<root> <query Die="AnUnion"> <union Type="AnUnion" Size="1200"> <array Name="structArray" Count="100"> <structure Type="MyStruct" Size="12"> <base Name="x" Type="MyStruct" Size="4"/> <base Name="y" Type="MyStruct" Size="4"/> <base Name="z" Type="MyStruct" Size="4"/> </structure> </array> <array Name="someOtherStuff" Count="10"> <base Type="unsigned int" Size="4"/> </array> </union> <enums /> </query> </root> |
It also does it quite quickly, since it takes few milliseconds for a 18k struct with about 10000 symbols.
Code is available at:
https://github.com/CoRfr/SymbolQueryTool/
It works on Linux and relies on elfutils/libdw, I’m currently working for a way to make it work on Windows, but didn’t found a way yet.
As usual, a CMake file is provided.
Cheers
Be First to Comment