xref: /qemu/scripts/qemugdb/tcg.py (revision f1cd52d8912f124cc513a00143fe3baeb44772d1)
1*f1cd52d8SAlex Bennée#!/usr/bin/python
2*f1cd52d8SAlex Bennée# -*- coding: utf-8 -*-
3*f1cd52d8SAlex Bennée#
4*f1cd52d8SAlex Bennée# GDB debugging support, TCG status
5*f1cd52d8SAlex Bennée#
6*f1cd52d8SAlex Bennée# Copyright 2016 Linaro Ltd
7*f1cd52d8SAlex Bennée#
8*f1cd52d8SAlex Bennée# Authors:
9*f1cd52d8SAlex Bennée#  Alex Bennée <alex.bennee@linaro.org>
10*f1cd52d8SAlex Bennée#
11*f1cd52d8SAlex Bennée# This work is licensed under the terms of the GNU GPL, version 2.  See
12*f1cd52d8SAlex Bennée# the COPYING file in the top-level directory.
13*f1cd52d8SAlex Bennée#
14*f1cd52d8SAlex Bennée# Contributions after 2012-01-13 are licensed under the terms of the
15*f1cd52d8SAlex Bennée# GNU GPL, version 2 or (at your option) any later version.
16*f1cd52d8SAlex Bennée
17*f1cd52d8SAlex Bennée# 'qemu tcg-lock-status' -- display the TCG lock status across threads
18*f1cd52d8SAlex Bennée
19*f1cd52d8SAlex Bennéeimport gdb
20*f1cd52d8SAlex Bennée
21*f1cd52d8SAlex Bennéeclass TCGLockStatusCommand(gdb.Command):
22*f1cd52d8SAlex Bennée    '''Display TCG Execution Status'''
23*f1cd52d8SAlex Bennée    def __init__(self):
24*f1cd52d8SAlex Bennée        gdb.Command.__init__(self, 'qemu tcg-lock-status', gdb.COMMAND_DATA,
25*f1cd52d8SAlex Bennée                             gdb.COMPLETE_NONE)
26*f1cd52d8SAlex Bennée
27*f1cd52d8SAlex Bennée    def invoke(self, arg, from_tty):
28*f1cd52d8SAlex Bennée        gdb.write("Thread, BQL (iothread_mutex), Replay, Blocked?\n")
29*f1cd52d8SAlex Bennée        for thread in gdb.inferiors()[0].threads():
30*f1cd52d8SAlex Bennée            thread.switch()
31*f1cd52d8SAlex Bennée
32*f1cd52d8SAlex Bennée            iothread = gdb.parse_and_eval("iothread_locked")
33*f1cd52d8SAlex Bennée            replay = gdb.parse_and_eval("replay_locked")
34*f1cd52d8SAlex Bennée
35*f1cd52d8SAlex Bennée            frame = gdb.selected_frame()
36*f1cd52d8SAlex Bennée            if frame.name() == "__lll_lock_wait":
37*f1cd52d8SAlex Bennée                frame.older().select()
38*f1cd52d8SAlex Bennée                mutex = gdb.parse_and_eval("mutex")
39*f1cd52d8SAlex Bennée                owner = gdb.parse_and_eval("mutex->__data.__owner")
40*f1cd52d8SAlex Bennée                blocked = ("__lll_lock_wait waiting on %s from %d" %
41*f1cd52d8SAlex Bennée                           (mutex, owner))
42*f1cd52d8SAlex Bennée            else:
43*f1cd52d8SAlex Bennée                blocked = "not blocked"
44*f1cd52d8SAlex Bennée
45*f1cd52d8SAlex Bennée            gdb.write("%d/%d, %s, %s, %s\n" % (thread.num, thread.ptid[1],
46*f1cd52d8SAlex Bennée                                               iothread, replay, blocked))
47