Hello there,
I'm looking into the possibilities to get a list of all global and static variables that are in my application, with their name, size, and address.
The .map file provides some info, but not for static variables. I had a look at tools like readelf, objdump, dwarfdump, but as far as I can see they can't produce the list I need.
Then I found the TI nm2000 tool which seems to provide the information I need. When I test with this code:
typedef struct { uint32_t ui32; uint16_t ui16; uint8_t ui8; } T_TEST_STRUCT; uint8_t Test_ui8_glob; uint8_t Test_ui8_glob_init = 0; static uint8_t Test_ui8_stat; static uint8_t Test_ui8_stat_init = 0; uint16_t Test_ui16_glob; uint16_t Test_ui16_glob_init = 0; static uint16_t Test_ui16_stat; static uint16_t Test_ui16_stat_init = 0; uint32_t Test_ui32_glob; uint32_t Test_ui32_glob_init = 0; static uint32_t Test_ui32_stat; static uint32_t Test_ui32_stat_init = 0; T_TEST_STRUCT Test_struct_glob; T_TEST_STRUCT Test_struct_glob_init = { 0, 0, 0 }; static T_TEST_STRUCT Test_struct_stat; static T_TEST_STRUCT Test_struct_stat_init = { 0, 0, 0 };
And then run "nm2000 -l mytest.out", I get this result:
[index] value size bind type vis shndx symbol name ... ... [25332] |0x200100ac|8|GLOB |COMN |HIDN |14 |Test_struct_glob [25334] |0x20010830|8|GLOB |OBJT |HIDN |13 |Test_struct_glob_init [83] |0x2001008c|8|LOCL |OBJT |HIDN |14 |Test_struct_stat [84] |0x20010838|8|LOCL |OBJT |HIDN |13 |Test_struct_stat_init [25330] |0x2001011e|2|GLOB |COMN |HIDN |14 |Test_ui16_glob [25341] |0x20010746|2|GLOB |OBJT |HIDN |13 |Test_ui16_glob_init [79] |0x2000feda|0|LOCL |OBJT |HIDN |14 |Test_ui16_stat [80] |0x20010748|2|LOCL |OBJT |HIDN |13 |Test_ui16_stat_init [25331] |0x200100cc|4|GLOB |COMN |HIDN |14 |Test_ui32_glob [25342] |0x2001074c|4|GLOB |OBJT |HIDN |13 |Test_ui32_glob_init [81] |0x2000fedc|0|LOCL |OBJT |HIDN |14 |Test_ui32_stat [82] |0x20010750|4|LOCL |OBJT |HIDN |13 |Test_ui32_stat_init [25329] |0x20010123|1|GLOB |COMN |HIDN |14 |Test_ui8_glob [25339] |0x20010744|1|GLOB |OBJT |HIDN |13 |Test_ui8_glob_init [77] |0x2000fed8|0|LOCL |OBJT |HIDN |14 |Test_ui8_stat [78] |0x20010745|1|LOCL |OBJT |HIDN |13 |Test_ui8_stat_init ... ...
Most of this is OK, except when a variable is defined as static and not initialized. Then the size appears as 0. In all other cases the correct size is shown, even for an uninitialized static struct.
What is the cause of this behavior?
Also, what is the meaning of the nm2000 output fields 'index', 'vis', and 'shndx'? I couldn't find any documentation about it.
Other than the issue with uninitialized static variables, the nm2000 tool seems to fulfill my requirements. But if you have any suggestions for other tools that could do the same, please let me know.
Thanks and kind regards,
Arjan