scripts/qemu-gdb/timers.py: new helper to dump timer state
[qemu/ar7.git] / scripts / qemugdb / timers.py
blobbe71a001e333362cf2b0648071c4082a2bafee17
1 #!/usr/bin/python
2 # GDB debugging support
4 # Copyright 2017 Linaro Ltd
6 # Author: Alex Bennée <alex.bennee@linaro.org>
8 # This work is licensed under the terms of the GNU GPL, version 2. See
9 # the COPYING file in the top-level directory.
11 # 'qemu timers' -- display the current timerlists
13 import gdb
15 class TimersCommand(gdb.Command):
16 '''Display the current QEMU timers'''
18 def __init__(self):
19 'Register the class as a gdb command'
20 gdb.Command.__init__(self, 'qemu timers', gdb.COMMAND_DATA,
21 gdb.COMPLETE_NONE)
23 def dump_timers(self, timer):
24 "Follow a timer and recursively dump each one in the list."
25 # timer should be of type QemuTimer
26 gdb.write(" timer %s/%s (cb:%s,opq:%s)\n" % (
27 timer['expire_time'],
28 timer['scale'],
29 timer['cb'],
30 timer['opaque']))
32 if int(timer['next']) > 0:
33 self.dump_timers(timer['next'])
36 def process_timerlist(self, tlist, ttype):
37 gdb.write("Processing %s timers\n" % (ttype))
38 gdb.write(" clock %s is enabled:%s, last:%s\n" % (
39 tlist['clock']['type'],
40 tlist['clock']['enabled'],
41 tlist['clock']['last']))
42 if int(tlist['active_timers']) > 0:
43 self.dump_timers(tlist['active_timers'])
46 def invoke(self, arg, from_tty):
47 'Run the command'
48 main_timers = gdb.parse_and_eval("main_loop_tlg")
50 # This will break if QEMUClockType in timer.h is redfined
51 self.process_timerlist(main_timers['tl'][0], "Realtime")
52 self.process_timerlist(main_timers['tl'][1], "Virtual")
53 self.process_timerlist(main_timers['tl'][2], "Host")
54 self.process_timerlist(main_timers['tl'][3], "Virtual RT")