From patchwork Fri Dec 16 12:30:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 62001 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E5363848E32 for ; Fri, 16 Dec 2022 12:31:21 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by sourceware.org (Postfix) with ESMTPS id C726E384F723 for ; Fri, 16 Dec 2022 12:31:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C726E384F723 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f48.google.com with SMTP id v7so1796995wmn.0 for ; Fri, 16 Dec 2022 04:31:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=emuNgsOU2vHmpJlb+9IoPKuk2Q8vS7HKF6cIFCwrdBQ=; b=IWsMH1niTW1JJAJrCtAveKcUl1SwoapiGpDE9/8zHS6Ml4x+WJW00yKo5rfNl7bb2t JaMuzhk/URYWVBYXKL6KhPaYK+MhTXw30njTWE9sgNdeEL6f22ehpgp0IOMKk9SfMO0b PgF/nMAMWrePQ//FlKE3evJNKJCSXwKrEyI2ul010CRKFq6g95RoGYerczJxd9OGgsIV N4QVp66K7hkpJ61LuXjh5PNmuE23sj5pbwbrEet1nmG7jZkoa7x8m5FMFMPmOjewaAXf jNx/jB4e8VCIpWb/5FFOg88oXeZW4B23pmOFhNWLK02pL0wHoQDrU366AuT1y88+0x0D CsiA== X-Gm-Message-State: ANoB5pnBFQzEgIRTjNrVjpubM5ORckH2B+8nFXGIxC09LPmMWeBI2BdH 4JknT53Q7wfyPUyFjG5nZb2e4KTrT094hw== X-Google-Smtp-Source: AA0mqf4Zr66mIAivXHFDzv87lxZXHTPGPyvOuZABBigFMstcvOq8TOLJedPUYpHKlO4jIlwsczwSXA== X-Received: by 2002:a05:600c:1d91:b0:3d0:274a:3171 with SMTP id p17-20020a05600c1d9100b003d0274a3171mr16464376wms.0.1671193861236; Fri, 16 Dec 2022 04:31:01 -0800 (PST) Received: from localhost ([2001:8a0:f912:6700:afd9:8b6d:223f:6170]) by smtp.gmail.com with ESMTPSA id y7-20020a05600c364700b003d33ab317dasm2730734wmq.14.2022.12.16.04.31.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Dec 2022 04:31:00 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH] Delay checking whether /proc/pid/mem is writable (PR gdb/29907) Date: Fri, 16 Dec 2022 12:30:59 +0000 Message-Id: <20221216123059.2458221-1-pedro@palves.net> X-Mailer: git-send-email 2.36.0 MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "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(-) base-commit: 429f0cd1396203204754141681b1bc65bd3f5259 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 (); }