This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler: dwarf die for function static variable

Tool/software: TI C/C++ Compiler

Hi,

how can I find dwarf debug Information (address, type) for function static variables in .out files?

I can find this information on all other variables anchored at tag DW_TAG_variable by scanning all compile units in .debug_info. 

thx,

Dieter

  • I presume you mean a static variable that is defined inside a function, and not at file scope.

    A static variable is yet another DW_TAG_variable inside the function.  The only difference is the DW_AT_location attribute.

    Consider this contrived function ...

    int fxn(int argument_variable)
    {
       static int static_variable = 0;
       int local_variable = argument_variable;
    
       ++static_variable;
       return static_variable + local_variable;
    }

    You don't say which TI compiler you use.  For now, I presume you use the TI ARM compiler.  These commands build it, then use the OFD utility to capture the .debug_info Dwarf information in a text file named dw.txt.

    % armcl -s --opt_level=off -mv7m3 file.c
    % armofd -g --obj_display=none --dwarf_display=none,dinfo file.obj > dw.txt

    Then inspect dw.txt and find these lines ...

        000000c2   4       DW_TAG_variable (.data)
        000000c3              DW_AT_location       DW_OP_addr 00000000
        000000c9              DW_AT_name           static_variable
        000000dd              DW_AT_TI_symbol_name static_variable$1
        000000ef   1       DW_TAG_formal_parameter (.text)
        000000f0              DW_AT_location       DW_OP_reg0
        000000f2              DW_AT_name           argument_variable
        00000108              DW_AT_TI_symbol_name argument_variable
        0000011a   4       DW_TAG_variable (.text)
        0000011b              DW_AT_location       DW_OP_breg13 0
        0000011e              DW_AT_name           argument_variable
        00000134              DW_AT_TI_symbol_name argument_variable
        00000146   4       DW_TAG_variable (.text)
        00000147              DW_AT_location       DW_OP_breg13 4
        0000014a              DW_AT_name           local_variable
        0000015d              DW_AT_TI_symbol_name local_variable

    They are all similar, except for the DW_AT_location attribute.

    Thanks and regards,

    -George

  • I'm using C2000 cgtools v18.1.3.
    I created the dwarf listing via ofd2000 and found the solution for my Problem:
    static variables in functions are "hided" behind DW_TAG_subprogram tags.
    Thx,
    Dieter