winedbg print fixes

Richard Cohen richard.cohen at virgin.net
Wed Aug 6 08:26:58 CDT 2003


print was writing "..." even after short variables.  The code didn't 
work if the length was not a multiple of 16.

Changelog
	+ Print short ASCII strings without the "..."
	+ Make printing for Unicode strings more similar to ASCII

-------------- next part --------------
diff -u programs/winedbg.0/memory.c programs/winedbg/memory.c
--- programs/winedbg.0/memory.c	2002-11-13 04:07:46.000000000 +0000
+++ programs/winedbg/memory.c	2003-08-06 14:07:14.000000000 +0100
@@ -336,6 +336,8 @@
 	}
 }
 
+#define CHARBUFSIZE 16
+
 /******************************************************************
  *		DEBUG_PrintStringA
  *
@@ -346,38 +348,43 @@
 int  DEBUG_PrintStringA(int chnl, const DBG_ADDR* address, int len)
 {
     char*       lin = (void*)DEBUG_ToLinear(address);
-    char        ach[16+1];
-    int         i, l;
+    char        ch[CHARBUFSIZE+1];
+    int         written = 0;
 
     if (len == -1) len = 32767; /* should be big enough */
 
-    for (i = len; i > 0; i -= l)
+    while (written < len)
     {
-        l = min(sizeof(ach) - 1, i);
-        DEBUG_READ_MEM_VERBOSE(lin, ach, l);
-	ach[l] = '\0';  /* protect from displaying junk */
-        l = strlen(ach);
-        DEBUG_OutputA(chnl, ach, l);
-        if (l < sizeof(ach) - 1) break;
-        lin += l;
+        int to_write = min(CHARBUFSIZE, len - written );
+        if (!DEBUG_READ_MEM_VERBOSE(lin, ch, to_write)) break;
+        ch[to_write] = '\0';  /* protect from displaying junk */
+        to_write = lstrlenA(ch);
+        DEBUG_OutputA(chnl, ch, to_write);
+        lin += to_write;
+        written += to_write;
+        if (to_write < CHARBUFSIZE) break;
     }
-    return len - i; /* number of actually written chars */
+    return written; /* number of actually written chars */
 }
 
 int  DEBUG_PrintStringW(int chnl, const DBG_ADDR* address, int len)
 {
     char*       lin = (void*)DEBUG_ToLinear(address);
-    WCHAR       wch;
-    int         ret = 0;
+    WCHAR       ch[CHARBUFSIZE+1];
+    int         written = 0;
 
     if (len == -1) len = 32767; /* should be big enough */
-    while (len--)
+
+    while  (written < len)
     {
-        if (!DEBUG_READ_MEM_VERBOSE(lin, &wch, sizeof(wch)) || !wch)
-            break;
-        lin += sizeof(wch);
-        DEBUG_OutputW(chnl, &wch, 1);
-        ret++;
+        int to_write = min(CHARBUFSIZE, len - written );
+        if (!DEBUG_READ_MEM_VERBOSE(lin, ch, to_write * sizeof(WCHAR))) break;
+        ch[to_write] = 0;  /* protect from displaying junk */
+        to_write = lstrlenW(ch);
+        DEBUG_OutputW(chnl, ch, to_write);
+        lin += to_write;
+        written += to_write;
+        if (to_write < CHARBUFSIZE) break;
     }
-    return ret;
+    return written; /* number of actually written chars */
 }
diff -u programs/winedbg.0/types.c programs/winedbg/types.c
--- programs/winedbg.0/types.c	2003-02-23 10:49:17.000000000 +0000
+++ programs/winedbg/types.c	2003-08-06 14:22:52.000000000 +0100
@@ -36,7 +36,7 @@
 #define NR_TYPE_HASH 521
 
 int		  DEBUG_nchar;
-static int	  DEBUG_maxchar = 1024;
+static const int  DEBUG_maxchar = 1024;
 
 struct en_values
 {
@@ -890,20 +890,14 @@
           switch (value->cookie)
           {
           case DV_TARGET:
-              clen = DEBUG_PrintStringA(DBG_CHN_MESG, &value->addr, clen);
+              DEBUG_nchar += DEBUG_PrintStringA(DBG_CHN_MESG, &value->addr, clen);
               break;
           case DV_HOST:
               DEBUG_OutputA(DBG_CHN_MESG, pnt, clen);
               break;
           default: assert(0);
           }
-          DEBUG_nchar += clen;
-          if (clen != len)
-          {
-              DEBUG_Printf(DBG_CHN_MESG, "...\"");
-              goto leave;
-          }
-          DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "\"");
+          DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, (len > clen) ? "...\"" : "\"");
           break;
         }
       val1 = *value;
@@ -943,7 +937,6 @@
     {
       DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "\n");
     }
-  return;
 }
 
 static void DEBUG_DumpAType(struct datatype* dt, BOOL deep)


More information about the wine-patches mailing list