[hatari-devel] patch for memory command to follow count and range values

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


I brought up the issue on another message that the 'm' command in the debugger would only output on line boundaries.

For instance "m b pc 1" would output an entire line instead of one byte.

Also, "m b 400-402" would output an entire line instead of 2 bytes. Same for word and long entries.

Attached is a patch to src/debug/debugcpu.c that corrects the memory dump routine to respect count and range values.

Tested here, but of course please try it out to see if it needs any adjustments.

Jeff
--- debugcpu.c-orig	2024-02-27 17:49:22.135538000 -0500
+++ debugcpu.c	2024-02-27 17:46:21.136202116 -0500
@@ -455,6 +455,7 @@
 	char c, mode;
 	int i, arg, size;
 	uint32_t value, memdump_upper = 0;
+	int count = 0;
 
 	arg = 1;
 	mode = 0;
@@ -505,7 +506,7 @@
 
 		if (nArgc > arg)
 		{
-			int count = atoi(psArgs[arg]);
+			count = atoi(psArgs[arg]);
 			if (!count)
 			{
 				fprintf(stderr, "Invalid count %d!\n", count);
@@ -515,18 +516,28 @@
 		}
 	}
 
+	int outputcount = MEMDUMP_COLS/size;
 	if (!memdump_upper)
 	{
 		int lines = DebugUI_GetPageLines(ConfigureParams.Debugger.nMemdumpLines, 8);
 		memdump_upper = memdump_addr + MEMDUMP_COLS * lines;
 	}
+	
+	if(count > 0)
+		outputcount = count;
+	else
+		outputcount = memdump_upper - memdump_addr;
 
+	int outputline =  MEMDUMP_COLS/size;
 	while (memdump_addr < memdump_upper)
 	{
 		fprintf(debugOutput, "%08X: ", memdump_addr);
 		
+		if(outputcount < outputline)
+			outputline =  outputcount;
+
 		/* print HEX data */
-		for (i = 0; i < MEMDUMP_COLS/size; i++)
+		for (i = 0; i < outputline; i++)
 		{
 			switch (mode)
 			{
@@ -544,17 +555,22 @@
 			fprintf(debugOutput, "%0*x ", 2*size, value);
 			memdump_addr += size;
 		}
+		if(outputline < MEMDUMP_COLS/size)
+			for (i = 0; i < (((size * 2) + 1) * ((MEMDUMP_COLS / size) - outputline)); i++)
+				fprintf(debugOutput, "%c", ' ');
 
 		/* print ASCII data */
 		fprintf(debugOutput, "  ");
-		for (i = 0; i < MEMDUMP_COLS; i++)
+		for (i = 0; i < outputline * size; i++)
 		{
-			c = STMemory_ReadByte(memdump_addr-MEMDUMP_COLS+i);
+			c = STMemory_ReadByte(memdump_addr-(outputline*size)+i);
 			if(!isprint((unsigned)c))
 				c = NON_PRINT_CHAR;             /* non-printable as dots */
 			fprintf(debugOutput,"%c", c);
 		}
 		fprintf(debugOutput, "\n");
+
+		outputcount -= outputline;
 	}
 	fflush(debugOutput);
 


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