"When running without debugger" option doesn't work as intended

Sysprogs forums Forums VisualGDB "When running without debugger" option doesn't work as intended

This topic contains 3 replies, has 2 voices, and was last updated by  support 1 week, 3 days ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #25769

    Gordon01
    Participant

    If I choose the option “Ignore profiling/semihosting calls” semihosting always disabled even if the debugger is attached.

    Looks like CanInvokeSemihostingCalls() from DebuggerChecker.h needs more robust check.

    Micro is STM32L071

    #25776

    support
    Keymaster

    Hi,

    We have indeed not checked this functionality with STM32L071, so it is possible that this MCU simply does not implement the “debugger attached” bit. Please try checking the DEBUGEN bit in the DHCR register either via the Hardware Registers window, or manually. Please also check the STM32 documentation for details on this. If this particular MCU does not implement a ‘debugger attached’ bit, the automatic enabling/disabling of semihosting based on it will indeed not work.

    #25786

    Gordon01
    Participant

    Oh, It’s not so clear from the first try.

    Cortex-M0+ doesn’t allow to read core debug registers from software at all! https://community.st.com/s/question/0D50X00009XkbSDSAZ/detect-debugger-connected-to-stm32l0-

    #25794

    support
    Keymaster

    No problem and thanks for checking this.

    Looks like the default implementation of CanInvokeSemihostingCalls() will indeed not work in this scenario, however you should be able to work around it using some advanced scripting:

    1. Define a global variable (e.g. int g_DebuggerAttached).
    2. Create an implementation of CanInvokeSemihostingCalls() that will check the global variable and set the “When running without debugger” setting to “Use a custom function to decide”.
    3. Create a noinline function with a “nop” statement and call it from main()
    4. Create a GDB script file that will add a breakpoint in the empty function and run the “set g_DebuggerAttached 1” command when the breakpoint is hit (see this page for details).
    5. Add “source <gdb script file>” to VisualGDB Project Properties -> GDB Commands -> Commands after selecting target.

    This won’t be as flexible as using the ARM Cortex registers (e.g. it won’t detect when a debugger is detached after starting the program), however it should allow distinguishing between starting a new debug session and just resetting the device without a debugger.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.