diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fb655954a26..075dd3ddb36 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2018-11-01 Jerome Guitton + Joel Brobecker + + * defs.h (enum gdb_osabi): Add GDB_OSABI_PIKEOS. + * osabi.c (gdb_osabi_names): Add name for GDB_OSABI_PIKEOS. + * arm-pikeos-tdep.c: New file. + * configure.tgt: Add arm-pikeos-tdep.o to the case of ARM + embedded system. + * Makefile.in (ALL_TARGET_OBS): Add arm-pikeos-tdep.o. + 2018-11-01 Simon Marchi * common/pathstuff.c (get_standard_temp_dir): New. diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 73e15fcf121..5c04a59a07a 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -670,6 +670,7 @@ ALL_TARGET_OBS = \ arm-linux-tdep.o \ arm-nbsd-tdep.o \ arm-obsd-tdep.o \ + arm-pikeos-tdep.o \ arm-symbian-tdep.o \ arm-tdep.o \ arm-wince-tdep.o \ diff --git a/gdb/arm-pikeos-tdep.c b/gdb/arm-pikeos-tdep.c new file mode 100644 index 00000000000..4662a286a7d --- /dev/null +++ b/gdb/arm-pikeos-tdep.c @@ -0,0 +1,92 @@ +/* Copyright (C) 2016-2018 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 "objfiles.h" +#include "arm-tdep.h" +#include "osabi.h" + +/* The gdbarch_register_osabi handler for ARM PikeOS; it performs + the gdbarch initialization for that platform. */ + +static void +arm_pikeos_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) +{ + /* Single stepping. */ + set_gdbarch_software_single_step (gdbarch, arm_software_single_step); +} + +/* The ARM PikeOS OSABI sniffer (see gdbarch_register_osabi_sniffer). + Returns GDB_OSABI_PIKEOS if the given BFD is a PikeOS binary, + GDB_OSABI_UNKNOWN otherwise. */ + +static enum gdb_osabi +arm_pikeos_osabi_sniffer (bfd *abfd) +{ + long number_of_symbols; + long i; + int pikeos_stack_found = 0; + int pikeos_stack_size_found = 0; + + /* The BFD target of PikeOS is really just standard elf, so we + cannot use it to detect this variant. The only common thing that + may be found in PikeOS modules are symbols _vm_stack/__p4_stack and + _vm_stack_size/__p4_stack_end. They are used to specify the stack + location and size; and defined by the default linker script. + + OS ABI sniffers are called before the minimal symtabs are + created. So inspect the symbol table using BFD. */ + + long storage_needed = bfd_get_symtab_upper_bound (abfd); + if (storage_needed <= 0) + return GDB_OSABI_UNKNOWN; + + gdb::unique_xmalloc_ptr symbol_table + ((asymbol **) xmalloc (storage_needed)); + number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table.get ()); + + if (number_of_symbols <= 0) + return GDB_OSABI_UNKNOWN; + + for (i = 0; i < number_of_symbols; i++) + { + const char *name = bfd_asymbol_name (symbol_table.get ()[i]); + + if (strcmp (name, "_vm_stack") == 0 + || strcmp (name, "__p4_stack") == 0) + pikeos_stack_found = 1; + + if (strcmp (name, "_vm_stack_size") == 0 + || strcmp (name, "__p4_stack_end") == 0) + pikeos_stack_size_found = 1; + } + + if (pikeos_stack_found && pikeos_stack_size_found) + return GDB_OSABI_PIKEOS; + else + return GDB_OSABI_UNKNOWN; +} + +void +_initialize_arm_pikeos_tdep (void) +{ + /* Register the sniffer for the PikeOS targets. */ + gdbarch_register_osabi_sniffer (bfd_arch_arm, bfd_target_elf_flavour, + arm_pikeos_osabi_sniffer); + gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_PIKEOS, + arm_pikeos_init_abi); +} diff --git a/gdb/configure.tgt b/gdb/configure.tgt index 5e9bc361154..e6ba3330827 100644 --- a/gdb/configure.tgt +++ b/gdb/configure.tgt @@ -180,6 +180,7 @@ arm*-*-symbianelf*) ;; arm*-*-*) # Target: ARM embedded system + gdb_target_obs="arm-pikeos-tdep.o" gdb_sim=../sim/arm/libsim.a ;; diff --git a/gdb/defs.h b/gdb/defs.h index 6e3f4df116f..9e879711192 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -498,6 +498,7 @@ enum gdb_osabi GDB_OSABI_LYNXOS178, GDB_OSABI_NEWLIB, GDB_OSABI_SDE, + GDB_OSABI_PIKEOS, GDB_OSABI_INVALID /* keep this last */ }; diff --git a/gdb/osabi.c b/gdb/osabi.c index 7d0540b1818..68f466521a4 100644 --- a/gdb/osabi.c +++ b/gdb/osabi.c @@ -80,6 +80,7 @@ static const struct osabi_names gdb_osabi_names[] = { "LynxOS178", NULL }, { "Newlib", NULL }, { "SDE", NULL }, + { "PikeOS", NULL }, { "", NULL } };