Re: [hatari-devel] Debugger 'n' command

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

On 04/11/2016 01:01 AM, Nicolas Pomarède wrote:
Le 10/04/2016 23:40, Eero Tamminen a écrit :

The reason why it's not currently supported, is that branching
can also be forwards.  Then "n" command breakpoint for the next
instruction might never terminate, which IMHO is worse than
lacking support for skipping loops.

Does somebody feel adding support for determining when instruction
at PC is a branch going backwards?  :-)


For bne/beq it would be more complicated, but in the case of dbcc it
will mostly be backward ; dbcc uses 2 words, 1 with the opcode, 1 with
the displacement ; if the the 2nd word is <0, then it will go backward
and a breakpoint after the dbcc will work.

format for DBcc is : 0101 cccc 1100 1rrr  . so if ( opcode & 0x50A8 ) ==
0x50a8, then you have a DBcc and you can check the next word.

Does the attached patch work OK?


	- Eero

diff -r 9ffbbc92221e src/debug/debugcpu.c
--- a/src/debug/debugcpu.c	Mon Apr 11 01:52:50 2016 +0300
+++ b/src/debug/debugcpu.c	Mon Apr 11 01:53:52 2016 +0300
@@ -537,15 +537,25 @@
 		Uint32 optype, nextpc;
 
 		optype = DebugCpu_OpcodeType();
-		/* can this instruction be stepped normally? */
-		if (optype != CALL_SUBROUTINE && optype != CALL_EXCEPTION)
+		/* should this instruction be stepped normally, or is it
+		 * - subroutine call
+		 * - exception
+		 * - loop branch backwards
+		 */
+		if (optype == CALL_SUBROUTINE ||
+		    optype == CALL_EXCEPTION ||
+		    (optype == CALL_BRANCH &&
+		     (STMemory_ReadWord(M68000_GetPC()) & 0xf0f8) == 0x50c8 &&
+		     (Sint16)STMemory_ReadWord(M68000_GetPC()+SIZE_WORD) < 0))
+		{
+			nextpc = Disasm_GetNextPC(M68000_GetPC());
+			sprintf(command, "pc=$%x :once :quiet\n", nextpc);
+		}
+		else
 		{
 			nCpuSteps = 1;
 			return DEBUGGER_END;
 		}
-
-		nextpc = Disasm_GetNextPC(M68000_GetPC());
-		sprintf(command, "pc=$%x :once :quiet\n", nextpc);
 	}
 	/* use breakpoint, not steps */
 	if (BreakCond_Command(command, false))


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/