Skip to content

Commit 1b91949

Browse files
Vyacheslav Barinovpalves
authored andcommitted
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 <[email protected]> Pedro Alves <[email protected]> * 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 <[email protected]> Pedro Alves <[email protected]> * linux-low.c (initialize_low): Call linux_proc_init_warnings.
1 parent 94d401b commit 1b91949

File tree

6 files changed

+45
-5
lines changed

6 files changed

+45
-5
lines changed

gdb/ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2018-07-04 Vyacheslav Barinov <[email protected]>
2+
Pedro Alves <[email protected]>
3+
4+
* linux-nat.c (linux_init_ptrace): Rename to ...
5+
(linux_init_ptrace_procfs): ... this. Call
6+
linux_proc_init_warnings.
7+
(linux_nat_target::post_attach)
8+
(linux_nat_target::post_startup_inferior): Adjust.
9+
* nat/linux-procfs.c (linux_proc_init_warnings): Define function.
10+
* nat/linux-procfs.h (linux_proc_init_warnings): Declare function.
11+
112
2018-07-04 Tom de Vries <[email protected]>
213

314
* dwarf2read.c (error_check_comp_unit_head): Move dwarf version

gdb/gdbserver/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2018-07-04 Vyacheslav Barinov <[email protected]>
2+
Pedro Alves <[email protected]>
3+
4+
* linux-low.c (initialize_low): Call linux_proc_init_warnings.
5+
16
2018-07-03 Tom Tromey <[email protected]>
27

38
* linux-low.c: Update.

gdb/gdbserver/linux-low.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7558,6 +7558,7 @@ initialize_low (void)
75587558
set_target_ops (&linux_target_ops);
75597559

75607560
linux_ptrace_init_warnings ();
7561+
linux_proc_init_warnings ();
75617562

75627563
sigchld_action.sa_handler = sigchld_handler;
75637564
sigemptyset (&sigchld_action.sa_mask);

gdb/linux-nat.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,18 +384,19 @@ linux_nat_ptrace_options (int attached)
384384
return options;
385385
}
386386

387-
/* Initialize ptrace warnings and check for supported ptrace
388-
features given PID.
387+
/* Initialize ptrace and procfs warnings and check for supported
388+
ptrace features given PID.
389389
390390
ATTACHED should be nonzero iff we attached to the inferior. */
391391

392392
static void
393-
linux_init_ptrace (pid_t pid, int attached)
393+
linux_init_ptrace_procfs (pid_t pid, int attached)
394394
{
395395
int options = linux_nat_ptrace_options (attached);
396396

397397
linux_enable_event_reporting (pid, options);
398398
linux_ptrace_init_warnings ();
399+
linux_proc_init_warnings ();
399400
}
400401

401402
linux_nat_target::~linux_nat_target ()
@@ -404,13 +405,13 @@ linux_nat_target::~linux_nat_target ()
404405
void
405406
linux_nat_target::post_attach (int pid)
406407
{
407-
linux_init_ptrace (pid, 1);
408+
linux_init_ptrace_procfs (pid, 1);
408409
}
409410

410411
void
411412
linux_nat_target::post_startup_inferior (ptid_t ptid)
412413
{
413-
linux_init_ptrace (ptid.pid (), 0);
414+
linux_init_ptrace_procfs (ptid.pid (), 0);
414415
}
415416

416417
/* Return the number of known LWPs in the tgid given by PID. */

gdb/nat/linux-procfs.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,20 @@ linux_proc_pid_to_exec_file (int pid)
357357

358358
return buf;
359359
}
360+
361+
/* See linux-procfs.h. */
362+
363+
void
364+
linux_proc_init_warnings ()
365+
{
366+
static bool warned = false;
367+
368+
if (warned)
369+
return;
370+
warned = true;
371+
372+
struct stat st;
373+
374+
if (stat ("/proc/self", &st) != 0)
375+
warning (_("/proc is not accessible."));
376+
}

gdb/nat/linux-procfs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,9 @@ extern int linux_proc_task_list_dir_exists (pid_t pid);
8080

8181
extern char *linux_proc_pid_to_exec_file (int pid);
8282

83+
/* Display possible problems on this system. Display them only once
84+
per GDB execution. */
85+
86+
extern void linux_proc_init_warnings ();
87+
8388
#endif /* COMMON_LINUX_PROCFS_H */

0 commit comments

Comments
 (0)