[PATCH 05/11] btrace: Use function segment index in insn iterator.
Tim Wiederhake
tim.wiederhake@intel.com
Fri Feb 17 13:27:00 GMT 2017
2017-02-17 Tim Wiederhake <tim.wiederhake@intel.com>
gdb/ChangeLog
* btrace.c: (btrace_insn_get, btrace_insn_get_error, btrace_insn_number,
btrace_insn_begin, btrace_insn_end, btrace_insn_next, btrace_insn_prev,
btrace_find_insn_by_number): Replaced function segment pointer with
index.
(btrace_insn_cmp): Simplify.
* btrace.h: (struct btrace_insn_iterator) Renamed index to
insn_index. Replaced function segment pointer with index into function
segment vector.
* record-btrace.c (record_btrace_call_history): Replaced function
segment pointer use with index.
(record_btrace_frame_sniffer): Retrieve function call segment through
vector.
(record_btrace_set_replay): Remove defunc't safety check.
---
gdb/btrace.c | 59 +++++++++++++++++++++++++++++++++--------------------
gdb/btrace.h | 8 ++++----
gdb/record-btrace.c | 7 ++++---
3 files changed, 45 insertions(+), 29 deletions(-)
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 31590ce..1e110cc 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -2236,8 +2236,8 @@ btrace_insn_get (const struct btrace_insn_iterator *it)
const struct btrace_function *bfun;
unsigned int index, end;
- index = it->index;
- bfun = it->function;
+ index = it->insn_index;
+ bfun = VEC_index (btrace_fun_p, it->btinfo->functions, it->call_index);
/* Check if the iterator points to a gap in the trace. */
if (bfun->errcode != 0)
@@ -2256,7 +2256,10 @@ btrace_insn_get (const struct btrace_insn_iterator *it)
int
btrace_insn_get_error (const struct btrace_insn_iterator *it)
{
- return it->function->errcode;
+ const struct btrace_function *bfun;
+
+ bfun = VEC_index (btrace_fun_p, it->btinfo->functions, it->call_index);
+ return bfun->errcode;
}
/* See btrace.h. */
@@ -2264,7 +2267,10 @@ btrace_insn_get_error (const struct btrace_insn_iterator *it)
unsigned int
btrace_insn_number (const struct btrace_insn_iterator *it)
{
- return it->function->insn_offset + it->index;
+ const struct btrace_function *bfun;
+
+ bfun = VEC_index (btrace_fun_p, it->btinfo->functions, it->call_index);
+ return bfun->insn_offset + it->insn_index;
}
/* See btrace.h. */
@@ -2280,8 +2286,8 @@ btrace_insn_begin (struct btrace_insn_iterator *it,
error (_("No trace."));
it->btinfo = btinfo;
- it->function = bfun;
- it->index = 0;
+ it->call_index = 0;
+ it->insn_index = 0;
}
/* See btrace.h. */
@@ -2306,8 +2312,8 @@ btrace_insn_end (struct btrace_insn_iterator *it,
length -= 1;
it->btinfo = btinfo;
- it->function = bfun;
- it->index = length;
+ it->call_index = bfun->number - 1;
+ it->insn_index = length;
}
/* See btrace.h. */
@@ -2318,9 +2324,9 @@ btrace_insn_next (struct btrace_insn_iterator *it, unsigned int stride)
const struct btrace_function *bfun;
unsigned int index, steps;
- bfun = it->function;
+ bfun = VEC_index (btrace_fun_p, it->btinfo->functions, it->call_index);
steps = 0;
- index = it->index;
+ index = it->insn_index;
while (stride != 0)
{
@@ -2386,8 +2392,8 @@ btrace_insn_next (struct btrace_insn_iterator *it, unsigned int stride)
}
/* Update the iterator. */
- it->function = bfun;
- it->index = index;
+ it->call_index = bfun->number - 1;
+ it->insn_index = index;
return steps;
}
@@ -2400,9 +2406,9 @@ btrace_insn_prev (struct btrace_insn_iterator *it, unsigned int stride)
const struct btrace_function *bfun;
unsigned int index, steps;
- bfun = it->function;
+ bfun = VEC_index (btrace_fun_p, it->btinfo->functions, it->call_index);
steps = 0;
- index = it->index;
+ index = it->insn_index;
while (stride != 0)
{
@@ -2444,8 +2450,8 @@ btrace_insn_prev (struct btrace_insn_iterator *it, unsigned int stride)
}
/* Update the iterator. */
- it->function = bfun;
- it->index = index;
+ it->call_index = bfun->number - 1;
+ it->insn_index = index;
return steps;
}
@@ -2456,12 +2462,21 @@ int
btrace_insn_cmp (const struct btrace_insn_iterator *lhs,
const struct btrace_insn_iterator *rhs)
{
- unsigned int lnum, rnum;
+ gdb_assert (lhs->btinfo == rhs->btinfo);
- lnum = btrace_insn_number (lhs);
- rnum = btrace_insn_number (rhs);
+ if (lhs->call_index > rhs->call_index)
+ return 1;
+
+ if (lhs->call_index < rhs->call_index)
+ return -1;
+
+ if (lhs->insn_index > rhs->insn_index)
+ return 1;
+
+ if (lhs->insn_index < rhs->insn_index)
+ return -1;
- return (int) (lnum - rnum);
+ return 0;
}
/* See btrace.h. */
@@ -2510,8 +2525,8 @@ btrace_find_insn_by_number (struct btrace_insn_iterator *it,
}
it->btinfo = btinfo;
- it->function = bfun;
- it->index = number - bfun->insn_offset;
+ it->call_index = bfun->number - 1;
+ it->insn_index = number - bfun->insn_offset;
return 1;
}
diff --git a/gdb/btrace.h b/gdb/btrace.h
index c49b114..53df6e9 100644
--- a/gdb/btrace.h
+++ b/gdb/btrace.h
@@ -196,12 +196,12 @@ struct btrace_insn_iterator
/* The branch trace information for this thread. Will never be NULL. */
const struct btrace_thread_info *btinfo;
- /* The branch trace function segment containing the instruction.
- Will never be NULL. */
- const struct btrace_function *function;
+ /* The index of the function call segment in struct btrace_thread_info's
+ FUNCTIONS vector. Note that index + 1 == number. */
+ unsigned int call_index;
/* The index into the function segment's instruction vector. */
- unsigned int index;
+ unsigned int insn_index;
};
/* A branch trace function call iterator. */
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index ba83be0..83e65e7 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -1111,7 +1111,7 @@ record_btrace_call_history (struct target_ops *self, int size, int int_flags)
if (replay != NULL)
{
begin.btinfo = btinfo;
- begin.call_index = replay->function->number - 1;
+ begin.call_index = replay->call_index;
}
else
btrace_call_end (&begin, btinfo);
@@ -1692,7 +1692,8 @@ record_btrace_frame_sniffer (const struct frame_unwind *self,
replay = tp->btrace.replay;
if (replay != NULL)
- bfun = replay->function;
+ bfun = VEC_index (btrace_fun_p, tp->btrace.functions,
+ replay->call_index);
}
else
{
@@ -2705,7 +2706,7 @@ record_btrace_set_replay (struct thread_info *tp,
btinfo = &tp->btrace;
- if (it == NULL || it->function == NULL)
+ if (it == NULL)
record_btrace_stop_replaying (tp);
else
{
--
2.7.4
More information about the Gdb-patches
mailing list