exists. BTINFO is the branch trace information for the current thread. */
static struct btrace_function *
+ftrace_find_call_by_number (struct btrace_thread_info *btinfo,
+ unsigned int number)
+{
+ if (number == 0 || number > btinfo->functions.size ())
+ return NULL;
+
+ return &btinfo->functions[number - 1];
+}
+
+/* A const version of the function above. */
+
+static const struct btrace_function *
ftrace_find_call_by_number (const struct btrace_thread_info *btinfo,
unsigned int number)
{
if (number == 0 || number > btinfo->functions.size ())
return NULL;
- return btinfo->functions[number - 1];
+ return &btinfo->functions[number - 1];
}
/* Return non-zero if BFUN does not match MFUN and FUN,
/* Allocate and initialize a new branch trace function segment at the end of
the trace.
BTINFO is the branch trace information for the current thread.
- MFUN and FUN are the symbol information we have for this function. */
+ MFUN and FUN are the symbol information we have for this function.
+ This invalidates all struct btrace_function pointer currently held. */
static struct btrace_function *
ftrace_new_function (struct btrace_thread_info *btinfo,
struct minimal_symbol *mfun,
struct symbol *fun)
{
- struct btrace_function *bfun;
-
- bfun = XCNEW (struct btrace_function);
-
- bfun->msym = mfun;
- bfun->sym = fun;
+ int level;
+ unsigned int number, insn_offset;
if (btinfo->functions.empty ())
{
- /* Start counting at one. */
- bfun->number = 1;
- bfun->insn_offset = 1;
+ /* Start counting NUMBER and INSN_OFFSET at one. */
+ level = 0;
+ number = 1;
+ insn_offset = 1;
}
else
{
- struct btrace_function *prev = btinfo->functions.back ();
-
- bfun->number = prev->number + 1;
- bfun->insn_offset = prev->insn_offset + ftrace_call_num_insn (prev);
- bfun->level = prev->level;
+ const struct btrace_function *prev = &btinfo->functions.back ();
+ level = prev->level;
+ number = prev->number + 1;
+ insn_offset = prev->insn_offset + ftrace_call_num_insn (prev);
}
- btinfo->functions.push_back (bfun);
- return bfun;
+ btinfo->functions.emplace_back (mfun, fun, number, insn_offset, level);
+ return &btinfo->functions.back ();
}
/* Update the UP field of a function segment. */
struct minimal_symbol *mfun,
struct symbol *fun)
{
- struct btrace_function *prev = btinfo->functions.back ();
- struct btrace_function *bfun, *caller;
+ struct btrace_function *prev, *bfun, *caller;
bfun = ftrace_new_function (btinfo, mfun, fun);
+ prev = ftrace_find_call_by_number (btinfo, bfun->number - 1);
/* It is important to start at PREV's caller. Otherwise, we might find
PREV itself, if PREV is a recursive function. */
struct minimal_symbol *mfun,
struct symbol *fun)
{
- struct btrace_function *prev = btinfo->functions.back ();
- struct btrace_function *bfun;
+ struct btrace_function *prev, *bfun;
/* This is an unexplained function switch. We can't really be sure about the
call stack, yet the best I can think of right now is to preserve it. */
bfun = ftrace_new_function (btinfo, mfun, fun);
+ prev = ftrace_find_call_by_number (btinfo, bfun->number - 1);
bfun->up = prev->up;
bfun->flags = prev->flags;
else
{
/* We hijack the previous function segment if it was empty. */
- bfun = btinfo->functions.back ();
+ bfun = &btinfo->functions.back ();
if (bfun->errcode != 0 || !VEC_empty (btrace_insn_s, bfun->insn))
bfun = ftrace_new_function (btinfo, NULL, NULL);
}
return ftrace_new_function (btinfo, mfun, fun);
/* If we had a gap before, we create a function. */
- bfun = btinfo->functions.back ();
+ bfun = &btinfo->functions.back ();
if (bfun->errcode != 0)
return ftrace_new_function (btinfo, mfun, fun);
unsigned int length = btinfo->functions.size() - 1;
for (unsigned int i = 0; i < length; ++i)
- level = std::min (level, btinfo->functions[i]->level);
+ level = std::min (level, btinfo->functions[i].level);
/* The last function segment contains the current instruction, which is not
really part of the trace. If it contains just this one instruction, we
ignore the segment. */
- struct btrace_function *last = btinfo->functions.back();
+ struct btrace_function *last = &btinfo->functions.back();
if (VEC_length (btrace_insn_s, last->insn) != 1)
level = std::min (level, last->level);
gdb_assert (!btinfo->functions.empty ());
gdb_assert (!VEC_empty (btrace_block_s, btrace->blocks));
- last_bfun = btinfo->functions.back ();
+ last_bfun = &btinfo->functions.back ();
/* If the existing trace ends with a gap, we just glue the traces
together. We need to drop the last (i.e. chronologically first) block
btinfo = &tp->btrace;
for (auto &bfun : btinfo->functions)
- {
- VEC_free (btrace_insn_s, bfun->insn);
- xfree (bfun);
- }
+ VEC_free (btrace_insn_s, bfun.insn);
btinfo->functions.clear ();
btinfo->ngaps = 0;
unsigned int index, end;
index = it->insn_index;
- bfun = it->btinfo->functions[it->call_index];
+ bfun = &it->btinfo->functions[it->call_index];
/* Check if the iterator points to a gap in the trace. */
if (bfun->errcode != 0)
int
btrace_insn_get_error (const struct btrace_insn_iterator *it)
{
- const struct btrace_function *bfun;
-
- bfun = it->btinfo->functions[it->call_index];
- return bfun->errcode;
+ return it->btinfo->functions[it->call_index].errcode;
}
/* See btrace.h. */
unsigned int
btrace_insn_number (const struct btrace_insn_iterator *it)
{
- const struct btrace_function *bfun;
-
- bfun = it->btinfo->functions[it->call_index];
- return bfun->insn_offset + it->insn_index;
+ return it->btinfo->functions[it->call_index].insn_offset + it->insn_index;
}
/* See btrace.h. */
if (btinfo->functions.empty ())
error (_("No trace."));
- bfun = btinfo->functions.back ();
+ bfun = &btinfo->functions.back ();
length = VEC_length (btrace_insn_s, bfun->insn);
/* The last function may either be a gap or it contains the current
const struct btrace_function *bfun;
unsigned int index, steps;
- bfun = it->btinfo->functions[it->call_index];
+ bfun = &it->btinfo->functions[it->call_index];
steps = 0;
index = it->insn_index;
const struct btrace_function *bfun;
unsigned int index, steps;
- bfun = it->btinfo->functions[it->call_index];
+ bfun = &it->btinfo->functions[it->call_index];
steps = 0;
index = it->insn_index;
return 0;
lower = 0;
- bfun = btinfo->functions[lower];
+ bfun = &btinfo->functions[lower];
if (number < bfun->insn_offset)
return 0;
upper = btinfo->functions.size () - 1;
- bfun = btinfo->functions[upper];
+ bfun = &btinfo->functions[upper];
if (number >= bfun->insn_offset + ftrace_call_num_insn (bfun))
return 0;
{
const unsigned int average = lower + (upper - lower) / 2;
- bfun = btinfo->functions[average];
+ bfun = &btinfo->functions[average];
if (number < bfun->insn_offset)
{
if (btinfo->functions.empty ())
return false;
- bfun = btinfo->functions.back ();
+ bfun = &btinfo->functions.back ();
if (bfun->errcode != 0)
return false;
if (it->index >= it->btinfo->functions.size ())
return NULL;
- return it->btinfo->functions[it->index];
+ return &it->btinfo->functions[it->index];
}
/* See btrace.h. */
We do not allow function segments without instructions otherwise. */
struct btrace_function
{
+ btrace_function (struct minimal_symbol *msym_, struct symbol *sym_,
+ unsigned int number_, unsigned int insn_offset_, int level_)
+ : msym (msym_), sym (sym_), insn_offset (insn_offset_), number (number_),
+ level (level_)
+ {
+ }
+
/* The full and minimal symbol for the function. Both may be NULL. */
struct minimal_symbol *msym;
struct symbol *sym;
the same function. If a function calls another function, the former will
have at least two segments: one before the call and another after the
return. Will be zero if there is no such function segment. */
- unsigned int prev;
- unsigned int next;
+ unsigned int prev = 0;
+ unsigned int next = 0;
/* The function segment number of the directly preceding function segment in
a (fake) call stack. Will be zero if there is no such function segment in
the record. */
- unsigned int up;
+ unsigned int up = 0;
/* The instructions in this function segment.
The instruction vector will be empty if the function segment
represents a decode error. */
- VEC (btrace_insn_s) *insn;
+ VEC (btrace_insn_s) *insn = NULL;
/* The error code of a decode error that led to a gap.
Must be zero unless INSN is empty; non-zero otherwise. */
- int errcode;
+ int errcode = 0;
/* The instruction number offset for the first instruction in this
function segment.
int level;
/* A bit-vector of btrace_function_flag. */
- btrace_function_flags flags;
+ btrace_function_flags flags = 0;
};
/* A branch trace instruction iterator. */
/* The raw branch trace data for the below branch trace. */
struct btrace_data data;
- /* Vector of pointer to decoded function segments in execution flow order.
+ /* Vector of decoded function segments in execution flow order.
Note that the numbering for btrace function segments starts with 1, so
function segment i will be at index (i - 1). */
- std::vector<btrace_function *> functions;
+ std::vector<btrace_function> functions;
/* The function level offset. When added to each function's LEVEL,
this normalizes the function levels such that the smallest level