aboutsummaryrefslogtreecommitdiff
path: root/gdb/arm-pikeos-tdep.c
diff options
context:
space:
mode:
authorJerome Guitton <guitton@adacore.com>2018-11-01 14:32:30 -0700
committerJoel Brobecker <brobecker@adacore.com>2018-11-01 14:43:44 -0700
commite1c3a3737536c57e43d4ad693341717e326f4e17 (patch)
tree1fe742d3db7938be4c6de702d2c2b4c4b5b71922 /gdb/arm-pikeos-tdep.c
parente8d8cce69b34481a27562267d94a1aff19b05518 (diff)
downloadgdb-e1c3a3737536c57e43d4ad693341717e326f4e17.zip
gdb-e1c3a3737536c57e43d4ad693341717e326f4e17.tar.gz
gdb-e1c3a3737536c57e43d4ad693341717e326f4e17.tar.bz2
arm-pikeos: software single step
On ARM, PikeOS does not support hardware single step, causing various semi-random errors when trying to next/step over some user code. So this patch changes this target to use software-single-step instead. The challenge is that, up to now, the PikeOS target was in all respects identical to a baremetal target as far as GDB was concerned, meaning we were using the baremetal osabi for this target too. This is no longer possible, and we need to introduce a new OSABI variant. Unfortunately, there isn't anything in the object file that would allow us to differentiate between the two platforms. So we have to rely on a heuristic instead, where we look for some known symbols that are required in a PikeOS application (these symbols are expected to be defined by the default linker script, and correspond to routines used to allocate the application stack). For the long run, the hope is that the stub implementation provided by PikeOS is enhanced so that it includes vContSupported+ to the $qSupported query, and then that the reply to the "vCont?" query only return support for "continue" operations (thus exclusing "step" operations). We could then use that information to reliably determine at connection time that the target does not support single-stepping and therefore automatically turn software single-stepping automatically based on it. gdb/ChangeLog: * 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. Tested on arm-pikeos and arm-elf using AdaCore's testsuite. We also evaluated it on armhf-linux as a cross platform.
Diffstat (limited to 'gdb/arm-pikeos-tdep.c')
-rw-r--r--gdb/arm-pikeos-tdep.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/gdb/arm-pikeos-tdep.c b/gdb/arm-pikeos-tdep.c
new file mode 100644
index 0000000..4662a28
--- /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 <http://www.gnu.org/licenses/>. */
+
+#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<asymbol *> 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);
+}