How to Debug and detect (optimized C++) code

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Debug and detect (optimized C++) code

68 Views
bwinter
Contributor I

I ported a working project to MCUXpresso but not everything seems to work as it should do.
I started to place some breakpoints on points that shouldn't happen and bumped into the following situation:

I have a small piece of code that turns on/off a lamp when there is a connection.
The lamp sometimes went on without a reason, so i ended up placing 3 breakpoints.(Picture A, IDE breakpoints 3x)
1) on the if statement, 2) the "true" result and 3) the "false" result

when stepping through this piece of code ALL 3 breakpoints are(/seem to) executed
looking at the ASM code shows the reason i think. (Picture B, IDE breakpoints ASM 3x)
Code is optimized? merging the code in a way breakpoints make no sense.
(i original only wanted a breakpoint on one of the results but it always stopped so i ended up placeing 3 to see why)

Question:
It seems that only one of the C++ statements is executed but how can i place a real breakpoint in this kinds of situations without having to look at the asm code?
I already had another situation (reading a switch) which never got trapped by an other breakpoint before i placed some __nops around it. (didn't look at asm code)

This kind of behavior makes debugging hard to do.

 

 

 

 

0 Kudos
0 Replies