From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) by sourceware.org (Postfix) with ESMTPS id 38C40386F036 for ; Fri, 2 Oct 2020 17:32:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 38C40386F036 Received: by mail-io1-xd44.google.com with SMTP id z25so2365685iol.10 for ; Fri, 02 Oct 2020 10:32:49 -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:from:date:message-id:subject:to; bh=kzg5Zn77sQTbM6KoMITne30z44f4q7faMl/2yZ7FOZc=; b=e8e9e0KAO59JfZguDJzQB0mePx516zbR6eO6cOGFpxmNz5mtNuKvMSZoA/Y7EySTWz SbTqhauv22laewXDaEp/cCWHpjAYkUFodh4IBeQXGGTSkKd0ZQjh/VcypF+sSm3Zfh4b pjepRrQqtfRFW9rBAR/63iOInm6yoNGUOgP9GupG+OSLryK5yRa0/ePa+DQQPPsDAk+N /2H1uUO5tgqUMpS4Euxu5RGDdbiwy6dh652JN9TCxMTbb5GnkQRmIMXjrO2eqY2C5Wfe VZwkHx2D0aq96NhWlU6KVkpYLbofpWbUs0tBfN9cc91qXQMo97u5o54u6N9+Y17oIjk/ oyuQ== X-Gm-Message-State: AOAM532J7nNeVzVo118WVxC7koAfJ9cwDqI0ywJu2Ux5Sh0VdstjYknP jyyU/EHj2f/BecqlA6RcIs8d7Dsd6HvmEMjKeyXefPhOGYsM7A== X-Google-Smtp-Source: ABdhPJybO0vzRAkC3wsO3arjLmUnOCl6TbTX3ztSumLpvWZhxJrwYJsP2aWdZd2nbXEG8X+G0Z9WReR3WfT1pit+IY8= X-Received: by 2002:a02:7fc7:: with SMTP id r190mr3210236jac.13.1601659968054; Fri, 02 Oct 2020 10:32:48 -0700 (PDT) MIME-Version: 1.0 From: Paul Mathieu Date: Fri, 2 Oct 2020 10:32:35 -0700 Message-ID: Subject: [PATCH] gdb: add support for handling core dumps on arm-none-eabi To: gdb-patches@sourceware.org X-Spam-Status: No, score=-26.2 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 17:32:51 -0000 Core dump files really help debugging crashes. It is not uncommon for embedded targets to have the ability to generate memory and CPU register dumps, which can easily be converted into core dump files. This patch adds support for loading core files into gdb on arm-none-eabi targets. The patch was originally written by Robin Haberkorn < robin.haberkorn@googlemail.com> gdb/ChangeLog: 2018-09-29 Robin Haberkorn 2020-10-02 Paul Mathieu * arm-none-tdep.c: Added. Provide CPU registers from a core file * floating point registers not yet supported (FIXME) --- gdb/Makefile.in | 2 + gdb/arm-none-tdep.c | 140 ++++++++++++++++++++++++++++++++++++++++++++ gdb/configure.tgt | 2 +- 3 files changed, 143 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..7641a9f7f0 --- /dev/null +++ b/gdb/arm-none-tdep.c @@ -0,0 +1,140 @@ +/* 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 "command.h" +#include "gdbarch.h" +#include "gdbcore.h" +#include "inferior.h" +#include "target.h" +#include "regcache.h" + +#include "arch/arm.h" + +#if 0 +#include +#include +#ifdef HAVE_SYS_PROCFS_H +#include +#endif +#endif + +typedef struct { + uint32_t reg[18]; +} gdb_gregset_t; + +#define ARM_CPSR_GREGNUM 16 + +extern int arm_apcs_32; + +static void +arm_supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregs) +{ + struct gdbarch *gdbarch = regcache->arch (); + enum bfd_endian byte_order = type_byte_order (register_type(gdbarch, 0)); + int regno; + CORE_ADDR reg_pc; + gdb_byte pc_buf[ARM_INT_REGISTER_SIZE]; + + for (regno = ARM_A1_REGNUM; regno < ARM_PC_REGNUM; regno++) + regcache->raw_supply (regno, gregs->reg + regno); + + if (arm_apcs_32) + regcache->raw_supply (ARM_PS_REGNUM, gregs->reg + ARM_CPSR_GREGNUM); + else + regcache->raw_supply (ARM_PS_REGNUM, gregs->reg + ARM_PC_REGNUM); + + reg_pc = extract_unsigned_integer ((const gdb_byte*)(gregs->reg + ARM_PC_REGNUM), + ARM_INT_REGISTER_SIZE, byte_order); + reg_pc = gdbarch_addr_bits_remove (gdbarch, reg_pc); + store_unsigned_integer (pc_buf, ARM_INT_REGISTER_SIZE, byte_order, reg_pc); + regcache->raw_supply (ARM_PC_REGNUM, pc_buf); +} + +/* Provide registers to GDB from a core file. + + CORE_REG_SECT points to an array of bytes, which are the contents + of a `note' from a core file which BFD thinks might contain + register contents. CORE_REG_SIZE is its size. + + WHICH says which register set corelow suspects this is: + 0 --- the general-purpose register set, in gregset_t format + 2 --- the floating-point register set, in fpregset_t format + + REG_ADDR is ignored. */ + +static void +fetch_core_registers (struct regcache *regcache, + char *core_reg_sect, + unsigned core_reg_size, + int which, + CORE_ADDR reg_addr) +{ + switch (which) + { + case 0: + if (core_reg_size != sizeof (gdb_gregset_t)) + warning (_("Wrong size gregset in core file.")); + else + { + gdb_gregset_t gregset; + memcpy (&gregset, core_reg_sect, sizeof (gregset)); + arm_supply_gregset (regcache, &gregset); + } + break; + +#if 0 // TODO + case 2: + if (core_reg_size != sizeof (gdb_fpregset_t)) + warning (_("Wrong size fpregset in core file.")); + else + { + gdb_fpregset_t fpregset; + memcpy (&fpregset, core_reg_sect, sizeof (fpregset)); + if (gdbarch_fp0_regnum (regcache->arch ()) >= 0) + arm_supply_fpregset (regcache, &fpregset); + } + break; +#endif + + default: + /* We've covered all the kinds of registers we know about here, + so this must be something we wouldn't know what to do with + anyway. Just ignore it. */ + break; + } +} + +/* Register that we are able to handle ELF core file formats using + standard procfs "regset" structures. */ + +static struct core_fns arm_none_core_fns = +{ + bfd_target_elf_flavour, /* core_flavour */ + default_check_format, /* check_format */ + default_core_sniffer, /* core_sniffer */ + fetch_core_registers, /* core_read_registers */ + NULL /* next */ +}; + +void +_initialize_arm_none_tdep (void) +{ + deprecated_add_core_fns (&arm_none_core_fns); +} 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 ;; --