This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gdbserver] win32, add OUTPUT_DEBUG_STRING_EVENT handling.


Hi all,

This patch adds support for sending OUTPUT_DEBUG_STRING_EVENT
messages to the controller gdb.  Compared to the version found in
gdb/win32-nat.c, this handles Unicode messages, needed for
WinCE, but will not handle the special cygwin signal markers.
Perhaps someone (maybe me) will get annoyed by the spurious console
messages and implement proper support later.  I'm sending the messages
using the 'O' packet, but somehow I guess that there should be an
extra packet for these debugger-specific messages, and 'O' should be
left for real output redirection, or would it be the other way
around?  Anyway, the native debugger also puts the output debug
strings into the console using warning, so...

OK?

Cheers,
Pedro Alves

---
gdb/gdbserver/ChangeLog:

2007-02-25 Pedro Alves <pedro_alves@portugalmail.pt>

    * server.h (console_output): Declare.
    * remote-utils.c (console_output): Define.
    * win32-i386-low.c (handle_output_debug_string): New.
    (win32_kill): Use handle_output_debug_string.
    (get_child_debug_event): Use handle_output_debug_string.


--- .pc/outputdebustring.diff/gdb/gdbserver/remote-utils.c	2007-02-25 18:06:48.000000000 +0000
+++ gdb/gdbserver/remote-utils.c	2007-02-25 20:57:40.000000000 +0000
@@ -567,6 +567,18 @@ putpkt (char *buf)
   return putpkt_binary (buf, strlen (buf));
 }
 
+void
+console_output (const char *msg)
+{
+  size_t msg_len = strlen (msg);
+  char *outpkt = malloc (1 + (msg_len * 2) + 1);
+  outpkt[0] = 'O';
+  convert_int_to_ascii ((unsigned char *) msg, outpkt + 1, msg_len);
+  outpkt[1 + (msg_len * 2)] = '\0';
+  putpkt (outpkt);
+  free (outpkt);
+}
+
 #ifndef USE_WIN32API
 
 /* Come here when we get an input interrupt from the remote side.  This
--- .pc/outputdebustring.diff/gdb/gdbserver/server.h	2007-02-25 12:46:40.000000000 +0000
+++ gdb/gdbserver/server.h	2007-02-25 20:53:18.000000000 +0000
@@ -170,6 +170,8 @@ int remote_escape_output (const gdb_byte
 
 int look_up_one_symbol (const char *name, CORE_ADDR *addrp);
 
+void console_output (const char *msg);
+
 /* Functions from ``signals.c''.  */
 enum target_signal target_signal_from_host (int hostsig);
 int target_signal_to_host_p (enum target_signal oursig);
--- .pc/outputdebustring.diff/gdb/gdbserver/win32-i386-low.c	2007-02-25 17:43:50.000000000 +0000
+++ gdb/gdbserver/win32-i386-low.c	2007-02-25 21:08:58.000000000 +0000
@@ -577,6 +577,40 @@ win32_attach (unsigned long pid)
   return res;
 }
 
+/* Handle OUTPUT_DEBUG_STRING_EVENT from child process.  */
+static void
+handle_output_debug_string (struct target_waitstatus *ourstatus)
+{
+#define READ_BUFFER_LEN 1024
+  CORE_ADDR addr;
+  char s[READ_BUFFER_LEN + 1] = { 0 };
+  DWORD nbytes = current_event.u.DebugString.nDebugStringLength;
+
+  if (nbytes == 0)
+    return;
+
+  if (nbytes > READ_BUFFER_LEN)
+    nbytes = READ_BUFFER_LEN;
+
+  addr = (CORE_ADDR) (size_t) current_event.u.DebugString.lpDebugStringData;
+
+  if (current_event.u.DebugString.fUnicode)
+    {
+      /* The event tells us how many bytes, not chars, even
+         in Unicode.  */
+      WCHAR buffer[(READ_BUFFER_LEN + 1) / sizeof (WCHAR)] = { 0 };
+      read_inferior_memory (addr, (unsigned char *) buffer, nbytes);
+      wcstombs (s, buffer, (nbytes + 1) / sizeof (WCHAR));
+    }
+  else
+    {
+      read_inferior_memory (addr, (unsigned char *) s, nbytes);
+    }
+
+  console_output (s);
+#undef READ_BUFFER_LEN
+}
+
 /* Kill all inferiors.  */
 static void
 win32_kill (void)
@@ -593,6 +627,11 @@ win32_kill (void)
 	break;
       if (current_event.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT)
 	break;
+      else if (current_event.dwDebugEventCode == OUTPUT_DEBUG_STRING_EVENT)
+	{
+  	  struct target_waitstatus our_status = { 0 };
+	  handle_output_debug_string (&our_status);
+  	}
     }
 }
 
@@ -940,6 +979,7 @@ in:
 		"for pid=%d tid=%x\n",
 		(unsigned) current_event.dwProcessId,
 		(unsigned) current_event.dwThreadId));
+      handle_output_debug_string (ourstatus);
       break;
 
     default:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]