GDB (xrefs)
/tmp/gdb-8.1/gdb/arm-symbian-tdep.c
Go to the documentation of this file.
1 /* ARM Symbian OS target support.
2 
3  Copyright (C) 2008-2018 Free Software Foundation, Inc.
4 
5  This file is part of GDB.
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 
20 #include "defs.h"
21 #include "frame.h"
22 #include "objfiles.h"
23 #include "osabi.h"
24 #include "solib.h"
25 #include "solib-target.h"
26 #include "target.h"
27 #include "elf-bfd.h"
28 
29 /* If PC is in a DLL import stub, return the address of the `real'
30  function belonging to the stub. */
31 
32 static CORE_ADDR
34 {
35  struct gdbarch *gdbarch;
36  enum bfd_endian byte_order;
37  ULONGEST insn;
38  CORE_ADDR dest;
39  gdb_byte buf[4];
40 
41  if (!in_plt_section (pc))
42  return 0;
43 
44  if (target_read_memory (pc, buf, 4) != 0)
45  return 0;
46 
47  gdbarch = get_frame_arch (frame);
49 
50  /* ldr pc, [pc, #-4]. */
51  insn = extract_unsigned_integer (buf, 4, byte_order);
52  if (insn != 0xe51ff004)
53  return 0;
54 
55  if (target_read_memory (pc + 4, buf, 4) != 0)
56  return 0;
57 
58  dest = extract_unsigned_integer (buf, 4, byte_order);
59  return gdbarch_addr_bits_remove (gdbarch, dest);
60 }
61 
62 static void
64  struct gdbarch *gdbarch)
65 {
66  /* Shared library handling. */
68 
69  /* On this target, the toolchain outputs ELF files, with `sym' for
70  filename extension (e.g., `FOO.sym'); these are post-linker
71  processed into PE-ish DLLs (e.g., `FOO.dll'), and it's these that
72  are actually copied to and run on the target. Naturally, when
73  listing shared libraries, Symbian stubs report the DLL filenames.
74  Setting this makes it so that GDB automatically looks for the
75  corresponding ELF files on the host's filesystem. */
77 
78  /* Canonical paths on this target look like `c:\sys\bin\bar.dll',
79  for example. */
81 
83 }
84 
85 /* Recognize Symbian object files. */
86 
87 static enum gdb_osabi
89 {
90  Elf_Internal_Phdr *phdrs;
91  long phdrs_size;
92  int num_phdrs, i;
93 
94  /* Symbian executables are always shared objects (ET_DYN). */
95  if (elf_elfheader (abfd)->e_type == ET_EXEC)
96  return GDB_OSABI_UNKNOWN;
97 
98  if (elf_elfheader (abfd)->e_ident[EI_OSABI] != ELFOSABI_NONE)
99  return GDB_OSABI_UNKNOWN;
100 
101  /* Check for the ELF headers not being part of any PT_LOAD segment.
102  Symbian is the only GDB supported (or GNU binutils supported) ARM
103  target which uses a postlinker to flatten ELF files, dropping the
104  ELF dynamic info in the process. */
105  phdrs_size = bfd_get_elf_phdr_upper_bound (abfd);
106  if (phdrs_size == -1)
107  return GDB_OSABI_UNKNOWN;
108 
109  phdrs = (Elf_Internal_Phdr *) alloca (phdrs_size);
110  num_phdrs = bfd_get_elf_phdrs (abfd, phdrs);
111  if (num_phdrs == -1)
112  return GDB_OSABI_UNKNOWN;
113 
114  for (i = 0; i < num_phdrs; i++)
115  if (phdrs[i].p_type == PT_LOAD && phdrs[i].p_offset == 0)
116  return GDB_OSABI_UNKNOWN;
117 
118  /* Looks like a Symbian binary. */
119  return GDB_OSABI_SYMBIAN;
120 }
121 
122 void
124 {
125  gdbarch_register_osabi_sniffer (bfd_arch_arm,
126  bfd_target_elf_flavour,
128 
129  gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_SYMBIAN,
131 }
bfd_vma CORE_ADDR
Definition: common-types.h:41
void _initialize_arm_symbian_tdep(void)
void set_solib_ops(struct gdbarch *gdbarch, const struct target_so_ops *new_ops)
Definition: solib.c:77
void set_gdbarch_skip_trampoline_code(struct gdbarch *gdbarch, gdbarch_skip_trampoline_code_ftype skip_trampoline_code)
Definition: gdbarch.c:3316
void gdbarch_register_osabi_sniffer(enum bfd_architecture arch, enum bfd_flavour flavour, enum gdb_osabi(*sniffer_fn)(bfd *))
Definition: osabi.c:219
struct target_so_ops solib_target_so_ops
Definition: solib-target.c:462
void set_gdbarch_solib_symbols_extension(struct gdbarch *gdbarch, const char *solib_symbols_extension)
Definition: gdbarch.c:4730
CORE_ADDR gdbarch_addr_bits_remove(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition: gdbarch.c:3208
static ULONGEST extract_unsigned_integer(const gdb_byte *addr, int len, enum bfd_endian byte_order)
Definition: defs.h:577
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1509
void gdbarch_register_osabi(enum bfd_architecture arch, unsigned long machine, enum gdb_osabi osabi, void(*init_osabi)(struct gdbarch_info, struct gdbarch *))
Definition: osabi.c:143
bfd_byte gdb_byte
Definition: common-types.h:38
static CORE_ADDR arm_symbian_skip_trampoline_code(struct frame_info *frame, CORE_ADDR pc)
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: target.c:1370
static int in_plt_section(CORE_ADDR pc)
Definition: objfiles.h:542
unsigned long long ULONGEST
Definition: common-types.h:53
void set_gdbarch_has_dos_based_file_system(struct gdbarch *gdbarch, int has_dos_based_file_system)
Definition: gdbarch.c:4747
static void arm_symbian_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
enum bfd_endian byte_order
Definition: gdbarch.c:137
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2691
static enum gdb_osabi arm_symbian_osabi_sniffer(bfd *abfd)
gdb_osabi
Definition: defs.h:508