2023-01-02 09:32:04

by Lin Ma

[permalink] [raw]
Subject: [PATCH v2] scripts/gdb: fix 'lx-timerlist' on newer kernel

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 <[email protected]>
---
V1->V2: remove the support of old versions, fix typo and adjust the
commit message

scripts/gdb/linux/timerlist.py | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/scripts/gdb/linux/timerlist.py b/scripts/gdb/linux/timerlist.py
index 071d0dd5a634..73534da92745 100644
--- a/scripts/gdb/linux/timerlist.py
+++ b/scripts/gdb/linux/timerlist.py
@@ -4,6 +4,7 @@

import binascii
import gdb
+import re

from linux import constants
from linux import cpus
@@ -43,8 +44,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 +76,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 +167,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 +186,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)
--
2.17.1