1#!/usr/bin/python 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. See 9# the COPYING file in the top-level directory. 10 11# 'qemu timers' -- display the current timerlists 12 13import gdb 14 15class TimersCommand(gdb.Command): 16 '''Display the current QEMU timers''' 17 18 def __init__(self): 19 'Register the class as a gdb command' 20 gdb.Command.__init__(self, 'qemu timers', gdb.COMMAND_DATA, 21 gdb.COMPLETE_NONE) 22 23 def dump_timers(self, timer): 24 "Follow a timer and recursively dump each one in the list." 25 # timer should be of type QemuTimer 26 gdb.write(" timer %s/%s (cb:%s,opq:%s)\n" % ( 27 timer['expire_time'], 28 timer['scale'], 29 timer['cb'], 30 timer['opaque'])) 31 32 if int(timer['next']) > 0: 33 self.dump_timers(timer['next']) 34 35 36 def process_timerlist(self, tlist, ttype): 37 gdb.write("Processing %s timers\n" % (ttype)) 38 gdb.write(" clock %s is enabled:%s, last:%s\n" % ( 39 tlist['clock']['type'], 40 tlist['clock']['enabled'], 41 tlist['clock']['last'])) 42 if int(tlist['active_timers']) > 0: 43 self.dump_timers(tlist['active_timers']) 44 45 46 def invoke(self, arg, from_tty): 47 'Run the command' 48 main_timers = gdb.parse_and_eval("main_loop_tlg") 49 50 # This will break if QEMUClockType in timer.h is redfined 51 self.process_timerlist(main_timers['tl'][0], "Realtime") 52 self.process_timerlist(main_timers['tl'][1], "Virtual") 53 self.process_timerlist(main_timers['tl'][2], "Host") 54 self.process_timerlist(main_timers['tl'][3], "Virtual RT") 55