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.

CCS: Adding Local Variables to Debug / Expressions list?

Other Parts Discussed in Thread: TMS320F28377D

Tool/software: Code Composer Studio

How can I add variables that are in a function to the Debug / Expressions list?

I have no problem adding and removing global variables to the Expressions watch window.  I have no problem changing the format of global variables to the Expressions watch window.

I really need to monitor local variables that exist only in a function.  I can make them global for debug purposes, but that is time consuming and prone to errors.  And what if the function is in a header file.

I see a variables watch window, but it seems to be useless.

Any help would be greatly appreciated.

I am using CCS Version: 6.2.0.00050.

  • John,

    What device are you using?  Do you have the optimizer turned on?

    In general both the Expressions view and Variables view should be able to show local variables if they are in scope.  If the optimizer is turned on there is a good chance that they are being optimized out.

    Does it ever work or just not for some variables?

    Regards,

    John

  • I am using a TMS320F28377D Delfino DSC with an XDS100v2 USB JTAG Emulator.

    Optimization level is OFF.

    I have been working with Code Composer Studio for about a year and there is still a lot I do not know.

    I do not understand what you mean by "if they are in scope".

    Global Variables, those declared outside of a function, always work in the expressions list.

    I have never been able to see a local variable, declared inside of a function, in either the expressions or variables windows.

  • John,

    By in scope I mean is the program counter in the function where the variable is in scope:

    Here I am in main() so i and j and in scope but c is not:

    Here I am in john() so c and count are in scope but i and j are not:

    The global variable is always in scope as it is allocated in data memory.  The local variables are on the stack and only available when in scope.

    Is there a project that you can share that shows the problem you are seeing? 

    Regards,

    John

  • I have read Debug Handbook for CCS, and GSG:Debugging projects v5 and I have not seen the method you are describing.  No information about program counter.

    When I place a breakpoint in my function I see variables without names or values. But I am able to add local variable to expression list.

    When I suspend the program I do not have access to the functions

    Where can I find more information about placing program counter?

  • The program counter or PC is a register that contains the address that the CPU is currently executing.
    whatis.techtarget.com/.../program-counter

    When debugging a C program that address will typically map to a line in a source file. CCS will show an arrow on the left hand side of the editor marking the line about to be executed. i.e. from my last post the first capture the PC is on line 12 and in the second on line 6.

    Looking at your capture the callstack shows that you are halted somewhere inside the F2837xD_usDelay.asm file. You are not going to be able to see any local C variables when you are halted at this location.

    What happens if you set a breakpoint on line 58 in ethernet_test_v105.c, then reload the program and run? In general when you launch your debugger is it halting at main automatically?

    John
  • So I have to set a breakpoint and halt the program to look at local variables?

    Yes, I am using "DELAY_US();" a lot and it usually stops there if I suspend the program.

    When I launch the program it halts at MAIN automatically as shown below. But the Variables list does not show name or value, only (x)=

    The first picture from my last post showed the Variables list when I placed a breakpoint in my function "Read_Data".  When I did that I could add the local variables to the Expressions list.

  • Are you able to add i to the Expressions view when you are at that line?

    If not if you step a couple more lines (i.e. to line 58) does it work then?

    Note that i is never initialized in your code so step is going to have a random value. Does it get used in the code? Try changing the line to int i =0;



    "So I have to set a breakpoint and halt the program to look at local variables?"

    You need to be halted at a point where the variables are in scope. If not then you will not be able to see them. So you can either set a breakpoint in the function where you wish to inspect the variables or you can step into it.
  • Yes, I am able to add i to the expressions view

    OK, I understand how to view local variables now. I would really like to monitor while program is running, but I think that is not possible.

    I do not understand why the Variables view is not showing names or values, but I guess I do not need if I can add to Expressions view.

    Thank you for your help.
  • I was able to make my variables view look like yours.

    Try the following to fix the variables view.

    Click the down arrow on the menu bar

    click on 

    Layout-> show columns

    That should add the columns back

    Regards,

    John

  • That worked!

    Thanks again.