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.

Check if debugger is attached.

Other Parts Discussed in Thread: MSP430F5510, MSP-EXP430F5529LP

Hi all,

(Windows 7 64-bit, CCSv6.0.1.00040, MSP430F5510, MSP-FET430UIF)

Is there a way to check if there is a debugger attached and perform a function call only if there is.

Basically I can programme my MP430F5510 either using the .hex file or by using CCS whilst debugging and I only want to perform a certain function if I am debugging using CCS.

I know I can change the build configuration to Release or Debug and have a #define but I'm hoping for a cleaner way just in case I, or somebody else, forgets to change it.

Thank you,
Callum

  • Callum Dunster said:
    Is there a way to check if there is a debugger attached and perform a function call only if there is.

    A similar question was asked in MSP430 detect attached debugger from the code, but there doesn't appear a way of automatically detecting when a debugger is attached.

    Callum Dunster said:
    Basically I can programme my MP430F5510 either using the .hex file or by using CCS whilst debugging and I only want to perform a certain function if I am debugging using CCS.

    One possible method may be to:

    a) Add a global variable, say called debugger_connected, which is initialized to zero in the loaded program.

    b) The program tests the "debugger_connected" global variable to decide it to perform the function only required when debugging.

    c) When the .hex file is programmed (outside of a CCS debug session) the "debugger_connected" variable will remain at zero.

    b) When debugging in CCS, use a GEL file in the Target Configuration, where the GEL file has a OnFileLoaded() function which sets the "debugger_connected" variable to one. This should occur before the program is started under the debugger control.

    [Note that I haven't tested this idea myself]

  • Hi Chester,
    Thank you for your reply.

    This sounds like exactly what I want although I can't get it to work.
    I have read through the SPRAA74A documentation and some other examples, the GEL file is set to run on startup in the Target Configuration and I have defined the function OnFileLoaded(int nErrorCode, int bSymbolsOnly) and within this function I set the variable to 1. The variable is defined globally in my main file. However the variable never changes and thus is always 0.

    Do you have any hints on how to correctly use GEL files as I haven't used them before.

    Thank you,
    Callum
  • Callum Dunster said:
    However the variable never changes and thus is always 0.

    Having thought about this again my original suggestion of using OnFileLoaded to set a global variable was flawed. This is because while OnFileLoaded can set the value of a global variable, that is undone when the C run-time library start-up code gets to run.

    An an alternative I found the OnHalt GEL callback can be used to set a global variable, when the target halts at entry to the main() function which is the default behavior when debugging. The following GEL file was used to set a global variable called debugger_connected:

    int debugger_connection_selected;
    int file_loaded;
    
    OnFileLoaded(int nErrorCode, int bSymbolsOnly)
    {
    	debugger_connection_selected = 0;
    	file_loaded = 1;
    }
    
    OnHalt ()
    {
    	if (GEL_IsConnected() && file_loaded && !debugger_connection_selected)
    	{
    		debugger_connection_selected = 1;
    		debugger_connected = 1;
    		GEL_TextOut ("debugger_connected has been set true\n");
    	}
    }

    My example CCS 6.1 project is attached MSP430F5559_detect_debugger.zipThis is for a MSP-EXP430F5529LP. When the program is run without the debugger, it flashes the green LED. When started in a CCS debugger it flashes the red LED, trigger via the GEL file which sets the debugger_connected global to one.