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?= 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 +#include +#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