From patchwork Fri Aug 14 17:46:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 52456 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by patches.linaro.org (Postfix) with ESMTPS id 6A9812031F for ; Fri, 14 Aug 2015 17:46:47 +0000 (UTC) Received: by lbsm2 with SMTP id m2sf28941530lbs.1 for ; Fri, 14 Aug 2015 10:46:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=IoZa9clU8Bg0IC/L/1xwfm2fc9mOXKMkQppvY5FyDLA=; b=bACmPYhltSgVf45SvY5OCrfciiKQQdnTBZwHsTOe058G7OZld/wQGdvLCJ/YLGTaWR /Sm9A4eVoBYIk+yxAqlIzh44+rZWHQXkM+QXF+xagIrIdDTZgHgZ7RSwH8YJeqjKVHgc r2XtjhXDw/iAD6isrGrLtbBJCzFHOhooqrBQ8VBgiF0RmusUErSghsZK3UiHDUf4OQDb q4+zh8a7DU6zp0t+yGMX5lskTFBX5aAAKK4KgO5HEUkggVl5fcItHJVOwDKHkLNSp5Nu mmWfKHRw0kEZWhWjJhCkFEcEarB1BtYlds4OpK6eXl0fQbjZ4fsShsZ4Y0xwp2CJOVhL 48IQ== X-Gm-Message-State: ALoCoQkv6Zx7XdT7x5DxRGaW0aE/PMnYmaUH9aONZIOwRyOlTVeHmaaXEjsX3uZJkILm6gnNUhXa X-Received: by 10.180.12.205 with SMTP id a13mr1294674wic.4.1439574406319; Fri, 14 Aug 2015 10:46:46 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.146 with SMTP id j18ls396637laa.44.gmail; Fri, 14 Aug 2015 10:46:46 -0700 (PDT) X-Received: by 10.152.27.41 with SMTP id q9mr26126613lag.104.1439574406156; Fri, 14 Aug 2015 10:46:46 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id c1si6372372lah.119.2015.08.14.10.46.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Aug 2015 10:46:46 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by labd1 with SMTP id d1so48216832lab.1 for ; Fri, 14 Aug 2015 10:46:46 -0700 (PDT) X-Received: by 10.112.140.68 with SMTP id re4mr44979365lbb.72.1439574406035; Fri, 14 Aug 2015 10:46:46 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.7.198 with SMTP id l6csp1780102lba; Fri, 14 Aug 2015 10:46:44 -0700 (PDT) X-Received: by 10.66.249.166 with SMTP id yv6mr18647315pac.126.1439574400658; Fri, 14 Aug 2015 10:46:40 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id rb6si10109691pab.13.2015.08.14.10.46.38 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 14 Aug 2015 10:46:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1ZQJ3o-00019Y-CC; Fri, 14 Aug 2015 18:46:32 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Stefan Hajnoczi , "Dr. David Alan Gilbert" , Jan Kiszka , Markus Armbruster Subject: [PATCH v2 1/4] scripts/qemu-gdb: Split MtreeCommand into its own module Date: Fri, 14 Aug 2015 18:46:29 +0100 Message-Id: <1439574392-4403-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1439574392-4403-1-git-send-email-peter.maydell@linaro.org> References: <1439574392-4403-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , As we add more commands to our Python gdb debugging support, it's going to get unwieldy to have everything in a single file. Split the implementation of the 'mtree' command from qemu-gdb.py into its own module. Signed-off-by: Peter Maydell Reviewed-by: Stefan Hajnoczi --- scripts/qemu-gdb.py | 70 +++++--------------------------------- scripts/qemugdb/__init__.py | 28 ++++++++++++++++ scripts/qemugdb/mtree.py | 82 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 62 deletions(-) create mode 100644 scripts/qemugdb/__init__.py create mode 100644 scripts/qemugdb/mtree.py diff --git a/scripts/qemu-gdb.py b/scripts/qemu-gdb.py index 6c7f4fb..7b072ad 100644 --- a/scripts/qemu-gdb.py +++ b/scripts/qemu-gdb.py @@ -16,11 +16,14 @@ import gdb -def isnull(ptr): - return ptr == gdb.Value(0).cast(ptr.type) +import os, sys -def int128(p): - return long(p['lo']) + (long(p['hi']) << 64) +# Annoyingly, gdb doesn't put the directory of scripts onto the +# module search path. Do it manually. + +sys.path.append(os.path.dirname(__file__)) + +from qemugdb import mtree def get_fs_base(): '''Fetch %fs base value using arch_prctl(ARCH_GET_FS)''' @@ -102,63 +105,6 @@ class CoroutineCommand(gdb.Command): coroutine_pointer = gdb.parse_and_eval(argv[0]).cast(gdb.lookup_type('CoroutineUContext').pointer()) bt_jmpbuf(coroutine_pointer['env']['__jmpbuf']) -class MtreeCommand(gdb.Command): - '''Display the memory tree hierarchy''' - def __init__(self): - gdb.Command.__init__(self, 'qemu mtree', gdb.COMMAND_DATA, - gdb.COMPLETE_NONE) - self.queue = [] - def invoke(self, arg, from_tty): - self.seen = set() - self.queue_root('address_space_memory') - self.queue_root('address_space_io') - self.process_queue() - def queue_root(self, varname): - ptr = gdb.parse_and_eval(varname)['root'] - self.queue.append(ptr) - def process_queue(self): - while self.queue: - ptr = self.queue.pop(0) - if long(ptr) in self.seen: - continue - self.print_item(ptr) - def print_item(self, ptr, offset = gdb.Value(0), level = 0): - self.seen.add(long(ptr)) - addr = ptr['addr'] - addr += offset - size = int128(ptr['size']) - alias = ptr['alias'] - klass = '' - if not isnull(alias): - klass = ' (alias)' - elif not isnull(ptr['ops']): - klass = ' (I/O)' - elif bool(ptr['ram']): - klass = ' (RAM)' - gdb.write('%s%016x-%016x %s%s (@ %s)\n' - % (' ' * level, - long(addr), - long(addr + (size - 1)), - ptr['name'].string(), - klass, - ptr, - ), - gdb.STDOUT) - if not isnull(alias): - gdb.write('%s alias: %s@%016x (@ %s)\n' % - (' ' * level, - alias['name'].string(), - ptr['alias_offset'], - alias, - ), - gdb.STDOUT) - self.queue.append(alias) - subregion = ptr['subregions']['tqh_first'] - level += 1 - while not isnull(subregion): - self.print_item(subregion, addr, level) - subregion = subregion['subregions_link']['tqe_next'] - QemuCommand() CoroutineCommand() -MtreeCommand() +mtree.MtreeCommand() diff --git a/scripts/qemugdb/__init__.py b/scripts/qemugdb/__init__.py new file mode 100644 index 0000000..969f552 --- /dev/null +++ b/scripts/qemugdb/__init__.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +# GDB debugging support +# +# Copyright (c) 2015 Linaro Ltd +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see +# +# + +# We don't need to do anything in our init file currently. + +""" +Support routines for debugging QEMU under GDB +""" + +__license__ = "GPL version 2 or (at your option) any later version" diff --git a/scripts/qemugdb/mtree.py b/scripts/qemugdb/mtree.py new file mode 100644 index 0000000..06011c3 --- /dev/null +++ b/scripts/qemugdb/mtree.py @@ -0,0 +1,82 @@ +#!/usr/bin/python + +# GDB debugging support +# +# Copyright 2012 Red Hat, Inc. and/or its affiliates +# +# Authors: +# Avi Kivity +# +# This work is licensed under the terms of the GNU GPL, version 2. See +# the COPYING file in the top-level directory. +# +# Contributions after 2012-01-13 are licensed under the terms of the +# GNU GPL, version 2 or (at your option) any later version. + +# 'qemu mtree' -- display the memory hierarchy + +import gdb + +def isnull(ptr): + return ptr == gdb.Value(0).cast(ptr.type) + +def int128(p): + return long(p['lo']) + (long(p['hi']) << 64) + +class MtreeCommand(gdb.Command): + '''Display the memory tree hierarchy''' + def __init__(self): + gdb.Command.__init__(self, 'qemu mtree', gdb.COMMAND_DATA, + gdb.COMPLETE_NONE) + self.queue = [] + def invoke(self, arg, from_tty): + self.seen = set() + self.queue_root('address_space_memory') + self.queue_root('address_space_io') + self.process_queue() + def queue_root(self, varname): + ptr = gdb.parse_and_eval(varname)['root'] + self.queue.append(ptr) + def process_queue(self): + while self.queue: + ptr = self.queue.pop(0) + if long(ptr) in self.seen: + continue + self.print_item(ptr) + def print_item(self, ptr, offset = gdb.Value(0), level = 0): + self.seen.add(long(ptr)) + addr = ptr['addr'] + addr += offset + size = int128(ptr['size']) + alias = ptr['alias'] + klass = '' + if not isnull(alias): + klass = ' (alias)' + elif not isnull(ptr['ops']): + klass = ' (I/O)' + elif bool(ptr['ram']): + klass = ' (RAM)' + gdb.write('%s%016x-%016x %s%s (@ %s)\n' + % (' ' * level, + long(addr), + long(addr + (size - 1)), + ptr['name'].string(), + klass, + ptr, + ), + gdb.STDOUT) + if not isnull(alias): + gdb.write('%s alias: %s@%016x (@ %s)\n' % + (' ' * level, + alias['name'].string(), + ptr['alias_offset'], + alias, + ), + gdb.STDOUT) + self.queue.append(alias) + subregion = ptr['subregions']['tqh_first'] + level += 1 + while not isnull(subregion): + self.print_item(subregion, addr, level) + subregion = subregion['subregions_link']['tqe_next'] +