2021-09-06 06:18 PM
When I start the debugger of my program (c++), a function gets called even before
the debugger halts at first default breakpoint (usually at HAL_Init).
The name of this function is getElapsed (returns double, no parameters) and its a
public member function of my custom class named Clock. The funny thing is that if
I rename the function (for example getElapsedEx) then it does not get called anymore.
Additional information:
- It exists a global object of Clock but there are no member calls in global scope.
- I think this strange call just happens when using the debugger.
- I identified the strange function call by placing a breakpoint at the beginning of the
function body before I start the debugger.
- Microcontroller: STM32H743VIT
How is it possible that a function gets called even before the first default breakpoint?
And why does it change the behavior if I change the name of the function? Linker problem?
Solved! Go to Solution.
2021-09-08 02:21 AM
Hello @KKase.1 ,
When the debugger is out-of-sync with the expected execution behavior then the most common issue is that the user does not have the intended binary loaded in the target device.
It could be the case that the flash operation failed. Then GDB might have loaded the symbols from a new/modified elf file, while an old binary is still executing in flash.
To test this hypothesis do this:
2021-09-07 03:16 AM
Unlikely to be a linker issue. More likely to be an IDE display bug or a software bug. What is the call stack when it hits that point and where does it go if you single step through?
2021-09-08 02:21 AM
Hello @KKase.1 ,
When the debugger is out-of-sync with the expected execution behavior then the most common issue is that the user does not have the intended binary loaded in the target device.
It could be the case that the flash operation failed. Then GDB might have loaded the symbols from a new/modified elf file, while an old binary is still executing in flash.
To test this hypothesis do this:
2021-09-08 07:03 AM
Thanks for your answers.
I renamed the function and kept on programming. Now when I rename it back, the problem does not occur anymore.
@TDK It was not an IDE display bug, because the function call caused a hard fault error because it was reading an uninitialized timer.
@Markus GIRDLAND But if I remember correctly, it always printed "Download verified successfully" when I ran the debugger.
But now when I think about the flash, I feel like sometimes the program does not get uploaded correctly. I uploaded the same program twice and it showed different behavior. Therefore when I implement something critical I always upload it multiple times, because I want to be sure it uploaded correctly (even though it shows "Download verified successfully" in the console).
I use the ST-Link programmer from the NUCLEO-F446RE to program my custom board. Might I have a problem with the programmer?
2021-09-09 02:11 AM
If you want to be sure I would probably recommend the second bullet in my answer above, using the monitor flash mass_erase which shouldn't leave any possibility for old binary being left running on target.
2021-09-09 05:18 PM
@Markus GIRDLAND Where are the commands like "monitor flash mass_erase" documented? How one can discover them?
2021-09-10 12:54 AM
Hello @Pavel A. ,
The documentation from STM32CubeIDE's perspective is mentioned in the User Guide (UM2609) where the chapter covering the startup tab (chapter 3.2.4) mentions what commands can be used as:
"...any kind of GDB or GDB server monitor commands if there is any special need to send some commands to the GDB server before load commands are sent."
So that leads to the next part of your question, where to find them. We have a "Quick Reference Card" document and a "Debugger - Debugging with GDB" document that's packaged with the installer and available in the Information Center. However, as the User Guide document mentions, any GDB or GDB server monitor commands should work if you have another document in mind.
2021-09-10 02:03 PM
Thank you
2021-09-10 07:23 PM
If your code starts to act differently between runs comes multiple bugs phase. Stack size, project copied to a new folder but editor keeps opened older source files, startup function and linker file incorrect. As soon as the debug misbehave find the root cause and remedy.