Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: Sergio Durigan Junior <sergiodj@redhat.com>
Cc: "Jose E. Marchesi" <jose.marchesi@oracle.com>,
	gdb-patches@sourceware.org
Subject: Re: [PATCH V4 5/9] New probe type: DTrace USDT probes.
Date: Wed, 25 Mar 2015 19:14:00 -0000	[thread overview]
Message-ID: <20150325191418.GA32233@adacore.com> (raw)
In-Reply-To: <87r3tp722i.fsf@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 4984 bytes --]

Jose,

> > 2015-02-02  Jose E. Marchesi  <jose.marchesi@oracle.com>
> >
> > 	* breakpoint.c (BREAK_ARGS_HELP): help string updated to mention
> > 	the -probe-dtrace new vpossible value for PROBE_MODIFIER.
> > 	* configure.ac (CONFIG_OBS): dtrace-probe.o added if BFD can
> > 	handle ELF files.
> > 	* Makefile.in (SFILES): dtrace-probe.c added.
> > 	* configure: Regenerate.
> > 	* dtrace-probe.c: New file.
> > 	(SHT_SUNW_dof): New constant.
> > 	(dtrace_probe_type): New enum.
> > 	(dtrace_probe_arg): New struct.
> > 	(dtrace_probe_arg_s): New typedef.
> > 	(struct dtrace_probe_enabler): New struct.
> > 	(dtrace_probe_enabler_s): New typedef.
> > 	(dtrace_probe): New struct.
> > 	(dtrace_probe_is_linespec): New function.
> > 	(dtrace_dof_sect_type): New enum.
> > 	(dtrace_dof_dofh_ident): Likewise.
> > 	(dtrace_dof_encoding): Likewise.
> > 	(DTRACE_DOF_ENCODE_LSB): Likewise.
> > 	(DTRACE_DOF_ENCODE_MSB): Likewise.
> > 	(dtrace_dof_hdr): New struct.
> > 	(dtrace_dof_sect): Likewise.
> > 	(dtrace_dof_provider): Likewise.
> > 	(dtrace_dof_probe): Likewise.
> > 	(DOF_UINT): New macro.
> > 	(DTRACE_DOF_PTR): Likewise.
> > 	(DTRACE_DOF_SECT): Likewise.
> > 	(dtrace_process_dof_probe): New function.
> > 	(dtrace_process_dof): Likewise.
> > 	(dtrace_build_arg_exprs): Likewise.
> > 	(dtrace_get_arg): Likewise.
> > 	(dtrace_get_probes): Likewise.
> > 	(dtrace_get_probe_argument_count): Likewise.
> > 	(dtrace_can_evaluate_probe_arguments): Likewise.
> > 	(dtrace_evaluate_probe_argument): Likewise.
> > 	(dtrace_compile_to_ax): Likewise.
> > 	(dtrace_probe_destroy): Likewise.
> > 	(dtrace_gen_info_probes_table_header): Likewise.
> > 	(dtrace_gen_info_probes_table_values): Likewise.
> > 	(dtrace_probe_is_enabled): Likewise.
> > 	(dtrace_probe_ops): New variable.
> > 	(info_probes_dtrace_command): New function.
> > 	(_initialize_dtrace_probe): Likewise.
> > 	(dtrace_type_name): Likewise.

Unfortunately, this patch is breaking GDB completely on Solaris.
The first issue I started investigating is the following, which
happens with nearly any unthreaded program:

    (gdb) start
    Temporary breakpoint 1 at 0x80593bc: file simple_main.adb, line 4.
    Starting program: /[...]/simple_main 
    [Thread debugging using libthread_db enabled]
    No definition of "mutex_t" in current context.

The error happens in...

