From patchwork Fri Jan 26 14:14:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Metzger, Markus T" X-Patchwork-Id: 25581 Received: (qmail 118169 invoked by alias); 26 Jan 2018 14:14:40 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 118004 invoked by uid 89); 26 Jan 2018 14:14:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.0 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=Hx-languages-length:2303 X-HELO: mga11.intel.com Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 26 Jan 2018 14:14:38 +0000 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jan 2018 06:14:35 -0800 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga006.jf.intel.com with ESMTP; 26 Jan 2018 06:14:34 -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 w0QEEYm1020640; Fri, 26 Jan 2018 14:14:34 GMT Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id w0QEEXCk019612; Fri, 26 Jan 2018 15:14:33 +0100 Received: (from mmetzger@localhost) by ulvlx001.iul.intel.com with LOCAL id w0QEEXKp019608; Fri, 26 Jan 2018 15:14:33 +0100 From: Markus Metzger To: gdb-patches@sourceware.org Subject: [PATCH v2 7/7] btrace: check perf_event_paranoid Date: Fri, 26 Jan 2018 15:14:32 +0100 Message-Id: <1516976072-19282-8-git-send-email-markus.t.metzger@intel.com> In-Reply-To: <1516976072-19282-1-git-send-email-markus.t.metzger@intel.com> References: <1516976072-19282-1-git-send-email-markus.t.metzger@intel.com> X-IsSubscribed: yes 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-26 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 4425539..c0b031f 100644 --- a/gdb/nat/linux-btrace.c +++ b/gdb/nat/linux-btrace.c @@ -409,6 +409,34 @@ cpu_supports_bts (void) } } +/* The perf_event_open syscall failed. Try to print a helpful error + message. */ + +static void +diagnose_perf_event_open_fail () +{ + 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 * @@ -448,7 +476,7 @@ linux_enable_bts (ptid_t ptid, const struct btrace_config_bts *conf) errno = 0; scoped_fd fd (syscall (SYS_perf_event_open, &bts->attr, pid, -1, -1, 0)); if (fd.get () < 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 @@ -578,7 +606,7 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf) errno = 0; scoped_fd fd (syscall (SYS_perf_event_open, &pt->attr, pid, -1, -1, 0)); if (fd.get () < 0) - error (_("Failed to start recording: %s"), safe_strerror (errno)); + diagnose_perf_event_open_fail (); /* Allocate the configuration page. */ scoped_mmap data (nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,