[PATCH v4 1/2] Add back gdb_pretty_print_insn
Pedro Alves
palves@redhat.com
Wed Feb 1 20:02:00 GMT 2017
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
More information about the Gdb-patches
mailing list