public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v4 1/2] Add back gdb_pretty_print_insn
Date: Wed, 01 Feb 2017 20:31:00 -0000	[thread overview]
Message-ID: <3d886f4f-ba53-4ef6-3767-a7fe8a17ba85@redhat.com> (raw)
In-Reply-To: <31c02e39-d45f-8b65-2ff5-c21582d0f43d@redhat.com>

On 02/01/2017 08:01 PM, Pedro Alves wrote:

> Yeah.  It's simple to add a string_file parameter to gdb_pretty_print_insn,
> in order to pass in a buffer that is reused, like it used to be,
> if found necessary.
> 
> gdb_disassembler is on the stack so practically doesn't
> count, in overhead terms.  I think for this series it may end
> up balanced by allocating fewer cleanups, and also I suspect
> most disassembled instructions fit std::string's
> "small string optimization", meaning no heap allocation.

If we do that, I think a better idea occurred to me.  Note that
gdb_disassembler::pretty_print_insn has yet another local
buffer:

      /* Build the opcodes using a temporary stream so we can
	 write them out in a single go for the MI.  */
      struct ui_file *opcode_stream = mem_fileopen ();
      struct cleanup *cleanups =
	make_cleanup_ui_file_delete (opcode_stream);

so it would make sense to treat both buffers the same
way.  I.e., if we want to reuse one, we should probably
reuse both.  Which suggests creating a new struct to hold
whatever should survive across calls.  And then we can
go the step further, and make that a class, with
pretty_print_insn a method of _that_ class instead of
of gdb_disassembler.  Like:

struct gdb_pretty_disassembler
{
  int pretty_print_insn (struct ui_out *uiout, 
                         const struct disasm_insn *insn,
                         int flags);

private:
  string_file m_insn_buffer;
  string_file m_opcode_buffer;
};

and then the use in loops would be something like:

func ()
{
  gdb_pretty_disassembler disasm;

  while (whatever)
    {
       disasm.print_insn (uiout, ....);
    }
}

I can try that, but I think I'd rather do it after
string_file is in already.

Thanks,
Pedro Alves

  reply	other threads:[~2017-02-01 20:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-01  0:30 [PATCH v4 0/2] Eliminate cleanups & make ui_file a C++ class hierarchy Pedro Alves
2017-02-01  0:30 ` [PATCH v4 1/2] Add back gdb_pretty_print_insn Pedro Alves
2017-02-01 17:01   ` Luis Machado
2017-02-01 18:10   ` Simon Marchi
2017-02-01 18:26     ` Simon Marchi
2017-02-02  0:00       ` Pedro Alves
2017-02-01 20:02     ` Pedro Alves
2017-02-01 20:31       ` Pedro Alves [this message]
2017-02-01 23:50         ` Pedro Alves
2017-02-02  1:20           ` Simon Marchi
2017-02-02 11:37             ` [pushed] Reuse buffers across gdb_pretty_print_insn calls (Re: [PATCH v4 1/2] Add back gdb_pretty_print_insn) Pedro Alves
2017-02-01  0:31 ` [PATCH v4 2/2] Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy Pedro Alves
2017-02-01 17:37   ` Luis Machado
2017-02-01 22:49     ` Pedro Alves
2017-02-01 23:24       ` Luis Machado
2017-02-02  0:02         ` Pedro Alves
2017-02-27 19:43           ` Edjunior Barbosa Machado
2017-03-07 14:02             ` Pedro Alves

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=3d886f4f-ba53-4ef6-3767-a7fe8a17ba85@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.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).