1 /* ARM Symbian OS target support.
3 Copyright (C) 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GDB.
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.
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.
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/>. */
26 #include "solib-target.h"
30 /* If PC is in a DLL import stub, return the address of the `real'
31 function belonging to the stub. */
34 arm_symbian_skip_trampoline_code (struct frame_info
*frame
, CORE_ADDR pc
)
36 struct gdbarch
*gdbarch
;
37 enum bfd_endian byte_order
;
42 if (!in_plt_section (pc
, NULL
))
45 if (target_read_memory (pc
, buf
, 4) != 0)
48 gdbarch
= get_frame_arch (frame
);
49 byte_order
= gdbarch_byte_order (gdbarch
);
51 /* ldr pc, [pc, #-4]. */
52 insn
= extract_unsigned_integer (buf
, 4, byte_order
);
53 if (insn
!= 0xe51ff004)
56 if (target_read_memory (pc
+ 4, buf
, 4) != 0)
59 dest
= extract_unsigned_integer (buf
, 4, byte_order
);
60 return gdbarch_addr_bits_remove (gdbarch
, dest
);
64 arm_symbian_init_abi (struct gdbarch_info info
,
65 struct gdbarch
*gdbarch
)
67 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
69 /* Shared library handling. */
70 set_gdbarch_skip_trampoline_code (gdbarch
, arm_symbian_skip_trampoline_code
);
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");
81 /* Canonical paths on this target look like `c:\sys\bin\bar.dll',
83 set_gdbarch_has_dos_based_file_system (gdbarch
, 1);
85 set_solib_ops (gdbarch
, &solib_target_so_ops
);
88 /* Recognize Symbian object files. */
91 arm_symbian_osabi_sniffer (bfd
*abfd
)
93 Elf_Internal_Phdr
*phdrs
, **segments
;
97 /* Symbian executables are always shared objects (ET_DYN). */
98 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
)
99 return GDB_OSABI_UNKNOWN
;
101 if (elf_elfheader (abfd
)->e_ident
[EI_OSABI
] != ELFOSABI_NONE
)
102 return GDB_OSABI_UNKNOWN
;
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
;
112 phdrs
= alloca (phdrs_size
);
113 num_phdrs
= bfd_get_elf_phdrs (abfd
, phdrs
);
115 return GDB_OSABI_UNKNOWN
;
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
;
121 /* Looks like a Symbian binary. */
122 return GDB_OSABI_SYMBIAN
;
126 _initialize_arm_symbian_tdep (void)
128 gdbarch_register_osabi_sniffer (bfd_arch_arm
,
129 bfd_target_elf_flavour
,
130 arm_symbian_osabi_sniffer
);
132 gdbarch_register_osabi (bfd_arch_arm
, 0, GDB_OSABI_SYMBIAN
,
133 arm_symbian_init_abi
);