Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2914005pxj; Mon, 31 May 2021 14:34:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzH1OTT/CLHoZ+bb5AP3Lmr72a3t8z2JWlcgpnzYI/LrBn+aNlp5qAukTkDwLdvHUOTPgs3 X-Received: by 2002:aa7:c0cb:: with SMTP id j11mr7809234edp.177.1622496893911; Mon, 31 May 2021 14:34:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622496893; cv=none; d=google.com; s=arc-20160816; b=m6vcn1Nj7LwbBC/XcFblSVT1QDy6+P/IIX9mH1D9Z3Z6KWigHjlzwWqhE7BPDkcKjp wq2RLf6MH8JAFrwXqEkFvJJX1jEBim3FSUDFRhIqTf/Wl/37wulPQwv7XK3Uz6ORgSPR sPLXDouZAFV7H0tYmnb3WdVEzTSK6s6IXpcUPlLHoNfnYvb9Bb2UfBsquWnPhMr9HVYj xU39N6y4HdelttootMviPoL0gj8yRHf4ITSAryKSPtNfghYy1BhMkj1G93FquNT8DLfV ktQO9DBK3rqJ76ksXx3KbGtMIe46AFTUHgYUWoEkzCMsW+9zEqm4NQQdn80+yLs+65dn 0RFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=BUzR9q9xMCrnYk7GXKRktXhKYKGCLSyWr6ZPj2PNhxU=; b=zApMyDE53Tt0ioBM2E7xFCR3Pmj2JsbQ9w2QAKDuRnEPbNXHJ0Rv4sBsSOjT8/YmT4 Oa4zERrw9ZytmVjRAcWEs7QRl8vmjlO9xOiQOZVAqnSsYQx3AGDKO8/05RTd41HaVOxO LuYTsWmHoteIoxKdFbb2OFXFGSVwPlNkc4EM1xzBTxENSasSZLvBKmaxAAf7VENdhmV9 Py8cLgVlMdy1+NxQgZCoqyaHZFMYzqCUB3LN6Giu5tWgw/Zp0X9TsR+YEU+agC2F8Q6b fjQ0lVXzXD45+FtHwFxKqsAI/8k/MxiXhreoSDK25pE+DA4eCOACSZKc43MrhIAlHMaQ +9Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=e1T7AgkC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nb17si4976509ejc.226.2021.05.31.14.34.22; Mon, 31 May 2021 14:34:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=e1T7AgkC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231629AbhEaVda (ORCPT + 99 others); Mon, 31 May 2021 17:33:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230433AbhEaVda (ORCPT ); Mon, 31 May 2021 17:33:30 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D17F7C061574; Mon, 31 May 2021 14:31:48 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id b11so8057300edy.4; Mon, 31 May 2021 14:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=BUzR9q9xMCrnYk7GXKRktXhKYKGCLSyWr6ZPj2PNhxU=; b=e1T7AgkCjMbptDQBztdPgw4yrRR2awCT20SxhaqPT+g3tgygJtGok/JpGEdM0BbG2m /SghMH9LWm3dafuF/OrD9L7bczCiFJYK0zGbTYeDr7bcdy6aXADkmcjkj8xMPiJFwoKT V6rtLhdXEazSEEJI9KFzkuS4LBeSrT9lhvEKitbYeEa8chDKNWjPlGzxO9XCflMHF3hy myKttnjOqyEB2jBghwGnUGMXGCKHK2l+cXFrRw9U4CeVvzu4XOP7HwuLGBGlca0JZQtP CnIfl69h6PkkxXKoX9il2R3j/yfjDNwJpycPxnXY496xlc1lTPOGD09P51Fgm9V8C/R6 nVmQ== 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:mime-version :content-transfer-encoding; bh=BUzR9q9xMCrnYk7GXKRktXhKYKGCLSyWr6ZPj2PNhxU=; b=BDoz84GwR7ZrGrigTGmPgntrsntOXykdI0wbWOcYZ3FvCULxsfnUUmo3xinoGKgzy3 0e5g71/TXtvyqf3jZUyytgfnaPzmlxdjnQf4Mb07nG2amXADtK6n34xGZRXcq/oG7lDY h5R3WR8EGUNgZmTsSiWg8NqpwXuT5qswHTnK8voO99vF64mwdel4sYWDl9Jm1xWIYdq7 lRXN5C1/0ygulBNcGJbNW9km/iksuievbuNP63xt+GsohPThhdDHaynN9KgSZN84YiMO EvbDgyt2t8IHq3D2l/OMNc6RkUcYyXTfiSYsVZqrBWMGOhOb0kheAcSacbbVn355Si0Z ZwOw== X-Gm-Message-State: AOAM530Iye7BLYyceCHdgEH68HCdyBxvcVMk3sDE2C+BPZ3Jedmoe9XP MV++iLA2mm+pIA98aKpn2VY= X-Received: by 2002:a05:6402:1648:: with SMTP id s8mr20501261edx.256.1622496707315; Mon, 31 May 2021 14:31:47 -0700 (PDT) Received: from honeypot.. ([151.29.82.133]) by smtp.googlemail.com with ESMTPSA id m16sm7364358edq.56.2021.05.31.14.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 May 2021 14:31:46 -0700 (PDT) From: Riccardo Mancini To: Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers Cc: Riccardo Mancini , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] perf: fix segfault when wrong option for --debug is provided Date: Mon, 31 May 2021 23:28:28 +0200 Message-Id: <20210531212828.240077-1-rickyman7@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The command `perf --debug record` causes a segfault instead of notifying the user of the unrecognized option for --debug (the correct syntax would be `perf --debug verbose=2 record`). The bug is caused by a call to pr_err before debug_file (debug.c:34) is set via perf_debug_setup(). It has been introduced in commit 8abceacff87d ("perf debug: Add debug_set_file function"). This patch resolves the bug by calling perf_debug_setup earlier in the main, so that debug_file is set to stderr before any call to a debug printing function is made. Signed-off-by: Riccardo Mancini --- tools/perf/perf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 20cb91ef06ffc..cffbab2d085a7 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c @@ -448,6 +448,7 @@ int main(int argc, const char **argv) pager_init(PERF_PAGER_ENVIRONMENT); libperf_init(libperf_print); + perf_debug_setup(); cmd = extract_argv0_path(argv[0]); if (!cmd) @@ -531,8 +532,6 @@ int main(int argc, const char **argv) */ pthread__block_sigwinch(); - perf_debug_setup(); - while (1) { static int done_help; -- 2.23.0