From 58d3018c84b96507ae13d39d7d59c3bf5364b01b 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. Intended to be used in conjunction with AeDebug on W32. Can be (and is) used to attach a debugger manually. Adds configure option to enable this feature. By default it is enabled for MinGW and Cygwin. PR gdb/14529 --- gdb/configure.ac | 33 +++++++++++++++++++++++++++++++-- gdb/infcmd.c | 27 +++++++++++++++++++++++++++ gdb/inferior.h | 4 ++++ gdb/main.c | 25 ++++++++++++++++++++++++- 4 files changed, 86 insertions(+), 3 deletions(-) diff --git a/gdb/configure.ac b/gdb/configure.ac index 0c62b46..19dec6d 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -599,6 +599,9 @@ if test x"$enable_tui" != xno; then fi fi +# Default value for w32_jitdbg (see below) +default_w32_jitdbg=0 + # Since GDB uses Readline, we need termcap functionality. In many # cases this will be provided by the curses library, but some systems # have a seperate termcap library, or no curses library at all. @@ -608,16 +611,42 @@ case $host_os in if test -d $srcdir/libtermcap; then LIBS="../libtermcap/libtermcap.a $LIBS" ac_cv_search_tgetent="../libtermcap/libtermcap.a" - fi ;; + fi + default_w32_jitdbg=1 + ;; go32* | *djgpp*) ac_cv_search_tgetent="none required" ;; *mingw32*) ac_cv_search_tgetent="none required" CONFIG_OBS="$CONFIG_OBS windows-termcap.o" + default_w32_jitdbg=1 ;; esac +# This feature requires 3 things: +# 1) windows.h with SetEvent() and CloseHandle() prototypes +# 2) inttypes.h with uintptr_t type defined +# 3) libkernel32 that exports SetEvent() and CloseHandle() +# Because functions in (1) use stdcall on W32, it's impossible to +# check them with AC_SEARCH_LIBS. +# Until a more elaborate check is written (compile_ifelse or something), +# users will have to enable this feature explicitly. +# However, this feature is enabled by default for platforms where it should +# normally work (MinGW and Cygwin). + +AC_ARG_ENABLE(w32-jitdbg, +AS_HELP_STRING([--enable-w32-jitdbg], [enable W32 JIT debugging]), + [case $enableval in + yes) w32_jitdbg=1 ;; + no) w32_jitdbg=0 ;; + *) + AC_MSG_ERROR([bad value $enableval for --enable-w32-jitdbg]) ;; + esac], + [w32_jitdbg=$default_w32_jitdbg]) +AC_DEFINE_UNQUOTED(W32_JITDBG, $w32_jitdbg, + [Define to 1 if W32 JIT debugging support is enabled, to 0 otherwise]) + # These are the libraries checked by Readline. AC_SEARCH_LIBS(tgetent, [termcap tinfo curses ncurses]) @@ -1071,7 +1100,7 @@ AC_CHECK_HEADERS([nlist.h machine/reg.h poll.h sys/poll.h proc_service.h \ sys/reg.h sys/debugreg.h sys/select.h sys/syscall.h \ sys/types.h sys/wait.h wait.h termios.h termio.h \ sgtty.h unistd.h elf_hp.h ctype.h time.h locale.h \ - dlfcn.h sys/socket.h sys/un.h]) + dlfcn.h sys/socket.h sys/un.h windows.h inttypes.h]) AC_CHECK_HEADERS(link.h, [], [], [#if HAVE_SYS_TYPES_H # include diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 8e2f74e..7d304a3 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -57,6 +57,11 @@ #include "continuations.h" #include "linespec.h" +#if W32_JITDBG +#include +#include +#endif + /* Functions exported for general use, in inferior.h: */ void all_registers_info (char *, int); @@ -2636,6 +2641,29 @@ attach_command (char *args, int from_tty) discard_cleanups (back_to); } +#if W32_JITDBG +void +signal_event_command (char *args, int from_tty) +{ + int async_exec = 0; + uintptr_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 ((errno == ERANGE) || (event_id == 0) || (event_id > UINTPTR_MAX) || + ((HANDLE) event_id == INVALID_HANDLE_VALUE)) + error (_("Failed to convert event id `%s' to event id"), args); + + SetEvent ((HANDLE) event_id); + CloseHandle ((HANDLE) event_id); + discard_cleanups (back_to); +} +#endif + /* 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..c733032 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -241,6 +241,10 @@ extern void post_create_inferior (struct target_ops *, int); extern void attach_command (char *, int); +#if W32_JITDBG +extern void signal_event_command (char *, int); +#endif + extern char *get_inferior_args (void); extern void set_inferior_args (char *); diff --git a/gdb/main.c b/gdb/main.c index 155b609..76ac3c1 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -278,6 +278,9 @@ captured_main (void *data) char *symarg = NULL; char *execarg = NULL; char *pidarg = NULL; +#if W32_JITDBG + char *eventarg = NULL; +#endif char *corearg = NULL; char *pid_or_core_arg = NULL; char *cdarg = NULL; @@ -402,6 +405,9 @@ captured_main (void *data) OPT_TUI, OPT_NOWINDOWS, OPT_WINDOWS, +#if W32_JITDBG + OPT_EVENT, +#endif OPT_IX, OPT_IEX }; @@ -438,6 +444,9 @@ captured_main (void *data) {"c", required_argument, 0, 'c'}, {"pid", required_argument, 0, 'p'}, {"p", required_argument, 0, 'p'}, +#if W32_JITDBG + {"event", required_argument, 0, OPT_EVENT}, +#endif {"command", required_argument, 0, 'x'}, {"eval-command", required_argument, 0, 'X'}, {"version", no_argument, &print_version, 1}, @@ -582,6 +591,11 @@ captured_main (void *data) VEC_safe_push (cmdarg_s, cmdarg_vec, &cmdarg); } break; +#if W32_JITDBG + case OPT_EVENT: + eventarg = optarg; + break; +#endif case 'B': batch_flag = batch_silent = 1; gdb_stdout = ui_file_new(); @@ -927,7 +941,11 @@ captured_main (void *data) catch_command_errors (core_file_command, pid_or_core_arg, !batch_flag, RETURN_MASK_ALL); } - +#if W32_JITDBG + if (eventarg != NULL) + catch_command_errors (signal_event_command, eventarg, + !batch_flag, RETURN_MASK_ALL); +#endif if (ttyarg != NULL) set_inferior_io_terminal (ttyarg); @@ -1059,6 +1077,11 @@ Options:\n\n\ --fullname Output information used by emacs-GDB interface.\n\ --help Print this message.\n\ "), stream); +#if W32_JITDBG + fputs_unfiltered (_("\ + --event=EVENT Signal the EVENT when attached to a process.\n\ +"), stream); +#endif fputs_unfiltered (_("\ --interpreter=INTERP\n\ Select a specific interpreter / user interface\n\ -- 1.7.4