From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 89091 invoked by alias); 5 Nov 2018 23:37:28 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 89069 invoked by uid 89); 5 Nov 2018 23:37:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=HX-HELO:sk:mail-vs X-HELO: mail-vs1-f48.google.com Received: from mail-vs1-f48.google.com (HELO mail-vs1-f48.google.com) (209.85.217.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Nov 2018 23:37:26 +0000 Received: by mail-vs1-f48.google.com with SMTP id t17so6224451vsc.8 for ; Mon, 05 Nov 2018 15:37:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jCGM0C88xRQ/RIggIvZhpOrq8vfrGsWYmWtU3nd51Y0=; b=kf7awcIuYSRMJ0RyS/3Xx59GcpEV1xt4o6LJn5fn25s0fBnSsMUxc0+xVknyYuYHlx jVZ4qZICiXKKc0CaBAhB5CG3mwOpSJszckHfRyDdZBCdhru12oDE5GjSC/LTzl5s4RRW vxWnTLV5lBdYIRUfm0XYWyHSYnCz/KL88zT8Ybn4mUOtEPQLiRHm+SYy048Jhv5oaTt2 bu6V+biXGJIhtRHG/J51xzHpuKbgxdRsoYFcWZ2iqwTXHID4eTlqvTOU7R7HnPQj0kPc tS2BdvLnQfjVofjCUNvFKHVXJKQea2TANkWMcPBeZO+X9QSzP8+DH7X07TazKtks2kLk Mp5Q== MIME-Version: 1.0 References: <1ab6341c3c73c6e0b501e7b25d6d64744d7cdbc0.1541459121.git.andrew.burgess@embecosm.com> In-Reply-To: <1ab6341c3c73c6e0b501e7b25d6d64744d7cdbc0.1541459121.git.andrew.burgess@embecosm.com> From: Jim Wilson Date: Mon, 05 Nov 2018 23:37:00 -0000 Message-ID: Subject: Re: [PATCH 1/2] gdb/riscv: Stop prologue scan if instruction fetch/decode fails To: Andrew Burgess Cc: gdb-patches@sourceware.org, Palmer Dabbelt , John Baldwin Content-Type: text/plain; charset="UTF-8" X-SW-Source: 2018-11/txt/msg00055.txt.bz2 On Mon, Nov 5, 2018 at 3:10 PM Andrew Burgess wrote: > If the target has not yet had a program loaded into it, and the $pc > value is pointing an unreadable memory, then the prologue scan would > throw an error, this would then cause GDB to abandon its attempt to > connect to the target. It was in fact impossible to connect to the > target at all. In my case, with openocd/spike, the pc value is actually correct and there is a valid instruction there. The problem rather happens in riscv_frame_cache which calls get_frame_func, and this returns 0 because there is no program loaded yet. This then causes a scan for the prologue to start at address zero, which is wrong, and leads to the null deref error that kills the connection. I have a simpler fix based on code I found in mips-tdep.c, which just returns from riscv_frame_cache if start_addr is zero, and also in riscv_frame_this_id we don't set this_id if the frame_base is zero. With your fix, riscv_scan_prologue will be run, the frame cache will be filled with incorrect values, and we will try to compute a frame id based on bad info. That doesn't look like the right solution to me. My patch is a slightly cleaned up version of the workarounds I sent to you last week, which I am testing now. Jim PS Did you see my code_elim testcase fix? Simon Marchi suggested that you should review it.