From patchwork Thu Feb 4 14:56:18 2016 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: 61197 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp508582lbl; Thu, 4 Feb 2016 07:03:45 -0800 (PST) X-Received: by 10.140.97.202 with SMTP id m68mr9420208qge.102.1454598225632; Thu, 04 Feb 2016 07:03:45 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c13si10976491qkj.48.2016.02.04.07.03.45 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 04 Feb 2016 07:03:45 -0800 (PST) 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; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dkim=fail header.i=@linaro.org Received: from localhost ([::1]:42272 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRLRh-0004Sf-6S for patch@linaro.org; Thu, 04 Feb 2016 10:03:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39046) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRLKs-0001kG-1V for qemu-devel@nongnu.org; Thu, 04 Feb 2016 09:56:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRLKq-0001TO-Hu for qemu-devel@nongnu.org; Thu, 04 Feb 2016 09:56:41 -0500 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]:36504) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRLKq-0001Sx-0V for qemu-devel@nongnu.org; Thu, 04 Feb 2016 09:56:40 -0500 Received: by mail-wm0-x22a.google.com with SMTP id p63so215700825wmp.1 for ; Thu, 04 Feb 2016 06:56:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=9zLzD0YyC9bPVZj+GnbX9Kjhnoc+7sTw3x74sAwu4Xk=; b=fOsgL7gIu9JPN2Su8m2Fv74DnZRRGR/us0TS6csahWbJD7OfgvYoAQIIsc/JX6aTMf kueLqaYwmK6vStruiROS0c5Sgy8O596xThXFnzhkDIWpgkIyWjqeClDaDpZUdI2ZRKLH clZDetohhb7X1W8Y+YmYGiYSTj7jt90e+9mmE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=9zLzD0YyC9bPVZj+GnbX9Kjhnoc+7sTw3x74sAwu4Xk=; b=ZntFflgMiC0WbI4Hvil+bDOnRHGFIr/H3X2Pxw9MuMhutxXQHOW+BIXjXxPYQkuffg 257+fa7/FcJ0xIOJ+V7HezdqSXwhA8p0wmd5CodDai5LUVbk9JoJXXFTIiVnYtbrGwHQ lckLXARJdbXjPMNElBrW5TBU007KApo5fmMehn/uGQrK6bFPylijpLVsAgZFwTWw81ea 2Qc9FDbkMuC1QvAtU9dIxbSQLagAjyU/cmUBVSRP6Eisn9DDDBuMBifbFYsaLh+luT/e hvzagq6uIYNuptXv5UppCKWGKciHxxX9xreki8j/+ojzen9SH4twpa9+tp4cDk1BYOAL wtHg== X-Gm-Message-State: AG10YORcMGQV6j0M5oYw+F2LNBrCGBpxCQ9jyZxBGcS8UuIhfmUuHtTcWoS/AEi0glc/D0Vh X-Received: by 10.194.79.194 with SMTP id l2mr9663021wjx.160.1454597799272; Thu, 04 Feb 2016 06:56:39 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id q73sm26686716wmb.1.2016.02.04.06.56.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Feb 2016 06:56:34 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 04D183E07A3; Thu, 4 Feb 2016 14:56:30 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 4 Feb 2016 14:56:18 +0000 Message-Id: <1454597781-18115-7-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1454597781-18115-1-git-send-email-alex.bennee@linaro.org> References: <1454597781-18115-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] X-Received-From: 2a00:1450:400c:c09::22a Cc: peter.maydell@linaro.org, dgilbert@redhat.com, crosthwaitepeter@gmail.com, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , aurelien@aurel32.net, rth@twiddle.net Subject: [Qemu-devel] [PATCH v5 6/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 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 v5 - minor re-base conflicts - *did not* convert to -d dfilter=x fmt as easier to document - strtoul -> qemu_strtoul - fix a few checkpatch spacing warnings - made range operator .., - now intuitively subtracts from start - no added r-b tag as changes a bit --- include/qemu/log.h | 2 ++ qemu-log.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 18 ++++++++++++ vl.c | 3 ++ 4 files changed, 108 insertions(+) -- 2.7.0 diff --git a/include/qemu/log.h b/include/qemu/log.h index 776ceaf..34a8fe6 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -190,6 +190,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 2eebac0..5433a78 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,89 @@ 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 *range_op = g_strstr_len(r, -1, "-"); + if (!range_op) { + range_op = g_strstr_len(r, -1, "+"); + } + if (!range_op) { + range_op = g_strstr_len(r, -1, "."); + } + if (range_op) { + struct Range range; + int err; + gchar d = *range_op; + gchar *range_val = range_op + 1; + /* ensure first value terminated and stray extra + * range_ops are swallowed to keep qemu_stroul happy + */ + *range_op = 0; + g_strdelimit(range_val, ".", ' '); + + err = qemu_strtoul(r, NULL, 0, &range.begin); + switch (d) { + case '+': + { + unsigned long len; + err |= qemu_strtoul(range_val, NULL, 0, &len); + range.end = range.begin + len; + break; + } + case '-': + { + unsigned long len; + err |= qemu_strtoul(range_val, NULL, 0, &len); + range.end = range.begin; + range.begin = range.end - len; + break; + } + case '.': + err |= qemu_strtoul(range_val, NULL, 0, &range.end); + break; + default: + g_assert_not_reached(); + } + if (err) { + g_error("Failed to parse range in: %s, %d", r, err); + } else { + 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 f31a240..ca0f4c9 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3090,6 +3090,24 @@ 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{size}, @var{start}-@var{size} or +@var{start}..@var{end} where @var{start} @var{end} and @var{size} are the +addresses and sizes required. For example: +@example + -dfilter 0x8000..0x9000,0xffffffc000080000+0x200,0xffffffc000060000-0x1000 +@end example +Will dump output for any code in the 0x1000 sized block starting at 0x8000 and +the 0x200 sized block starting at 0xffffffc000080000 and another 0x1000 sized +block starting at 0xffffffc00005f000. +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 f043009..a0a546f 100644 --- a/vl.c +++ b/vl.c @@ -3361,6 +3361,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_s: add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT); break;