Sort includes for files gdb/[a-f]*.[chyl].
[deliverable/binutils-gdb.git] / gdb / arm-pikeos-tdep.c
CommitLineData
42a4f53d 1/* Copyright (C) 2016-2019 Free Software Foundation, Inc.
e1c3a373
JG
2
3 This file is part of GDB.
4
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.
9
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.
14
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/>. */
17
18#include "defs.h"
d55e5aa6
TT
19
20/* Local non-gdb includes. */
e1c3a373 21#include "arm-tdep.h"
d55e5aa6 22#include "objfiles.h"
e1c3a373
JG
23#include "osabi.h"
24
25/* The gdbarch_register_osabi handler for ARM PikeOS; it performs
26 the gdbarch initialization for that platform. */
27
28static void
29arm_pikeos_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
30{
31 /* Single stepping. */
32 set_gdbarch_software_single_step (gdbarch, arm_software_single_step);
33}
34
35/* The ARM PikeOS OSABI sniffer (see gdbarch_register_osabi_sniffer).
36 Returns GDB_OSABI_PIKEOS if the given BFD is a PikeOS binary,
37 GDB_OSABI_UNKNOWN otherwise. */
38
39static enum gdb_osabi
40arm_pikeos_osabi_sniffer (bfd *abfd)
41{
42 long number_of_symbols;
43 long i;
44 int pikeos_stack_found = 0;
45 int pikeos_stack_size_found = 0;
46
47 /* The BFD target of PikeOS is really just standard elf, so we
48 cannot use it to detect this variant. The only common thing that
49 may be found in PikeOS modules are symbols _vm_stack/__p4_stack and
50 _vm_stack_size/__p4_stack_end. They are used to specify the stack
51 location and size; and defined by the default linker script.
52
53 OS ABI sniffers are called before the minimal symtabs are
54 created. So inspect the symbol table using BFD. */
55
56 long storage_needed = bfd_get_symtab_upper_bound (abfd);
57 if (storage_needed <= 0)
58 return GDB_OSABI_UNKNOWN;
59
60 gdb::unique_xmalloc_ptr<asymbol *> symbol_table
61 ((asymbol **) xmalloc (storage_needed));
62 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table.get ());
63
64 if (number_of_symbols <= 0)
65 return GDB_OSABI_UNKNOWN;
66
67 for (i = 0; i < number_of_symbols; i++)
68 {
69 const char *name = bfd_asymbol_name (symbol_table.get ()[i]);
70
71 if (strcmp (name, "_vm_stack") == 0
72 || strcmp (name, "__p4_stack") == 0)
73 pikeos_stack_found = 1;
74
75 if (strcmp (name, "_vm_stack_size") == 0
76 || strcmp (name, "__p4_stack_end") == 0)
77 pikeos_stack_size_found = 1;
78 }
79
80 if (pikeos_stack_found && pikeos_stack_size_found)
81 return GDB_OSABI_PIKEOS;
82 else
83 return GDB_OSABI_UNKNOWN;
84}
85
86void
87_initialize_arm_pikeos_tdep (void)
88{
89 /* Register the sniffer for the PikeOS targets. */
90 gdbarch_register_osabi_sniffer (bfd_arch_arm, bfd_target_elf_flavour,
91 arm_pikeos_osabi_sniffer);
92 gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_PIKEOS,
93 arm_pikeos_init_abi);
94}
This page took 0.082752 seconds and 4 git commands to generate.