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