From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 6D78738515D3 for ; Fri, 3 Jun 2022 15:18:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6D78738515D3 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-126-qnnxt8XCPS60MlIKWUCbNw-1; Fri, 03 Jun 2022 11:18:40 -0400 X-MC-Unique: qnnxt8XCPS60MlIKWUCbNw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 90B533C1014B; Fri, 3 Jun 2022 15:18:40 +0000 (UTC) Received: from guittard.uglyboxes.com (unknown [10.2.17.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3390A8287E; Fri, 3 Jun 2022 15:18:40 +0000 (UTC) From: Keith Seitz To: gdb-patches@sourceware.org Cc: pedro@palves.net Subject: Re: [PATCH] linux_nat_target::xfer_partial: Fallback to ptrace Date: Fri, 3 Jun 2022 08:18:39 -0700 Message-Id: <20220603151839.2632317-1-keiths@redhat.com> In-Reply-To: d0126796-67ae-cf3d-a88c-44f204018f07@palves.net References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: , X-List-Received-Date: Fri, 03 Jun 2022 15:18:45 -0000 Pedro Alves wrote: > I guess the write to /proc/pid/mem fails with EIO for you, and there's nothing > else we can use to detect the scenario. So we probably want to check TARGET_XFER_E_IO > instead. And, maybe only do the fallback if writing. I've updated the patch to include these changes and retested on all the "usual" target boards on Fedora 36 x86_64, s390x, ppc64le, and aarch64 and on RHEL6 x86_64. Keith -- Commit 05c06f318fd9a112529dfc313e6512b399a645e4 enabled GDB to access memory while threads are running. It did this by accessing /proc/PID/task/LWP/mem. Unfortunately, this interface is not implemented for writing in older kernels (such as RHEL6). This means that GDB is unable to insert breakpoints on these hosts: $ ./gdb -q gdb -ex start Reading symbols from gdb... Temporary breakpoint 1 at 0x40fdd5: file ../../src/gdb/gdb.c, line 28. Starting program: /home/rhel6/fsf/linux/gdb/gdb Warning: Cannot insert breakpoint 1. Cannot access memory at address 0x40fdd5 (gdb) Before this patch, linux_proc_xfer_memory_partial (previously called linux_proc_xfer_partial) would return TARGET_XFER_EOF if the write to /proc/PID/mem failed. [More specifically, linux_proc_xfer_partial would not "bother for one word," but the effect is the essentially same.] This status was checked by linux_nat_target::xfer_partial, which would then fallback to using ptrace to perform the operation. This is the specific hunk that removed the fallback: - xfer = linux_proc_xfer_partial (object, annex, readbuf, writebuf, - offset, len, xfered_len); - if (xfer != TARGET_XFER_EOF) - return xfer; + return linux_proc_xfer_memory_partial (readbuf, writebuf, + offset, len, xfered_len); + } return inf_ptrace_target::xfer_partial (object, annex, readbuf, writebuf, offset, len, xfered_len); This patch restores this fallback mechanism, enabling GDB to insert breakpoints on these older kernels. Note that a recent patch changed the return status from TARGET_XFER_EOF to TARGET_XFER_E_IO. Tested on {unix,native-gdbserver,native-extended-gdbserver}/-m{32,64} on x86_64, s390x, aarch64, and ppc64le. --- gdb/linux-nat.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 3b5400896bc..571c97137c2 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -3706,8 +3706,12 @@ linux_nat_target::xfer_partial (enum target_object object, if (addr_bit < (sizeof (ULONGEST) * HOST_CHAR_BIT)) offset &= ((ULONGEST) 1 << addr_bit) - 1; - return linux_proc_xfer_memory_partial (readbuf, writebuf, - offset, len, xfered_len); + enum target_xfer_status xfer + = linux_proc_xfer_memory_partial (readbuf, writebuf, + offset, len, xfered_len); + if (xfer != TARGET_XFER_E_IO || readbuf != nullptr) + return xfer; + /* Fallthrough to ptrace. /proc/pid/mem wasn't writable before Linux 2.6.39. */ } return inf_ptrace_target::xfer_partial (object, annex, readbuf, writebuf, -- 2.36.1