prefix, fun, file, level, ibegin, iend);
}
+/* Return the number of instructions in a given function call segment. */
+
+static unsigned int
+ftrace_call_num_insn (const struct btrace_function* bfun)
+{
+ if (bfun == NULL)
+ return 0;
+
+ /* A gap is always counted as one instruction. */
+ if (bfun->errcode != 0)
+ return 1;
+
+ return VEC_length (btrace_insn_s, bfun->insn);
+}
+
/* Return non-zero if BFUN does not match MFUN and FUN,
return zero otherwise. */
prev->flow.next = bfun;
bfun->number = prev->number + 1;
- bfun->insn_offset = (prev->insn_offset
- + VEC_length (btrace_insn_s, prev->insn));
+ bfun->insn_offset = prev->insn_offset + ftrace_call_num_insn (prev);
bfun->level = prev->level;
}
/* See btrace.h. */
-unsigned int
-btrace_insn_number (const struct btrace_insn_iterator *it)
+int
+btrace_insn_get_error (const struct btrace_insn_iterator *it)
{
- const struct btrace_function *bfun;
-
- bfun = it->function;
+ return it->function->errcode;
+}
- /* Return zero if the iterator points to a gap in the trace. */
- if (bfun->errcode != 0)
- return 0;
+/* See btrace.h. */
- return bfun->insn_offset + it->index;
+unsigned int
+btrace_insn_number (const struct btrace_insn_iterator *it)
+{
+ return it->function->insn_offset + it->index;
}
/* See btrace.h. */
lnum = btrace_insn_number (lhs);
rnum = btrace_insn_number (rhs);
- /* A gap has an instruction number of zero. Things are getting more
- complicated if gaps are involved.
-
- We take the instruction number offset from the iterator's function.
- This is the number of the first instruction after the gap.
-
- This is OK as long as both lhs and rhs point to gaps. If only one of
- them does, we need to adjust the number based on the other's regular
- instruction number. Otherwise, a gap might compare equal to an
- instruction. */
-
- if (lnum == 0 && rnum == 0)
- {
- lnum = lhs->function->insn_offset;
- rnum = rhs->function->insn_offset;
- }
- else if (lnum == 0)
- {
- lnum = lhs->function->insn_offset;
-
- if (lnum == rnum)
- lnum -= 1;
- }
- else if (rnum == 0)
- {
- rnum = rhs->function->insn_offset;
-
- if (rnum == lnum)
- rnum -= 1;
- }
-
return (int) (lnum - rnum);
}
unsigned int number)
{
const struct btrace_function *bfun;
- unsigned int end, length;
for (bfun = btinfo->end; bfun != NULL; bfun = bfun->flow.prev)
- {
- /* Skip gaps. */
- if (bfun->errcode != 0)
- continue;
-
- if (bfun->insn_offset <= number)
- break;
- }
+ if (bfun->insn_offset <= number)
+ break;
if (bfun == NULL)
return 0;
- length = VEC_length (btrace_insn_s, bfun->insn);
- gdb_assert (length > 0);
-
- end = bfun->insn_offset + length;
- if (end <= number)
+ if (bfun->insn_offset + ftrace_call_num_insn (bfun) <= number)
return 0;
it->function = bfun;
extern const struct btrace_insn *
btrace_insn_get (const struct btrace_insn_iterator *);
+/* Return the error code for a branch trace instruction iterator. Returns zero
+ if there is no error, i.e. the instruction is valid. */
+extern int btrace_insn_get_error (const struct btrace_insn_iterator *);
+
/* Return the instruction number for a branch trace iterator.
- Returns one past the maximum instruction number for the end iterator.
- Returns zero if the iterator does not point to a valid instruction. */
+ Returns one past the maximum instruction number for the end iterator. */
extern unsigned int btrace_insn_number (const struct btrace_insn_iterator *);
/* Initialize a branch trace instruction iterator to point to the begin/end of
extern int btrace_insn_cmp (const struct btrace_insn_iterator *lhs,
const struct btrace_insn_iterator *rhs);
-/* Find an instruction in the function branch trace by its number.
+/* Find an instruction or gap in the function branch trace by its number.
If the instruction is found, initialize the branch trace instruction
iterator to point to this instruction and return non-zero.
Return zero otherwise. */
calls = btrace_call_number (&call);
btrace_insn_end (&insn, btinfo);
-
insns = btrace_insn_number (&insn);
- if (insns != 0)
- {
- /* The last instruction does not really belong to the trace. */
- insns -= 1;
- }
- else
- {
- unsigned int steps;
- /* Skip gaps at the end. */
- do
- {
- steps = btrace_insn_prev (&insn, 1);
- if (steps == 0)
- break;
-
- insns = btrace_insn_number (&insn);
- }
- while (insns == 0);
- }
+ /* If the last instruction is not a gap, it is the current instruction
+ that is not actually part of the record. */
+ if (btrace_insn_get (&insn) != NULL)
+ insns -= 1;
gaps = btinfo->ngaps;
}
/* We have trace so we must have a configuration. */
gdb_assert (conf != NULL);
- btrace_ui_out_decode_error (uiout, it.function->errcode,
+ uiout->field_fmt ("insn-number", "%u",
+ btrace_insn_number (&it));
+ uiout->text ("\t");
+
+ btrace_ui_out_decode_error (uiout, btrace_insn_get_error (&it),
conf->format);
}
else
tp = require_btrace_thread ();
found = btrace_find_insn_by_number (&it, &tp->btrace, number);
- if (found == 0)
+
+ /* Check if the instruction could not be found or is a gap. */
+ if (found == 0 || btrace_insn_get (&it) == NULL)
error (_("No such instruction."));
record_btrace_set_replay (tp, &it);