From patchwork Thu Jul 31 13:06:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 34646 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oi0-f72.google.com (mail-oi0-f72.google.com [209.85.218.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C04CA20792 for ; Thu, 31 Jul 2014 13:28:20 +0000 (UTC) Received: by mail-oi0-f72.google.com with SMTP id a141sf11933690oig.3 for ; Thu, 31 Jul 2014 06:28:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=64+wZ+QGm52kh1+1mvqpbiXAaQkiL0gXauKunPqQFQ0=; b=VTOI66Ae5OsY9j8thm4HWmtKo6ogLNloZUY7rZBaM4h2a21RFx50OttOzPJiwUiKTJ gbdg8FHgJHLNceeuqunOG7g4pVurfA5RSrXR+36cxUtp0ToY56S38UfGeZ+0+8KJ38l2 5pGxp55dTSNkW3l7m/xVllJfefvOqiVp8MNdpQz5y0EvpNP7pWe2ATTBU1k/1/W6BCbN LQYmCT1HaJs3WxutJ2KNAoC3zgB6g+7X+ZLR6UG/7o0gmG6GE8vXrgZN5YuLfHxVgTY8 dibs5R5mvIrQkre5mCrTaed49LDaHAjXTuTTd6/qCYTy93rsS1ND8C5d7Xntf3Yje6ja Nn3w== X-Gm-Message-State: ALoCoQmheV9LwX2rugv1vTCObRv3IuTZcy3hw4njRWh6jmlicIEyESt6wdr0jdsaOJ0XJyTsPiw9 X-Received: by 10.182.128.234 with SMTP id nr10mr1616003obb.0.1406813300388; Thu, 31 Jul 2014 06:28:20 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.100.214 with SMTP id s80ls897844qge.99.gmail; Thu, 31 Jul 2014 06:28:20 -0700 (PDT) X-Received: by 10.221.42.135 with SMTP id ty7mr12785461vcb.14.1406813300250; Thu, 31 Jul 2014 06:28:20 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id z17si4335024vct.60.2014.07.31.06.28.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 31 Jul 2014 06:28:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id hq11so4116542vcb.24 for ; Thu, 31 Jul 2014 06:28:20 -0700 (PDT) X-Received: by 10.52.120.38 with SMTP id kz6mr1827680vdb.86.1406813300165; Thu, 31 Jul 2014 06:28:20 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp18317vcb; Thu, 31 Jul 2014 06:28:19 -0700 (PDT) X-Received: by 10.140.105.72 with SMTP id b66mr17004087qgf.30.1406813299670; Thu, 31 Jul 2014 06:28:19 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id cj3si9718920qcb.26.2014.07.31.06.28.19 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 31 Jul 2014 06:28:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:56711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XCqP5-0002zE-6L for patch@linaro.org; Thu, 31 Jul 2014 09:28:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XCq4H-00007I-NR for qemu-devel@nongnu.org; Thu, 31 Jul 2014 09:06:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XCq49-0001F3-1o for qemu-devel@nongnu.org; Thu, 31 Jul 2014 09:06:49 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:50104 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XCq48-0001Eq-PF for qemu-devel@nongnu.org; Thu, 31 Jul 2014 09:06:40 -0400 Received: from localhost ([127.0.0.1] helo=zen.linaro.local) by socrates.bennee.com with esmtp (Exim 4.80) (envelope-from ) id 1XCqDz-0002HE-HA; Thu, 31 Jul 2014 15:16:51 +0200 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 31 Jul 2014 14:06:30 +0100 Message-Id: <1406811992-6766-8-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.0.3 In-Reply-To: <1406811992-6766-1-git-send-email-alex.bennee@linaro.org> References: <1406811992-6766-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: alex.bennee@linaro.org X-SA-Exim-Scanned: No (on socrates.bennee.com); SAEximRunCond expanded to false X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 88.198.71.155 Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , l@dorileo.org, Anthony Liguori Subject: [Qemu-devel] [PATCH v3 7/9] qemu-log: new option -dfilter to limit output X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: alex.bennee@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.220.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 When debugging big programs or system emulation sometimes you want both the verbosity of cpu,exec et all but don't want to generate lots of logs for unneeded stuff. This patch adds a new option -dfilter which allows you to specify interesting address ranges in the form: -dfilter 0x8000-0x9000,0xffffffc000080000+0x200,... Then logging code can use the new qemu_log_in_addr_range() function to decide if it will output logging information for the given range. Signed-off-by: Alex Bennée ---- v2 - More clean-ups to the documentation v3 - re-base - use GArray instead of GList to avoid cache bouncing - checkpatch fixes diff --git a/include/qemu/log.h b/include/qemu/log.h index da22e13..8cfe57f 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -181,6 +181,8 @@ static inline void qemu_set_log(int log_flags) } void qemu_set_log_filename(const char *filename); +void qemu_set_dfilter_ranges(const char *ranges); +bool qemu_log_in_addr_range(uint64_t addr); int qemu_str_to_log_mask(const char *str); /* Print a usage message listing all the valid logging categories diff --git a/qemu-log.c b/qemu-log.c index 4dd530c..70956b8 100644 --- a/qemu-log.c +++ b/qemu-log.c @@ -19,11 +19,13 @@ #include "qemu-common.h" #include "qemu/log.h" +#include "qemu/range.h" static char *logfilename; FILE *qemu_logfile; int qemu_loglevel; static int log_append = 0; +static GArray *debug_regions; void qemu_log(const char *fmt, ...) { @@ -92,6 +94,61 @@ void qemu_set_log_filename(const char *filename) qemu_set_log(qemu_loglevel); } +/* Returns true if addr is in our debug filter or no filter defined + */ +bool qemu_log_in_addr_range(uint64_t addr) +{ + if (debug_regions) { + int i = 0; + for (i = 0; i < debug_regions->len; i++) { + struct Range *range = &g_array_index(debug_regions, Range, i); + if (addr >= range->begin && addr <= range->end) { + return true; + } + } + return false; + } else { + return true; + } +} + + +void qemu_set_dfilter_ranges(const char *filter_spec) +{ + gchar **ranges = g_strsplit(filter_spec, ",", 0); + if (ranges) { + gchar **next = ranges; + gchar *r = *next++; + debug_regions = g_array_sized_new(FALSE, FALSE, + sizeof(Range), g_strv_length(ranges)); + while (r) { + gchar *delim = g_strrstr(r, "-"); + if (!delim) { + delim = g_strrstr(r, "+"); + } + if (delim) { + struct Range range; + range.begin = strtoul(r, NULL, 0); + switch (*delim) { + case '+': + range.end = range.begin + strtoul(delim+1, NULL, 0); + break; + case '-': + range.end = strtoul(delim+1, NULL, 0); + break; + default: + g_assert_not_reached(); + } + g_array_append_val(debug_regions, range); + } else { + g_error("Bad range specifier in: %s", r); + } + r = *next++; + } + g_strfreev(ranges); + } +} + const QEMULogItem qemu_log_items[] = { { CPU_LOG_TB_OUT_ASM, "out_asm", "show generated host assembly code for each compiled TB" }, diff --git a/qemu-options.hx b/qemu-options.hx index 3defba8..7ac9ed3 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2867,6 +2867,22 @@ STEXI Output log in @var{logfile} instead of to stderr ETEXI +DEF("dfilter", HAS_ARG, QEMU_OPTION_DFILTER, \ + "-dfilter range,.. filter debug output to range of addresses (useful for -d cpu,exec,etc..)\n", + QEMU_ARCH_ALL) +STEXI +@item -dfilter @var{range1}[,...] +@findex -dfilter +Filter debug output to that relevant to a range of target addresses. The filter +spec can be either @var{start}-@var{end} or @var{start}+@var{size} where @var{start} +@var{end} and @var{size} are the addresses and sizes required. For example: +@example + -dfilter 0x8000-0x9000,0xffffffc000080000+0x200 +@end example +Will dump output for any code in the 0x1000 sized block starting at 0x8000 and +the 0x200 sized block starting at 0xffffffc000080000. +ETEXI + DEF("L", HAS_ARG, QEMU_OPTION_L, \ "-L path set the directory for the BIOS, VGA BIOS and keymaps\n", QEMU_ARCH_ALL) diff --git a/vl.c b/vl.c index f07f6e0..3d72752 100644 --- a/vl.c +++ b/vl.c @@ -3386,6 +3386,9 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_D: log_file = optarg; break; + case QEMU_OPTION_DFILTER: + qemu_set_dfilter_ranges(optarg); + break; case QEMU_OPTION_PERFMAP: tb_enable_perfmap(); break;