From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by sourceware.org (Postfix) with ESMTPS id 925CB382CCA4 for ; Fri, 20 May 2022 18:51:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 925CB382CCA4 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-f49.google.com with SMTP id 67-20020a1c1946000000b00397382b44f4so1620370wmz.2 for ; Fri, 20 May 2022 11:51:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=yLQ9/nS6pJiNRCTVs3OxxYYKKrZ4HwrtihRaAJOmdcU=; b=NPIW9BkNOFfMw6TRM7HIoRqkT/MzU2T2DRnWKL5sQpZv8NweqYw0EzxcFHgXJND1Xg +wp3JdUhD4o39VPINx4yK0Qab4easLiv0Tao3vWzry6WusV2eLfQf1tJa1NZiB0N2oQ4 0BrzQvr3Btk2HkPnFjwf+EHuNUNLMfeM8s5jWMUh+GjLeBx17n6iHD2NpOwUixaMTuTr nr+Kq1wZn7jN7wUgxkPKAhEoAr81xrabNX/If2CwoHQlm1bzg8qlf8R5+MTYEPiCRDdz E0m4DhOXIWtWWheXQeBYUtfGU4TeJeOKKap3Im4LbenQODjCr2+bX4f/HTkg8nRyE7B2 r3/g== X-Gm-Message-State: AOAM532KWQMiAJ9cP112Lmtecgd4T2qdT2tup7Eg3EVjTYH6pRoQOeVy o6a9PzMqDVEDc1hdb2tKvQDsNQoKPgs= X-Google-Smtp-Source: ABdhPJz3kRUUTtgrSgFrucC2XMW4Ih2iQQEubZ+1QWH26in7g0H5J77n50fYnJvqCi9CbOOMo1M8AA== X-Received: by 2002:a05:600c:4f52:b0:394:61af:a168 with SMTP id m18-20020a05600c4f5200b0039461afa168mr9806890wmq.114.1653072669200; Fri, 20 May 2022 11:51:09 -0700 (PDT) Received: from ?IPV6:2001:8a0:f924:2600:209d:85e2:409e:8726? ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id g22-20020adfa496000000b0020c5253d907sm3069101wrb.83.2022.05.20.11.51.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 May 2022 11:51:07 -0700 (PDT) Message-ID: <23154482-133e-8bfe-6d14-17f7e79b716b@palves.net> Date: Fri, 20 May 2022 19:51:06 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH] linux_nat_target::xfer_partial: Fallback to ptrace Content-Language: en-US To: Keith Seitz , gdb-patches@sourceware.org References: <20220512181557.2093666-1-keiths@redhat.com> From: Pedro Alves In-Reply-To: <20220512181557.2093666-1-keiths@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, 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, 20 May 2022 18:51:12 -0000 On 2022-05-12 19:15, Keith Seitz via Gdb-patches wrote: > Commit 05c06f318fd9a112529dfc313e6512b399a645e4 enabled GDB > to access memory while threads are running. It did this by accessing > /proc/PID/task/LWP/mem. > > Unfortunatley, this interface is not implemented for writing in older kernels Unfortunatley -> Unfortunately > (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) > Oh man. I thought such kernels were already older than the oldest version we support, but looks like not. :-/ I don't suppose you could instead convince the kernel team to backport the patches that made /proc/pid/mem writable (https://lore.kernel.org/lkml/20110314151320.GG21770@outflux.net/T/).. :-P Both gdb and gdbserver are now relying on this to access memory of running threads. This never worked for gdb, but it did for gdbserver, by stopping all threads temporarily. I would really-really-really prefer not to add that code back for ancient kernels... > --- 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_EOF) > + return xfer; > + /* Fallthrough to ptrace. */ Seems fine, but I'd like a comment here giving a hint that we'll be able to remove this once we stop supporting such old kernels. Something like: /* Fallthrough to ptrace. /proc/pid/mem wasn't writable before Linux 2.6.39. */ I got that number by finding commit 198214a7ee50, and looking at git tag --contains 198214a7ee50. AFAICT, RHEL 6 is on 2.6.32.