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:02:00 -0000 [thread overview]
Message-ID: <31c02e39-d45f-8b65-2ff5-c21582d0f43d@redhat.com> (raw)
In-Reply-To: <df4b6203d89992b02f45dae5c45a2fa4@polymtl.ca>
On 02/01/2017 06:09 PM, Simon Marchi wrote:
> I don't think I understand the situation fully, but what you suggest
> looks good to me. I was confused by the fact that the gdb_disassembler
> constructor accepts a stream, but the pretty_print_insn method takes a
> uiout. Which one is used for printing then? I think that your patch
> clears that up.
>
Let me try to clear up a bit. v3, which predated the gdb_disassembler
changes, did this:
gdb_pretty_print_insn (struct gdbarch *gdbarch, struct ui_out *uiout,
struct disassemble_info * di,
const struct disasm_insn *insn, int flags,
- struct ui_file *stb)
+ string_file &stb)
{
/* parts of the symbolic representation of the address */
int unmapped;
@@ -240,7 +240,7 @@ gdb_pretty_print_insn (struct gdbarch *gdbarch, struct ui_out *uiout,
if (name != NULL)
xfree (name);
- ui_file_rewind (stb);
+ stb.clear ();
[...]
uiout->field_stream ("inst", stb);
- ui_file_rewind (stb);
+ stb.clear ();
do_cleanups (ui_out_chain);
uiout->text ("\n");
while in current master we have:
int
gdb_disassembler::pretty_print_insn (struct ui_out *uiout,
const struct disasm_insn *insn,
int flags)
{
[...]
struct ui_file *stb = stream ();
[...]
ui_file_rewind (stb);
[...]
So we can no longer do the same thing v3 did, because
"stream ();" is generic. Looking at the callers of
pretty_print_insn, we know that the ui_file returned by
"stream ();" here is "string_file *", but doing:
- struct ui_file *stb = stream ();
+ string_file *stb = (string_file *) stream ();
would be a gross hack, for baking in knowledge of who
are the current callers.
> The only possible issue I can see is that in your version, one
> gdb_disassembler and one string_file object are constructed for each
> disassembled instruction, rather than re-using them for as long as we
> need to disassemble. I don't know how much impact it has on the
> performance (probably negligible), but something to keep in mind.
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.
Thanks,
Pedro Alves
next prev parent reply other threads:[~2017-02-01 20:02 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 [this message]
2017-02-01 20:31 ` Pedro Alves
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=31c02e39-d45f-8b65-2ff5-c21582d0f43d@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).