From patchwork Wed Jul 4 15:23:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 28226 Received: (qmail 84018 invoked by alias); 4 Jul 2018 15:23: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 84002 invoked by uid 89); 4 Jul 2018 15:23:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=spirit, ptid X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 04 Jul 2018 15:23:38 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA71D87A76; Wed, 4 Jul 2018 15:23:36 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C8F77C57; Wed, 4 Jul 2018 15:23:35 +0000 (UTC) Subject: [pushed] Warn if /proc is not accessible (was: Re: [PATCH] Check if /proc is usable on gdbserver start) To: Vyacheslav Barinov References: <20180704073447eucas1p1541c2021074eb8faa58e49f1abe8d733~_GikXtils0124801248eucas1p1n@eucas1p1.samsung.com> <85d64cca-716b-b098-dc1c-b5a3e978fe3e@redhat.com> <20180704111926eucas1p13d4a3f7ef6ca0341162da4dab2b80770~_Jmt0fTkD2770727707eucas1p1K@eucas1p1.samsung.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <3a074939-376d-22ec-27ce-43ac3d14d5cd@redhat.com> Date: Wed, 4 Jul 2018 16:23:35 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180704111926eucas1p13d4a3f7ef6ca0341162da4dab2b80770~_Jmt0fTkD2770727707eucas1p1K@eucas1p1.samsung.com> On 07/04/2018 12:19 PM, Vyacheslav Barinov wrote: > > Okay, if the gdbserver can work without /proc, then just warning for cases > like this is enough. Alright, here's what I've merged. I added a new linux_ptrace_init_warnings routine to nat/linux-procfs.c very similar in spirit to the existing linux_ptrace_init_warnings and called it from the same places. This makes native debugging with GDB warn too. From 7c65a87e84f79155a9e9f59890340f85387df8a1 Mon Sep 17 00:00:00 2001 From: Vyacheslav Barinov Date: Wed, 4 Jul 2018 16:13:29 +0100 Subject: [PATCH] Warn if /proc is not accessible There's a buildroot where I want to debug a binary, and I tried to connect to it from outside, but got very weird errors like architecture mismatch or protocol errors. At last, after switching on '--debug' for gdbserver I found a message 'Can't open /proc/pid/' message and suddenly found that I forgot to mount procfs in my buildroot. Make discovering the problem easier by making GDB / GDBserver warn (even without --debug) if /proc can not be accessed. Native debugging: (gdb) start Temporary breakpoint 1 at 0x400835: file test.c, line 10. Starting program: /tmp/test warning: /proc is not accessible. GDBserver/remote debugging: $ ./gdbserver :9999 ./gdbserver gdbserver: /proc is not accessible. gdb/ChangeLog: 2018-07-04 Vyacheslav Barinov Pedro Alves * linux-nat.c (linux_init_ptrace): Rename to ... (linux_init_ptrace_procfs): ... this. Call linux_proc_init_warnings. (linux_nat_target::post_attach) (linux_nat_target::post_startup_inferior): Adjust. * nat/linux-procfs.c (linux_proc_init_warnings): Define function. * nat/linux-procfs.h (linux_proc_init_warnings): Declare function. gdb/gdbserver/ChangeLog: 2018-07-04 Vyacheslav Barinov Pedro Alves * linux-low.c (initialize_low): Call linux_proc_init_warnings. --- gdb/gdbserver/linux-low.c | 1 + gdb/linux-nat.c | 11 ++++++----- gdb/nat/linux-procfs.c | 17 +++++++++++++++++ gdb/nat/linux-procfs.h | 5 +++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 6e026f1aab8..7c396ae3662 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -7558,6 +7558,7 @@ initialize_low (void) set_target_ops (&linux_target_ops); linux_ptrace_init_warnings (); + linux_proc_init_warnings (); sigchld_action.sa_handler = sigchld_handler; sigemptyset (&sigchld_action.sa_mask); diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 567cb064d3a..18d9a3872a5 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -384,18 +384,19 @@ linux_nat_ptrace_options (int attached) return options; } -/* Initialize ptrace warnings and check for supported ptrace - features given PID. +/* Initialize ptrace and procfs warnings and check for supported + ptrace features given PID. ATTACHED should be nonzero iff we attached to the inferior. */ static void -linux_init_ptrace (pid_t pid, int attached) +linux_init_ptrace_procfs (pid_t pid, int attached) { int options = linux_nat_ptrace_options (attached); linux_enable_event_reporting (pid, options); linux_ptrace_init_warnings (); + linux_proc_init_warnings (); } linux_nat_target::~linux_nat_target () @@ -404,13 +405,13 @@ linux_nat_target::~linux_nat_target () void linux_nat_target::post_attach (int pid) { - linux_init_ptrace (pid, 1); + linux_init_ptrace_procfs (pid, 1); } void linux_nat_target::post_startup_inferior (ptid_t ptid) { - linux_init_ptrace (ptid.pid (), 0); + linux_init_ptrace_procfs (ptid.pid (), 0); } /* Return the number of known LWPs in the tgid given by PID. */ diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c index 1c236c543d9..6c15ea5cce3 100644 --- a/gdb/nat/linux-procfs.c +++ b/gdb/nat/linux-procfs.c @@ -357,3 +357,20 @@ linux_proc_pid_to_exec_file (int pid) return buf; } + +/* See linux-procfs.h. */ + +void +linux_proc_init_warnings () +{ + static bool warned = false; + + if (warned) + return; + warned = true; + + struct stat st; + + if (stat ("/proc/self", &st) != 0) + warning (_("/proc is not accessible.")); +} diff --git a/gdb/nat/linux-procfs.h b/gdb/nat/linux-procfs.h index efb2911cb8f..2f8932e89c7 100644 --- a/gdb/nat/linux-procfs.h +++ b/gdb/nat/linux-procfs.h @@ -80,4 +80,9 @@ extern int linux_proc_task_list_dir_exists (pid_t pid); extern char *linux_proc_pid_to_exec_file (int pid); +/* Display possible problems on this system. Display them only once + per GDB execution. */ + +extern void linux_proc_init_warnings (); + #endif /* COMMON_LINUX_PROCFS_H */