Im using ARM-GCC 4.7.4 to compile code for Cortex-M4. For our Debug tool, I need knowledge of the names, types, and addresses of all variables in a humanoid format (e.g. .txt). The map file provides most of the information, unfortunately, not for the contents of the structure, as shown below:
typedef struct { float32_t Ref;
float32_t Fdb;
float32_t Err;
float32_t Kp;
float32_t Up;
float32_t Ki;
float32_t Ui;
float32_t OutPreSat;
float32_t OutMax;
float32_t OutMin;
float32_t Out;
} PI_REG;
PI_REG BU_Uctrl_Udc_PI_Reg = BU_UCTRL_UDC_PI_REG_INIT;
So I tried the nm, readelf and objdump tools to get something from the .elf file, which was compiled with the -g3 option in dwarf-2 format. Only with objdump could I find the information I was looking for:
objdump –Wi myfile.elf >symbols.txt
The following typedef PI_REG information can be found in symbol.txt:
<1><38883>: Abbrev Number: 2 (DW_TAG_base_type)
<38884> DW_AT_byte_size : 4
<38885> DW_AT_encoding : 4 (float)
<38886> DW_AT_name : (indirect string, offset: 0x2c63e): float
<1><38891>: Abbrev Number: 11 (DW_TAG_typedef)
<38892> DW_AT_name : (indirect string, offset: 0xb336d): float32_t
<38896> DW_AT_decl_file : 4
<38897> DW_AT_decl_line : 370
<38899> DW_AT_type : <0x38883>
<1><390d7>: Abbrev Number: 14 (DW_TAG_structure_type)
<390d8> DW_AT_byte_size : 44
<390d9> DW_AT_decl_file : 6
<390da> DW_AT_decl_line : 26
<390db> DW_AT_sibling : <0x39176>
<2><390df>: Abbrev Number: 16 (DW_TAG_member)
<390e0> DW_AT_name : Ref
<390e4> DW_AT_decl_file : 6
<390e5> DW_AT_decl_line : 26
<390e6> DW_AT_type : <0x38891>
<390ea> DW_AT_data_member_location: 2 byte block: 23 0 (DW_OP_plus_uconst: 0)
<2><390ed>: Abbrev Number: 16 (DW_TAG_member)
<390ee> DW_AT_name : Fdb
<390f2> DW_AT_decl_file : 6
<390f3> DW_AT_decl_line : 27
<390f4> DW_AT_type : <0x38891>
<390f8> DW_AT_data_member_location: 2 byte block: 23 4 (DW_OP_plus_uconst: 4)
[structural elements with offsets of 6-32 left]
<2><39159>: Abbrev Number: 15 (DW_TAG_member)
<3915a> DW_AT_name : (indirect string, offset: 0xc1d9a): OutMin
<3915e> DW_AT_decl_file : 6
<3915f> DW_AT_decl_line : 35
<39160> DW_AT_type : <0x38891>
<39164> DW_AT_data_member_location: 2 byte block: 23 24 (DW_OP_plus_uconst: 36)
<2><39167>: Abbrev Number: 16 (DW_TAG_member)
<39168> DW_AT_name : Out
<3916c> DW_AT_decl_file : 6
<3916d> DW_AT_decl_line : 36
<3916e> DW_AT_type : <0x38891>
<39172> DW_AT_data_member_location: 2 byte block: 23 28 (DW_OP_plus_uconst: 40)
<1><39176>: Abbrev Number: 3 (DW_TAG_typedef)
<39177> DW_AT_name : (indirect string, offset: 0xc00d0): PI_REG
<3917b> DW_AT_decl_file : 6
<3917c> DW_AT_decl_line : 37
<3917d> DW_AT_type : <0x390d7>
<1><3c348>: Abbrev Number: 29 (DW_TAG_variable)
<3c349> DW_AT_name : (indirect string, offset: 0xc3ece): BU_Uctrl_Udc_PI_Reg
<3c34d> DW_AT_decl_file : 1
<3c34e> DW_AT_decl_line : 40
<3c34f> DW_AT_type : <0x39176>
<3c353> DW_AT_external : 1
<3c354> DW_AT_location : 5 byte block: 3 fc 67 0 20 (DW_OP_addr: 200067fc)
, . BU_Uctrl_Udc_PI_Reg, :
Find an entry called "DW_TAG_variable" and gather following information:
------------------------------------------------------------------------
- DW_AT_name: The name is BU_Uctrl_Udc_PI_Reg
- DW_OP_addr: Base address is 200067fc
- DW_AT_type: The data type can be found at line 39176
Search line 39176 and gather following information:
-----------------------------------------------------
- It is a typedef (DW_TAG_typedef)
- DW_AT_name: The typedef name is PI_REG
- DW_AT_type: The definition can be found at line 390d7
Search line 390d7 and gather following information:
---------------------------------------------------
- It is a structure (DW_TAG_structure_type)
- DW_AT_byte_size: It is 44 bytes wide
Search the structure Members in upcoming lines until 44 bytes are reached:
--------------------------------------------------------
1. Member (DW_TAG_member):
- DW_AT_name: Ref
- DW_AT_data_member_location: 200067fc + 0
- DW_AT_type: The data type can be found at line 38891:
- DW_TAG_typedef: float32_t
- DW_AT_type: The data type can be found at line 38883:
- DW_TAG_base_type: float
- DW_AT_byte_size: 4 bytes
2. Member (DW_TAG_member):
- DW_AT_name: Fdb
- DW_AT_data_member_location: 200067fc + 4
- DW_AT_type: The data type can be found at line 38891:
- DW_TAG_typedef: float32_t
- DW_AT_type: The data type can be found at line 38883:
- DW_TAG_base_type: float
- DW_AT_byte_size: 4 bytes
[left out Members 3-9]
10. Member (DW_TAG_member):
- DW_AT_name: OutMin
- DW_AT_data_member_location: 200067fc + 36
- DW_AT_type: The data type can be found at line 38891:
- DW_TAG_typedef: float32_t
- DW_AT_type: The data type can be found at line 38883:
- DW_TAG_base_type: float
- DW_AT_byte_size: 4 bytes
11. Member (DW_TAG_member):
- DW_AT_name: Out
- DW_AT_data_member_location: 200067fc + 40
- DW_AT_type: The data type can be found at line 38891:
- DW_TAG_typedef: float32_t
- DW_AT_type: The data type can be found at line 38883:
- DW_TAG_base_type: float
- DW_AT_byte_size: 4 bytes
, script, , , , . , , , script. ? , - objdump, , , ? - , ? ( , , , , .elf):
0x200067fc float BU_Uctrl_Udc_PI_Reg.Ref
0x20006800 float BU_Uctrl_Udc_PI_Reg.Fdb
[…]
0x20006832 float BU_Uctrl_Udc_PI_Reg.OutMin
0x20006836 float BU_Uctrl_Udc_PI_Reg.Out
Fromelf http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0477c/index.html ( Keil μVision) --text , , , , , -, .elf .axf, Arm, . , .
.