From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6DHgCipJP2E9JAAAWB0awg (envelope-from ) for ; Mon, 13 Sep 2021 08:50:50 -0400 Received: by simark.ca (Postfix, from userid 112) id 299501EE26; Mon, 13 Sep 2021 08:50:50 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id AC04E1EE24 for ; Mon, 13 Sep 2021 08:50:48 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6AEBC385782C for ; Mon, 13 Sep 2021 12:50:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6AEBC385782C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1631537448; bh=vSq8R34tQ+zIyqGIe+r5nu+terplmtnoknsbAkSd/Ks=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=JfwLNuIreJPhNk/i6+asAIWTXsHo8zjL/tOSDyltegO2uKvIyJsGgq5514QcdVsew 0lPL5GVvu/6+y682Jerv6yK1qNLXRom8qh8hqHRVRZ3PclcpMXFtTEvKv4HlTtmUzr GiLTCDmgJW3SwCWugsEQwBMv87FocGU4dHvyi8mM= Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 04E8B385783E for ; Mon, 13 Sep 2021 12:48:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 04E8B385783E Received: by mail-pg1-x52b.google.com with SMTP id 17so9359091pgp.4 for ; Mon, 13 Sep 2021 05:48:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vSq8R34tQ+zIyqGIe+r5nu+terplmtnoknsbAkSd/Ks=; b=ywnnpeX1oo1sN9DuR1KvczfTl2qauH62Xj22qjlheVzqFK6m6hrxTRZe3GGW3j92AT vJJQ5EvXPwXdUWe/ioRgOFypBXdB+RCA0oFiZQpxlVno5LoUWzKUFHrSrJM8IczhTYzC dN7jnDKfIHhCcH0c5altADHbAvhR6ABwrH9+SzPHhoRZ9FkNfq3rZviz4jPUl4KQYZll 8vGw4Y2j+YunDzWoqirVv8YmAYhti1rm6n0ITf/kNNkfY0XvI42ARrZ7agjn8mC15ZLY y03y09At6E92UY6qdiAI1HK0JXGd2XA7ITGaQMFJy6mNjW4Jp0FUFIF0vcXitTDLnlt4 4lxw== X-Gm-Message-State: AOAM530AlwEY9telU+oJcuOlPS1u0RIMCA+KKabGdKvy/ahXwWmI+I2V wWoGX4fIWXsQkY7sQwmnBdzhQqFsAMw= X-Google-Smtp-Source: ABdhPJyyxZWqw5B1NsliMIsyTlNab3u9jyyF3/yykgDaDD0HxIn3d+Qns5xsp4+B3hgELNGH6uYzuw== X-Received: by 2002:a63:ea58:: with SMTP id l24mr11149214pgk.334.1631537317738; Mon, 13 Sep 2021 05:48:37 -0700 (PDT) Received: from localhost (g245.61-45-50.ppp.wakwak.ne.jp. [61.45.50.245]) by smtp.gmail.com with ESMTPSA id h24sm7319115pfn.180.2021.09.13.05.48.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Sep 2021 05:48:37 -0700 (PDT) To: GDB patches Subject: [PATCH 5/5] gdb: or1k: add single step for linux native debugging Date: Mon, 13 Sep 2021 21:48:00 +0900 Message-Id: <20210913124800.471680-6-shorne@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210913124800.471680-1-shorne@gmail.com> References: <20210913124800.471680-1-shorne@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , From: Stafford Horne via Gdb-patches Reply-To: Stafford Horne Cc: Openrisc Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Needed for single stepping in Linux, this adds the or1k implementation of or1k_software_single_step. Most of the implementation is borrowed from the bare metal single step code from or1k_single_step_through_delay which has been extracted and shared in helper function or1k_delay_slot_p. --- gdb/or1k-linux-tdep.c | 2 ++ gdb/or1k-tdep.c | 66 ++++++++++++++++++++++++++++++------------- gdb/or1k-tdep.h | 5 ++++ 3 files changed, 54 insertions(+), 19 deletions(-) diff --git a/gdb/or1k-linux-tdep.c b/gdb/or1k-linux-tdep.c index a71a8202b1e..63c4171e295 100644 --- a/gdb/or1k-linux-tdep.c +++ b/gdb/or1k-linux-tdep.c @@ -154,6 +154,8 @@ or1k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) /* GNU/Linux uses the dynamic linker included in the GNU C Library. */ set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver); + set_gdbarch_software_single_step (gdbarch, or1k_software_single_step); + /* Enable TLS support. */ set_gdbarch_fetch_tls_load_module_address (gdbarch, svr4_fetch_objfile_link_map); diff --git a/gdb/or1k-tdep.c b/gdb/or1k-tdep.c index 91f21576bd5..5bf617e78c4 100644 --- a/gdb/or1k-tdep.c +++ b/gdb/or1k-tdep.c @@ -346,6 +346,33 @@ constexpr gdb_byte or1k_break_insn[] = {0x21, 0x00, 0x00, 0x01}; typedef BP_MANIPULATION (or1k_break_insn) or1k_breakpoint; +static int +or1k_delay_slot_p (struct gdbarch *gdbarch, CORE_ADDR pc) +{ + const CGEN_INSN *insn; + CGEN_FIELDS tmp_fields; + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + insn = cgen_lookup_insn (tdep->gdb_cgen_cpu_desc, + NULL, + or1k_fetch_instruction (gdbarch, pc), + NULL, 32, &tmp_fields, 0); + + /* NULL here would mean the last instruction was not understood by cgen. + This should not usually happen, but if does its not a delay slot. */ + if (insn == NULL) + return 0; + + /* TODO: we should add a delay slot flag to the CGEN_INSN and remove + this hard coded test. */ + return ((CGEN_INSN_NUM (insn) == OR1K_INSN_L_J) + || (CGEN_INSN_NUM (insn) == OR1K_INSN_L_JAL) + || (CGEN_INSN_NUM (insn) == OR1K_INSN_L_JR) + || (CGEN_INSN_NUM (insn) == OR1K_INSN_L_JALR) + || (CGEN_INSN_NUM (insn) == OR1K_INSN_L_BNF) + || (CGEN_INSN_NUM (insn) == OR1K_INSN_L_BF)); +} + /* Implement the single_step_through_delay gdbarch method. */ static int @@ -355,10 +382,7 @@ or1k_single_step_through_delay (struct gdbarch *gdbarch, ULONGEST val; CORE_ADDR ppc; CORE_ADDR npc; - CGEN_FIELDS tmp_fields; - const CGEN_INSN *insn; struct regcache *regcache = get_current_regcache (); - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); /* Get the previous and current instruction addresses. If they are not adjacent, we cannot be in a delay slot. */ @@ -370,24 +394,28 @@ or1k_single_step_through_delay (struct gdbarch *gdbarch, if (0x4 != (npc - ppc)) return 0; - insn = cgen_lookup_insn (tdep->gdb_cgen_cpu_desc, - NULL, - or1k_fetch_instruction (gdbarch, ppc), - NULL, 32, &tmp_fields, 0); + return or1k_delay_slot_p (gdbarch, ppc); +} - /* NULL here would mean the last instruction was not understood by cgen. - This should not usually happen, but if does its not a delay slot. */ - if (insn == NULL) - return 0; +/* or1k_software_single_step() is called just before we want to resume + the inferior, if we want to single-step it but there is no hardware + or kernel single-step support (OpenRISC on GNU/Linux for example). We + find the target of the coming instruction skipping over delay slots + and breakpoint it. */ - /* TODO: we should add a delay slot flag to the CGEN_INSN and remove - this hard coded test. */ - return ((CGEN_INSN_NUM (insn) == OR1K_INSN_L_J) - || (CGEN_INSN_NUM (insn) == OR1K_INSN_L_JAL) - || (CGEN_INSN_NUM (insn) == OR1K_INSN_L_JR) - || (CGEN_INSN_NUM (insn) == OR1K_INSN_L_JALR) - || (CGEN_INSN_NUM (insn) == OR1K_INSN_L_BNF) - || (CGEN_INSN_NUM (insn) == OR1K_INSN_L_BF)); +std::vector +or1k_software_single_step (struct regcache *regcache) +{ + struct gdbarch *gdbarch = regcache->arch (); + CORE_ADDR pc, next_pc; + + pc = regcache_read_pc (regcache); + next_pc = pc + 4; + + if (or1k_delay_slot_p (gdbarch, pc)) + next_pc += 4; + + return {next_pc}; } /* Name for or1k general registers. */ diff --git a/gdb/or1k-tdep.h b/gdb/or1k-tdep.h index d9dc1aca3c3..81d902ae49e 100644 --- a/gdb/or1k-tdep.h +++ b/gdb/or1k-tdep.h @@ -52,4 +52,9 @@ #define OR1K_NUM_TAP_RECORDS 8 #define OR1K_FRAME_RED_ZONE_SIZE 2536 +/* Single step based on where the current instruction will take us. */ +extern std::vector or1k_software_single_step + (struct regcache *regcache); + + #endif /* OR1K_TDEP_H */ -- 2.31.1