GDB (xrefs)

/tmp/gdb-8.1/gdb/ia64-linux-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for the IA-64 for GDB, the GNU debugger.
2
3 Copyright (C) 2000-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 "ia64-tdep.h"
22 #include "arch-utils.h"
23 #include "gdbcore.h"
24 #include "regcache.h"
25 #include "osabi.h"
26 #include "solib-svr4.h"
27 #include "symtab.h"
28 #include "linux-tdep.h"
29 #include "regset.h"
30
31 #include <ctype.h>
32
33 /* The sigtramp code is in a non-readable (executable-only) region
34 of memory called the ``gate page''. The addresses in question
35 were determined by examining the system headers. They are
36 overly generous to allow for different pages sizes. */
37
38 #define GATE_AREA_START 0xa000000000000100LL
39 #define GATE_AREA_END 0xa000000000020000LL
40
41 /* Offset to sigcontext structure from frame of handler. */
42 #define IA64_LINUX_SIGCONTEXT_OFFSET 192
43
44 static int
45 ia64_linux_pc_in_sigtramp (CORE_ADDR pc)
46 {
47 return (pc >= (CORE_ADDR) GATE_AREA_START && pc < (CORE_ADDR) GATE_AREA_END);
48 }
49
50 /* IA-64 GNU/Linux specific function which, given a frame address and
51 a register number, returns the address at which that register may be
52 found. 0 is returned for registers which aren't stored in the
53 sigcontext structure. */
54
55 static CORE_ADDR
56 ia64_linux_sigcontext_register_address (struct gdbarch *gdbarch,
57 CORE_ADDR sp, int regno)
58 {
59 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
60 gdb_byte buf[8];
61 CORE_ADDR sigcontext_addr = 0;
62
63 /* The address of the sigcontext area is found at offset 16 in the
64 sigframe. */
65 read_memory (sp + 16, buf, 8);
66 sigcontext_addr = extract_unsigned_integer (buf, 8, byte_order);
67
68 if (IA64_GR0_REGNUM <= regno && regno <= IA64_GR31_REGNUM)
69 return sigcontext_addr + 200 + 8 * (regno - IA64_GR0_REGNUM);
70 else if (IA64_BR0_REGNUM <= regno && regno <= IA64_BR7_REGNUM)
71 return sigcontext_addr + 136 + 8 * (regno - IA64_BR0_REGNUM);
72 else if (IA64_FR0_REGNUM <= regno && regno <= IA64_FR127_REGNUM)
73 return sigcontext_addr + 464 + 16 * (regno - IA64_FR0_REGNUM);
74 else
75 switch (regno)
76 {
77 case IA64_IP_REGNUM :
78 return sigcontext_addr + 40;
79 case IA64_CFM_REGNUM :
80 return sigcontext_addr + 48;
81 case IA64_PSR_REGNUM :
82 return sigcontext_addr + 56; /* user mask only */
83 /* sc_ar_rsc is provided, from which we could compute bspstore, but
84 I don't think it's worth it. Anyway, if we want it, it's at offset
85 64. */
86 case IA64_BSP_REGNUM :
87 return sigcontext_addr + 72;
88 case IA64_RNAT_REGNUM :
89 return sigcontext_addr + 80;
90 case IA64_CCV_REGNUM :
91 return sigcontext_addr + 88;
92 case IA64_UNAT_REGNUM :
93 return sigcontext_addr + 96;
94 case IA64_FPSR_REGNUM :
95 return sigcontext_addr + 104;
96 case IA64_PFS_REGNUM :
97 return sigcontext_addr + 112;
98 case IA64_LC_REGNUM :
99 return sigcontext_addr + 120;
100 case IA64_PR_REGNUM :
101 return sigcontext_addr + 128;
102 default :
103 return 0;
104 }
105 }
106
107 static void
108 ia64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
109 {
110 ia64_write_pc (regcache, pc);
111
112 /* We must be careful with modifying the instruction-pointer: if we
113 just interrupt a system call, the kernel would ordinarily try to
114 restart it when we resume the inferior, which typically results
115 in SIGSEGV or SIGILL. We prevent this by clearing r10, which
116 will tell the kernel that r8 does NOT contain a valid error code
117 and hence it will skip system-call restart.
118
119 The clearing of r10 is safe as long as ia64_write_pc() is only
120 called as part of setting up an inferior call. */
121 regcache_cooked_write_unsigned (regcache, IA64_GR10_REGNUM, 0);
122 }
123
124 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
125 gdbarch.h. */
126
127 static int
128 ia64_linux_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
129 {
130 return ((isdigit (*s) && s[1] == '[' && s[2] == 'r') /* Displacement. */
131 || *s == 'r' /* Register value. */
132 || isdigit (*s)); /* Literal number. */
133 }
134
135 /* Core file support. */
136
137 static const struct regcache_map_entry ia64_linux_gregmap[] =
138 {
139 { 32, IA64_GR0_REGNUM, 8 }, /* r0 ... r31 */
140 { 1, REGCACHE_MAP_SKIP, 8 }, /* FIXME: NAT collection bits? */
141 { 1, IA64_PR_REGNUM, 8 },
142 { 8, IA64_BR0_REGNUM, 8 }, /* b0 ... b7 */
143 { 1, IA64_IP_REGNUM, 8 },
144 { 1, IA64_CFM_REGNUM, 8 },
145 { 1, IA64_PSR_REGNUM, 8 },
146 { 1, IA64_RSC_REGNUM, 8 },
147 { 1, IA64_BSP_REGNUM, 8 },
148 { 1, IA64_BSPSTORE_REGNUM, 8 },
149 { 1, IA64_RNAT_REGNUM, 8 },
150 { 1, IA64_CCV_REGNUM, 8 },
151 { 1, IA64_UNAT_REGNUM, 8 },
152 { 1, IA64_FPSR_REGNUM, 8 },
153 { 1, IA64_PFS_REGNUM, 8 },
154 { 1, IA64_LC_REGNUM, 8 },
155 { 1, IA64_EC_REGNUM, 8 },
156 { 0 }
157 };
158
159 /* Size of 'gregset_t', as defined by the Linux kernel. Note that
160 this is more than actually mapped in the regmap above. */
161
162 #define IA64_LINUX_GREGS_SIZE (128 * 8)
163
164 static const struct regcache_map_entry ia64_linux_fpregmap[] =
165 {
166 { 128, IA64_FR0_REGNUM, 16 }, /* f0 ... f127 */
167 { 0 }
168 };
169
170 #define IA64_LINUX_FPREGS_SIZE (128 * 16)
171
172 static void
173 ia64_linux_supply_fpregset (const struct regset *regset,
174 struct regcache *regcache,
175 int regnum, const void *regs, size_t len)
176 {
177 const gdb_byte f_zero[16] = { 0 };
178 const gdb_byte f_one[16] =
179 { 0, 0, 0, 0, 0, 0, 0, 0x80, 0xff, 0xff, 0, 0, 0, 0, 0, 0 };
180
181 regcache_supply_regset (regset, regcache, regnum, regs, len);
182
183 /* Kernel generated cores have fr1==0 instead of 1.0. Older GDBs
184 did the same. So ignore whatever might be recorded in fpregset_t
185 for fr0/fr1 and always supply their expected values. */
186 if (regnum == -1 || regnum == IA64_FR0_REGNUM)
187 regcache_raw_supply (regcache, IA64_FR0_REGNUM, f_zero);
188 if (regnum == -1 || regnum == IA64_FR1_REGNUM)
189 regcache_raw_supply (regcache, IA64_FR1_REGNUM, f_one);
190 }
191
192 static const struct regset ia64_linux_gregset =
193 {
194 ia64_linux_gregmap,
195 regcache_supply_regset, regcache_collect_regset
196 };
197
198 static const struct regset ia64_linux_fpregset =
199 {
200 ia64_linux_fpregmap,
201 ia64_linux_supply_fpregset, regcache_collect_regset
202 };
203
204 static void
205 ia64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
206 iterate_over_regset_sections_cb *cb,
207 void *cb_data,
208 const struct regcache *regcache)
209 {
210 cb (".reg", IA64_LINUX_GREGS_SIZE, &ia64_linux_gregset, NULL, cb_data);
211 cb (".reg2", IA64_LINUX_FPREGS_SIZE, &ia64_linux_fpregset, NULL, cb_data);
212 }
213
214 static void
215 ia64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
216 {
217 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
218 static const char *const stap_register_prefixes[] = { "r", NULL };
219 static const char *const stap_register_indirection_prefixes[] = { "[",
220 NULL };
221 static const char *const stap_register_indirection_suffixes[] = { "]",
222 NULL };
223
224 linux_init_abi (info, gdbarch);
225
226 /* Set the method of obtaining the sigcontext addresses at which
227 registers are saved. */
228 tdep->sigcontext_register_address = ia64_linux_sigcontext_register_address;
229
230 /* Set the pc_in_sigtramp method. */
231 tdep->pc_in_sigtramp = ia64_linux_pc_in_sigtramp;
232
233 set_gdbarch_write_pc (gdbarch, ia64_linux_write_pc);
234
235 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
236
237 set_solib_svr4_fetch_link_map_offsets
238 (gdbarch, svr4_lp64_fetch_link_map_offsets);
239
240 /* Enable TLS support. */
241 set_gdbarch_fetch_tls_load_module_address (gdbarch,
242 svr4_fetch_objfile_link_map);
243
244 /* Core file support. */
245 set_gdbarch_iterate_over_regset_sections
246 (gdbarch, ia64_linux_iterate_over_regset_sections);
247
248 /* SystemTap related. */
249 set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes);
250 set_gdbarch_stap_register_indirection_prefixes (gdbarch,
251 stap_register_indirection_prefixes);
252 set_gdbarch_stap_register_indirection_suffixes (gdbarch,
253 stap_register_indirection_suffixes);
254 set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
255 set_gdbarch_stap_is_single_operand (gdbarch,
256 ia64_linux_stap_is_single_operand);
257 }
258
259 void
260 _initialize_ia64_linux_tdep (void)
261 {
262 gdbarch_register_osabi (bfd_arch_ia64, 0, GDB_OSABI_LINUX,
263 ia64_linux_init_abi);
264 }
gdbarch
Definition: gdbarch.c:127
IA64_FPSR_REGNUM
#define IA64_FPSR_REGNUM
Definition: ia64-tdep.h:189
GATE_AREA_END
#define GATE_AREA_END
Definition: ia64-linux-tdep.c:39
ia64_linux_fpregmap
static const struct regcache_map_entry ia64_linux_fpregmap[]
Definition: ia64-linux-tdep.c:164
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
set_gdbarch_fetch_tls_load_module_address
void set_gdbarch_fetch_tls_load_module_address(struct gdbarch *gdbarch, gdbarch_fetch_tls_load_module_address_ftype fetch_tls_load_module_address)
Definition: gdbarch.c:3038
svr4_lp64_fetch_link_map_offsets
struct link_map_offsets * svr4_lp64_fetch_link_map_offsets(void)
Definition: solib-svr4.c:3214
iterate_over_regset_sections_cb
void() iterate_over_regset_sections_cb(const char *sect_name, int size, const struct regset *regset, const char *human_name, void *cb_data)
Definition: gdbarch.h:99
set_gdbarch_skip_trampoline_code
void set_gdbarch_skip_trampoline_code(struct gdbarch *gdbarch, gdbarch_skip_trampoline_code_ftype skip_trampoline_code)
Definition: gdbarch.c:3316
ia64-tdep.h
set_gdbarch_write_pc
void set_gdbarch_write_pc(struct gdbarch *gdbarch, gdbarch_write_pc_ftype write_pc)
Definition: gdbarch.c:1943
IA64_BSP_REGNUM
#define IA64_BSP_REGNUM
Definition: ia64-tdep.h:176
ia64_linux_init_abi
static void ia64_linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: ia64-linux-tdep.c:215
GDB_OSABI_LINUX
Definition: defs.h:517
set_gdbarch_stap_register_prefixes
void set_gdbarch_stap_register_prefixes(struct gdbarch *gdbarch, const char *const *stap_register_prefixes)
Definition: gdbarch.c:4366
IA64_LINUX_FPREGS_SIZE
#define IA64_LINUX_FPREGS_SIZE
Definition: ia64-linux-tdep.c:170
gdbarch_tdep::pc
struct m32c_reg * pc
Definition: m32c-tdep.c:116
gdbarch_tdep
Definition: aarch64-tdep.h:55
regcache_supply_regset
void regcache_supply_regset(const struct regset *regset, struct regcache *regcache, int regnum, const void *buf, size_t size)
Definition: regcache.c:1192
GATE_AREA_START
#define GATE_AREA_START
Definition: ia64-linux-tdep.c:38
linux_init_abi
void linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: linux-tdep.c:2492
ia64_linux_write_pc
static void ia64_linux_write_pc(struct regcache *regcache, CORE_ADDR pc)
Definition: ia64-linux-tdep.c:108
gdbarch_tdep::sigcontext_addr
CORE_ADDR(* sigcontext_addr)(struct frame_info *)
Definition: alpha-tdep.h:82
ia64_linux_gregmap
static const struct regcache_map_entry ia64_linux_gregmap[]
Definition: ia64-linux-tdep.c:137
IA64_RNAT_REGNUM
#define IA64_RNAT_REGNUM
Definition: ia64-tdep.h:178
IA64_GR10_REGNUM
#define IA64_GR10_REGNUM
Definition: ia64-tdep.h:42
ia64_linux_stap_is_single_operand
static int ia64_linux_stap_is_single_operand(struct gdbarch *gdbarch, const char *s)
Definition: ia64-linux-tdep.c:128
defs.h
gdbarch_tdep
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1491
IA64_RSC_REGNUM
#define IA64_RSC_REGNUM
Definition: ia64-tdep.h:175
IA64_CCV_REGNUM
#define IA64_CCV_REGNUM
Definition: ia64-tdep.h:187
set_gdbarch_stap_register_indirection_suffixes
void set_gdbarch_stap_register_indirection_suffixes(struct gdbarch *gdbarch, const char *const *stap_register_indirection_suffixes)
Definition: gdbarch.c:4417
arch-utils.h
svr4_fetch_objfile_link_map
CORE_ADDR svr4_fetch_objfile_link_map(struct objfile *objfile)
Definition: solib-svr4.c:1579
regset
Definition: regset.h:34
set_gdbarch_stap_gdb_register_prefix
void set_gdbarch_stap_gdb_register_prefix(struct gdbarch *gdbarch, const char *stap_gdb_register_prefix)
Definition: gdbarch.c:4434
IA64_GR31_REGNUM
#define IA64_GR31_REGNUM
Definition: ia64-tdep.h:45
symtab.h
IA64_PFS_REGNUM
#define IA64_PFS_REGNUM
Definition: ia64-tdep.h:191
IA64_BSPSTORE_REGNUM
#define IA64_BSPSTORE_REGNUM
Definition: ia64-tdep.h:177
IA64_FR1_REGNUM
#define IA64_FR1_REGNUM
Definition: ia64-tdep.h:51
IA64_FR127_REGNUM
#define IA64_FR127_REGNUM
Definition: ia64-tdep.h:64
ia64_linux_supply_fpregset
static void ia64_linux_supply_fpregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *regs, size_t len)
Definition: ia64-linux-tdep.c:173
find_solib_trampoline_target
CORE_ADDR find_solib_trampoline_target(struct frame_info *frame, CORE_ADDR pc)
Definition: minsyms.c:1492
solib-svr4.h
IA64_GR0_REGNUM
#define IA64_GR0_REGNUM
Definition: ia64-tdep.h:32
extract_unsigned_integer
static ULONGEST extract_unsigned_integer(const gdb_byte *addr, int len, enum bfd_endian byte_order)
Definition: defs.h:577
osabi.h
regcache.h
IA64_FR0_REGNUM
#define IA64_FR0_REGNUM
Definition: ia64-tdep.h:50
IA64_BR0_REGNUM
#define IA64_BR0_REGNUM
Definition: ia64-tdep.h:137
ia64_write_pc
void ia64_write_pc(struct regcache *regcache, CORE_ADDR new_pc)
Definition: ia64-tdep.c:892
gdbarch_byte_order
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1509
IA64_LINUX_GREGS_SIZE
#define IA64_LINUX_GREGS_SIZE
Definition: ia64-linux-tdep.c:162
set_solib_svr4_fetch_link_map_offsets
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
Definition: solib-svr4.c:3137
IA64_BR7_REGNUM
#define IA64_BR7_REGNUM
Definition: ia64-tdep.h:144
set_gdbarch_stap_register_indirection_prefixes
void set_gdbarch_stap_register_indirection_prefixes(struct gdbarch *gdbarch, const char *const *stap_register_indirection_prefixes)
Definition: gdbarch.c:4400
regcache_collect_regset
void regcache_collect_regset(const struct regset *regset, const struct regcache *regcache, int regnum, void *buf, size_t size)
Definition: regcache.c:1211
IA64_EC_REGNUM
#define IA64_EC_REGNUM
Definition: ia64-tdep.h:193
ia64_linux_sigcontext_register_address
static CORE_ADDR ia64_linux_sigcontext_register_address(struct gdbarch *gdbarch, CORE_ADDR sp, int regno)
Definition: ia64-linux-tdep.c:56
IA64_IP_REGNUM
#define IA64_IP_REGNUM
Definition: ia64-tdep.h:161
regnum
int regnum
Definition: aarch64-tdep.c:77
read_memory
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: corefile.c:258
gdbarch_register_osabi
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
IA64_PSR_REGNUM
#define IA64_PSR_REGNUM
Definition: ia64-tdep.h:164
ia64_linux_fpregset
static const struct regset ia64_linux_fpregset
Definition: ia64-linux-tdep.c:198
gdbarch_tdep::sigcontext_register_address
CORE_ADDR(* sigcontext_register_address)(struct gdbarch *, CORE_ADDR, int)
Definition: ia64-tdep.h:232
IA64_PR_REGNUM
#define IA64_PR_REGNUM
Definition: ia64-tdep.h:158
REGCACHE_MAP_SKIP
Definition: regcache.h:168
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
gdbarch_tdep::pc_in_sigtramp
int(* pc_in_sigtramp)(struct gdbarch *gdbarch, CORE_ADDR pc, const char *name)
Definition: alpha-tdep.h:88
gdbcore.h
regcache_cooked_write_unsigned
void regcache_cooked_write_unsigned(struct regcache *regcache, int regnum, ULONGEST val)
Definition: regcache.c:806
set_gdbarch_stap_is_single_operand
void set_gdbarch_stap_is_single_operand(struct gdbarch *gdbarch, gdbarch_stap_is_single_operand_ftype stap_is_single_operand)
Definition: gdbarch.c:4475
IA64_UNAT_REGNUM
#define IA64_UNAT_REGNUM
Definition: ia64-tdep.h:188
linux-tdep.h
ia64_linux_iterate_over_regset_sections
static void ia64_linux_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
Definition: ia64-linux-tdep.c:205
IA64_CFM_REGNUM
#define IA64_CFM_REGNUM
Definition: ia64-tdep.h:167
ia64_linux_pc_in_sigtramp
static int ia64_linux_pc_in_sigtramp(CORE_ADDR pc)
Definition: ia64-linux-tdep.c:45
gdbarch_tdep::sp
struct m32c_reg * sp
Definition: m32c-tdep.c:119
regcache_raw_supply
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1004
regcache
Definition: regcache.h:232
gdbarch_info
Definition: gdbarch.h:1626
regset.h
ia64_linux_gregset
static const struct regset ia64_linux_gregset
Definition: ia64-linux-tdep.c:192
set_gdbarch_iterate_over_regset_sections
void set_gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype iterate_over_regset_sections)
Definition: gdbarch.c:3647
_initialize_ia64_linux_tdep
void _initialize_ia64_linux_tdep(void)
Definition: ia64-linux-tdep.c:260
IA64_LC_REGNUM
#define IA64_LC_REGNUM
Definition: ia64-tdep.h:192
regcache_map_entry
Definition: regcache.h:157