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.129.124]) by sourceware.org (Postfix) with ESMTPS id 878753858280 for ; Thu, 21 Jul 2022 15:03:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 878753858280 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-637-Z_fq-_YZOtOo5EA15Umlfw-1; Thu, 21 Jul 2022 11:03:38 -0400 X-MC-Unique: Z_fq-_YZOtOo5EA15Umlfw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D9E518001EA; Thu, 21 Jul 2022 15:03:37 +0000 (UTC) Received: from [10.2.16.251] (unknown [10.2.16.251]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8DF71492C3B; Thu, 21 Jul 2022 15:03:37 +0000 (UTC) Message-ID: Date: Thu, 21 Jul 2022 08:03:36 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] linux_nat_target::xfer_partial: Fallback to ptrace To: gdb-patches@sourceware.org Cc: pedro@palves.net References: <20220603151839.2632317-1-keiths@redhat.com> From: Keith Seitz In-Reply-To: <20220603151839.2632317-1-keiths@redhat.com> X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, 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: , X-List-Received-Date: Thu, 21 Jul 2022 15:03:48 -0000 Ping On 6/3/22 08:18, Keith Seitz via Gdb-patches wrote: > 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,