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