Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [Bug win32/14529] Make gdb capable of JIT-debugging on W32
@ 2012-08-29 17:55 LRN
  2012-08-31 14:53 ` Eli Zaretskii
  2012-10-01 22:37 ` Sergio Durigan Junior
  0 siblings, 2 replies; 44+ messages in thread
From: LRN @ 2012-08-29 17:55 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1608 bytes --]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

To be a JIT-debugger [1] on Windows, gdb has to be able to signal an
event, which is passed to it by command line. If that is not done, the
process being debugged will not come out of a waiting loop after gdb
attaches to it.
If the event is signaled, Windows will break the loop, and let the
exception fall into gdb's lap (well, stack will be a bit borked, but
that's another issue for another day, and there are ways of working
around it), after gdb user does 'continue'.

The attached patch [2] does exactly that by adding extra
"--event=EVENT" argument, thus AeDebug command line will look like this:
c:\mingw32\bin\gdb.exe --pid=%ld --event=%ld

Here [3] is the changelog entry.
Here [4] is a bug entry on the tracker.

[1] http://msdn.microsoft.com/en-us/library/5hs4b7a6%28v=vs.80%29.aspx
[2] http://sourceware.org/bugzilla/attachment.cgi?id=6619&action=diff
[3] http://sourceware.org/bugzilla/attachment.cgi?id=6620
[4] http://sourceware.org/bugzilla/show_bug.cgi?id=14529

[2] and [3] are also attached.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQEcBAEBAgAGBQJQPldbAAoJEOs4Jb6SI2CwuPYH/iSQJq2NEmsMGJ7dECdfFlWB
TF3hmodpd+CPfo/M/jB6DwRAGVM3l5goLXH6oWU1/sffUlTWwFJmI+Z66AQXayt5
xCMYRUs8lsBNloVsGWoHeVBhBD9yLpPrnG7CIK4RyE1FmXeEa1+/8YSfg8R/VqxL
Bjo6dVynXwqwuVmoFZnIqYd0X7v86p+6znpojFAqgYlJa640XyXel1wrJb9tPpiy
NV2iW03tnNPzVm+czwl7T1IA5DQUaOmPTbuTL1O9nO7S6xJu3juo7ZcFe0tZvtZn
eFHT6r0DI4meJ1DQ4KtvT2d0k6gJkHk4/HxzjZ9neuaE/lWFG5ug6tGZcY4+GS4=
=o1gF
-----END PGP SIGNATURE-----

