From patchwork Thu May 14 16:43:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 48528 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2EBEF21411 for ; Thu, 14 May 2015 16:44:07 +0000 (UTC) Received: by layy10 with SMTP id y10sf22026937lay.0 for ; Thu, 14 May 2015 09:44:06 -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=CeKYMrins+bwAlcq3g4t1Qn6PBDtkL7TXGJty8GhdGU=; b=cQ/Vk8vWBYqUcRnh0Wow9rEqHPw1hOPSp+TJEsm2y0q1vkykleABxIUUPA0qLr7BWb 1un96z1XQNZjfV7Q81hjASWV0SBvpO3HTmCKDMlQVuX//4ykrwC9ByRkfyfjSJgDAuHM y0E45U0zXAVaiJ2UtFGuAz8euSqIX5pxOFr3VBA76N0ZWz14E7eBfKC0ROXuOqsmzhaT QGci60SYUJVxKPrPY9Uo0IlDkmWUIEGhXNxXr2NNrGddqeHSXGLMADyalm+d57thvfbH 9rDryYLpJU9q+Ksfxek86I8XMUNtdO21TSZHr/eHmxjYxW98cHpkLKd4QaQSHnYlhaPQ Ms7w== X-Gm-Message-State: ALoCoQmjX7NsR4qEOnj/FTjOIhyDauS4dkELu9fpIRqKA+qSkU3om5hOy5sQeur+SuYhNW0qS6+G X-Received: by 10.112.142.170 with SMTP id rx10mr3636208lbb.12.1431621846136; Thu, 14 May 2015 09:44:06 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.206.98 with SMTP id ln2ls438029lac.61.gmail; Thu, 14 May 2015 09:44:05 -0700 (PDT) X-Received: by 10.152.4.72 with SMTP id i8mr4004152lai.32.1431621845917; Thu, 14 May 2015 09:44:05 -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 mr8si14891819lbb.104.2015.05.14.09.44.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 May 2015 09:44:05 -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 layy10 with SMTP id y10so76073453lay.0 for ; Thu, 14 May 2015 09:44:05 -0700 (PDT) X-Received: by 10.112.204.6 with SMTP id ku6mr3876760lbc.73.1431621845613; Thu, 14 May 2015 09:44:05 -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.108.230 with SMTP id hn6csp1394354lbb; Thu, 14 May 2015 09:44:04 -0700 (PDT) X-Received: by 10.70.91.206 with SMTP id cg14mr9928106pdb.158.1431621842501; Thu, 14 May 2015 09:44:02 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id bb2si5543019pbc.135.2015.05.14.09.44.00 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 14 May 2015 09:44:02 -0700 (PDT) Received-SPF: none (google.com: pm215@archaic.org.uk does not designate permitted sender hosts) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1YswEl-0001yf-SK; Thu, 14 May 2015 17:43:55 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Stefan Hajnoczi Subject: [PATCH 3/3] scripts/qemu-gdb: Add support for printing trace events Date: Thu, 14 May 2015 17:43:55 +0100 Message-Id: <1431621835-7565-4-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1431621835-7565-1-git-send-email-peter.maydell@linaro.org> References: <1431621835-7565-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.mail=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: , Add two new commands to our gdb support: qemu trace-enable eventname qemu trace-disable eventname which allow dynamically enabling and disabling printing of QEMU trace events during a debugging session. These work with the "null" trace backend, by putting breakpoints on the stub trace_eventname() functions. Signed-off-by: Peter Maydell --- scripts/qemu-gdb.py | 4 +- scripts/qemugdb/trace.py | 188 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 scripts/qemugdb/trace.py diff --git a/scripts/qemu-gdb.py b/scripts/qemu-gdb.py index 1c94b2a..6d27c06 100644 --- a/scripts/qemu-gdb.py +++ b/scripts/qemu-gdb.py @@ -23,7 +23,7 @@ import os, sys sys.path.append(os.path.dirname(__file__)) -from qemugdb import mtree, coroutine +from qemugdb import mtree, coroutine, trace class QemuCommand(gdb.Command): '''Prefix for QEMU debug support commands''' @@ -34,3 +34,5 @@ class QemuCommand(gdb.Command): QemuCommand() coroutine.CoroutineCommand() mtree.MtreeCommand() +trace.TraceEnableCommand() +trace.TraceDisableCommand() diff --git a/scripts/qemugdb/trace.py b/scripts/qemugdb/trace.py new file mode 100644 index 0000000..24543e1 --- /dev/null +++ b/scripts/qemugdb/trace.py @@ -0,0 +1,188 @@ +#!/usr/bin/python + +# GDB debugging support: selecting printing of trace events +# +# 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 +# + +# qemu trace-enable trace-event-name +# qemu trace-disable trace-event-name +# * enable/disable printing of tracing for QEMU trace events (works +# even if QEMU was built with the null trace backend; may not work +# with non-debug QEMU builds) + +import gdb +import re, os + +# Assume the trace-events file is at ../../ relative to where we are + +trace_events_filename = os.path.join(os.path.dirname(__file__), + os.pardir,os.pardir, + "trace-events") + +def gdb_bp_list(): + '''Like gdb.breakpoints(), but return empty list if no bps, not None''' + # The point is that this is always iterable + bplist = gdb.breakpoints() + if not bplist: + return [] + return bplist + +class TraceEventInfo: + def __init__(self, name, formatstring, arglist): + self.name = name + self.formatstring = formatstring + self.arglist = arglist + self.argstr = ", ".join(arglist) + if self.argstr != "": + self.argstr = ", " + self.argstr + +# Hash of trace events read in from the 'trace-events' file; +# values are TraceEventInfo objects +trace_events = {} + +def extract_identifier(s): + '''Extract the identifier from a C argument declaration''' + # That is, given "const char *filename" return "filename". + r = re.sub(r'.*?([a-zA-Z_][a-zA-Z_0-9]*)\s*$', r'\1', s) + if r == 'void': + return None + return r + +# Preprocessor symbols which we know about. +# These should work for both 32 bit and 64 bit Linux, at least. +# If we needed to, we could determine whether the target was +# 32 or 64 bit with +# is_64bit = gdb.lookup_type('void').pointer().sizeof == 8 +# but we can get away without it. +fmtstr_dict = { + "PRIu8":"u", + "PRIx32":"x", + "PRIu32":"u", + "PRId32":"d", + "PRIx64":"llx", + "PRIu64":"llu", + "PRId64":"lld", + "PRIxPTR":"llx", +} + +def fixup_fmtstr(s): + # fmtstr needs to have leading space and " removed, + # trailing " removed, and handling of interpolated PRIxfoo + # dealt with (including trailing PRIxfoo) + inquotes = False + inescape = False + new = "" + sym = "" + for c in s: + if inquotes: + if inescape: + new = new + c + inescape = False + elif c == '\\': + inescape = True + new = new + c + elif c == '"': + inquotes = False + sym = "" + else: + new = new + c + else: + if c == '"': + # end of unquoted section + sym = sym.strip() + if sym != "": + new = new + fmtstr_dict[sym] + inquotes = True + else: + sym = sym + c + + # gdb printf doesn't understand the 'z' length modifier, + # so convert to 'l' + return re.sub(r'(? + # set up breakpoint to print info and continue + # add bp to hash table with key being the event name + if arg not in trace_events: + gdb.write('Unknown trace event %s\n') + return + gdb.write("Enabled trace event %s\n" % arg) + QemuTraceBreakpoint(arg) + +class TraceDisableCommand(gdb.Command): + '''Disable in-gdb tracing of the specified QEMU trace event''' + def __init__(self): + gdb.Command.__init__(self, 'qemu trace-disable', gdb.COMMAND_DATA, + gdb.COMPLETE_NONE) + + def invoke(self, arg, from_tty): + # delete the bp set on trace_ by the enable command + for bp in gdb_bp_list(): + if isinstance(bp, QemuTraceBreakpoint) and bp.event.name == arg: + bp.delete() + gdb.write("Disabled trace event %s\n" % arg) + return + gdb.write("Can't disable trace event %s: unknown or not enabled\n" % arg) + +read_trace_events_file(trace_events_filename)