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