/* Compute the trace, provided we have any. */
if (!btrace_data_empty (&btrace))
{
+ struct btrace_function *bfun;
+
/* Store the raw trace data. The stored data will be cleared in
btrace_clear, so we always append the new trace. */
btrace_data_append (&btinfo->data, &btrace);
btrace_maint_clear (btinfo);
+ VEC_truncate (btrace_fun_p, btinfo->functions, 0);
btrace_clear_history (btinfo);
btrace_compute_ftrace (tp, &btrace);
+
+ for (bfun = btinfo->begin; bfun != NULL; bfun = bfun->flow.next)
+ VEC_safe_push (btrace_fun_p, btinfo->functions, bfun);
}
do_cleanups (cleanup);
btinfo = &tp->btrace;
+ VEC_free (btrace_fun_p, btinfo->functions);
+
it = btinfo->begin;
while (it != NULL)
{
unsigned int number)
{
const struct btrace_function *bfun;
+ unsigned int upper, lower;
- for (bfun = btinfo->end; bfun != NULL; bfun = bfun->flow.prev)
- if (bfun->insn_offset <= number)
- break;
+ if (VEC_empty (btrace_fun_p, btinfo->functions))
+ return 0;
- if (bfun == NULL)
+ lower = 0;
+ bfun = VEC_index (btrace_fun_p, btinfo->functions, lower);
+ if (number < bfun->insn_offset)
return 0;
- if (bfun->insn_offset + ftrace_call_num_insn (bfun) <= number)
+ upper = VEC_length (btrace_fun_p, btinfo->functions) - 1;
+ bfun = VEC_index (btrace_fun_p, btinfo->functions, upper);
+ if (number >= bfun->insn_offset + ftrace_call_num_insn (bfun))
return 0;
+ /* We assume that there are no holes in the numbering. */
+ for (;;)
+ {
+ const unsigned int average = lower + (upper - lower) / 2;
+
+ bfun = VEC_index (btrace_fun_p, btinfo->functions, average);
+
+ if (number < bfun->insn_offset)
+ {
+ upper = average - 1;
+ continue;
+ }
+
+ if (number >= bfun->insn_offset + ftrace_call_num_insn (bfun))
+ {
+ lower = average + 1;
+ continue;
+ }
+
+ break;
+ }
+
it->function = bfun;
it->index = number - bfun->insn_offset;
-
return 1;
}
btrace_function_flags flags;
};
+typedef struct btrace_function *btrace_fun_p;
+DEF_VEC_P (btrace_fun_p);
+
/* A branch trace instruction iterator. */
struct btrace_insn_iterator
{
struct btrace_function *begin;
struct btrace_function *end;
+ /* Vector of pointer to decoded function segments. These are in execution
+ order with the first element == BEGIN and the last element == END. */
+ VEC (btrace_fun_p) *functions;
+
/* The function level offset. When added to each function's LEVEL,
this normalizes the function levels such that the smallest level
becomes zero. */