From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31547 invoked by alias); 27 Aug 2011 14:51:18 -0000 Received: (qmail 31537 invoked by uid 22791); 27 Aug 2011 14:51:17 -0000 X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL,BAYES_50,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,TW_BJ X-Spam-Check-By: sourceware.org Received: from mail-bw0-f41.google.com (HELO mail-bw0-f41.google.com) (209.85.214.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 27 Aug 2011 14:51:03 +0000 Received: by bkbzt4 with SMTP id zt4so3624608bkb.0 for ; Sat, 27 Aug 2011 07:51:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.135.150 with SMTP id n22mr1138352bkt.389.1314456662000; Sat, 27 Aug 2011 07:51:02 -0700 (PDT) Received: by 10.204.36.74 with HTTP; Sat, 27 Aug 2011 07:51:01 -0700 (PDT) In-Reply-To: <1314450736-19389-5-git-send-email-sanjoy@playingwithpointers.com> References: <1314450736-19389-1-git-send-email-sanjoy@playingwithpointers.com> <1314450736-19389-5-git-send-email-sanjoy@playingwithpointers.com> Date: Sat, 27 Aug 2011 14:51:00 -0000 Message-ID: Subject: Re: [PATCH 4/7] New commands for loading and unloading a reader. From: Abhijit Halder To: Sanjoy Das Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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/msg00535.txt.bz2 On Sat, Aug 27, 2011 at 6:42 PM, Sanjoy Das wrote: > Introduces two new GDB commands - `load-jit-reader' and > `unload-jit-reader'. > > gdb/ChangeLog: > =A0 =A0 =A0 =A0* gdb/jit.c: Include gdb-dlfcn.h. > =A0 =A0 =A0 =A0(loaded_jit_reader, reader_init_fn_sym): New static variab= les. > =A0 =A0 =A0 =A0(jit_reader_load, jit_reader_load_command) > =A0 =A0 =A0 =A0(jit_reader_unload_command): New functions. > =A0 =A0 =A0 =A0(_initialize_jit): Add commands "jit-reader-load" and > =A0 =A0 =A0 =A0"jit-reader-unload". > --- > =A0gdb/ChangeLog | =A0 =A09 +++++ > =A0gdb/jit.c =A0 =A0 | =A0103 +++++++++++++++++++++++++++++++++++++++++++= ++++++++++++++ > =A02 files changed, 112 insertions(+), 0 deletions(-) > > diff --git a/gdb/ChangeLog b/gdb/ChangeLog > index 3536807..78076ef 100644 > --- a/gdb/ChangeLog > +++ b/gdb/ChangeLog > @@ -1,5 +1,14 @@ > =A02011-08-27 =A0Sanjoy Das =A0 > > + =A0 =A0 =A0 * gdb/jit.c: Include gdb-dlfcn.h. > + =A0 =A0 =A0 (loaded_jit_reader, reader_init_fn_sym): New static variabl= es. > + =A0 =A0 =A0 (jit_reader_load, jit_reader_load_command) > + =A0 =A0 =A0 (jit_reader_unload_command): New functions. > + =A0 =A0 =A0 (_initialize_jit): Add commands "jit-reader-load" and > + =A0 =A0 =A0 "jit-reader-unload". > + > +2011-08-27 =A0Sanjoy Das =A0 > + > =A0 =A0 =A0 =A0* gdb/Makefile.in: Add gdb-dlfcn.c and gdb-dlfcn.h to build > =A0 =A0 =A0 =A0system. > =A0 =A0 =A0 =A0* gdb/config.in: Add new #define HAVE_LIBDL. > diff --git a/gdb/jit.c b/gdb/jit.c > index cab27a9..4fc5819 100644 > --- a/gdb/jit.c > +++ b/gdb/jit.c > @@ -31,6 +31,7 @@ > =A0#include "symfile.h" > =A0#include "symtab.h" > =A0#include "target.h" > +#include "gdb-dlfcn.h" > =A0#include "gdb_stat.h" > > =A0static const char *jit_reader_dir =3D NULL; > @@ -115,6 +116,97 @@ mem_bfd_iovec_stat (struct bfd *abfd, void *stream, = struct stat *sb) > =A0 return 0; > =A0} > > +/* One reader that has been loaded successfully, and can potentially be = used to > + =A0 parse debug info. */ > + > +static struct jit_reader > +{ > + =A0struct gdb_reader_funcs *functions; > +} *loaded_jit_reader =3D NULL; > + > +typedef struct gdb_reader_funcs * (reader_init_fn_type) (void); > +static const char *reader_init_fn_sym =3D "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) > +{ > + =A0void *so; > + =A0reader_init_fn_type *init_fn; > + =A0struct jit_reader *new_reader =3D NULL; > + =A0struct gdb_reader_funcs *funcs =3D NULL; > + =A0struct cleanup *old_cleanups; > + > + =A0if (jit_debug) > + =A0 =A0fprintf_unfiltered (gdb_stdlog, _("Opening shared object %s.\n"), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0file_name); > + =A0so =3D gdb_dlopen (file_name); > + =A0old_cleanups =3D make_cleanup_dlclose (so); > + > + =A0init_fn =3D gdb_dlsym (so, reader_init_fn_sym); > + =A0if (!init_fn) > + =A0 =A0error(_("Could not locate initialization function: %s."), > + =A0 =A0 =A0 =A0 =A0reader_init_fn_sym); > + > + =A0if (gdb_dlsym (so, "plugin_is_GPL_compatible") =3D=3D NULL) > + =A0 =A0error(_("Reader not GPL compatible.")); > + > + =A0funcs =3D init_fn (); > + =A0if (funcs->reader_version !=3D GDB_READER_INTERFACE_VERSION) > + =A0 =A0error(_("Reader version does not match GDB version.")); > + > + =A0new_reader =3D XZALLOC (struct jit_reader); > + =A0new_reader->functions =3D funcs; > + > + =A0discard_cleanups (old_cleanups); > + =A0return new_reader; > +} > + > +/* Provides the jit-reader-load command. */ > + > +static void > +jit_reader_load_command (char *args, int from_tty) > +{ > + =A0char so_name[PATH_MAX]; > + =A0int len; > + > + =A0if (args =3D=3D NULL) > + =A0 =A0{ > + =A0 =A0 =A0error (_("No reader name provided.")); > + =A0 =A0 =A0return; This return statement is of no use. > + =A0 =A0} > + > + =A0if (loaded_jit_reader !=3D NULL) > + =A0 =A0{ > + =A0 =A0 =A0error (_("JIT reader already loaded. =A0Run jit-reader-unloa= d first.")); > + =A0 =A0 =A0return; Same here. > + =A0 =A0} > + > + =A0len =3D strlen (jit_reader_dir); > + =A0strcpy(so_name, jit_reader_dir); > + =A0so_name[len] =3D '/'; > + =A0so_name[len + 1] =3D 0; > + > + =A0strncat (so_name, args, PATH_MAX - (len + 1)); Why can't you use snprintf instead of all the above functions as below? snprintf (so_name, sizeof (so_name), "%s/%s", jit_reader_dir, args); > + =A0loaded_jit_reader =3D jit_reader_load (so_name); > +} > + > +/* Provides the jit-reader-unload command. */ > + > +static void > +jit_reader_unload_command (char *args, int from_tty) > +{ > + =A0if (!loaded_jit_reader) > + =A0 =A0{ > + =A0 =A0 =A0error(_("No JIT reader loaded.")); > + =A0 =A0 =A0return; return statement of no use. > + =A0 =A0} > + =A0loaded_jit_reader->functions->destroy (loaded_jit_reader->functions); > + =A0free (loaded_jit_reader); Should be xfree instead of free. > + =A0loaded_jit_reader =3D NULL; > +} > + > =A0/* Open a BFD from the target's memory. =A0*/ > > =A0static struct bfd * > @@ -566,4 +658,15 @@ _initialize_jit (void) > =A0 jit_objfile_data =3D register_objfile_data (); > =A0 jit_inferior_data =3D > =A0 =A0 register_inferior_data_with_cleanup (jit_inferior_data_cleanup); > + =A0add_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`.")); > + =A0add_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\ > +")); > =A0} > -- > 1.7.5.4 > >