[-- Attachment #2: 0001-Make-gdb-JIT-capable-W32.patch --]
[-- Type: text/plain, Size: 4408 bytes --]

From 4554c48a13b22b3ed1b5f5239552e4c959d34cc9 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=D1?=
 =?UTF-8?q?=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= <lrn1986@gmail.com>
Date: Wed, 29 Aug 2012 17:00:47 +0400
Subject: [PATCH] Make gdb JIT-capable (W32)

Adds the --event=EVENT commandline arugment. After attaching to a process,
gdb will signal that event.
Only does anything on W32. On other platforms the argument is accepted, but
gdb does nothing.
Intended to be used in conjunction with AeDebug on W32.
Can be (and is) used to attach a debugger manually.

PR gdb/14529
---
 gdb/infcmd.c   |   29 +++++++++++++++++++++++++++++
 gdb/inferior.h |    2 ++
 gdb/main.c     |   13 ++++++++++++-
 3 files changed, 43 insertions(+), 1 deletions(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 8e2f74e..218f713 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -57,6 +57,11 @@
 #include "continuations.h"
 #include "linespec.h"
 
+#ifdef __MINGW32__
+#include <windows.h>
+#include <inttypes.h>
+#endif
+
 /* Functions exported for general use, in inferior.h: */
 
 void all_registers_info (char *, int);
@@ -2636,6 +2641,30 @@ attach_command (char *args, int from_tty)
   discard_cleanups (back_to);
 }
 
+void
+signal_event_command (char *args, int from_tty)
+{
+  int async_exec = 0;
+  uintmax_t event_id = 0;
+  char *endargs = NULL;
+  struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
+
+  dont_repeat ();		/* Not for the faint of heart */
+
+  event_id = strtoumax (args, &endargs, 10);
+
+  if ((event_id == UINTMAX_MAX && errno == ERANGE) || event_id == 0)
+    error (_("Failed to convert event id `%s' to integer"), args);
+
+#ifdef __MINGW32__
+  SetEvent ((HANDLE) event_id);
+  CloseHandle ((HANDLE) event_id);
+#else
+  /* Does nothing on other platforms */
+#endif
+  discard_cleanups (back_to);
+}
+
 /* We had just found out that the target was already attached to an
    inferior.  PTID points at a thread of this new inferior, that is
    the most likely to be stopped right now, but not necessarily so.
diff --git a/gdb/inferior.h b/gdb/inferior.h
index b2607c3..b9592af 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -241,6 +241,8 @@ extern void post_create_inferior (struct target_ops *, int);
 
 extern void attach_command (char *, int);
 
+extern void signal_event_command (char *, int);
+
 extern char *get_inferior_args (void);
 
 extern void set_inferior_args (char *);
diff --git a/gdb/main.c b/gdb/main.c
index 326b101..f84c278 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -278,6 +278,7 @@ captured_main (void *data)
   char *symarg = NULL;
   char *execarg = NULL;
   char *pidarg = NULL;
+  char *eventarg = NULL;
   char *corearg = NULL;
   char *pid_or_core_arg = NULL;
   char *cdarg = NULL;
@@ -403,7 +404,8 @@ captured_main (void *data)
       OPT_NOWINDOWS,
       OPT_WINDOWS,
       OPT_IX,
-      OPT_IEX
+      OPT_IEX,
+      OPT_EVENT
     };
     static struct option long_options[] =
     {
@@ -438,6 +440,7 @@ captured_main (void *data)
       {"c", required_argument, 0, 'c'},
       {"pid", required_argument, 0, 'p'},
       {"p", required_argument, 0, 'p'},
+      {"event", required_argument, 0, OPT_EVENT},
       {"command", required_argument, 0, 'x'},
       {"eval-command", required_argument, 0, 'X'},
       {"version", no_argument, &print_version, 1},
@@ -582,6 +585,9 @@ captured_main (void *data)
 	      VEC_safe_push (cmdarg_s, cmdarg_vec, &cmdarg);
 	    }
 	    break;
+	  case OPT_EVENT:
+	    eventarg = optarg;
+	    break;
 	  case 'B':
 	    batch_flag = batch_silent = 1;
 	    gdb_stdout = ui_file_new();
@@ -928,6 +934,10 @@ captured_main (void *data)
 			      !batch_flag, RETURN_MASK_ALL);
     }
 
+  if (eventarg != NULL)
+    catch_command_errors (signal_event_command, eventarg,
+			  !batch_flag, RETURN_MASK_ALL);
+
   if (ttyarg != NULL)
     set_inferior_io_terminal (ttyarg);
 
@@ -1055,6 +1065,7 @@ Options:\n\n\
   --dbx              DBX compatibility mode.\n\
   --directory=DIR    Search for source files in DIR.\n\
   --epoch            Output information used by epoch emacs-GDB interface.\n\
+  --event=EVENT      Signal the EVENT when attached to a process. W32 only.\n\
   --exec=EXECFILE    Use EXECFILE as the executable.\n\
   --fullname         Output information used by emacs-GDB interface.\n\
   --help             Print this message.\n\
-- 
1.7.4


[-- Attachment #3: ChangeLog.14529 --]
[-- Type: text/plain, Size: 168 bytes --]

2012-08-29  Руслан Ижбулатов <lrn1986@gmail.com>

	* infcmd.c, inferior.h, main.c: Add --event=%ld argument for W32 compatibility
	Fix PR gdb/14529.


^ permalink raw reply	[flat|nested] 44+ messages in thread

end of thread, other threads:[~2016-07-23  8:41 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-29 17:55 [Bug win32/14529] Make gdb capable of JIT-debugging on W32 LRN
2012-08-31 14:53 ` Eli Zaretskii
2012-08-31 15:37   ` LRN
2012-09-10  2:22     ` LRN
2012-09-10 18:15       ` Tom Tromey
2012-09-10 18:32         ` LRN
2012-09-11 18:21       ` Pedro Alves
2012-09-11 18:27         ` LRN
2012-09-11 18:30           ` Pedro Alves
2012-09-11 18:09     ` Pedro Alves
2012-09-11 18:23       ` LRN
2012-09-11 18:27         ` Pedro Alves
2012-09-11 18:31           ` LRN
2012-09-29 12:42           ` LRN
2012-09-29 13:05             ` Eli Zaretskii
2012-09-29 19:32               ` LRN
2012-09-30  7:51                 ` Eli Zaretskii
2012-09-30 12:46                   ` LRN
2012-10-01 13:18                     ` Eli Zaretskii
2012-10-01 16:22                       ` LRN
2012-08-31 15:37   ` Christopher Faylor
2012-08-31 15:40     ` LRN
2012-10-01 22:37 ` Sergio Durigan Junior
2012-10-01 22:48   ` LRN
2012-10-02  5:53     ` Sergio Durigan Junior
2012-10-02 12:48       ` Joel Brobecker
2012-10-02 12:57         ` LRN
2016-06-30 13:17           ` LRN
2016-06-30 15:25             ` Eli Zaretskii
2016-06-30 15:44               ` LRN
2016-06-30 16:23                 ` Eli Zaretskii
2016-06-30 17:19                   ` LRN
2016-06-30 17:42                     ` Eli Zaretskii
2016-06-30 18:36                       ` LRN
2016-06-30 18:57                         ` Eli Zaretskii
2016-06-30 19:14                           ` LRN
2016-07-02  1:16                             ` LRN
2016-07-02  7:48                               ` Eli Zaretskii
2016-07-10 13:06                                 ` LRN
2016-07-10 14:55                                   ` Eli Zaretskii
2016-07-18 10:08                                     ` LRN
2016-07-19 19:10                                       ` Eli Zaretskii
2016-07-20  4:43                                         ` LRN
2016-07-23  8:41                                           ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox