This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [gdbserver] win32, add OUTPUT_DEBUG_STRING_EVENT handling.
- From: Pedro Alves <pedro_alves at portugalmail dot pt>
- To: Pedro Alves <pedro_alves at portugalmail dot pt>
- Cc: gdb-patches at sourceware dot org
- Date: Wed, 28 Feb 2007 23:46:43 +0000
- Subject: Re: [gdbserver] win32, add OUTPUT_DEBUG_STRING_EVENT handling.
- References: <45E20065.2050705@portugalmail.pt>
Pedro Alves wrote:
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...
In case I wasn't clear, this is needed so OutputDebugString
messages/calls made
by the debuggee are seen on the controller gdb's console.
Here is an updated version. It turns out Cygwin signals aren't
handleable in gdb
yet, even in native debugging (I had assumed they where, based on what is
found in gdb/win32-nat.c, and ported the support to gdbserver, before I
realized
they weren't), so, we might as well ignore the special Cygwin
OutputDebugStrings, like gdb/win32-nat.c. Also, since we now have the new
monitor_output, I ditched my similar console_output.
OK?
Cheers,
Pedro Alves
2007-02-28 Pedro Alves <pedro_alves@portugalmail.pt>
* remote-utils.c (monitor_output): Constify msg parameter.
* server (monitor_output): Likewise.
(handle_output_debug_string): New.
(win32_kill): Handle OUTPUT_DEBUG_STRING_EVENT events using
handle_output_debug_string.
(get_child_debug_event): Likewise.
---
gdb/gdbserver/remote-utils.c | 2 -
gdb/gdbserver/server.h | 2 -
gdb/gdbserver/win32-i386-low.c | 43 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 2 deletions(-)
Index: src/gdb/gdbserver/remote-utils.c
===================================================================
--- src.orig/gdb/gdbserver/remote-utils.c 2007-02-28 22:53:38.000000000 +0000
+++ src/gdb/gdbserver/remote-utils.c 2007-02-28 22:55:42.000000000 +0000
@@ -1087,7 +1087,7 @@ look_up_one_symbol (const char *name, CO
}
void
-monitor_output (char *msg)
+monitor_output (const char *msg)
{
char *buf = malloc (strlen (msg) * 2 + 2);
Index: src/gdb/gdbserver/server.h
===================================================================
--- src.orig/gdb/gdbserver/server.h 2007-02-28 22:53:38.000000000 +0000
+++ src/gdb/gdbserver/server.h 2007-02-28 22:55:42.000000000 +0000
@@ -172,7 +172,7 @@ int remote_escape_output (const gdb_byte
int look_up_one_symbol (const char *name, CORE_ADDR *addrp);
-void monitor_output (char *msg);
+void monitor_output (const char *msg);
/* Functions from ``signals.c''. */
enum target_signal target_signal_from_host (int hostsig);
Index: src/gdb/gdbserver/win32-i386-low.c
===================================================================
--- src.orig/gdb/gdbserver/win32-i386-low.c 2007-02-28 22:53:38.000000000 +0000
+++ src/gdb/gdbserver/win32-i386-low.c 2007-02-28 23:27:26.000000000 +0000
@@ -576,6 +576,43 @@ 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 };
+ if (read_inferior_memory (addr, (unsigned char *) buffer, nbytes) != 0)
+ return;
+ wcstombs (s, buffer, (nbytes + 1) / sizeof (WCHAR));
+ }
+ else
+ {
+ if (read_inferior_memory (addr, (unsigned char *) s, nbytes) != 0)
+ return;
+ }
+
+ if (strncmp (s, "cYg", 3) != 0)
+ monitor_output (s);
+#undef READ_BUFFER_LEN
+}
+
/* Kill all inferiors. */
static void
win32_kill (void)
@@ -592,6 +629,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);
+ }
}
}
@@ -939,6 +981,7 @@ in:
"for pid=%d tid=%x\n",
(unsigned) current_event.dwProcessId,
(unsigned) current_event.dwThreadId));
+ handle_output_debug_string (ourstatus);
break;
default: