GDB (xrefs)
/tmp/gdb-7.10/gdb/arm-wince-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for Windows CE running on ARM processors,
2  for GDB.
3 
4  Copyright (C) 2007-2015 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 "osabi.h"
23 #include "gdbcore.h"
24 #include "target.h"
25 #include "frame.h"
26 
27 #include "arm-tdep.h"
28 #include "windows-tdep.h"
29 
30 static const gdb_byte arm_wince_le_breakpoint[] = { 0x10, 0x00, 0x00, 0xe6 };
31 static const gdb_byte arm_wince_thumb_le_breakpoint[] = { 0xfe, 0xdf };
32 
33 /* Description of the longjmp buffer. */
34 #define ARM_WINCE_JB_ELEMENT_SIZE INT_REGISTER_SIZE
35 #define ARM_WINCE_JB_PC 10
36 
37 static CORE_ADDR
39 {
40  struct gdbarch *gdbarch = get_frame_arch (frame);
41  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
42  ULONGEST indirect;
43  struct bound_minimal_symbol indsym;
44  const char *symname;
45  CORE_ADDR next_pc;
46 
47  /* The format of an ARM DLL trampoline is:
48 
49  ldr ip, [pc]
50  ldr pc, [ip]
51  .dw __imp_<func>
52 
53  */
54 
55  if (pc == 0
56  || read_memory_unsigned_integer (pc + 0, 4, byte_order) != 0xe59fc000
57  || read_memory_unsigned_integer (pc + 4, 4, byte_order) != 0xe59cf000)
58  return 0;
59 
60  indirect = read_memory_unsigned_integer (pc + 8, 4, byte_order);
61  if (indirect == 0)
62  return 0;
63 
64  indsym = lookup_minimal_symbol_by_pc (indirect);
65  if (indsym.minsym == NULL)
66  return 0;
67 
68  symname = MSYMBOL_LINKAGE_NAME (indsym.minsym);
69  if (symname == NULL || !startswith (symname, "__imp_"))
70  return 0;
71 
72  next_pc = read_memory_unsigned_integer (indirect, 4, byte_order);
73  if (next_pc != 0)
74  return next_pc;
75 
76  /* Check with the default arm gdbarch_skip_trampoline. */
77  return arm_skip_stub (frame, pc);
78 }
79 
80 /* GCC emits a call to __gccmain in the prologue of main.
81 
82  The function below examines the code pointed at by PC and checks to
83  see if it corresponds to a call to __gccmain. If so, it returns
84  the address of the instruction following that call. Otherwise, it
85  simply returns PC. */
86 
87 static CORE_ADDR
89 {
90  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
91  ULONGEST this_instr;
92 
93  this_instr = read_memory_unsigned_integer (pc, 4, byte_order);
94 
95  /* bl offset <__gccmain> */
96  if ((this_instr & 0xfff00000) == 0xeb000000)
97  {
98 #define sign_extend(V, N) \
99  (((long) (V) ^ (1L << ((N) - 1))) - (1L << ((N) - 1)))
100 
101  long offset = sign_extend (this_instr & 0x000fffff, 23) << 2;
102  CORE_ADDR call_dest = (pc + 8 + offset) & 0xffffffffU;
103  struct bound_minimal_symbol s = lookup_minimal_symbol_by_pc (call_dest);
104 
105  if (s.minsym != NULL
106  && MSYMBOL_LINKAGE_NAME (s.minsym) != NULL
107  && strcmp (MSYMBOL_LINKAGE_NAME (s.minsym), "__gccmain") == 0)
108  pc += 4;
109  }
110 
111  return pc;
112 }
113 
114 static void
116 {
117  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
118 
119  windows_init_abi (info, gdbarch);
120 
126 
128 
129  tdep->jb_pc = ARM_WINCE_JB_PC;
131 
132  /* On ARM WinCE char defaults to signed. */
133  set_gdbarch_char_signed (gdbarch, 1);
134 
135  /* Shared library handling. */
137 
138  /* Single stepping. */
140 
141  /* Skip call to __gccmain that gcc places in main. */
143 }
144 
145 static enum gdb_osabi
147 {
148  const char *target_name = bfd_get_target (abfd);
149 
150  if (strcmp (target_name, "pei-arm-wince-little") == 0)
151  return GDB_OSABI_WINCE;
152 
153  return GDB_OSABI_UNKNOWN;
154 }
155 
156 /* Provide a prototype to silence -Wmissing-prototypes. */
157 void _initialize_arm_wince_tdep (void);
158 
159 void
161 {
162  gdbarch_register_osabi_sniffer (bfd_arch_arm, bfd_target_coff_flavour,
164 
165  gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_WINCE,
167 }
#define sign_extend(V, N)
void set_gdbarch_skip_main_prologue(struct gdbarch *gdbarch, gdbarch_skip_main_prologue_ftype skip_main_prologue)
Definition: gdbarch.c:2614
static CORE_ADDR arm_wince_skip_main_prologue(struct gdbarch *gdbarch, CORE_ADDR pc)
const gdb_byte * thumb_breakpoint
Definition: arm-tdep.h:181
#define MSYMBOL_LINKAGE_NAME(symbol)
Definition: symtab.h:409
bfd_vma CORE_ADDR
Definition: common-types.h:41
int arm_software_single_step(struct frame_info *frame)
Definition: arm-tdep.c:5302
void set_gdbarch_skip_trampoline_code(struct gdbarch *gdbarch, gdbarch_skip_trampoline_code_ftype skip_trampoline_code)
Definition: gdbarch.c:3084
void _initialize_arm_wince_tdep(void)
static CORE_ADDR arm_pe_skip_trampoline_code(struct frame_info *frame, CORE_ADDR pc)
enum arm_float_model fp_model
Definition: arm-tdep.h:161
struct m32c_reg * pc
Definition: m32c-tdep.c:111
void gdbarch_register_osabi_sniffer(enum bfd_architecture arch, enum bfd_flavour flavour, enum gdb_osabi(*sniffer_fn)(bfd *))
Definition: osabi.c:225
const gdb_byte * arm_breakpoint
Definition: arm-tdep.h:179
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1402
int thumb_breakpoint_size
Definition: arm-tdep.h:182
#define ARM_WINCE_JB_ELEMENT_SIZE
enum struct_return struct_return
Definition: arm-tdep.h:197
static enum gdb_osabi arm_wince_osabi_sniffer(bfd *abfd)
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1420
static int startswith(const char *string, const char *pattern)
Definition: common-utils.h:75
size_t jb_elt_size
Definition: aarch64-tdep.h:83
void set_gdbarch_software_single_step(struct gdbarch *gdbarch, gdbarch_software_single_step_ftype software_single_step)
Definition: gdbarch.c:3026
static void arm_wince_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
bfd_byte gdb_byte
Definition: common-types.h:38
void set_gdbarch_char_signed(struct gdbarch *gdbarch, int char_signed)
Definition: gdbarch.c:1754
struct bound_minimal_symbol lookup_minimal_symbol_by_pc(CORE_ADDR pc)
Definition: minsyms.c:801
void windows_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: windows-tdep.c:491
struct minimal_symbol * minsym
Definition: minsyms.h:32
int offset
Definition: agent.c:65
const char target_name[]
Definition: version.c:4
#define ARM_WINCE_JB_PC
static const gdb_byte arm_wince_le_breakpoint[]
unsigned long long ULONGEST
Definition: common-types.h:53
ULONGEST read_memory_unsigned_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order)
Definition: corefile.c:321
static const gdb_byte arm_wince_thumb_le_breakpoint[]
enum bfd_endian byte_order
Definition: gdbarch.c:128
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:148
CORE_ADDR arm_skip_stub(struct frame_info *frame, CORE_ADDR pc)
Definition: arm-tdep.c:9295
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2535
int arm_breakpoint_size
Definition: arm-tdep.h:180
gdb_osabi
Definition: defs.h:540