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