From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) by sourceware.org (Postfix) with ESMTPS id B81173851C07 for ; Fri, 2 Oct 2020 21:54:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B81173851C07 Received: by mail-il1-x144.google.com with SMTP id c5so2581936ilk.11 for ; Fri, 02 Oct 2020 14:54:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EEwdi9iI+/y4v7FI56X8fhf9s1D8016qp2qAvZNSAMM=; b=aj7EjihewTtlpGoh95JntHYdUXQHg/K4Ko8prZWuvXeFqLo5yWU7g/gsPmnAbMb+hr TxNFNwH5NIgIGly4vXyURtlJgssDcF8LUMdBpugv0ILasuLcHG8mDqCiYvCrWbQH61XI i9JatN3WHmbVhxK3algNpVUCmM3aZb9Thf3cLA/iZyW8OiU4xpC/ARiTYqoE3vBwvWmR tHU3S4FdpPmcmwCklAXUd4qKht0kRiZOhMz/ZgLUkQBfQMMe7yqmWgALOc7paA5naFYg CNiQPRa/T+wA/WAfXtG2agutrer1Og3ynXWBq3xcYvk2W0Crrhr035KpJ2tjC+YGzo1s msPw== X-Gm-Message-State: AOAM531dUfdQSSzOScKwJsYNFjPKRg9BfRo6OzRMLXvPlQZNzJ/VG1AS 2LqhNVWl7v5P6Pq1bgG+fVW44Yr5sM5f37exi37hqg== X-Google-Smtp-Source: ABdhPJx9HFZ/X1/eOi0FxujvSLJitjvAghwKfjM7lWTpJwle4FWG/LSZ7twkzqNsH0dRr2ZQwU3Ir4YYzr/YqSugTsQ= X-Received: by 2002:a92:4982:: with SMTP id k2mr3448578ilg.240.1601675676907; Fri, 02 Oct 2020 14:54:36 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Paul Mathieu Date: Fri, 2 Oct 2020 14:54:25 -0700 Message-ID: Subject: Re: [PATCH] gdb: add support for handling core dumps on arm-none-eabi To: Luis Machado Cc: gdb-patches@sourceware.org, Alan Hayward X-Spam-Status: No, score=-26.0 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, HTML_MESSAGE, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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, 02 Oct 2020 21:54:39 -0000 Hi Luis, Thanks for the quick feedback! It seems the e-mail client has messed up the proper formatting > (spaces/tabs) of the patch. I'll defer formatting review until the patch > comes through clean of e-mail client interferences. Woops, sorry about this. I'm submitting a new patch, hopefully it will be treated well by the email gods. > Also, it would be nice to get rid of dead code (like "#if 0" blocks). If > it is not functional, then there is little point in including such code. > Done. > Who is generating such core files? Is there some way I can access the > tool to give it a try? How can I test the patch itself? > I made one myself, with a python script that I wrote. I have a live embedded target that I can use to dump memory regions and CPU registers over a serial line. My python script then formats the memory dumps into PT_LOAD segments, and the CPU registers into a NT_PRSTATUS note segment, and stores it as an ELF32 core file. I'm happy to share any material that would help testing this, including the python script, an example of firmware and core file and some embedded source code. I addressed the rest of your feedback through essentially re-writing the patch to not use `deprecated_add_core_fns` In the new patch, I had to use the GDB_OSABI_LINUX, otherwise my core wouldn't be recognized. I'm not sure if this can potentially interfere with the arm-linux implementation. Since it has its own entry in configure.tgt, I imagine not? Thanks! gdb/ChangeLog: 2018-09-29 Robin Haberkorn 2020-10-02 Paul Mathieu * arm-none-tdep.c: Source file added. Provide CPU registers from a core file * floating point registers not yet supported (FIXME) --- gdb/Makefile.in | 2 + gdb/arm-none-tdep.c | 107 ++++++++++++++++++++++++++++++++++++++++++++ gdb/configure.tgt | 2 +- 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 gdb/arm-none-tdep.c diff --git a/gdb/Makefile.in b/gdb/Makefile.in index dbede7a9cf..7f0e3ea0b0 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -720,6 +720,7 @@ ALL_TARGET_OBS = \ arm-obsd-tdep.o \ arm-pikeos-tdep.o \ arm-symbian-tdep.o \ + arm-none-tdep.o \ arm-tdep.o \ arm-wince-tdep.o \ avr-tdep.o \ @@ -2150,6 +2151,7 @@ ALLDEPFILES = \ arm-nbsd-tdep.c \ arm-obsd-tdep.c \ arm-symbian-tdep.c \ + arm-none-tdep.c \ arm-tdep.c \ avr-tdep.c \ bfin-linux-tdep.c \ diff --git a/gdb/arm-none-tdep.c b/gdb/arm-none-tdep.c new file mode 100644 index 0000000000..bdf346bdc3 --- /dev/null +++ b/gdb/arm-none-tdep.c @@ -0,0 +1,107 @@ +/* Native-dependent code for GDB targetting embedded ARM. + + Copyright (C) 2020 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "defs.h" +#include "osabi.h" + +#include "arch/arm.h" +#include "gdbarch.h" +#include "regcache.h" +#include "regset.h" + +struct arm_none_reg +{ + uint32_t reg[13]; + uint32_t sp; + uint32_t lr; + uint32_t pc; + uint32_t cpsr; + uint32_t orig_r0; +}; + +extern int arm_apcs_32; + +static void +arm_none_supply_gregset (const struct regset *regset, + struct regcache *regcache, int regnum, + const void *gregs, size_t len) +{ + const arm_none_reg *gregset = static_cast (gregs); + gdb_assert (len >= sizeof (arm_none_reg)); + + /* Integer registers. */ + for (int i = ARM_A1_REGNUM; i < ARM_SP_REGNUM; i++) + if (regnum == -1 || regnum == i) + regcache->raw_supply (i, (char *)&gregset->reg[i]); + + if (regnum == -1 || regnum == ARM_SP_REGNUM) + regcache->raw_supply (ARM_SP_REGNUM, (char *)&gregset->sp); + + if (regnum == -1 || regnum == ARM_LR_REGNUM) + regcache->raw_supply (ARM_LR_REGNUM, (char *)&gregset->lr); + + if (regnum == -1 || regnum == ARM_PC_REGNUM) + { + CORE_ADDR r_pc + = gdbarch_addr_bits_remove (regcache->arch (), gregset->pc); + regcache->raw_supply (ARM_PC_REGNUM, (char *)&r_pc); + } + + if (regnum == -1 || regnum == ARM_PS_REGNUM) + { + if (arm_apcs_32) + regcache->raw_supply (ARM_PS_REGNUM, (char *)&gregset->cpsr); + else + regcache->raw_supply (ARM_PS_REGNUM, (char *)&gregset->pc); + } +} + +static const struct regset arm_none_regset + = { nullptr, arm_none_supply_gregset, + /* We don't need a collect function because we only use this reading + registers (via iterate_over_regset_sections and + fetch_regs/fetch_register). */ + nullptr, 0 }; + +static void +arm_none_iterate_over_regset_sections (struct gdbarch *gdbarch, + iterate_over_regset_sections_cb *cb, + void *cb_data, + const struct regcache *regcache) +{ + cb (".reg", sizeof (arm_none_reg), sizeof (arm_none_reg), &arm_none_regset, + NULL, cb_data); +} + +static void arm_none_elf_init_abi (struct gdbarch_info info, + struct gdbarch *gdbarch); +static void +arm_none_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) +{ + set_gdbarch_iterate_over_regset_sections ( + gdbarch, arm_none_iterate_over_regset_sections); +} + +void _initialize_arm_none_tdep (void); +void +_initialize_arm_none_tdep (void) +{ + gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_LINUX, + arm_none_elf_init_abi); +} diff --git a/gdb/configure.tgt b/gdb/configure.tgt index a3e11c4b9b..0cf05efdd1 100644 --- a/gdb/configure.tgt +++ b/gdb/configure.tgt @@ -189,7 +189,7 @@ arm*-*-symbianelf*) ;; arm*-*-*) # Target: ARM embedded system - gdb_target_obs="arm-pikeos-tdep.o" + gdb_target_obs="arm-pikeos-tdep.o arm-none-tdep.o" gdb_sim=../sim/arm/libsim.a ;; --