public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Delay checking whether /proc/pid/mem is writable (PR gdb/29907)
@ 2022-12-16 12:30 Pedro Alves
  2022-12-16 14:20 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Pedro Alves @ 2022-12-16 12:30 UTC (permalink / raw)
  To: gdb-patches

As of 1bcb0708f229 ("gdb/linux-nat: Check whether /proc/pid/mem is
writable"), GDB checks if /proc/pid/mem is writable.  This is done
early in GDB startup, in order to get a consistent warning, instead of
a warning that depends on whenever GDB writes to inferior memory.

PR gdb/29907 points out that some build systems (like QEMU's,
apparently) may call 'gdb --version' to check GDB's presence & its
version on the system, and that Gentoo's build process has sandboxing
which blocks the /proc/pid/mem access and thus GDB warns, which
results in build fails.

To help with that, this patch delays the /proc/pid/mem check until we
start or attach to an inferior.  Ends up potentially emiting a warning
close where we already emit other ptrace- and /proc- related warnings,
which just Feels Right.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29907
Change-Id: I5537653ecfbbe76a04ab035e40e59d09b4980763
---
 gdb/linux-nat.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 1d207c4e31d..57444671c48 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -372,6 +372,7 @@ linux_init_ptrace_procfs (pid_t pid, int attached)
   linux_enable_event_reporting (pid, options);
   linux_ptrace_init_warnings ();
   linux_proc_init_warnings ();
+  proc_mem_file_is_writable ();
 }
 
 linux_nat_target::~linux_nat_target ()
@@ -3955,7 +3956,11 @@ linux_proc_xfer_memory_partial (int pid, gdb_byte *readbuf,
    return true if so.  It wasn't writable before Linux 2.6.39, but
    there's no way to know whether the feature was backported to older
    kernels.  So we check to see if it works.  The result is cached,
-   and this is garanteed to be called once early at startup.  */
+   and this is garanteed to be called once early during inferior
+   startup, so that any warning is print out consistently between GDB
+   invocations.  Note we don't call it during GDB startup instead
+   though, because then we might warn with e.g. just "gdb --version"
+   on sandboxed systems.  See PR gdb/29907.  */
 
 static bool
 proc_mem_file_is_writable ()
@@ -4490,8 +4495,6 @@ Enables printf debugging output."),
   sigemptyset (&blocked_mask);
 
   lwp_lwpid_htab_create ();
-
-  proc_mem_file_is_writable ();
 }
 \f
 

base-commit: 429f0cd1396203204754141681b1bc65bd3f5259
-- 
2.36.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Delay checking whether /proc/pid/mem is writable (PR gdb/29907)
  2022-12-16 12:30 [PATCH] Delay checking whether /proc/pid/mem is writable (PR gdb/29907) Pedro Alves
@ 2022-12-16 14:20 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2022-12-16 14:20 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:

Pedro> To help with that, this patch delays the /proc/pid/mem check until we
Pedro> start or attach to an inferior.  Ends up potentially emiting a warning
Pedro> close where we already emit other ptrace- and /proc- related warnings,
Pedro> which just Feels Right.

Looks good to me.  Thank you.

Tom

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-16 14:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-16 12:30 [PATCH] Delay checking whether /proc/pid/mem is writable (PR gdb/29907) Pedro Alves
2022-12-16 14:20 ` Tom Tromey

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).