gdb/arm-symbian-tdep.c - gdb

Functions defined

Source code

  1. /* ARM Symbian OS target support.

  2.    Copyright (C) 2008-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "frame.h"
  16. #include "objfiles.h"
  17. #include "osabi.h"
  18. #include "solib.h"
  19. #include "solib-target.h"
  20. #include "target.h"
  21. #include "elf-bfd.h"

  22. /* If PC is in a DLL import stub, return the address of the `real'
  23.    function belonging to the stub.  */

  24. static CORE_ADDR
  25. arm_symbian_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
  26. {
  27.   struct gdbarch *gdbarch;
  28.   enum bfd_endian byte_order;
  29.   ULONGEST insn;
  30.   CORE_ADDR dest;
  31.   gdb_byte buf[4];

  32.   if (!in_plt_section (pc))
  33.     return 0;

  34.   if (target_read_memory (pc, buf, 4) != 0)
  35.     return 0;

  36.   gdbarch = get_frame_arch (frame);
  37.   byte_order = gdbarch_byte_order (gdbarch);

  38.   /* ldr pc, [pc, #-4].  */
  39.   insn = extract_unsigned_integer (buf, 4, byte_order);
  40.   if (insn != 0xe51ff004)
  41.     return 0;

  42.   if (target_read_memory (pc + 4, buf, 4) != 0)
  43.     return 0;

  44.   dest = extract_unsigned_integer (buf, 4, byte_order);
  45.   return gdbarch_addr_bits_remove (gdbarch, dest);
  46. }

  47. static void
  48. arm_symbian_init_abi (struct gdbarch_info info,
  49.                       struct gdbarch *gdbarch)
  50. {
  51.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  52.   /* Shared library handling.  */
  53.   set_gdbarch_skip_trampoline_code (gdbarch, arm_symbian_skip_trampoline_code);

  54.   /* On this target, the toolchain outputs ELF files, with `sym' for
  55.      filename extension (e.g., `FOO.sym'); these are post-linker
  56.      processed into PE-ish DLLs (e.g., `FOO.dll'), and it's these that
  57.      are actually copied to and run on the target.  Naturally, when
  58.      listing shared libraries, Symbian stubs report the DLL filenames.
  59.      Setting this makes it so that GDB automatically looks for the
  60.      corresponding ELF files on the host's filesystem.  */
  61.   set_gdbarch_solib_symbols_extension (gdbarch, "sym");

  62.   /* Canonical paths on this target look like `c:\sys\bin\bar.dll',
  63.      for example.  */
  64.   set_gdbarch_has_dos_based_file_system (gdbarch, 1);

  65.   set_solib_ops (gdbarch, &solib_target_so_ops);
  66. }

  67. /* Recognize Symbian object files.  */

  68. static enum gdb_osabi
  69. arm_symbian_osabi_sniffer (bfd *abfd)
  70. {
  71.   Elf_Internal_Phdr *phdrs;
  72.   long phdrs_size;
  73.   int num_phdrs, i;

  74.   /* Symbian executables are always shared objects (ET_DYN).  */
  75.   if (elf_elfheader (abfd)->e_type == ET_EXEC)
  76.     return GDB_OSABI_UNKNOWN;

  77.   if (elf_elfheader (abfd)->e_ident[EI_OSABI] != ELFOSABI_NONE)
  78.     return GDB_OSABI_UNKNOWN;

  79.   /* Check for the ELF headers not being part of any PT_LOAD segment.
  80.      Symbian is the only GDB supported (or GNU binutils supported) ARM
  81.      target which uses a postlinker to flatten ELF files, dropping the
  82.      ELF dynamic info in the process.  */
  83.   phdrs_size = bfd_get_elf_phdr_upper_bound (abfd);
  84.   if (phdrs_size == -1)
  85.     return GDB_OSABI_UNKNOWN;

  86.   phdrs = alloca (phdrs_size);
  87.   num_phdrs = bfd_get_elf_phdrs (abfd, phdrs);
  88.   if (num_phdrs == -1)
  89.     return GDB_OSABI_UNKNOWN;

  90.   for (i = 0; i < num_phdrs; i++)
  91.     if (phdrs[i].p_type == PT_LOAD && phdrs[i].p_offset == 0)
  92.       return GDB_OSABI_UNKNOWN;

  93.   /* Looks like a Symbian binary.  */
  94.   return GDB_OSABI_SYMBIAN;
  95. }

  96. /* -Wmissing-prototypes */
  97. extern initialize_file_ftype _initialize_arm_symbian_tdep;

  98. void
  99. _initialize_arm_symbian_tdep (void)
  100. {
  101.   gdbarch_register_osabi_sniffer (bfd_arch_arm,
  102.                                   bfd_target_elf_flavour,
  103.                                   arm_symbian_osabi_sniffer);

  104.   gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_SYMBIAN,
  105.                           arm_symbian_init_abi);
  106. }