From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26939 invoked by alias); 25 Jan 2018 09:12:39 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 26843 invoked by uid 89); 25 Jan 2018 09:12:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mga01.intel.com Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 25 Jan 2018 09:12:33 +0000 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jan 2018 01:12:09 -0800 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga004.jf.intel.com with ESMTP; 25 Jan 2018 01:12:08 -0800 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id w0P9C8Yh026720; Thu, 25 Jan 2018 09:12:08 GMT Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id w0P9C88Q032507; Thu, 25 Jan 2018 10:12:08 +0100 Received: (from mmetzger@localhost) by ulvlx001.iul.intel.com with LOCAL id w0P9C7hq032503; Thu, 25 Jan 2018 10:12:08 +0100 From: Markus Metzger To: gdb-patches@sourceware.org Subject: [PATCH 5/5] btrace: check perf_event_paranoid Date: Thu, 25 Jan 2018 09:12:00 -0000 Message-Id: <1516871526-32129-6-git-send-email-markus.t.metzger@intel.com> In-Reply-To: <1516871526-32129-1-git-send-email-markus.t.metzger@intel.com> References: <1516871526-32129-1-git-send-email-markus.t.metzger@intel.com> X-IsSubscribed: yes X-SW-Source: 2018-01/txt/msg00500.txt.bz2 One recurring error on Debian systems is that the default perf_event_paranoid setting disables the perf_event interface for user-space. Check the current level and point the user to the file. 2018-01-25 Markus Metzger gdb/ * nat/linux-btrace.c (diagnose_perf_event_open_fail): New. (linux_enable_pt, linux_enable_bts): Call diagnose_perf_event_open_fail. --- gdb/nat/linux-btrace.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c index db93739..956b945 100644 --- a/gdb/nat/linux-btrace.c +++ b/gdb/nat/linux-btrace.c @@ -484,6 +484,34 @@ public: } }; +/* The perf_event_open syscall failed. Try to print a helpful error + message. */ + +static void +diagnose_perf_event_open_fail (void) +{ + switch (errno) + { + case EPERM: + case EACCES: + { + const char *filename = "/proc/sys/kernel/perf_event_paranoid"; + gdb_file_up file = gdb_fopen_cloexec (filename, "r"); + if (file.get () == nullptr) + break; + + int level, found = fscanf (file.get (), "%d", &level); + if (found == 1 && level > 2) + error (_("You do not have permission to record the process. " + "Try setting %s to 2 or less."), filename); + } + + break; + } + + error (_("Failed to start recording: %s"), safe_strerror (errno)); +} + /* Enable branch tracing in BTS format. */ static struct btrace_target_info * @@ -524,7 +552,7 @@ linux_enable_bts (ptid_t ptid, const struct btrace_config_bts *conf) scoped_close_fd fd (syscall (SYS_perf_event_open, &bts->attr, pid, -1, -1, 0)); if (fd < 0) - error (_("Failed to start recording: %s"), safe_strerror (errno)); + diagnose_perf_event_open_fail (); /* Convert the requested size in bytes to pages (rounding up). */ pages = ((size_t) conf->size / PAGE_SIZE @@ -650,7 +678,7 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf) errno = 0; scoped_close_fd fd (syscall (SYS_perf_event_open, &pt->attr, pid, -1, -1, 0)); if (fd < 0) - error (_("Failed to start recording: %s"), safe_strerror (errno)); + diagnose_perf_event_open_fail (); /* Allocate the configuration page. */ scoped_mmap header (NULL, PAGE_SIZE, -- 1.8.3.1