[PATCH 6/6] btrace: use gdb_disassembly_vec and new source interleaving method

Markus Metzger
2015-09-21T14:54:53Z

Use the new gdb_disassembly_vec interface for the "record instruction-
history" command.

Use the new source interleaving method. We stick to the /m modifier.
The old version is broken and there's no point in keeping it as alternative
to this new version.

2015-09-21 Markus Metzger <markus.t.metzger@intel.com>

gdb/
* record-btrace.c (btrace_insn_history): Call gdb_disassembly_vec
instead of gdb_disassembly. Set DISASSEMBLY_SPECULATIVE.
* record.c (get_insn_history_modifiers): Set DISASSEMBLY_SOURCE
instead of DISASSEMBLY_SOURCE_DEPRECATED.
---
gdb/record-btrace.c | 54 ++++++++++++++++++++++++++---------------------------
gdb/record.c | 2 +-
2 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index d14e6cf..ecb8085 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -538,11 +538,17 @@ btrace_insn_history (struct ui_out *uiout,
{
struct gdbarch *gdbarch;
struct btrace_insn_iterator it;
+ VEC (disas_insn_t) *insns;
+ struct cleanup *cleanups;

DEBUG ("itrace (0x%x): [%u; %u)", flags, btrace_insn_number (begin),
btrace_insn_number (end));

+ flags |= DISASSEMBLY_SPECULATIVE;
+
gdbarch = target_gdbarch ();
+ insns = NULL;
+ cleanups = make_cleanup (VEC_cleanup (disas_insn_t), &insns);

for (it = *begin; btrace_insn_cmp (&it, end) != 0; btrace_insn_next (&it, 1))
{
@@ -560,42 +566,34 @@ btrace_insn_history (struct ui_out *uiout,
/* We have trace so we must have a configuration. */
gdb_assert (conf != NULL);

+ /* Print the instructions we collected, so far, then the error.
+
+ This will result in two disjoint "asm_insns" lists with a
+ stand-alone error in-between. It's better than what we had
+ before but still not OK for MI users. */
+ gdb_disassembly_vec (gdbarch, uiout, flags, insns);
+
btrace_ui_out_decode_error (uiout, it.function->errcode,
conf->format);
+
+ /* Start over. */
+ VEC_free (disas_insn_t, insns);
}
else
{
- char prefix[4];
-
- /* We may add a speculation prefix later. We use the same space
- that is used for the pc prefix. */
- if ((flags & DISASSEMBLY_OMIT_PC) == 0)
- strncpy (prefix, pc_prefix (insn->pc), 3);
- else
- {
- prefix[0] = ' ';
- prefix[1] = ' ';
- prefix[2] = ' ';
- }
- prefix[3] = 0;
+ struct disas_insn *dinsn;

- /* Print the instruction index. */
- ui_out_field_uint (uiout, "index", btrace_insn_number (&it));
- ui_out_text (uiout, "\t");
-
- /* Indicate speculative execution by a leading '?'. */
- if ((insn->flags & BTRACE_INSN_FLAG_SPECULATIVE) != 0)
- prefix[0] = '?';
-
- /* Print the prefix; we tell gdb_disassembly below to omit it. */
- ui_out_field_fmt (uiout, "prefix", "%s", prefix);
-
- /* Disassembly with '/m' flag may not produce the expected result.
- See PR gdb/11833. */
- gdb_disassembly (gdbarch, uiout, NULL, flags | DISASSEMBLY_OMIT_PC,
- 1, insn->pc, insn->pc + 1);
+ dinsn = VEC_safe_push (disas_insn_t, insns, NULL);
+ dinsn->addr = insn->pc;
+ dinsn->number = btrace_insn_number (&it);
+ dinsn->is_speculative = (insn->flags & BTRACE_INSN_FLAG_SPECULATIVE) != 0;
}
}
+
+ /* Print the instructions we collected. */
+ gdb_disassembly_vec (gdbarch, uiout, flags, insns);
+
+ do_cleanups (cleanups);
}

/* The to_insn_history method of target record-btrace. */
diff --git a/gdb/record.c b/gdb/record.c
index 71ef973..c17b199 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -458,7 +458,7 @@ get_insn_history_modifiers (char **arg)
switch (*args)
{
case 'm':
- modifiers |= DISASSEMBLY_SOURCE_DEPRECATED;
+ modifiers |= DISASSEMBLY_SOURCE;
modifiers |= DISASSEMBLY_FILENAME;
break;
case 'r':
--
1.8.3.1