Hey Community
I look for a method to export all the details of existing structures (location of the fields and padding).
The goal of this is to share variables of our software and their location with other teams, so they can validate the software by reading internal variables or modify control parameters for some other tests.
Currently I am looking the .map file in order to know where the structures and variables are located. I have an Excel file where I put all information manually about the fields of the structures, and with a macro I scan the .map file to export the base address of structs and the variables.
I would like to automatize this. Maybe there exists a configuration, so that the compiler has an output file where it is nicely visible or extractable by another script. Analyse the .map file in order to export the base address of all variables and structures should not be the problem, also not the padding between the variables / structs. But how extract the paddin and alignement inside a structure? And how extract the existing fields of a structure?
Is there a way to do/know this without looking the header files?
I know the good approach should be to define the structures in a way, to have no incertitude about the packing and padding. The problem is that this was not done at the start of the project, also not all of the team members care about such “details” as padding and alignment and the general knowledge of the compiler is not so well (me including).
Details about the system:IDE-Version:µVision V5.20.0.0Copyright (C) 2016 ARM Ltd and ARM Germany GmbH. All rights reserved.Tool Version Numbers:Toolchain: MDK-ARM Standard Cortex-M only: 2 user(s) Version: 5.20Toolchain Path: C:\Keil_v5\ARM\ARMCC\BinC Compiler: Armcc.exe V5.06 update 2 (build 183)Assembler: Armasm.exe V5.06 update 2 (build 183)Linker/Locator: ArmLink.exe V5.06 update 2 (build 183)Library Manager: ArmAr.exe V5.06 update 2 (build 183)Hex Converter: FromElf.exe V5.06 update 2 (build 183)CPU DLL: SARMCM3.DLL V5.20Dialog DLL: DARMCM1.DLL V1.14.0.0Target DLL: Segger\JL2CM3.dll V2.99.20.0Dialog DLL: TARMCM1.DLL V1.10.0.0
Hi again,To specify the fromelf command, use the "After build" section of the settings, similar to:As for your issue, I think I understand. The compiler will by default put each element on it's natural boundary (chars on any byte boundary, shorts on 2-byte boundary, int on 4-byte boundary (0x0, 0x4, 0x8, 0xc...)), with padding betwixt the elements if necessary.If you want to eliminate padding, you can use the packed attribute, either for the entire structure, or specific elements within that structure (ordering of elements within the struct will of course not be affected).
Hi thank you for you explanation. Finally I was able with your help to generate the same output than you showed me in the first reply. But how I thought it is not really what I need.
Ronan Synnott said:As for your issue, I think I understand. The compiler will by default put each element on it's natural boundary (chars on any byte boundary, shorts on 2-byte boundary, int on 4-byte boundary (0x0, 0x4, 0x8, 0xc...)), with padding betwixt the elements if necessary.
Yeah exactly, if I look at the structure I am able to manually determine where he puts padding to align each element on their natural boundary. That is not a problem at all. But to do it automatically is way more challenging for me. Also I want to show all members of every structure (structure type) in a file.
No I don’t want to eliminate padding at all, I will just know, every time I will compile, where the compiler puts padding without doing it manually when something in the definition of a structure changes or even when new structure types are created.
You can get a summary of this by adding --info=sizes to the linker command line (you can also specify multiple with for example --info=sizes,totals).