Bug 29907 - gdb tries to open /proc/pid/mem even for --version
Summary: gdb tries to open /proc/pid/mem even for --version
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Pedro Alves
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-16 06:56 UTC by Sam James
Modified: 2022-12-16 23:10 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sam James 2022-12-16 06:56:45 UTC
Build systems (like QEMU's, apparently) may call 'gdb --version' to check gdb's presence & its version on the system.

As of 1bcb0708f22956d5128a2e75df6eba5a18327892, gdb will check if /proc/pid/mem is writable, including for 'gdb --version' calls.

Gentoo's build process has sandboxing which blocks this access and then as a result the build fails.

Is it possible to skip this the /proc/pid/mem check for simple --version invocations? Thanks.
Comment 1 Pedro Alves 2022-12-16 12:32:17 UTC
Fix posted here:

 [PATCH] Delay checking whether /proc/pid/mem is writable (PR gdb/29907)
 https://sourceware.org/pipermail/gdb-patches/2022-December/194817.html
Comment 2 Sourceware Commits 2022-12-16 16:06:14 UTC
The master branch has been updated by Pedro Alves <palves@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9dff6a5d54f212f875b6551444393691a2410f3e

commit 9dff6a5d54f212f875b6551444393691a2410f3e
Author: Pedro Alves <pedro@palves.net>
Date:   Fri Dec 16 12:04:54 2022 +0000

    Delay checking whether /proc/pid/mem is writable (PR gdb/29907)
    
    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 at 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
Comment 3 Pedro Alves 2022-12-16 16:14:37 UTC
Fixed.
Comment 4 Sam James 2022-12-16 23:10:51 UTC
Many thanks for the speedy resolution!