From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19532 invoked by alias); 24 Aug 2011 18:57:33 -0000 Received: (qmail 19353 invoked by uid 22791); 24 Aug 2011 18:57:32 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_SOFTFAIL,TW_BJ X-Spam-Check-By: sourceware.org Received: from mail-yw0-f41.google.com (HELO mail-yw0-f41.google.com) (209.85.213.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 24 Aug 2011 18:57:17 +0000 Received: by ywm13 with SMTP id 13so1185589ywm.0 for ; Wed, 24 Aug 2011 11:57:16 -0700 (PDT) Received: by 10.142.166.15 with SMTP id o15mr2758466wfe.196.1314212236219; Wed, 24 Aug 2011 11:57:16 -0700 (PDT) Received: from localhost.localdomain ([203.110.240.178]) by mx.google.com with ESMTPS id i1sm2375961pbi.10.2011.08.24.11.57.13 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 24 Aug 2011 11:57:15 -0700 (PDT) From: Sanjoy Das To: gdb-patches@sourceware.org Cc: Sanjoy Das Subject: [PATCH 4/7] New commands for loading and unloading a reader. Date: Wed, 24 Aug 2011 18:57:00 -0000 Message-Id: <1314212467-7391-5-git-send-email-sanjoy@playingwithpointers.com> In-Reply-To: <1314212467-7391-1-git-send-email-sanjoy@playingwithpointers.com> References: <1314212467-7391-1-git-send-email-sanjoy@playingwithpointers.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-08/txt/msg00453.txt.bz2 Introduces two new GDB commands - `load-jit-reader' and `unload-jit-reader'. --- gdb/jit.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 102 insertions(+), 1 deletions(-) diff --git a/gdb/jit.c b/gdb/jit.c index cab27a9..f813625 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -31,6 +31,7 @@ #include "symfile.h" #include "symtab.h" #include "target.h" +#include "gdb-dlfcn.h" #include "gdb_stat.h" static const char *jit_reader_dir = NULL; @@ -115,6 +116,96 @@ mem_bfd_iovec_stat (struct bfd *abfd, void *stream, struct stat *sb) return 0; } +/* One reader that has been loaded successfully, and can potentially be used to + parse debug info. */ +static struct jit_reader +{ + struct gdb_reader_funcs *functions; +} *loaded_jit_reader = NULL; + +typedef struct gdb_reader_funcs * (reader_init_fn_type) (void); +static const char *reader_init_fn_sym = "gdb_init_reader"; + +/* Try to load FILE_NAME as a JIT debug info reader. */ + +static struct jit_reader * +jit_reader_load (const char *file_name) +{ + void *so; + reader_init_fn_type *init_fn; + struct jit_reader *new_reader = NULL; + struct gdb_reader_funcs *funcs = NULL; + struct cleanup *old_cleanups; + + if (jit_debug) + fprintf_unfiltered (gdb_stdlog, _("Opening shared object %s.\n"), + file_name); + so = gdb_dlopen (file_name); + old_cleanups = make_cleanup_dlclose (so); + + init_fn = gdb_dlsym (so, reader_init_fn_sym); + if (!init_fn) + error(_("Could not locate initialization function: %s."), + reader_init_fn_sym); + + if (gdb_dlsym (so, "plugin_is_GPL_compatible") == NULL) + error(_("Reader not GPL compatible.")); + + funcs = init_fn (); + if (funcs->reader_version != GDB_READER_INTERFACE_VERSION) + error(_("Reader version does not match GDB version.")); + + new_reader = XZALLOC (struct jit_reader); + new_reader->functions = funcs; + + discard_cleanups (old_cleanups); + return new_reader; +} + +/* Provides the jit-reader-load command. */ + +static void +jit_reader_load_command (char *args, int from_tty) +{ + char so_name[PATH_MAX]; + int len; + + if (args == NULL) + { + error (_("No reader name provided.")); + return; + } + + if (loaded_jit_reader != NULL) + { + error (_("JIT reader already loaded. Run jit-reader-unload first.")); + return; + } + + len = strlen (jit_reader_dir); + strcpy(so_name, jit_reader_dir); + so_name[len] = '/'; + so_name[len + 1] = 0; + + strncat (so_name, args, PATH_MAX - (len + 1)); + loaded_jit_reader = jit_reader_load (so_name); +} + +/* Provides the jit-reader-unload command. */ + +static void +jit_reader_unload_command (char *args, int from_tty) +{ + if (!loaded_jit_reader) + { + error(_("No JIT reader loaded.")); + return; + } + loaded_jit_reader->functions->destroy (loaded_jit_reader->functions); + free (loaded_jit_reader); + loaded_jit_reader = NULL; +} + /* Open a BFD from the target's memory. */ static struct bfd * @@ -535,7 +626,6 @@ jit_event_handler (struct gdbarch *gdbarch) paddress (gdbarch, entry_addr)); else jit_unregister_code (objf); - break; default: error (_("Unknown action_flag value in JIT descriptor!")); @@ -566,4 +656,15 @@ _initialize_jit (void) jit_objfile_data = register_objfile_data (); jit_inferior_data = register_inferior_data_with_cleanup (jit_inferior_data_cleanup); + add_com ("jit-reader-load", no_class, jit_reader_load_command, _("\ +Load FILE as debug info reader and unwinder for JIT compiled code.\n\ +Try to load file FILE as a debug info reader (and unwinder) for\n\ +JIT compiled code. The file is loaded from\n\ +" JIT_READER_DIR ", relocated \n\ +relative to the GDB executable if required.\n\ +Usage is `jit-reader-load FILE`.")); + add_com ("jit-reader-unload", no_class, jit_reader_unload_command, _("\ +Unload the currently loaded JIT debug info reader.\n\ +See jit-reader-load for how to load JIT debug readers.\n\ +")); } -- 1.7.5.4