From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by sourceware.org (Postfix) with ESMTPS id 829AC386CE76 for ; Thu, 30 Jun 2022 09:40:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 829AC386CE76 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-f46.google.com with SMTP id h14-20020a1ccc0e000000b0039eff745c53so1272153wmb.5 for ; Thu, 30 Jun 2022 02:40:48 -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=zCkUcCmqoopr9+zmo1gcqHeKy4CjcibqigOpmaCwaFQ=; b=ouf7R3r6IfJjxzQ9wt2flI9B+itpr2ht629Z4ANMTmdRz0xiAIcg+Ajqq/f3/MOcDI XQRIQpb8NrOW+5VPnCdgaa2Tf2MvlG9to/mBXRFKwzFlvuKmtEnM8BoxCwibyv8J0PNz R7mEDHRvk9FcSzprcAys15zyL6hSv4cVtKzp9nalj68ya4VkFZ1rCtqq0A1x4Xs1ikLg c9x+TdNtHCxNhBNFrQdkhtj9b0A4+BSkxX41y/OHdWvnTOMQShjHirznp0Gz4zrMNeQK PDbFgIWWg49xCSlwq/BxyGZvJaGBVyeUBQA3EymQeh+SZnaARJveSVJjYp48dW7vPmGl 0NvQ== X-Gm-Message-State: AJIora9MGqiml9CJ8gEr/symku6EqYM5UJP1jwUyMm5IFJvaUHoUmMld WVGhcAG5HzKuqQI8QSx+GRd69NcPcZA= X-Google-Smtp-Source: AGRyM1sy6EyW7+OQENsKSumqecupEEeNKzAOQ0j1U2t5iL86GN0uwU7/mz+Yd8g0/GbKFtob4M579g== X-Received: by 2002:a05:600c:1797:b0:3a0:38a7:8675 with SMTP id x23-20020a05600c179700b003a038a78675mr10770085wmo.120.1656582047175; Thu, 30 Jun 2022 02:40:47 -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 o4-20020a5d6484000000b0020d02262664sm18830746wri.25.2022.06.30.02.40.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 30 Jun 2022 02:40:46 -0700 (PDT) Message-ID: <357a6158-6e3a-ae13-bdd6-cfb5f98fb84f@palves.net> Date: Thu, 30 Jun 2022 10:40:45 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: gdb for Riscv, single stepping issue Content-Language: en-US To: John Baldwin , James Becker , gdb@sourceware.org References: <069ae440-5fc5-b853-e415-e9643e6d8144@FreeBSD.org> <6068e741-8f0f-53b3-0664-548a4930d92c@palves.net> From: Pedro Alves In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00, BODY_8BITS, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, 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@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Jun 2022 09:40:50 -0000 Hi! Jim, could you check whether the patch below addresses the issue for you? I imagine it does, but it'd be good to hear just in case we're missing some more target_read_memory calls somewhere or some such. Pedro Alves On 2022-06-29 18:54, John Baldwin wrote: > On 6/29/22 2:34 AM, Pedro Alves wrote: >> OTOH, riscv_insn::fetch_instruction uses target_read_memory to read 2 bytes, >> so I wonder whether this is the access in question: >> >>    /* All insns are at least 16 bits.  */ >>    status = target_read_memory (addr, buf, 2); >>    if (status) >>      memory_error (TARGET_XFER_E_IO, addr); >> >> Why is this using target_read_memory instead of target_read_code, though? >> If it did that, then the code cache would be involved here too, papering over >> the issue, presumably. >> > Yes, I had reworked my e-mail part way through and I really meant to talk about > this code, not the breakpoint code.  I agree that target_read_code is probably > more correct in fetch_instruction and would in this case hide the odd behavior > of the stub: > > diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c > index 69f2123dcdb..09b2599e958 100644 > --- a/gdb/riscv-tdep.c > +++ b/gdb/riscv-tdep.c > @@ -1661,7 +1661,7 @@ riscv_insn::fetch_instruction (struct gdbarch *gdbarch, >    int instlen, status; >   >    /* All insns are at least 16 bits.  */ > -  status = target_read_memory (addr, buf, 2); > +  status = target_read_code (addr, buf, 2); >    if (status) >      memory_error (TARGET_XFER_E_IO, addr); >   > @@ -1672,7 +1672,7 @@ riscv_insn::fetch_instruction (struct gdbarch *gdbarch, >   >    if (instlen > 2) >      { > -      status = target_read_memory (addr + 2, buf + 2, instlen - 2); > +      status = target_read_code (addr + 2, buf + 2, instlen - 2); >        if (status) >      memory_error (TARGET_XFER_E_IO, addr + 2); >      } > >