winedbg Unicode strings output fix

Catalin Patulea catalins at vv.carleton.ca
Sun Jun 29 22:17:51 CDT 2003


Hello,

Here's the patch which fixes Bug #1558.
The bug is essentially winedbg not displaying Unicode strings correctly 
through DEBUG_OutputW. Fixed by adding a real Unicode-to-ANSI conversion 
and then calling DEBUG_OutputA with the new buffer.
(This behavior can be observed easiest in the x/u command.)

ChangeLog:
 - fixed winedbg Unicode string output

Catalin Patulea

-------------------------------------------
Catalin Patulea           VV Volunteer 2002
http://vv.carleton.ca/~catalins/
catalins at vv.carleton.ca
                                 VV Rocks!!
-------------- next part --------------
Index: programs/winedbg/winedbg.c
===================================================================
RCS file: /home/wine/wine/programs/winedbg/winedbg.c,v
retrieving revision 1.11
diff -u -r1.11 winedbg.c
--- programs/winedbg/winedbg.c	22 May 2003 03:44:01 -0000	1.11
+++ programs/winedbg/winedbg.c	30 Jun 2003 03:04:28 -0000
@@ -32,6 +32,7 @@
 #include "winuser.h"
 #include "excpt.h"
 #include "wine/library.h"
+#include "winnls.h"
 
 DBG_PROCESS*	DEBUG_CurrProcess = NULL;
 DBG_THREAD*	DEBUG_CurrThread = NULL;
@@ -58,12 +59,43 @@
 
 void	DEBUG_OutputW(int chn, const WCHAR* buffer, int len)
 {
-    /* FIXME: this won't work is std output isn't attached to a console */
-    if (DBG_IVAR(ConChannelMask) & chn)
-	WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), buffer, len, NULL, NULL);
-    /* simplistic Unicode to ANSI conversion */
-    if (DBG_IVAR(StdChannelMask) & chn)
-        while (len--) fputc((char)*buffer++, stderr);
+	char* ansi = NULL;
+	int newlen;
+	
+	/* do a serious Unicode to ANSI conversion
+	   FIXME: should CP_ACP be GetConsoleCP()? */
+	newlen = WideCharToMultiByte(CP_ACP, 0, buffer, len, NULL, 0, NULL, NULL);
+	if(newlen)
+	{
+		ansi = (char*)DBG_alloc(newlen);
+		if(ansi)
+		{
+			WideCharToMultiByte(CP_ACP, 0, buffer, len, ansi, newlen, NULL, NULL);
+		}
+	}
+	
+	/* fall back to a simple Unicode to ANSI conversion in case WC2MB failed */
+	if(!ansi)
+	{
+		ansi = DBG_alloc(len);
+		if(ansi)
+		{
+			int i;
+			for(i = 0; i < len; i++)
+			{
+				ansi[i] = (char)buffer[i];
+			}
+			
+			newlen = len;
+		}
+		/* else we are having REALLY bad luck today */
+	}	
+	
+	if(ansi)
+	{
+		DEBUG_OutputA(chn, ansi, newlen);
+		DBG_free(ansi);
+	}
 }
 
 int	DEBUG_Printf(int chn, const char* format, ...)


More information about the wine-patches mailing list