From patchwork Mon Feb 22 15:59:43 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: 62603 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1324416lbl; Mon, 22 Feb 2016 08:04:08 -0800 (PST) X-Received: by 10.129.135.135 with SMTP id x129mr14036365ywf.215.1456157048018; Mon, 22 Feb 2016 08:04:08 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id p67si11623169ywd.253.2016.02.22.08.04.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 22 Feb 2016 08:04:08 -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]:49742 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXsxz-0006vy-5T for patch@linaro.org; Mon, 22 Feb 2016 11:04:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40637) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXsu4-0000oO-Fn for qemu-devel@nongnu.org; Mon, 22 Feb 2016 11:00:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aXsu2-0001Ce-KH for qemu-devel@nongnu.org; Mon, 22 Feb 2016 11:00:04 -0500 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:34239) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXsu2-0001CS-5C for qemu-devel@nongnu.org; Mon, 22 Feb 2016 11:00:02 -0500 Received: by mail-wm0-x236.google.com with SMTP id b205so161910345wmb.1 for ; Mon, 22 Feb 2016 08:00:01 -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=zLfaGzPWA5q2xrfS71JS/Os3gqZSzvgh5Hs9hVCuI+M=; b=CMhoZCst6hruG/C+0Wih1cPSla+tal/9nUGYINwhS1hWBnJohG9mAbJg0nibX1ru8h DIH6zmDoz6zrWEBusJrrWvEjDRI4FKsLMcrGMBdf6R+fRs9QuyJrL0QeFvRQu6S6zctv TFVdwrI9JtGztl/NhLU7rXp8hxiLPjvvN2mgc= 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=zLfaGzPWA5q2xrfS71JS/Os3gqZSzvgh5Hs9hVCuI+M=; b=lFnP0hjHANA9gswbnuae3SrXsHHRksrH7FhE/1MtqC/fxYSbSkK5f1RbQjhnmtnzR4 vdCTOIzH4qORIayH4Bv3RBQl69iJevnEwxulZOvydHNfYRjl1LZ8og+DCwVPDQUzmDPf n8T4hmuP8Ae2j2xENxMQMVjNAi/WukIj0/t4Vh6OZbE877VSx8Cu1wmg2X/YDDIWpCXl 4B1uU5Y1u4uwViFoXYsZz+dhgJNnYoc8Z5gFkj6YWbE5MJ9Jdnfiz5Pz0eNKcrcw/dA0 +qznJWtkjp2FAGrTG7BwgteCNcH2EdGyrDbITTL34q4Oo6+MUUxY8oUEQgGmioskAeJM 6xkg== X-Gm-Message-State: AG10YOSaReyy7LnkMpBFl9f0/4MJFDPYLNMujOwxxIQqbkTAU+YTao6ZPa/K4e5WlbXkOCGs X-Received: by 10.194.84.66 with SMTP id w2mr16738441wjy.6.1456156801496; Mon, 22 Feb 2016 08:00:01 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id g3sm25273648wjw.31.2016.02.22.07.59.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Feb 2016 07:59:56 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id C5AEB3E0329; Mon, 22 Feb 2016 15:59:52 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Mon, 22 Feb 2016 15:59:43 +0000 Message-Id: <1456156787-17509-6-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.1 In-Reply-To: <1456156787-17509-1-git-send-email-alex.bennee@linaro.org> References: <1456156787-17509-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::236 Cc: 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 v7 5/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 v6 - make parsing suck less (stroull, strstr, err) - add some basic unit tests --- include/qemu/log.h | 2 ++ qemu-options.hx | 18 +++++++++++ tests/Makefile | 4 +++ tests/test-logging.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++ util/log.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 3 ++ 6 files changed, 187 insertions(+) create mode 100644 tests/test-logging.c -- 2.7.1 diff --git a/include/qemu/log.h b/include/qemu/log.h index 22c4dec..c0225e1 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -132,6 +132,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-options.hx b/qemu-options.hx index 2f0465e..c7e0486 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3094,6 +3094,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/tests/Makefile b/tests/Makefile index 04e34b5..63e90e6 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -92,6 +92,8 @@ check-unit-$(CONFIG_GNUTLS) += tests/test-io-channel-tls$(EXESUF) check-unit-y += tests/test-io-channel-command$(EXESUF) check-unit-y += tests/test-io-channel-buffer$(EXESUF) check-unit-y += tests/test-base64$(EXESUF) +gcov-files-test-logging-y = tests/test-logging.c +check-unit-y += tests/test-logging$(EXESUF) check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh @@ -432,6 +434,8 @@ tests/test-timed-average$(EXESUF): tests/test-timed-average.o qemu-timer.o \ tests/test-base64$(EXESUF): tests/test-base64.o \ libqemuutil.a libqemustub.a +tests/test-logging$(EXESUF): tests/test-logging.o $(test-util-obj-y) + tests/test-qapi-types.c tests/test-qapi-types.h :\ $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \ diff --git a/tests/test-logging.c b/tests/test-logging.c new file mode 100644 index 0000000..c2dae49 --- /dev/null +++ b/tests/test-logging.c @@ -0,0 +1,75 @@ +/* + * logging unit-tests + * + * Copyright (C) 2016 Linaro Ltd. + * + * Author: Alex Bennée + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "qemu-common.h" +#include "include/qemu/log.h" + +static void test_parse_range(void) +{ + qemu_set_dfilter_ranges("0x1000+0x100"); + + g_assert_false(qemu_log_in_addr_range(0xfff)); + g_assert(qemu_log_in_addr_range(0x1000)); + g_assert(qemu_log_in_addr_range(0x1100)); + g_assert_false(qemu_log_in_addr_range(0x1101)); + + qemu_set_dfilter_ranges("0x1000-0x100"); + + g_assert_false(qemu_log_in_addr_range(0x1001)); + g_assert(qemu_log_in_addr_range(0x1000)); + g_assert(qemu_log_in_addr_range(0x0f00)); + g_assert_false(qemu_log_in_addr_range(0x0e99)); + + qemu_set_dfilter_ranges("0x1000..0x1100"); + + g_assert_false(qemu_log_in_addr_range(0xfff)); + g_assert(qemu_log_in_addr_range(0x1000)); + g_assert(qemu_log_in_addr_range(0x1100)); + g_assert_false(qemu_log_in_addr_range(0x1101)); + + qemu_set_dfilter_ranges("0x1000..0x1000"); + + g_assert_false(qemu_log_in_addr_range(0xfff)); + g_assert(qemu_log_in_addr_range(0x1000)); + g_assert_false(qemu_log_in_addr_range(0x1001)); + + qemu_set_dfilter_ranges("0x1000+0x100,0x2100-0x100,0x3000..0x3100"); + g_assert(qemu_log_in_addr_range(0x1050)); + g_assert(qemu_log_in_addr_range(0x2050)); + g_assert(qemu_log_in_addr_range(0x3050)); + +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/logging/parse_range", test_parse_range); + + return g_test_run(); +} diff --git a/util/log.c b/util/log.c index c89b226..bd4a660 100644 --- a/util/log.c +++ b/util/log.c @@ -20,12 +20,14 @@ #include "qemu/osdep.h" #include "qemu-common.h" #include "qemu/log.h" +#include "qemu/range.h" #include "trace/control.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, ...) { @@ -84,6 +86,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) { + char *range_op = strstr(r, "-"); + char *r2 = range_op ? range_op + 1 : NULL; + if (!range_op) { + range_op = strstr(r, "+"); + r2 = range_op ? range_op + 1 : NULL; + } + if (!range_op) { + range_op = strstr(r, ".."); + r2 = range_op ? range_op + 2 : NULL; + } + if (range_op) { + struct Range range; + int err; + const char *e = NULL; + + err = qemu_strtoull(r, &e, 0, &range.begin); + + g_assert(e == range_op); + + switch (*range_op) { + case '+': + { + unsigned long len; + err |= qemu_strtoull(r2, NULL, 0, &len); + range.end = range.begin + len; + break; + } + case '-': + { + unsigned long len; + err |= qemu_strtoull(r2, NULL, 0, &len); + range.end = range.begin; + range.begin = range.end - len; + break; + } + case '.': + err |= qemu_strtoull(r2, NULL, 0, &range.end); + break; + default: + g_assert_not_reached(); + } + if (err) { + g_error("Failed to parse range in: %s", r); + } 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/vl.c b/vl.c index b87e292..753afb1 100644 --- a/vl.c +++ b/vl.c @@ -3353,6 +3353,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;