Skip to main content
temp2010
Associate III
November 26, 2019
Question

Funky source code stepping in debug mode

  • November 26, 2019
  • 4 replies
  • 1717 views

I know about optimizers and I've been debugging MCUs for many decades. But this behavior is just too weird and difficult to deal with...

I'm using Atollic TrueSTUDIO 9.3.0. When I debug my code and single step through the C source code, the highlighted green line (aka "green cursor") steps in all kinds of crazy order. Consider a block of assignment statements followed by a function call, and then another block and call. The green cursor jumps around in random order through the block of assignments, and then finally gets to the function call. Then I can step over or into/out of the function and go to the next block of assignment statements. However, it's not that clear cut. The green cursor will be on the function call, and I'll click the toolbar button to step into the function. Instead of stepping into the function, the green cursor jumps back to an earlier assignment statement. The some of the assignment statement appear to get executed multiple times, and the green cursor is on the function call multiple times, before the step into actually steps into the function.

All this makes it very difficult to debug things. I can't be sure of what's going on. The green cursor even goes through BOTH clauses of an if/else structure, LOL.

Is there a way to prevent this crazy behavior?

Thanks!

This topic has been closed for replies.

4 replies

Pavel A.
Super User
November 26, 2019

So you wrote you know about optimizers, eh? Tried to disable the optimization (-O0) ? Or, try -Og option (optimize for debugging). TL;DR.

-- pa

Tesla DeLorean
Guru
November 26, 2019

To get linear code turn optimization off. The C-to-ASM relationship with optimization can be more scattered but there is only one pointer (not one to many dispersed)

The CM0(+) can be harder to single-step, lacking some debug hw in higher functioning cores.

The earlier CM7 also have issues, but F72x/F73x and H7 devices use a newer core. As I recall the F76x/F77x don't have the original core.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
temp2010
temp2010Author
Associate III
November 26, 2019

Thanks, Pavel & Mr. Avogadro. Indeed, when I turn off optimization, the problem clears up. I thought it might be due to optimization, but I've NEVER before seen that extreme a mixup of sequencing, which is why I asked. Thinking further, there must be minor assembly code happening near the curly braces of C source code for if/else blocks, that cause the GUI to show the green cursor alternately in BOTH blocks. Were it an assy listing, it probably would not behave so apparently weird. Similar for function calls.

BTW, Mr. Avogadro, in confirming your suspected identity, I ran into something interesting. Wikipedia and Brittanica give you different values! I'm surprised to see that.

https://en.wikipedia.org/wiki/Avogadro_constant

https://www.britannica.com/science/Avogadros-number

Tesla DeLorean
Guru
November 26, 2019

I just copied and pasted from an interwebs source, Jan and I (Clive) were getting a bit annoyed at ST's use of User157.. as a default user name and our inability to easily differentiate one user from the next.

What STM32 part are you having issues with?

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
temp2010
temp2010Author
Associate III
November 27, 2019

STM32F105R8T6.