public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Vyacheslav Barinov <v.barinov@samsung.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] Check if /proc is usable on gdbserver start
Date: Wed, 04 Jul 2018 07:34:00 -0000	[thread overview]
Message-ID: <20180704073447eucas1p1541c2021074eb8faa58e49f1abe8d733~_GikXtils0124801248eucas1p1n@eucas1p1.samsung.com> (raw)
In-Reply-To: <CGME20180704073447eucas1p1541c2021074eb8faa58e49f1abe8d733@eucas1p1.samsung.com>

[-- Attachment #1: Type: text/plain, Size: 542 bytes --]

Hello,

Just lost a couple of hours trying to find while gdb can't connect to gdbserver
in my debug session.

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.

I think it's better to check this before running gdbserver.

Best Regards,
Slava Barinov.
    

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Check-if-proc-is-usable-on-gdbserver-start.patch --]
[-- Type: text/x-patch, Size: 982 bytes --]

From 0d9bc48e145195b9ce04dedb3ca75ee93d90a32c Mon Sep 17 00:00:00 2001
From: Slava Barinov <v.barinov@samsung.com>
Date: Wed, 4 Jul 2018 10:20:42 +0300
Subject: [PATCH] Check if /proc is usable on gdbserver start

Add check if procfs is mount and can be accessed by gdbserver.

gdbserver/
	* linux-low.c (initialize_low): Add /proc check.

Signed-off-by: Slava Barinov <v.barinov@samsung.com>
---
 gdb/gdbserver/linux-low.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 6e026f1aab..28273da1b9 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -7553,6 +7553,13 @@ void
 initialize_low (void)
 {
   struct sigaction sigchld_action;
+  struct stat st;
+
+  if (stat ("/proc/self", &st) != 0)
+    {
+      fprintf (stderr, "/proc is not accessible.\n");
+      exit (1);
+    }
 
   memset (&sigchld_action, 0, sizeof (sigchld_action));
   set_target_ops (&linux_target_ops);
-- 
2.18.0


       reply	other threads:[~2018-07-04  7:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20180704073447eucas1p1541c2021074eb8faa58e49f1abe8d733@eucas1p1.samsung.com>
2018-07-04  7:34 ` Vyacheslav Barinov [this message]
2018-07-04  9:57   ` Pedro Alves
2018-07-04 11:19     ` Vyacheslav Barinov
2018-07-04 15:23       ` [pushed] Warn if /proc is not accessible (was: Re: [PATCH] Check if /proc is usable on gdbserver start) Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='20180704073447eucas1p1541c2021074eb8faa58e49f1abe8d733~_GikXtils0124801248eucas1p1n@eucas1p1.samsung.com' \
    --to=v.barinov@samsung.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).