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