Debugging problems loaded code not matching .lss file

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

I'm using a Mega1284 in JTAG mode.

I'm not sure why but my program is exceptionally hard to debug and step through because the breakpoints I set either triggers because the code is merged and optimised, or doesn't trigger because it's somehow also optimised.

I've set the optimisation to various levels and also the debug level to optimised for debugging experience.

I've also set the Debug Level to maximum (-g3).

I must admit I've never ever touched the Debug Level on other projects, but I saw it and thought it would help.

 

Just now I was looking deeper into a breakpoint that gets triggered, ( devicepollcount++;)   but the code doesn't get executed..i.e. it doesn't get incremented. 

devicepollcount has been made volatile, 

However, the disassembled view shows the break actually on an RJMP. see below.

 

I've marked where the breakpoints are being set.

The program counter is indeed at 000325, so  I checked with the .lss file ( last code snippet) to see if there was any code for the increment and it is nothing like the loaded program.

 

The program appears to work as intended - but debugging is somewhat a nightmare, and I can't understand why the .lss file is nothing like the loaded code.

What am I doing wrong?

 

 

 

 

if (pollstate == POLLSEQUENTIAL )
{
    if (sensorpoll_timer == 0)
    {
		
		if (polledsensor >= 32)
			 {polledsensor = 0xffff;}		
		polledsensor += 1;
		if (polledsensor > 3) // sensors 4 ... 
		{
			
			// scen through jumping non allocated devices	
			while ( ( devices.device[polledsensor-4].allocated == 0 )  && (polledsensor < 30))
			{
*** BREAKPOINT HERE ***				devicepollcount++;
				polledsensor++;
			}
			

			
									

		}
		
			pollstate = POLLWAITSENSOR;
			//pollingstate = 1;// disable polling until response or no response dealt with
			pollsensor(polledsensor);			
									
			setup_timer (10,100, nopollresponse, polledsensor ); // timeout action if no reply
	}
}	

 

 

   809: 			 {polledsensor = 0xffff;}		
00000313 30.f0                BRCS PC+0x07		Branch if carry set 
00000314 8f.ef                SER R24		Set Register 
00000315 9f.ef                SER R25		Set Register 
00000316 90.93.f5.0d          STS 0x0DF5,R25		Store direct to data space 
00000318 80.93.f4.0d          STS 0x0DF4,R24		Store direct to data space 
0000031A 80.91.f4.0d          LDS R24,0x0DF4		Load direct from data space 
0000031C 90.91.f5.0d          LDS R25,0x0DF5		Load direct from data space 
0000031E 01.96                ADIW R24,0x01		Add immediate to word 
0000031F 90.93.f5.0d          STS 0x0DF5,R25		Store direct to data space 
00000321 80.93.f4.0d          STS 0x0DF4,R24		Store direct to data space 
00000323 04.97                SBIW R24,0x04		Subtract immediate from word 
00000324 80.f4                BRCC PC+0x11		Branch if carry cleared 
   817: 				devicepollcount++;
00000325 24.c0                RJMP PC+0x0025		Relative jump  *** BREAKPOINT HERE  ***  
00000326 20.91.fa.08          LDS R18,0x08FA		Load direct from data space 
00000328 30.91.fb.08          LDS R19,0x08FB		Load direct from data space 
0000032A 2f.5f                SUBI R18,0xFF		Subtract immediate 
0000032B 3f.4f                SBCI R19,0xFF		Subtract immediate with carry 
0000032C 30.93.fb.08          STS 0x08FB,R19		Store direct to data space 
--- C:\Users\Rob\Dropbox\AVR\Studio 7\Evolution\EVOLUTION2 AQUA 4 1284 V5\Default/.././EVOLUTION2.c 
0000032E 20.93.fa.08          STS 0x08FA,R18		Store direct to data space 
00000330 01.96                ADIW R24,0x01		Add immediate to word 
00000331 90.93.f5.0d          STS 0x0DF5,R25		Store direct to data space 
00000333 80.93.f4.0d          STS 0x0DF4,R24		Store direct to data space 
00000335 80.91.f4.0d          LDS R24,0x0DF4		Load direct from data space 
00000337 90.91.f5.0d          LDS R25,0x0DF5		Load direct from data space 
00000339 9c.01                MOVW R18,R24		Copy register pair 
0000033A 24.50                SUBI R18,0x04		Subtract immediate 
0000033B 31.09                SBC R19,R1		Subtract with carry 
0000033C 45.e2                LDI R20,0x25		Load immediate 
0000033D 42.9f                MUL R20,R18		Multiply unsigned 
0000033E f0.01                MOVW R30,R0		Copy register pair 
0000033F 43.9f                MUL R20,R19		Multiply unsigned 
00000340 f0.0d                ADD R31,R0		Add without carry 
00000341 11.24                CLR R1		Clear Register 
00000342 e7.5b                SUBI R30,0xB7		Subtract immediate 

 

