Hi all,

I need some clarification regarding the debug information generated
for var_args function. I am working with GCC 4.1.1. In my target,
var_args registers are saved in stack frame during function prologue
(similiar to fr30).

### sample program ###

#include <stdio.h>

int fun(const char *temp,...)
{
 return 9;
}

int main()
{
 fun("Hello World",1,2);
 return 0;

}

#####      objdump    #######

SP - stack pointer
FP - Frame Pointer

00000294 <_fun>:
    294:        STR  D3,-(SP)
    296:        STR  D2,-(SP)    // value '2'
    298:        STR  D1,-(SP)   // value '1'
    29a:        STR  D0,-(SP)  // value representing variable "temp",
address of Hello World
    29c:        STR  FP,-(SP)
    29e:         MOV  SP,FP
    2a0:         MOV 0x9,D0
    2a2:         LDR  (SP)+,FP
    2a4:         ADD 0x10,SP
    2a6:         RTS

##### readelf output #######

<1><102>: Abbrev Number: 6 (DW_TAG_subprogram)
    DW_AT_sibling     : <130>
    DW_AT_external    : 1
    DW_AT_name        : fun
    DW_AT_decl_file   : 10
    DW_AT_decl_line   : 4
    DW_AT_prototyped  : 1
    DW_AT_type        : <52>
    DW_AT_low_pc      : 0x294
    DW_AT_high_pc     : 0x2a8
    DW_AT_frame_base  : 0  (location list)

<2><11f>: Abbrev Number: 7 (DW_TAG_formal_parameter)
    DW_AT_name        : temp
    DW_AT_decl_file   : 10
    DW_AT_decl_line   : 3
    DW_AT_type        : <b8>
    DW_AT_location    : 2 byte block: 91 0   (DW_OP_fbreg: 0)

Contents of the .debug_loc section:

   Offset        Begin         End        Expression
   00000000 00000294 00000296 (DW_OP_regSP)
   00000000 00000296 00000298 (DW_OP_bregSP: 4)
   00000000 00000298 0000029a (DW_OP_bregSP: 8)
   00000000 0000029a 0000029c (DW_OP_bregSP: 12)
   00000000 0000029c 0000029e (DW_OP_bregSP: 16)
   00000000 0000029e 000002a0 (DW_OP_bregSP: 20)
   00000000 000002a0 000002a8 (DW_OP_bregFP: 20)
   00000000 <End of list>

From the debug info generated, frame base for "fun" starts from 0x00.
The corresponding location expression for "temp"  in address range
0x294 -0x296 is SP (Stack Pointer). But at that instant, it is not
correct.

The value of "temp" is in register D0 which gets stored in stack only
when instruction at 0x29a is executed. Until then this value is
undefined. Is it right?

Is this the right behavior or am i missing something?

Regards,
Rohit

Reply via email to