fast semihosting + segger j-link + ignore if no debugger = no semihosting

Sysprogs forums Forums VisualGDB fast semihosting + segger j-link + ignore if no debugger = no semihosting

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #28384
    davidoz
    Participant

    Hi Support,

    I have an application running on an STM32F0.  I would like it to execute regardless if a debugger is attached.  If a debugger is attached I would like it to send semihosting messages.  I can get that working with the st-link, but not with the Segger j-link.

    If I have this environment, I do get semihosting, but it won’t run without the debugger:
    <table style=”border-collapse: collapse; width: 61.2482%;” border=”1″>
    <tbody>
    <tr>
    <td>Fast Semihosting</td>
    <td>Enabled</td>
    </tr>
    <tr>
    <td>Debugger Probe</td>
    <td>J-Link Attached</td>
    </tr>
    <tr>
    <td>When running without a debugger</td>
    <td>Wait for debugger to attach</td>
    </tr>
    </tbody>
    </table>
     

    If I have this environment, I don’t get any semihosting when the debugger is attached:
    <table style=”width: 67.4342%; border-collapse: collapse; border-style: hidden; height: 59px;” border=”1″>
    <tbody>
    <tr style=”height: 13px;”>
    <td style=”width: 36.6818%; height: 13px; border-style: hidden;”>Fast Semihosting</td>
    <td style=”width: 54.2757%; height: 13px; border-style: hidden;”>Enabled</td>
    </tr>
    <tr style=”height: 23px;”>
    <td style=”width: 36.6818%; height: 23px; border-style: hidden;”>Debugger Probe</td>
    <td style=”width: 54.2757%; height: 23px; border-style: hidden;”>J-Link Attached</td>
    </tr>
    <tr style=”height: 23px;”>
    <td style=”width: 36.6818%; border-style: hidden; height: 23px;”>When running without a debugger</td>
    <td style=”width: 54.2757%; border-style: hidden; height: 23px;”><span style=”text-decoration: underline;”>Ignore profiling/semihosting calls</span></td>
    </tr>
    </tbody>
    </table>
    I’m assuming it is something to do with the J-Link because the st-link works ok.  Is there an easy fix for this issue?

    Cheers

    David

     

    • This topic was modified 4 years, 5 months ago by davidoz.
    • This topic was modified 4 years, 5 months ago by davidoz.
    #28387
    davidoz
    Participant

    Sorry, the tables aren’t working, but it’s suffice to say when the “When running without a debugger”  setting is “Ignore profiling/semihosting calls” and a J-Link is attached then no semihosting messages are received.

     

     

    #28389
    support
    Keymaster

    Hi,

    No problem, we can help you get it working, however we would first kindly ask you to renew your technical support here as it has recently expired.

    #28390
    davidoz
    Participant

    Wow, has it been a year already.  I’ll let you know when the payment is authorised.

    #29005
    davidoz
    Participant

    Hi, I forgot I had this question outstanding.  I believe we’re all paid up again, so do you have any suggestions on how to fix the issue?

    Cheers

    David

    #29006
    support
    Keymaster

    Thanks for renewing your license. We will explain how VisualGDB handles this.

    Please try locating the CanInvokeSemihostingCalls() function in DebuggerChecker.h and searching for all references to it. This function is invoked each time your program tries to write anything via the fast semihosting mechanism. It normally just checks the C_DEBUGEN bit to see if a debugger is attached.

    The easiest way to troubleshoot it is to set a breakpoint in the function and try outputting anything via the printf() call (don’t forget to end the printed line with “\n” as otherwise it will get buffered). Does the CanInvokeSemihostingCalls() get invoked? Does it return true as expected when running under debugger?

    #29161
    davidoz
    Participant

    Hi Support, sorry for late reply.

    When j-link debugger is attached and if “Ignore Semihosting If No Debugger is Attached” is selected, then CanInvokeSemihostingCalls() always returns FALSE.  i.e. the register @ 0xE000EDF0 contains 0x00000000.

    It’s strange because the debugger works – setting breakpoints, single stepping, etc, so it knows it is connected.

     

    Cheers

    David

     

    • This reply was modified 4 years, 1 month ago by davidoz.
    #29169
    support
    Keymaster

    This would make sense if the device did not properly implement the C_DEBUGEN bit in the DHCSR register. You can try double-checking it via the datasheet or the Hardware Registers window (it may not be listed there if the original header files did not mention it).

    If it’s not supported, please consider working around it by adding a custom implementation of CanInvokeSemihostingCalls().

    #29170
    davidoz
    Participant

    The DHCSR register returns 0x00000000 when read (i.e. C_DEBUGEN is 0).  Strangely the memory window shows the register address contains 0x00030003, but when I assign it to a variable it contains 0x00000000.

    I can write a custom CanInvokeSemihostingCalls(), but I don’t have anyway of checking if the debugger is attached either.

    I have seen in a forum the cortex-m0 does not have access to the DHCSR register, but I can’t find any documentation that supports that.  Assuming that is true, they say a BKPT instruction will cause a hard fault to occur if no debugger is attached.  That can be used to determine if it’s attached.  That does mean you will get a breakpoint every time if the debugger is attached.  Doesn’t sound worth the trouble.

     

    Cheers

    David

     

    #29177
    support
    Keymaster

    Thanks for the update, this makes sense. You might be able to work around the inaccessible DHCSR register by creating a global variable (e.g. g_DebuggerAttached) and checking it from the custom CanInvokeSemihostingCalls() implementation. Then you can use gdb scripting to set a breakpoint in some of the functions executed at startup (VisualGDB already sets a breakpoint in main()) and set this variable to 1, once the breakpoint is reached. This would require some non-trivial scripting, but should achieve the same effect as the DHCSR register.

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.