* read.c (cons_worker): Detect and reject unexpected string argument.
[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 /* Canonical paths on this target look like `c:\sys\bin\bar.dll',
82 for example. */
83 set_gdbarch_has_dos_based_file_system (gdbarch, 1);
84
85 set_solib_ops (gdbarch, &solib_target_so_ops);
86 }
87
88 /* Recognize Symbian object files. */
89
90 static enum gdb_osabi
91 arm_symbian_osabi_sniffer (bfd *abfd)
92 {
93 Elf_Internal_Phdr *phdrs, **segments;
94 long phdrs_size;
95 int num_phdrs, i;
96
97 /* Symbian executables are always shared objects (ET_DYN). */
98 if (elf_elfheader (abfd)->e_type == ET_EXEC)
99 return GDB_OSABI_UNKNOWN;
100
101 if (elf_elfheader (abfd)->e_ident[EI_OSABI] != ELFOSABI_NONE)
102 return GDB_OSABI_UNKNOWN;
103
104 /* Check for the ELF headers not being part of any PT_LOAD segment.
105 Symbian is the only GDB supported (or GNU binutils supported) ARM
106 target which uses a postlinker to flatten ELF files, dropping the
107 ELF dynamic info in the process. */
108 phdrs_size = bfd_get_elf_phdr_upper_bound (abfd);
109 if (phdrs_size == -1)
110 return GDB_OSABI_UNKNOWN;
111
112 phdrs = alloca (phdrs_size);
113 num_phdrs = bfd_get_elf_phdrs (abfd, phdrs);
114 if (num_phdrs == -1)
115 return GDB_OSABI_UNKNOWN;
116
117 for (i = 0; i < num_phdrs; i++)
118 if (phdrs[i].p_type == PT_LOAD && phdrs[i].p_offset == 0)
119 return GDB_OSABI_UNKNOWN;
120
121 /* Looks like a Symbian binary. */
122 return GDB_OSABI_SYMBIAN;
123 }
124
125 void
126 _initialize_arm_symbian_tdep (void)
127 {
128 gdbarch_register_osabi_sniffer (bfd_arch_arm,
129 bfd_target_elf_flavour,
130 arm_symbian_osabi_sniffer);
131
132 gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_SYMBIAN,
133 arm_symbian_init_abi);
134 }
This page took 0.036088 seconds and 4 git commands to generate.