From patchwork Fri Oct 5 15:48:50 2018 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: 148197 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp614815lji; Fri, 5 Oct 2018 08:52:40 -0700 (PDT) X-Google-Smtp-Source: ACcGV63LWEgcB2Sl7Sp+psofqIeXBJ9bgkhvs2wsuqfKRg4lC0jY2sfUTQKwxE6IEO62oS9Y8ycW X-Received: by 2002:ac8:7397:: with SMTP id t23-v6mr9740533qtp.4.1538754760147; Fri, 05 Oct 2018 08:52:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538754760; cv=none; d=google.com; s=arc-20160816; b=WKpAg4h+bwlX6rqE+FUfLkMLt3JeN1zqpihS50feO7026pjaomQ7RzrvTDq8ginB01 rewCxZIfPjJii42bs7PnPdLhxPfphO2yPz24wBL1kVTc2pznA56gyhhvtLq0P3wrUcmB Y03Numx8fVOlX7H+YblCiwyE7fn679LginHPtw55t+1MSbSqP4mUBbjEA5uhsYFvsma+ uqpXjWguWwbuTB4gHgzdbv4B58l0dK2+IzoVtg1aPr6Ukd3G1S6I+U3MpKRTGHO1rTvN FH0akrAi64kXdrmI5cy7ktIJPoddCgLofr3zKE9XclElKd1fd2Y+xS/+2YEfuhKZEjBQ vLLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=m9XHKczBCfZKJnBKtgcKHhJOx0keN4+gJldX0UXceRM=; b=sUT0fHuC8tC38e4sWf5saxV3jwW/ZdmpfK9ZIOC4/NLIYyOc9f7XqPBoNy2yQ2QEFV FsoDVC3Dw+zC8DRfPyj5RWWDSfa2B1CuA6tDkhWYNeLWWoUKuPL20kqKd6uZBVo7hSkS F7udrgSTuCQjHjPKYwL6Q1ysY+NU6jcEfYtlpyNyjm3QCO0k2NXaYbMMBF9uZ5rLfhjW gucsCi450c4stMPuP7K/+VM9OCAUyCdHyVVrbdPKsHsB+igI7n5W19DCet8bcpTyI4Yq Ow38EONkMZ/ec8f8t6J54zByizVm+cjjpWdpOznxfYWqQ+ZfasrSYQDML7nsYb9m81X/ VoDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=W56GmmE9; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id h16-v6si419658qta.340.2018.10.05.08.52.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 05 Oct 2018 08:52:40 -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; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=W56GmmE9; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g8SP9-0002IH-I2 for patch@linaro.org; Fri, 05 Oct 2018 11:52:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56692) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g8SM6-0006XV-TG for qemu-devel@nongnu.org; Fri, 05 Oct 2018 11:49:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g8SLz-00065Z-Gn for qemu-devel@nongnu.org; Fri, 05 Oct 2018 11:49:29 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]:52742) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g8SLv-0005ze-MZ for qemu-devel@nongnu.org; Fri, 05 Oct 2018 11:49:21 -0400 Received: by mail-wm1-x333.google.com with SMTP id 189-v6so2313543wmw.2 for ; Fri, 05 Oct 2018 08:49:14 -0700 (PDT) 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-transfer-encoding; bh=m9XHKczBCfZKJnBKtgcKHhJOx0keN4+gJldX0UXceRM=; b=W56GmmE957Z9OYZkUztYcIrfFmhChuRMZucfj7c2MKDbD7Ebcyl+VS0eMLLZJEi+gS LT+DkQM8SQyc7eoZuWJo1uw8UBfYQ0VHnHW9VriJUTFhbG7oirQPVbAMqnTD9BEnOM1c rlbvXEhNiaEaUXwzvHZiqLpfxgAYA0ujL1VmU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m9XHKczBCfZKJnBKtgcKHhJOx0keN4+gJldX0UXceRM=; b=tOKU0NQSbL8xR+X2AeR147HWmvS4obqkAImMrsbkVdMD/4jAXeLHWJgfvQeZ4gEkpX cA3ujY2Hm4B4qDaqu/2o9qT6XVJ/TcP93Kl9g1avCFN3f/1md9WuNhEJ+UiL4hWF+QnX TeV8cwjk+zkOggX7HHSFLxIOl3UO7fYiTyOGphxNyOR1MFbltjevuNGQ7G85I94Lmjjk SweQ+k9rFpff3BtAr/aSCPrEIJFEhaHplL2FqsIvpO7jdYofBesWSJ2bW9t/RUeDOawZ GiRgBvPtdSSubIrAbFsG8FbQmwoFs30nqkZnJoB32EvjD5frQ1jZ3hzkINtVpiEFcgG6 /fXw== X-Gm-Message-State: ABuFfogD7te+YwFL9vf4tUbKxlLvByc+anMwyxLS912gg2R3X+i0FRYs jiqTt9i1uXPXVdNJLqg7IfxeRg== X-Received: by 2002:a1c:2384:: with SMTP id j126-v6mr8228763wmj.124.1538754552898; Fri, 05 Oct 2018 08:49:12 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id e7-v6sm9219087wra.37.2018.10.05.08.49.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 05 Oct 2018 08:49:12 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id C5F743E032E; Fri, 5 Oct 2018 16:49:10 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Fri, 5 Oct 2018 16:48:50 +0100 Message-Id: <20181005154910.3099-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181005154910.3099-1-alex.bennee@linaro.org> References: <20181005154910.3099-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::333 Subject: [Qemu-devel] [RFC PATCH 01/21] util/log: allow -dfilter to stack X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , vilanova@ac.upc.edu, Pavel.Dovgaluk@ispras.ru Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The original dfilter was patched to avoid a leak in the case of multiple -dfilter ranges. There is no reason not to allow the user to stack several dfilter options rather than push them all into one mega line. We avoid the leak by simply only allocating the first time around. As we are using a g_array it will automatically re-size as needed. The allocation is pushed to a helper as future patches will offer additional ways to add to the dfilter. We also add a helper qemu_reset_dfilter_ranges() so we can be explicit in our unit tests. Signed-off-by: Alex Bennée --- include/qemu/log.h | 1 + tests/test-logging.c | 14 ++++++++++++++ util/log.c | 23 +++++++++++++++++------ 3 files changed, 32 insertions(+), 6 deletions(-) -- 2.17.1 Reviewed-by: Richard Henderson diff --git a/include/qemu/log.h b/include/qemu/log.h index b097a6cae1..8ed932ec24 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -116,6 +116,7 @@ void qemu_set_log(int log_flags); void qemu_log_needs_buffers(void); void qemu_set_log_filename(const char *filename, Error **errp); void qemu_set_dfilter_ranges(const char *ranges, Error **errp); +void qemu_reset_dfilter_ranges(void); bool qemu_log_in_addr_range(uint64_t addr); int qemu_str_to_log_mask(const char *str); diff --git a/tests/test-logging.c b/tests/test-logging.c index a12585f70a..fbddd70ebc 100644 --- a/tests/test-logging.c +++ b/tests/test-logging.c @@ -43,6 +43,8 @@ static void test_parse_range(void) g_assert(qemu_log_in_addr_range(0x10ff)); g_assert_false(qemu_log_in_addr_range(0x1100)); + qemu_reset_dfilter_ranges(); + qemu_set_dfilter_ranges("0x1000-0x100", &error_abort); g_assert_false(qemu_log_in_addr_range(0x1001)); @@ -50,6 +52,8 @@ static void test_parse_range(void) g_assert(qemu_log_in_addr_range(0x0f01)); g_assert_false(qemu_log_in_addr_range(0x0f00)); + qemu_reset_dfilter_ranges(); + qemu_set_dfilter_ranges("0x1000..0x1100", &error_abort); g_assert_false(qemu_log_in_addr_range(0xfff)); @@ -57,26 +61,36 @@ static void test_parse_range(void) g_assert(qemu_log_in_addr_range(0x1100)); g_assert_false(qemu_log_in_addr_range(0x1101)); + qemu_reset_dfilter_ranges(); + qemu_set_dfilter_ranges("0x1000..0x1000", &error_abort); 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_reset_dfilter_ranges(); + qemu_set_dfilter_ranges("0x1000+0x100,0x2100-0x100,0x3000..0x3100", &error_abort); g_assert(qemu_log_in_addr_range(0x1050)); g_assert(qemu_log_in_addr_range(0x2050)); g_assert(qemu_log_in_addr_range(0x3050)); + qemu_reset_dfilter_ranges(); + qemu_set_dfilter_ranges("0xffffffffffffffff-1", &error_abort); g_assert(qemu_log_in_addr_range(UINT64_MAX)); g_assert_false(qemu_log_in_addr_range(UINT64_MAX - 1)); + qemu_reset_dfilter_ranges(); + qemu_set_dfilter_ranges("0..0xffffffffffffffff", &err); g_assert(qemu_log_in_addr_range(0)); g_assert(qemu_log_in_addr_range(UINT64_MAX)); + qemu_reset_dfilter_ranges(); + qemu_set_dfilter_ranges("2..1", &err); error_free_or_abort(&err); diff --git a/util/log.c b/util/log.c index c0dbbd4700..c6c197cbb3 100644 --- a/util/log.c +++ b/util/log.c @@ -149,19 +149,30 @@ bool qemu_log_in_addr_range(uint64_t addr) } } +static void maybe_allocate_dfilter(int size_hint) +{ + if (!debug_regions) { + debug_regions = g_array_sized_new(FALSE, FALSE, + sizeof(Range), + size_hint ? size_hint : 1); + } +} + +/* This is only really used for testing, usually dfilter stacks */ +void qemu_reset_dfilter_ranges(void) +{ + GArray *old = debug_regions; + debug_regions = NULL; + g_array_free(old, TRUE); +} void qemu_set_dfilter_ranges(const char *filter_spec, Error **errp) { gchar **ranges = g_strsplit(filter_spec, ",", 0); int i; - if (debug_regions) { - g_array_unref(debug_regions); - debug_regions = NULL; - } + maybe_allocate_dfilter(g_strv_length(ranges)); - debug_regions = g_array_sized_new(FALSE, FALSE, - sizeof(Range), g_strv_length(ranges)); for (i = 0; ranges[i]; i++) { const char *r = ranges[i]; const char *range_op, *r2, *e;