Breakpoints not working as expected.

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm having a problem with Breakpoints in AVR Studio. On many ocassions I get a message that says something like this: "One or more breakpoints could not be set...."

Now when I set a breakpoint in the code below AVR Studio moves the brakpoint down a few lines as shown in the code. What is going on? I could use some help why this is happening.

		if(BitTime > MaxWaitBit)
		{
			Done = 0x01;   // <- I PUT THE BREAKPOINT ON THIS LINE!
		}
		else
		{
			NumBits = NumBits + 1; // <- THE BREAKPOINT GOES ON THIS LINE!
		}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you are compiling with optimization activated then theese kinds of phenomenon occur. Ther is no clear 1:1 mapping between the source code and the machine code. You have two options:

1) Switch off the optimization, which will make your application behave slightly different (timing, instruction sequences), or
2) trace/break in a disassembly window (which requires that you have a bit of understanding of AVR assembler)

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks JohanEkdahl.

Regarding turning off compiler optimization...

The Win AVR Manual says that optimization is set like this:

Quote:

You will also see a optimization level as well. This is how well the compiler will optimise the code, and
legal levels are 0 (no optimization), 1, 2, 3, and s. Each level is different, and level 3 is not always the best. Each level will perform different tasks on the code in order to make it as fast and small as possible (except level 0, which does nothing). If you use level 3 it is most likely to create the largest code size, but also may create the fastest. Level s is an optimization for code size, but is a good all-around level.

OPT = s


However; when I look at how AVR Studio is passing the optimization parameters to the compiler the closest thing I can see looks like this:
Quote:

-0s

I'm assuming that they are bot the same and to turn of compiler optimization I would just do the following
Quote:

-O0 //the letter "O" followed by the number zero

Or I could just delete that option all together and the default would be no optimization?

Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Open the "Configuration Options" and change the optimization level there.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But Johan's (2) is a far better idea than (1) anyway. If you are going to use an optimizing compiler get used to debugging the optimized code - i's a far better idea than handicapping the whole operation of your code just to be able to debug it a little easier.

Although not a great idea you could also make 'Done' a volatile variable so that code is generated that you can breakpoint more easily.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm gonna use Johan's idea (2) as my long term solution once I get a little more AVR ASSY under my belt. For the immediate I used idea (1) to turn off optimization, debugged my logic problem and then turned optimization back on. I know this is sort of "cheesy" because the final code is not what I degugged but for this immediate issue where I had a problem with the algorithm logic it appears to have worked.

As always, thanks for the help guys!