public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@mips.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: <gdb-patches@sourceware.org>, <binutils@sourceware.org>,
	Joel Brobecker	<brobecker@adacore.com>,
	Fredrik Noring <noring@nocrew.org>
Subject: Re: [PP?] [PATCH v3] GDB PR tdep/8282: MIPS: Wire in `set disassembler-options'
Date: Wed, 20 Jun 2018 15:40:00 -0000	[thread overview]
Message-ID: <alpine.DEB.2.00.1806201608250.20622@tp.orcam.me.uk> (raw)
In-Reply-To: <158bad5a-3a2d-cc7f-4a77-71135a93f0ac@polymtl.ca>

Hi Simon,

> > Existing affected target backends have been adjusted accordingly.  The 
> > only other backend (besides MIPS, now modernized) setting disassembler 
> > options in its own specific way turned out to be the i386 one.  As its 
> > `i386_print_insn' handler is always passed a NULL `disassembler_options' 
> > value, assert that and clear the pointer after use, so that code in 
> > `gdb_buffered_insn_length' doesn't choke on `free' being called on a 
> > static data pointer.
> 
> Having a field sometimes own the string and sometimes don't is a recipe for
> confusion.

 Indeed, however I decided not to complicate the thing further under an 
assumption (perhaps an unjustified one) that the i386 backend will 
eventually get converted to support `set disassembler-options ...' as 
well.  At which point the hack would go away naturally.

>  It would be better to make get_all_disassembler_options return a
> gdb::unique_xmalloc_ptr instead [1], and propagate to whatever object/scope really
> owns the string.  See the patch at the bottom implementing this idea (applied on
> top of this one).

 If you however think it's worth an extra effort to support the interim 
situation with the i386 backend, then I can't object.  Thanks for this 
update.

> [1] Or an std::string. but that does not play well with remove_whitespace_and_extra_commas.
>     Can we avoid calling remove_whitespace_and_extra_commas by not putting the comma if it
>     is not necessary?

 Yeah, why not.

> > Index: binutils/gdb/disasm.c
> > ===================================================================
> > --- binutils.orig/gdb/disasm.c	2018-06-13 16:00:05.000000000 +0100
> > +++ binutils/gdb/disasm.c	2018-06-14 21:45:24.771254073 +0100
> > @@ -722,6 +722,35 @@ fprintf_disasm (void *stream, const char
> >    return 0;
> >  }
> >  
> > +/* Combine implicit and user disassembler options and return them
> > +   in a newly-allocated buffer.  Return NULL if the string would be
> > +   empty.  */
> > +
> > +static const char *
> > +get_all_disassembler_options (struct gdbarch *gdbarch)
> > +{
> > +  const char *implicit_options;
> > +  const char *options;
> > +  char *all_options;
> > +  size_t len;
> > +
> > +  implicit_options = gdbarch_disassembler_options_implicit (gdbarch);
> > +  options = get_disassembler_options (gdbarch);
> > +  len = ((implicit_options != NULL ? strlen (implicit_options) : 0) + 1
> > +	 + (options != NULL ? strlen (options) : 0) + 1);
> > +  all_options = (char *) xmalloc (len);
> > +  sprintf (all_options, "%s,%s",
> > +	   implicit_options != NULL ? implicit_options : "",
> > +	   options != NULL ? options : "");
> 
> It would be better to use xstrprintf instead of computing the required length
> by hand.

 Good point, I didn't know of this one (or for that matter, the underlying 
`asprintf'/`vasprintf' functions, which are a GNU extension).  Thanks.

 I'll fold your change into my proposal and rewrite the necessary bits to 
use `std::string'.  Thank you for your review.

  Maciej

      reply	other threads:[~2018-06-20 15:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-14 22:08 Maciej W. Rozycki
2018-06-18  2:59 ` [PP?] " Simon Marchi
2018-06-20 15:40   ` Maciej W. Rozycki [this message]

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=alpine.DEB.2.00.1806201608250.20622@tp.orcam.me.uk \
    --to=macro@mips.com \
    --cc=binutils@sourceware.org \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=noring@nocrew.org \
    --cc=simon.marchi@polymtl.ca \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).