MPLAB Breakpoints

Thread Starter

mpuvdd

Joined Feb 11, 2007
50
I'm having trouble getting my breakpoints to work in MPLAB. I place them were I want them, turn on the MPLAB SIM, press play, and I get an error saying that one or more breakpoints could not be resolved. How do I fix this? They've worked before in the exact same places. It won't work for neither C nor assembly languages.
Thanks,
mpuvdd
 

n9352527

Joined Oct 14, 2005
1,198
Delete all breakpoints. Build the project and place a new one where you want it to be, make sure it is on a valid instruction. MAke sure the build process really builds it, i.e. edit the source code and undo the edit before building it.
 

Dave

Joined Nov 17, 2003
6,969
This can be one of those confusing things in MPLAB. The inserted breakpoint on a line of source code does not necessarily correspond to a machine instruction because of the code optimisation process. How MPLAB goes about this optimisation is somewhat random (unpredictable is probably a better word), and this is the very reason you get the error message in the OP.

There is a very simple way around this: insert a NOP instruction immediately after the point you wish to break at. The optimiser does not remove NOP instructions, and naturally the NOP instruction does nothing to affect the behaviour or structure of your code. Once your debugging session is over, remove the superfluous NOP instructions.

Dave
 

Thread Starter

mpuvdd

Joined Feb 11, 2007
50
Yeah, NOP would work, but I've gotten it to work without NOP.
For example, I just now rebuilt a C program project in MPLAB, added breakpoints to it, and what do you know, it worked!
If you look at parts of the disassembly listing you'll see this:
68: E = 1; E = 0;
350 1607 BSF 0x7, 0x4
351 1207 BCF 0x7, 0x4

69: j = Fivems;
352 302C MOVLW 0x2c
353 00A2 MOVWF 0x22
354 3001 MOVLW 0x1
355 00A3 MOVWF 0x23

68 and 69 represent the C code, and in blue is the C code compiled into assembly (with opcodes and addresses). I can place breakpoints on 68 and 69, or the corresponding C code, and I'll work.

So, I'm confused, I think it's just another one of MPLAB's screwy errors.
 

Dave

Joined Nov 17, 2003
6,969
So, I'm confused, I think it's just another one of MPLAB's screwy errors.
Whether you can call it an error is open to debate. As I stated previously the issues lies in the optimisation process which means breakpoints at lines of source code do not translate into machine workable breakpoints at the machine code level. I find this situation is rare but happens, seemingly for no reason. The NOP method is a simple and sure-fire way around this.

Dave
 
Top