From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by sourceware.org (Postfix) with ESMTPS id 53E4B385AC36; Thu, 10 Mar 2022 10:05:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 53E4B385AC36 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-f44.google.com with SMTP id n33-20020a05600c3ba100b003832caf7f3aso4123017wms.0; Thu, 10 Mar 2022 02:05:33 -0800 (PST) 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:cc:references:from:in-reply-to :content-transfer-encoding; bh=4mJN4NaskaAsp2c/pE2NwrepRDjGxTTY3Jt4PydudpY=; b=YYIelfWwsyhSeWSV9ZWZDLmBpvnmKSiccyK/ozP9efP/uKd5JIXXNTvCbo/Ch0b6HW IoJJRgA9y4tcrTgZtnHTBEobN5AioL8JnvAoYw2IJPOZfc8lM+puDTXkFTq/YjQ38l26 yKpIfjq0Uj0jHkARg3BXDN9M3jCPSQiknf1HRW/7mR5P3uPFoxGjYlbQzaDxT/UsMk5g pDdeznqHhbL9Brplx/b3eUbD636NabSTqHv4gSqJIANufFB2E694ubCJVidQ4aaQBOKl aQcoVURGrxGQ7SMW1Oz5Ha3b00fs+AB8FieWwEE6acHK1IR0u26+BqFAxoHThocgplrx 7GIA== X-Gm-Message-State: AOAM531YI2ofaKomkPtXTo0COxZRF9jYeigCu/xkT7yiHXXl266ych8s LJy0A8rJmayAISJIMOwD08q3Npi/qzVm8Q== X-Google-Smtp-Source: ABdhPJz+XXb2DgjETvrpyqGrBBwu6l/Al2+17Br8thIPJ3MIfP0/M30L20VwFyx+UU+9hpK3FR4f/A== X-Received: by 2002:a1c:4b0e:0:b0:389:bf16:d8fb with SMTP id y14-20020a1c4b0e000000b00389bf16d8fbmr11025951wma.103.1646906732262; Thu, 10 Mar 2022 02:05:32 -0800 (PST) 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 n8-20020adf8b08000000b001f046cc8891sm3871130wra.24.2022.03.10.02.05.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Mar 2022 02:05:31 -0800 (PST) Message-ID: Date: Thu, 10 Mar 2022 10:05:29 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: why ptrace read failed to read debugging process memory? Content-Language: en-US To: =?UTF-8?B?5ZGo5pil5piOKOaXpeaciCk=?= , Simon Marchi , Gdb-patches , gdb-patches Cc: Louis-He <1726110778@qq.com>, Dominique Quatravaux , Sam Warner References: From: Pedro Alves In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00, BODY_8BITS, 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=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, 10 Mar 2022 10:05:35 -0000 On 2022-03-10 06:40, 周春明(日月) via Gdb-patches wrote: > Hi GDB maintainers, > I tried update our gdb10 to gdb12, but I found new gdb seems cannot pread debugging process memory. > > 3897 linux_proc_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf, > 3898 ULONGEST offset, LONGEST len, > 3899 ULONGEST *xfered_len) > 3900 { > 3901 ssize_t ret; > 3902 auto iter = proc_mem_file_map.find (inferior_ptid.pid ()); > 3903 if (iter == proc_mem_file_map.end ()) > 3904 return TARGET_XFER_EOF; > 3905 > 3906 int fd = iter->second.fd (); > 3907 > 3908 gdb_assert (fd != -1); > 3909 > 3910 /* Use pread64/pwrite64 if available, since they save a syscall and can > 3911 handle 64-bit offsets even on 32-bit platforms (for instance, SPARC > 3912 debugging a SPARC64 application). */ > 3913 #ifdef HAVE_PREAD64 > 3914 ret = (readbuf ? pread64 (fd, readbuf, len, offset) > 3915 : pwrite64 (fd, writebuf, len, offset)); > 3916 #else > 3917 ret = lseek (fd, offset, SEEK_SET); > 3918 if (ret != -1) > 3919 ret = (readbuf ? read (fd, readbuf, len) > 3920 : write (fd, writebuf, len)); > 3921 #endif > 3922 > 3923 if (ret == -1) > 3924 { > 3925 printf ("accessing fd %d for pid %d failed: %s (%d)\n", ================> here always returns -EIO (5) errno. > 3926 fd, inferior_ptid.pid (), > 3927 safe_strerror (errno), errno); > 3928 return TARGET_XFER_EOF; > 3929 } > > any configure I missed in new GDB12? or new ptrace way needed? In prior GDB versions, GDB would always use PTRACE_PEEKTEXT/PTRACE_POKETEXT for memory accesses (< 3 * sizeof(long)). If the access was larger, then it would first try /proc/pid/mem, and if that failed, would would try with PTRACE_PEEKTEXT/PTRACE_POKETEXT. GDB 12 always goes straight to /proc/pid/mem, and the PTRACE_PEEKTEXT/PTRACE_POKETEXT fallback was removed. This was done because /proc/pid/mem lets you access memory even if the ptracee is not stopped, while ptrace fails in that case. I'd debug gdb10, and see how does linux_nat_target::xfer_partial manage to read memory there, see if the /proc access always fails there. If that is the case, then the next question would be, why does it fail in the first place?