[Bug,win32/14529] Make gdb capable of JIT-debugging on W32

Message ID 4be546e0-7811-6f51-e5a4-d441e8a9d16a@gmail.com
State New, archived
Headers

Commit Message

LRN June 30, 2016, 1:16 p.m. UTC
  On 02.10.2012 15:57, LRN wrote:
> On 02.10.2012 16:48, Joel Brobecker wrote:
>>>> I have a copyright assignment filed for GNUtls [1], would that
>>>> suffice?
> 
>> Unfortunately, that's not enough. It needs to include GDB (you
>> also have the option of saying "ANY" and be covered for all
>> projects). Do you want to start the paperwork?
> 
> Not now. Maybe later. I'll up this thread when i'm ready.
> 

I did the paperwork and now my rights on code that will be included in gdb
are assigned to FSF.
So i'm upping the thread. Also, attaching a version of the patch that can
be applied to current git master.
  

Comments

Eli Zaretskii June 30, 2016, 3:25 p.m. UTC | #1
> From: LRN <lrn1986@gmail.com>
> Date: Thu, 30 Jun 2016 16:16:40 +0300
> 
> I did the paperwork and now my rights on code that will be included in gdb
> are assigned to FSF.
> So i'm upping the thread. Also, attaching a version of the patch that can
> be applied to current git master.

Thanks.  The documentation change is approved, but please include a
NEWS entry, and also please show the ChangeLog entries for the
changes.
  

Patch

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index a068622..62a99e2 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -21520,6 +21520,33 @@  This command displays thread specific information stored in the
 Thread Information Block (readable on the X86 CPU family using @code{$fs}
 selector for 32-bit programs and @code{$gs} for 64-bit programs).
 
+@kindex signal-event
+@item signal-event @var{id}
+This command signals an event with user-provided @var{id}.  Used to resume
+crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
+
+To use it, create or edit the following keys in
+@code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
+@code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
+(for x86_64 versions):
+
+@itemize @minus
+@item
+@code{Debugger} (REG_SZ) --- a command to launch the debugger.  Suggested
+command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex "attach %ld"
+-ex "signal-event %ld" -ex "continue"}
+
+First @code{%ld} will be replaced by process ID, second @code{%ld} will be
+replaced by ID of the event that blocks the crashing process, waiting for
+debugger to attach.
+
+@item
+@code{Auto} (REG_SZ) --- either @code{1} or @code{0}.  @code{1} will make the
+system run debugger specified by Debugger key automatically, @code{0} will
+cause a dialog box with ``OK'' and ``Cancel'' buttons to appear, which allows
+the user to either terminate crashing process (OK) or debug it (Cancel).
+@end itemize
+
 @kindex set cygwin-exceptions
 @cindex debugging the Cygwin DLL
 @cindex Cygwin DLL, debugging
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 149403a..b1ab6c8 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -56,6 +56,7 @@ 
 #include "solist.h"
 #include "solib.h"
 #include "xml-support.h"
+#include "inttypes.h"
 
 #include "i386-tdep.h"
 #include "i387-tdep.h"
@@ -825,6 +826,25 @@  windows_clear_solib (void)
   solib_end = &solib_start;
 }
 
+static void
+signal_event_command (char *args, int from_tty)
+{
+  uintptr_t event_id = 0;
+  char *endargs = NULL;
+
+  if (args == NULL)
+    error (_("signal-event requires an argument (integer event id)"));
+
+  event_id = strtoumax (args, &endargs, 10);
+
+  if ((errno == ERANGE) || (event_id == 0) || (event_id > UINTPTR_MAX) ||
+      ((HANDLE) event_id == INVALID_HANDLE_VALUE))
+    error (_("Failed to convert `%s' to event id"), args);
+
+  SetEvent ((HANDLE) event_id);
+  CloseHandle ((HANDLE) event_id);
+}
+
 /* Handle DEBUG_STRING output from child process.
    Cygwin prepends its messages with a "cygwin:".  Interpret this as
    a Cygwin signal.  Otherwise just print the string as a warning.  */
@@ -2551,6 +2571,13 @@  _initialize_windows_nat (void)
   cygwin_internal (CW_SET_DOS_FILE_WARNING, 0);
 #endif
 
+  add_com ("signal-event", class_run, signal_event_command, _("\
+Signal a crashed process with event ID, to allow its debugging.\n\
+This command is needed in support of setting up GDB as JIT debugger on \
+MS-Windows.  The command should be invoked from the GDB command line using \
+the '-ex' command-line option.  The ID of the event that blocks the \
+crashed process will be supplied by the Windows JIT debugging mechanism."));
+
 #ifdef __CYGWIN__
   add_setshow_boolean_cmd ("shell", class_support, &useshell, _("\
 Set use of shell to start subprocess."), _("\