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

LRN
2016-07-20T04:43:09Z

[-- Attachment #1.1.1: Type: text/plain, Size: 1227 bytes --]

On 19.07.2016 22:09, Eli Zaretskii wrote:
> On 18.07.2016 13:08, LRN wrote:
>> On 10.07.2016 17:54, Eli Zaretskii wrote:
>>> On 10.07.2016 16:05, LRN wrote:
>>>> On 02.07.2016 10:47, Eli Zaretskii wrote:
>>>>> On 02.07.2016 4:16, LRN wrote:
>>>>>> So, anyway, is anything else expected of me? When should i expect to
>>>>>> see the patches pushed?
>>>>>
>>>>> Please wait for a week, and if it doesn't get pushed, ping us here.
>>>>
>>>> ping
>>>>
>>>
>>> Any objections to me pushing this to master? Anyone?
>>>
>>
>> ping
>>
>
> Sorry for the delay: life intervened big time.
>
> If no one beats me to it, I will push this weekend. Thank you for
> your patience.
>
> P.S. Do we really need a configure-time option? Why not enable the
> feature by default in the MinGW and Cygwin builds?
>

The latest version of the patch does not have a configure-time option. You
must be either looking at a patch from one of the early emails, or at a
patch on the bug tracker (which was never updated after the discussion
moved to the mailing list).

Just to ensure that you push the right thing, i'm attaching the patches again.

--
O< ascii ribbon - stop html email! - www.asciiribbon.org

[-- Attachment #1.1.2: 0001-Make-gdb-JIT-capable-MS-Windows.patch --]
[-- Type: text/plain, Size: 4061 bytes --]

From 04b8ea3eee4714f027159d2a496a2fa6569c7b8e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?=
=?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= <lrn1986@gmail.com>
Date: Sun, 26 Jun 2016 11:05:11 +0000
Subject: [PATCH 1/3] Make gdb JIT-capable (MS-Windows)

Adds the signal-event command (MS-Windows-only) that signals
an event with user-provided ID. Used to resume crashing
process when attached to it via MS-Windows JIT debugging (AeDebug).

PR gdb/14529
---
gdb/doc/gdb.texinfo | 27 +++++++++++++++++++++++++++
gdb/windows-nat.c | 27 +++++++++++++++++++++++++++
2 files changed, 54 insertions(+)

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."), _("\
--
2.4.0

[-- Attachment #1.1.3: 0002-Add-signal-event-command-to-the-NEWS-file.patch --]
[-- Type: text/plain, Size: 1105 bytes --]

From 756456c50c6bc2046ff6c37fcca4955086326946 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?=
=?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= <lrn1986@gmail.com>
Date: Thu, 30 Jun 2016 15:34:06 +0000
Subject: [PATCH 2/3] Add "signal-event" command to the NEWS file

---
gdb/NEWS | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/gdb/NEWS b/gdb/NEWS
index 3823f20..da04ae6 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -80,6 +80,12 @@ new-ui INTERP TTY
Start a new user interface instance running INTERP as interpreter,
using the TTY file for input/output.

+signal-event EVENTID
+ Signal ("set") the given Windows event object. This is used together
+ with Windows JIT debugging (AeDebug), where the OS suspends
+ a crashing process until a debugger can attach to it. Resuming
+ the process is done by siganlling an event.
+
* Support for tracepoints and fast tracepoints on s390-linux and s390x-linux
was added in GDBserver, including JIT compiling fast tracepoint's
conditional expression bytecode into native code.
--
2.4.0

[-- Attachment #1.1.4: 0003-Add-a-changelog-entry-for-the-signal-event-command.patch --]
[-- Type: text/plain, Size: 986 bytes --]

From c56681b5940cbe46d457028764819a00e6aa96ec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?=
=?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= <lrn1986@gmail.com>
Date: Thu, 30 Jun 2016 15:41:29 +0000
Subject: [PATCH 3/3] Add a changelog entry for the 'signal-event' command

---
gdb/ChangeLog | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 92c1337..f49ebe1 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2016-06-30 Руслан Ижбулатов <lrn1986@gmail.com>
+
+ PR gdb/14529
+ * windows-nat.c (signal_event_command): New command
+ 'signal-event' for W32 compatibility.
+ * gdb.texinfo (Cygwin Native): document the new 'signal-event'
+ command.
+ * NEWS: Add an entry about the new 'signal-event' command.
+
2016-07-07 Walfred Tedeschi <walfred.tedeschi@intel.com>

* cp-namespace.c (cp_lookup_bare_symbol): Initialize
--
2.4.0

[-- Attachment #1.1.5: 0x6759BA74.asc --]
[-- Type: application/pgp-keys, Size: 3540 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]