> > +static void
> > +dtrace_process_dof_probe (struct objfile *objfile,

... and more precisely...

> > +      /* Store argument type descriptions.  A description of the type
> > +         of the argument is in the (J+1)th null-terminated string
> > +         starting at 'strtab' + 'probe->dofpr_nargv'.  */
> > +      ret->args = NULL;
> > +      p = strtab + DOF_UINT (dof, probe->dofpr_nargv);
> > +      for (j = 0; j < ret->probe_argc; j++)
> > +	{
> > +	  struct dtrace_probe_arg arg;
> > +	  struct expression *expr;
> > +
> > +	  arg.type_str = xstrdup (p);
> > +
> > +	  /* Use strtab_size as a sentinel.  */
> > +	  while (*p++ != '\0' && p - strtab < strtab_size);
> > +
> > +	  /* Try to parse a type expression from the type string.  If
> > +	     this does not work then we set the type to `long
> > +	     int'.  */
> > +          arg.type = builtin_type (gdbarch)->builtin_long;
> > +	  expr = parse_expression (arg.type_str);
                 ^^^^^^^^^^^^^^^^
                 there

The most obvious issue is that type "mutex_t" does not exist in
my program, so I think that the code should handle that case.

The second, less obvious issue, is that the parsing is done using
the current language, which I don't think is a good idea. Attached
is small prototype that attempts to do something like that.
I think we need a function that parses an expression using
a specific language, but I went for short prototype to test
my theory first.

That solves most of the issues, even if I don't really know if
it's not just sweeping them under the carpet instead.

And once I had that fixed, the next issue that I looked at was:

    (gdb) b adainit
    Breakpoint 1 at 0x8051f03
    (gdb) run
    Starting program: /[...]/a
    [Thread debugging using libthread_db enabled]
    zsh: 12378 segmentation fault (core dumped)  /[...]/gdb -q a

This is where I'm getting even more out of my league, here.
The SEGV happens on the following line:

377           uint32_t enabler_offset
378             = ((uint32_t *) eofftab)[DOF_UINT (dof, probe->dofpr_enoffidx) + i];

... and eofftab seems to have a bogus value, because:

    (gdb) p eofftab
    $6 = 0x9479fb2 <error: Cannot access memory at address 0x9479fb2>

For me to investigate further, I think I'd have to investigate how
probes work and what's where, and I don't really have the time or
interest at the moment. So, I'm hoping that you have access to some
Solaris systems and you could look into this?

I can send you reproducers, if you need. I investigated the issue on
x86-solaris 2.10, but the same happens on sparc-solaris 2.10 and
sparc64-solaris 2.10.

Thank you,
-- 
Joel

[-- Attachment #2: dtrace.diff --]
[-- Type: text/x-diff, Size: 1261 bytes --]

diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c
index 491d853..5d5c5b2 100644
--- a/gdb/dtrace-probe.c
+++ b/gdb/dtrace-probe.c
@@ -414,6 +414,7 @@ dtrace_process_dof_probe (struct objfile *objfile,
 	{
 	  struct dtrace_probe_arg arg;
 	  struct expression *expr;
+	  struct cleanup *old_chain = NULL;
 
 	  /* Set arg.expr to ensure all fields in expr are initialized and
 	     the compiler will not warn when arg is used.  */
@@ -427,8 +428,24 @@ dtrace_process_dof_probe (struct objfile *objfile,
 	     this does not work then we set the type to `long
 	     int'.  */
           arg.type = builtin_type (gdbarch)->builtin_long;
-	  expr = parse_expression (arg.type_str);
-	  if (expr->elts[0].opcode == OP_TYPE)
+
+	  if (current_language->la_language != language_c)
+	    {
+	      old_chain = make_cleanup_restore_current_language ();
+	      set_language (language_c);
+	    }
+	  TRY
+	    {
+	      expr = parse_expression (arg.type_str);
+	    }
+	  CATCH (ex, RETURN_MASK_ERROR)
+	    {
+	      expr = NULL;
+	    }
+	  END_CATCH
+	  if (old_chain != NULL)
+	    do_cleanups (old_chain);
+	  if (expr != NULL && expr->elts[0].opcode == OP_TYPE)
 	    arg.type = expr->elts[1].type;
 
 	  VEC_safe_push (dtrace_probe_arg_s, ret->args, &arg);

  reply	other threads:[~2015-03-25 19:14 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-02 10:57 [PATCH V4 0/9] Add support for DTrace USDT probes to gdb Jose E. Marchesi
2015-02-02 10:57 ` [PATCH V4 3/9] New commands `enable probe' and `disable probe' Jose E. Marchesi
2015-02-02 16:01   ` Eli Zaretskii
2015-02-17  1:54   ` Sergio Durigan Junior
2015-02-02 10:57 ` [PATCH V4 7/9] Simple testsuite for DTrace USDT probes Jose E. Marchesi
2015-02-02 11:18   ` Jose E. Marchesi
2015-02-17  1:53   ` Sergio Durigan Junior
2015-02-17  1:58     ` Sergio Durigan Junior
2015-02-17 11:32       ` Pedro Alves
2015-02-02 10:57 ` [PATCH V4 1/9] Adapt `info probes' to support printing probes of different types Jose E. Marchesi
2015-02-17  1:12   ` Sergio Durigan Junior
2015-02-02 10:57 ` [PATCH V4 9/9] Announce the DTrace USDT probes support in NEWS Jose E. Marchesi
2015-02-02 16:03   ` Eli Zaretskii
2015-02-02 10:57 ` [PATCH V4 6/9] Support for DTrace USDT probes in x86_64 targets Jose E. Marchesi
2015-02-17  1:37   ` Sergio Durigan Junior
2015-02-02 10:57 ` [PATCH V4 4/9] New gdbarch functions: dtrace_parse_probe_argument, dtrace_probe_is_enabled, dtrace_enable_probe, dtrace_disable_probe Jose E. Marchesi
2015-02-17  1:14   ` Sergio Durigan Junior
2015-02-02 10:57 ` [PATCH V4 5/9] New probe type: DTrace USDT probes Jose E. Marchesi
2015-02-17  1:35   ` Sergio Durigan Junior
2015-03-25 19:14     ` Joel Brobecker [this message]
2015-03-26 16:15       ` Jose E. Marchesi
2015-03-26 17:50         ` Joel Brobecker
2015-03-26 18:43           ` Joel Brobecker
2015-03-26 18:53             ` Sergio Durigan Junior
2015-03-26 21:00               ` Joel Brobecker
2015-03-27  9:47                 ` gdb fails to compile with GCC 4.4.7 (was: [PATCH V4 5/9] New probe type: DTrace USDT probes.) Tobias Burnus
2015-03-27 13:42                   ` Joel Brobecker
2015-03-27 15:18                     ` Tobias Burnus
2015-03-27 15:27                       ` [pushed] " Joel Brobecker
2015-03-27 16:58                         ` H.J. Lu
2015-03-26 23:39           ` [PATCH V4 5/9] New probe type: DTrace USDT probes Jose E. Marchesi
2015-03-31 17:29           ` Jose E. Marchesi
2015-03-31 18:47             ` Joel Brobecker
2015-03-31 19:54               ` Jose E. Marchesi
2015-08-06 21:31                 ` Joel Brobecker
2015-08-07  2:03                   ` Sergio Durigan Junior
2015-08-07 15:20                     ` Joel Brobecker
2015-08-07 13:05                   ` Jose E. Marchesi
2015-08-07 13:14                   ` Jose E. Marchesi
2015-08-07 14:11                     ` Jose E. Marchesi
2015-08-07 15:12                       ` Joel Brobecker
2015-08-10  3:21                         ` Sergio Durigan Junior
2015-08-10 14:31                           ` Jose E. Marchesi
2015-02-02 10:57 ` [PATCH V4 8/9] Documentation for " Jose E. Marchesi
2015-02-02 16:03   ` Eli Zaretskii
2015-02-02 19:47     ` Jose E. Marchesi
2015-02-02 10:57 ` [PATCH V4 2/9] Move `compute_probe_arg' and `compile_probe_arg' to probe.c Jose E. Marchesi
2015-02-17  1:13   ` Sergio Durigan Junior
2015-02-16 13:20 ` [PATCH V4 0/9] Add support for DTrace USDT probes to gdb Jose E. Marchesi
2015-02-17  1:57 ` Sergio Durigan Junior
2015-02-17 11:56   ` Jose E. Marchesi

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=20150325191418.GA32233@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jose.marchesi@oracle.com \
    --cc=sergiodj@redhat.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