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