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