1 /* Copyright (C) 2016-2018 Free Software Foundation, Inc.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 /* The gdbarch_register_osabi handler for ARM PikeOS; it performs
24 the gdbarch initialization for that platform. */
27 arm_pikeos_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
29 /* Single stepping. */
30 set_gdbarch_software_single_step (gdbarch, arm_software_single_step);
33 /* The ARM PikeOS OSABI sniffer (see gdbarch_register_osabi_sniffer).
34 Returns GDB_OSABI_PIKEOS if the given BFD is a PikeOS binary,
35 GDB_OSABI_UNKNOWN otherwise. */
38 arm_pikeos_osabi_sniffer (bfd *abfd)
40 long number_of_symbols;
42 int pikeos_stack_found = 0;
43 int pikeos_stack_size_found = 0;
45 /* The BFD target of PikeOS is really just standard elf, so we
46 cannot use it to detect this variant. The only common thing that
47 may be found in PikeOS modules are symbols _vm_stack/__p4_stack and
48 _vm_stack_size/__p4_stack_end. They are used to specify the stack
49 location and size; and defined by the default linker script.
51 OS ABI sniffers are called before the minimal symtabs are
52 created. So inspect the symbol table using BFD. */
54 long storage_needed = bfd_get_symtab_upper_bound (abfd);
55 if (storage_needed <= 0)
56 return GDB_OSABI_UNKNOWN;
58 gdb::unique_xmalloc_ptr<asymbol *> symbol_table
59 ((asymbol **) xmalloc (storage_needed));
60 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table.get ());
62 if (number_of_symbols <= 0)
63 return GDB_OSABI_UNKNOWN;
65 for (i = 0; i < number_of_symbols; i++)
67 const char *name = bfd_asymbol_name (symbol_table.get ()[i]);
69 if (strcmp (name, "_vm_stack") == 0
70 || strcmp (name, "__p4_stack") == 0)
71 pikeos_stack_found = 1;
73 if (strcmp (name, "_vm_stack_size") == 0
74 || strcmp (name, "__p4_stack_end") == 0)
75 pikeos_stack_size_found = 1;
78 if (pikeos_stack_found && pikeos_stack_size_found)
79 return GDB_OSABI_PIKEOS;
81 return GDB_OSABI_UNKNOWN;
85 _initialize_arm_pikeos_tdep (void)
87 /* Register the sniffer for the PikeOS targets. */
88 gdbarch_register_osabi_sniffer (bfd_arch_arm, bfd_target_elf_flavour,
89 arm_pikeos_osabi_sniffer);
90 gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_PIKEOS,