From patchwork Mon Aug 3 09:14:47 2015 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: 51853 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by patches.linaro.org (Postfix) with ESMTPS id 99778229FD for ; Mon, 3 Aug 2015 09:19:06 +0000 (UTC) Received: by lbcjf8 with SMTP id jf8sf42144086lbc.0 for ; Mon, 03 Aug 2015 02:19:05 -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:content-type:content-transfer-encoding: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; bh=72/wPJNzxu4scsnUgHi1dFP6poEhvV6V+XH1if30AU4=; b=kSNNuQ7yRilhvvaOFwQv/+BRtO9BEaRliBs09D9VjNQ/eI2aK72aZPz5uwzfp+ccgx T/B4Q6XmKasNraG9Kbmvir4G7/IOxswvzDS9QDnrV9NV0AYA2TT2vtQC1vUUyiNWbKvu 3nsTqPdtqBCEBLKniX3+nlZq4qS+mR9sBP7uEZpKEnx788X3Y949i17XTtxupd3RzLw6 br+r64WKv9wl6BfXEKp/BXcsmOWh9RIAHMVgKXb2v2xig92HZb0Ox0e777gvyjwdArdn 8X5knBD++G/TjlQaHdBDM10nGqvfaCOkC1pODg/qu8d9R5T47VQgm5vT1qSrMREiAwQz u37g== X-Gm-Message-State: ALoCoQn5el4wC8Mi8JGnM+5neqja1GA0BKzc7CObEj4gXViBzWNqkIRho1XkLRJhV8Vlw/2civja X-Received: by 10.112.189.131 with SMTP id gi3mr5318782lbc.6.1438593545128; Mon, 03 Aug 2015 02:19:05 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.70 with SMTP id x6ls588663laa.5.gmail; Mon, 03 Aug 2015 02:19:04 -0700 (PDT) X-Received: by 10.112.133.72 with SMTP id pa8mr15666939lbb.117.1438593544726; Mon, 03 Aug 2015 02:19:04 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id lb8si7068204lac.108.2015.08.03.02.19.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Aug 2015 02:19:04 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbqc9 with SMTP id c9so49021140lbq.1 for ; Mon, 03 Aug 2015 02:19:04 -0700 (PDT) X-Received: by 10.112.131.98 with SMTP id ol2mr16104990lbb.56.1438593544267; Mon, 03 Aug 2015 02:19:04 -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.112.7.198 with SMTP id l6csp1755110lba; Mon, 3 Aug 2015 02:19:02 -0700 (PDT) X-Received: by 10.50.56.10 with SMTP id w10mr20598143igp.3.1438593542320; Mon, 03 Aug 2015 02:19:02 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o127si13461317ioo.183.2015.08.03.02.19.01 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 03 Aug 2015 02:19:02 -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]:58199 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMBtd-0002ua-1U for patch@linaro.org; Mon, 03 Aug 2015 05:19:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41273) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMBpt-0005OT-V2 for qemu-devel@nongnu.org; Mon, 03 Aug 2015 05:15:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZMBpr-0003Kj-DF for qemu-devel@nongnu.org; Mon, 03 Aug 2015 05:15:09 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:38615) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMBpr-0003Ii-4S for qemu-devel@nongnu.org; Mon, 03 Aug 2015 05:15:07 -0400 Received: by wibxm9 with SMTP id xm9so105251387wib.1 for ; Mon, 03 Aug 2015 02:15:06 -0700 (PDT) X-Received: by 10.194.59.237 with SMTP id c13mr34112062wjr.24.1438593306697; Mon, 03 Aug 2015 02:15:06 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id lj2sm12545730wic.1.2015.08.03.02.15.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Aug 2015 02:15:04 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id AFEAD3E085B; Mon, 3 Aug 2015 10:15:00 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Mon, 3 Aug 2015 10:14:47 +0100 Message-Id: <1438593291-27109-8-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1438593291-27109-1-git-send-email-alex.bennee@linaro.org> References: <1438593291-27109-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.212.178 Cc: qemu-trivial@nongnu.org, crosthwaitepeter@gmail.com, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , aurelien@aurel32.net, rth@twiddle.net Subject: [Qemu-devel] [PATCH v4 07/11] 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.217.170 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 --- include/qemu/log.h | 2 ++ qemu-log.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 16 +++++++++++++++ vl.c | 3 +++ 4 files changed, 78 insertions(+) diff --git a/include/qemu/log.h b/include/qemu/log.h index b80f8f5..ade1f76 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -182,6 +182,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 77ed7bc..b3ebd3c 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 ae53346..90f0df9 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2987,6 +2987,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 1d2de4f..05211cf 100644 --- a/vl.c +++ b/vl.c @@ -3349,6 +3349,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;