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.

TMS320F28335: local variable name and stack offset number

Part Number: TMS320F28335


Hi, Is there a utility, or complier option or any known method to view local variable names and their stack offset number within a function? I can do it manually by counting through the order in which the local variables were declared and assign them consecutive numbers that hopefully match those that I see in the assembled code. It seems the compiler does exactly that and then gives them that number as their stack offset. But this manual method is very tedious and prone to human error. Given that the compiler works it out anyway then it seems obvious that the local variable name and its stack offset number exists somewhere already in the background. Thanks

  • the local variable name and its stack offset number exists somewhere already in the background

    Yes.  It is in the debug information.  I'll illustrate with a contrived example.

    For this source file ...

    /* file.c */
    
    void init(int *, int *, int *);
    
    int fxn()
    {
       int aaa, bbb, ccc;
    
       init(&aaa, &bbb, &ccc);
    
       if (aaa)
          return bbb;
       else
          return ccc;
    }

    Use these commands to build it, then collect the debug information in a text file named file_ofd.txt.

    cl2000 file.c
    ofd2000 -g --obj_display=none --dwarf_display=none,dinfo -o=file_ofd.txt file.obj

    To learn more about the OFD utility ofd2000, please search for it in the C28x assembly tools manual.

    Here are some keys lines from file_ofd.txt ...

        000002e0   7       DW_TAG_variable (.text)
        000002e1              DW_AT_location       DW_OP_breg20 -3
        000002e4              DW_AT_name           aaa
        000002ec              DW_AT_TI_symbol_name _aaa
        000002f1   7       DW_TAG_variable (.text)
        000002f2              DW_AT_location       DW_OP_breg20 -4
        000002f5              DW_AT_name           bbb
        000002fd              DW_AT_TI_symbol_name _bbb
        00000302   7       DW_TAG_variable (.text)
        00000303              DW_AT_location       DW_OP_breg20 -5
        00000306              DW_AT_name           ccc
        0000030e              DW_AT_TI_symbol_name _ccc

    This shows that aaa is located at *-SP[3], bbb at *-SP[4], and ccc at *-SP[5].

    If you are are considering writing a utility to extract and format this information ... This same information can be obtained in XML format by using the ofd2000 -x option.  Example scripts which use this XML information can be found in the Code Generation Tools XML Processing Utilities.  Unfortunately, there is no existing script which works with the debug information for local variables.

    Thanks and regards,

    -George

  • Thanks so much George for your effort. I had already tried ofd2000 to no avail (sorry I did not mention that) and the extract above is what I can do already, that is what I meant by doing it manually. Yes it's fine when there are only a few variables but when you have a few hundred (in each function) it gets very tedious and difficult. It is especially difficult for what I am trying to do which is compare two old hex files (with only one lot of source code) and trying to reverse engineer where changes were made. In other words when I see a stack offset for a local variable I am not sure if it is the same variable in each of the hex files or if they have different offsets because one of the hex files had another variable added (or removed). Clear as mud. Anyway I will keep slogging away.  Thanks again.