[v3] scripts/gdb: fix 'lx-timerlist' on newer kernel
Commit Message
After commit 511885d7061e ("lib/timerqueue: Rely on rbtree semantics for
next timer"), the struct timerqueue_head changes the internal field hence
causes the old lx-timerlist command keeps reporting errors.
This fix adds a simple version comparison and necessary code for
traversing timerqueue on a newer kernel. Moreover, it fixes some
python 3.X compatibility bugs.
Test with python 2.7 and python 3.6
Test with gdb 10.2
Signed-off-by: Lin Ma <linma@zju.edu.cn>
---
V1->V2: remove the support of old versions, fix typo and adjust the
commit message
V2->V3: remove redundant re package
scripts/gdb/linux/timerlist.py | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
@@ -43,8 +43,10 @@ def print_timer(rb_node, idx):
def print_active_timers(base):
- curr = base['active']['next']['node']
- curr = curr.address.cast(rbtree.rb_node_type.get_type().pointer())
+ # 511885d7061e ("lib/timerqueue: Rely on rbtree semantics for next timer")
+ leftmost = base['active']['rb_root']['rb_leftmost']
+ curr = leftmost.cast(rbtree.rb_node_type.get_type().pointer())
+
idx = 0
while curr:
yield print_timer(curr, idx)
@@ -73,10 +75,9 @@ def print_cpu(hrtimer_bases, cpu, max_clock_bases):
ts = cpus.per_cpu(tick_sched_ptr, cpu)
text = "cpu: {}\n".format(cpu)
- for i in xrange(max_clock_bases):
+ for i in range(max_clock_bases):
text += " clock {}:\n".format(i)
text += print_base(cpu_base['clock_base'][i])
-
if constants.LX_CONFIG_HIGH_RES_TIMERS:
fmts = [(" .{} : {} nsecs", 'expires_next'),
(" .{} : {}", 'hres_active'),
@@ -165,7 +166,7 @@ def pr_cpumask(mask):
i -= 1
start = i * 2
end = start + 2
- chunks.append(buf[start:end])
+ chunks.append(str(buf[start:end]))
if i != 0 and i % 4 == 0:
chunks.append(',')
@@ -184,7 +185,7 @@ class LxTimerList(gdb.Command):
def invoke(self, arg, from_tty):
hrtimer_bases = gdb.parse_and_eval("&hrtimer_bases")
- max_clock_bases = gdb.parse_and_eval("HRTIMER_MAX_CLOCK_BASES")
+ max_clock_bases = gdb.parse_and_eval("(int)HRTIMER_MAX_CLOCK_BASES")
text = "Timer List Version: gdb scripts\n"
text += "HRTIMER_MAX_CLOCK_BASES: {}\n".format(max_clock_bases)