000002f2 <pulsebeeper>:
     2f2:	cf 93       	push	r28
     2f4:	df 93       	push	r29
     2f6:	ec 01       	movw	r28, r24
     2f8:	81 e0       	ldi	r24, 0x01	; 1
     2fa:	80 93 f9 08 	sts	0x08F9, r24	; 0x8008f9 <beeper>
     2fe:	0e 94 56 1e 	call	0x3cac	; 0x3cac <shiftout>
     302:	be 01       	movw	r22, r28
     304:	7f 70       	andi	r23, 0x0F	; 15
     306:	9e 01       	movw	r18, r28
     308:	4c e8       	ldi	r20, 0x8C	; 140
     30a:	51 e0       	ldi	r21, 0x01	; 1
     30c:	82 e0       	ldi	r24, 0x02	; 2
     30e:	0e 94 74 24 	call	0x48e8	; 0x48e8 <setup_timer>
     312:	df 91       	pop	r29
     314:	cf 91       	pop	r28
     316:	08 95       	ret

00000318 <beeperoff>:
     318:	cf 93       	push	r28
     31a:	df 93       	push	r29
     31c:	ec 01       	movw	r28, r24
     31e:	10 92 f9 08 	sts	0x08F9, r1	; 0x8008f9 <beeper>
     322:	0e 94 56 1e 	call	0x3cac	; 0x3cac <shiftout>
     326:	ce 01       	movw	r24, r28
     328:	89 2f       	mov	r24, r25
     32a:	99 27       	eor	r25, r25
     32c:	82 95       	swap	r24
     32e:	8f 70       	andi	r24, 0x0F	; 15
     330:	89 2b       	or	r24, r25
     332:	49 f0       	breq	.+18     	; 0x346 <beeperoff+0x2e>
     334:	9e 01       	movw	r18, r28
     336:	30 51       	subi	r19, 0x10	; 16
     338:	b9 01       	movw	r22, r18
     33a:	77 27       	eor	r23, r23
     33c:	49 e7       	ldi	r20, 0x79	; 121
     33e:	51 e0       	ldi	r21, 0x01	; 1
     340:	82 e0       	ldi	r24, 0x02	; 2
     342:	0e 94 74 24 	call	0x48e8	; 0x48e8 <setup_timer>
     346:	df 91       	pop	r29
     348:	cf 91       	pop	r28
     34a:	08 95       	ret

0000034c <cancelpollscan>:

 

This topic has a solution.
Last Edited: Tue. Jun 11, 2019 - 10:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One listing has addresses in bytes and the other is in words (2 bytes). It may also be that the word listing got relocated so doubling the word value doesn't get you the byte value, there's an offset to be added. You should be able to scroll through the .lss file until you get to some familiar bits in the <> and match it up with the other listing.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As ajcashin says the Atmel debugger uses word addressing the LSS uses byte addressing. So when you see:

   817: 				devicepollcount++;
00000325 24.c0                RJMP PC+0x0025		Relative jump  *** BREAKPOINT HERE  ***  

then you need to take the 325 here and double it. So look in the LSS to 64a: (325h * 2) to find the equivalent.

 

Conversely if you see this in the LSS:

000002f2 <pulsebeeper>:

then in the debugger this code will appear to be at 000179 (2F2 / 2)