Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Abhijit Halder <abhijit.k.halder@gmail.com>
To: Sanjoy Das <sanjoy@playingwithpointers.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 4/7] New commands for loading and unloading a reader.
Date: Sat, 27 Aug 2011 14:51:00 -0000	[thread overview]
Message-ID: <CAOhZP9w=mfLYPo4c1vrVw0AfkHbjEGXs9_J4Jmii3fLi7SYPZQ@mail.gmail.com> (raw)
In-Reply-To: <1314450736-19389-5-git-send-email-sanjoy@playingwithpointers.com>

On Sat, Aug 27, 2011 at 6:42 PM, Sanjoy Das
<sanjoy@playingwithpointers.com> wrote:
> Introduces two new GDB commands - `load-jit-reader' and
> `unload-jit-reader'.
>
> gdb/ChangeLog:
>        * gdb/jit.c: Include gdb-dlfcn.h.
>        (loaded_jit_reader, reader_init_fn_sym): New static variables.
>        (jit_reader_load, jit_reader_load_command)
>        (jit_reader_unload_command): New functions.
>        (_initialize_jit): Add commands "jit-reader-load" and
>        "jit-reader-unload".
> ---
>  gdb/ChangeLog |    9 +++++
>  gdb/jit.c     |  103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 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 @@
>  2011-08-27  Sanjoy Das  <sdas@igalia.com>
>
> +       * gdb/jit.c: Include gdb-dlfcn.h.
> +       (loaded_jit_reader, reader_init_fn_sym): New static variables.
> +       (jit_reader_load, jit_reader_load_command)
> +       (jit_reader_unload_command): New functions.
> +       (_initialize_jit): Add commands "jit-reader-load" and
> +       "jit-reader-unload".
> +
> +2011-08-27  Sanjoy Das  <sdas@igalia.com>
> +
>        * gdb/Makefile.in: Add gdb-dlfcn.c and gdb-dlfcn.h to build
>        system.
>        * 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 @@
>  #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,97 @@ 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;
This return statement is of no use.

> +    }
> +
> +  if (loaded_jit_reader != NULL)
> +    {
> +      error (_("JIT reader already loaded.  Run jit-reader-unload first."));
> +      return;
Same here.

> +    }
> +
> +  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));
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);

> +  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;
return statement of no use.

> +    }
> +  loaded_jit_reader->functions->destroy (loaded_jit_reader->functions);
> +  free (loaded_jit_reader);
Should be xfree instead of free.

> +  loaded_jit_reader = NULL;
> +}
> +
>  /* Open a BFD from the target's memory.  */
>
>  static struct bfd *
> @@ -566,4 +658,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
>
>


  reply	other threads:[~2011-08-27 14:51 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-27 13:08 JIT Debug Info Reader Sanjoy Das
2011-08-27 13:08 ` [PATCH 5/7] Use the loaded reader Sanjoy Das
2011-08-27 13:47   ` Abhijit Halder
2011-08-27 14:18     ` Abhijit Halder
2011-08-27 13:08 ` [PATCH 3/7] Platform agnostic dynamic loading code Sanjoy Das
2011-08-27 13:08 ` [PATCH 2/7] Relocatable directory for loading JIT readers Sanjoy Das
2011-08-27 13:08 ` [PATCH 4/7] New commands for loading and unloading a reader Sanjoy Das
2011-08-27 14:51   ` Abhijit Halder [this message]
2011-08-27 13:08 ` [PATCH 6/7] New JIT unwinder Sanjoy Das
2011-08-28  2:17   ` Sergio Durigan Junior
     [not found]   ` <1314518609-10204-1-git-send-email-sanjoy@playingwithpointers.com>
2011-08-28  8:04     ` Sanjoy Das
2011-08-30 19:28       ` Tom Tromey
2011-08-28  8:04     ` [PATCH 3/7] Platform agnostic dynamic loading code Sanjoy Das
2011-08-28  8:04     ` [PATCH 4/7] New commands for loading and unloading a reader Sanjoy Das
2011-08-30 18:52       ` Tom Tromey
2011-08-28  8:04     ` [PATCH 5/7] Use the loaded reader Sanjoy Das
2011-08-30 19:18       ` Tom Tromey
2011-08-28  8:04     ` [PATCH 7/7] Documentation Sanjoy Das
2011-08-30 19:43       ` Tom Tromey
2011-08-28  8:05     ` [PATCH 2/7] Relocatable directory for loading JIT readers Sanjoy Das
2011-08-30 18:32       ` Tom Tromey
2011-08-28  8:07     ` [PATCH 1/7] Introduce jit-reader.in and modify build system Sanjoy Das
2011-08-30 18:30       ` Tom Tromey
2011-08-31  3:16         ` Sanjoy Das
2011-08-31 17:44           ` Tom Tromey
2011-08-27 13:08 ` [PATCH 7/7] Documentation Sanjoy Das
2011-08-27 13:08 ` [PATCH 1/7] Introduce jit-reader.in and modify build system Sanjoy Das
  -- strict thread matches above, loose matches on Subject: below --
2011-08-31  3:31 JIT Reader (re-roll) Sanjoy Das
2011-08-31  3:32 ` [PATCH 4/7] New commands for loading and unloading a reader Sanjoy Das
2011-08-24 18:57 JIT Debug Info Reader (re-roll) Sanjoy Das
2011-08-24 18:57 ` [PATCH 4/7] New commands for loading and unloading a reader Sanjoy Das

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOhZP9w=mfLYPo4c1vrVw0AfkHbjEGXs9_J4Jmii3fLi7SYPZQ@mail.gmail.com' \
    --to=abhijit.k.halder@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sanjoy@playingwithpointers.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox