I'm writing tools for debugging Cortex-M and I have discovered an artefact when reviewing the DWARF .debug_info
section which the armcc outputs for some C source. (The exact compiler is ARM Compiler 5.05.)
For example when the C source contains a simple function such as:
int function(int a)
{
int x;
int y;
I have discovered that the .debug_info
describes the x and y local variables as expected, and additionally a "hidden variable" called __result
as follows:
<2><218>: Abbrev Number: 94 (DW_TAG_variable)
<219> DW_AT_name : __result
<222> DW_AT_type : DW_FORM_ref2 <0x188>
<225> DW_AT_location : 1 byte block: 50 (DW_OP_reg0 (r0))
<227> DW_AT_start_scope : 64
<228> DW_AT_artificial : 1
The clue of the "hidden" nature of this "variable", being the presence of the DW_AT_artificial
flag.
I've have read the DWARF documentation regarding the DW_AT_artificial
flag, which confirmed by suspicions. I've also deduced by experimentation that this feature relates to return value which this function, since this "variable" does not appear in the DWARF for a void
typed function.
What I cannot find is any confirmation of this entity's use as intended by the designers of the armcc
toolchain. Can anybody elaborate on the meaning and usage of my discovery?