Add target_ops argument to to_insert_hw_breakpoint
[deliverable/binutils-gdb.git] / gdb / arm-linux-nat.c
CommitLineData
ed9a39eb 1/* GNU/Linux on ARM native support.
ecd75fc8 2 Copyright (C) 1999-2014 Free Software Foundation, Inc.
ed9a39eb
JM
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
a9762ec7 8 the Free Software Foundation; either version 3 of the License, or
ed9a39eb
JM
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
a9762ec7 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
ed9a39eb
JM
18
19#include "defs.h"
20#include "inferior.h"
21#include "gdbcore.h"
0e9f083f 22#include <string.h>
4e052eda 23#include "regcache.h"
10d6c8cd
DJ
24#include "target.h"
25#include "linux-nat.h"
05a4558a 26#include "target-descriptions.h"
3b273a55 27#include "auxv.h"
e3039479
UW
28#include "observer.h"
29#include "gdbthread.h"
ed9a39eb 30
aeb98c60 31#include "arm-tdep.h"
cb587d83 32#include "arm-linux-tdep.h"
aeb98c60 33
3b273a55 34#include <elf/common.h>
ed9a39eb
JM
35#include <sys/user.h>
36#include <sys/ptrace.h>
37#include <sys/utsname.h>
41c49b06 38#include <sys/procfs.h>
ed9a39eb 39
0963b4bd 40/* Prototypes for supply_gregset etc. */
c60c0f5f
MS
41#include "gregset.h"
42
9308fc88
DJ
43/* Defines ps_err_e, struct ps_prochandle. */
44#include "gdb_proc_service.h"
45
46#ifndef PTRACE_GET_THREAD_AREA
47#define PTRACE_GET_THREAD_AREA 22
48#endif
49
05a4558a
DJ
50#ifndef PTRACE_GETWMMXREGS
51#define PTRACE_GETWMMXREGS 18
52#define PTRACE_SETWMMXREGS 19
53#endif
54
3b273a55
RE
55#ifndef PTRACE_GETVFPREGS
56#define PTRACE_GETVFPREGS 27
57#define PTRACE_SETVFPREGS 28
58#endif
59
e3039479
UW
60#ifndef PTRACE_GETHBPREGS
61#define PTRACE_GETHBPREGS 29
62#define PTRACE_SETHBPREGS 30
63#endif
64
05a4558a
DJ
65/* A flag for whether the WMMX registers are available. */
66static int arm_linux_has_wmmx_registers;
67
3b273a55 68/* The number of 64-bit VFP registers we have (expect this to be 0,
0963b4bd 69 16, or 32). */
3b273a55
RE
70static int arm_linux_vfp_register_count;
71
ed9a39eb
JM
72extern int arm_apcs_32;
73
fdf39c9a 74/* On GNU/Linux, threads are implemented as pseudo-processes, in which
41c49b06 75 case we may be tracing more than one process at a time. In that
39f77062 76 case, inferior_ptid will contain the main process ID and the
fdf39c9a
RE
77 individual thread (process) ID. get_thread_id () is used to get
78 the thread id if it's available, and the process id otherwise. */
41c49b06 79
4e841acf 80static int
39f77062 81get_thread_id (ptid_t ptid)
41c49b06 82{
dfd4cc63 83 int tid = ptid_get_lwp (ptid);
39f77062 84 if (0 == tid)
dfd4cc63 85 tid = ptid_get_pid (ptid);
41c49b06
SB
86 return tid;
87}
3b273a55 88
05a4558a 89#define GET_THREAD_ID(PTID) get_thread_id (PTID)
41c49b06 90
41c49b06 91/* Get the value of a particular register from the floating point
c6b92abd 92 state of the process and store it into regcache. */
41c49b06
SB
93
94static void
56be3814 95fetch_fpregister (struct regcache *regcache, int regno)
41c49b06
SB
96{
97 int ret, tid;
cb587d83 98 gdb_byte fp[ARM_LINUX_SIZEOF_NWFPE];
41c49b06
SB
99
100 /* Get the thread id for the ptrace call. */
39f77062 101 tid = GET_THREAD_ID (inferior_ptid);
41c49b06
SB
102
103 /* Read the floating point state. */
cb587d83 104 ret = ptrace (PT_GETFPREGS, tid, 0, fp);
41c49b06
SB
105 if (ret < 0)
106 {
edefbb7c 107 warning (_("Unable to fetch floating point register."));
41c49b06
SB
108 return;
109 }
110
111 /* Fetch fpsr. */
34e8f22d 112 if (ARM_FPS_REGNUM == regno)
56be3814 113 regcache_raw_supply (regcache, ARM_FPS_REGNUM,
cb587d83 114 fp + NWFPE_FPSR_OFFSET);
41c49b06
SB
115
116 /* Fetch the floating point register. */
34e8f22d 117 if (regno >= ARM_F0_REGNUM && regno <= ARM_F7_REGNUM)
56be3814 118 supply_nwfpe_register (regcache, regno, fp);
41c49b06
SB
119}
120
121/* Get the whole floating point state of the process and store it
c6b92abd 122 into regcache. */
ed9a39eb
JM
123
124static void
56be3814 125fetch_fpregs (struct regcache *regcache)
ed9a39eb 126{
41c49b06 127 int ret, regno, tid;
cb587d83 128 gdb_byte fp[ARM_LINUX_SIZEOF_NWFPE];
ed9a39eb 129
41c49b06 130 /* Get the thread id for the ptrace call. */
39f77062 131 tid = GET_THREAD_ID (inferior_ptid);
41c49b06 132
ed9a39eb 133 /* Read the floating point state. */
cb587d83 134 ret = ptrace (PT_GETFPREGS, tid, 0, fp);
ed9a39eb
JM
135 if (ret < 0)
136 {
edefbb7c 137 warning (_("Unable to fetch the floating point registers."));
ed9a39eb
JM
138 return;
139 }
140
141 /* Fetch fpsr. */
56be3814 142 regcache_raw_supply (regcache, ARM_FPS_REGNUM,
cb587d83 143 fp + NWFPE_FPSR_OFFSET);
ed9a39eb
JM
144
145 /* Fetch the floating point registers. */
34e8f22d 146 for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
56be3814 147 supply_nwfpe_register (regcache, regno, fp);
ed9a39eb
JM
148}
149
41c49b06 150/* Save a particular register into the floating point state of the
c6b92abd 151 process using the contents from regcache. */
41c49b06
SB
152
153static void
56be3814 154store_fpregister (const struct regcache *regcache, int regno)
41c49b06
SB
155{
156 int ret, tid;
cb587d83 157 gdb_byte fp[ARM_LINUX_SIZEOF_NWFPE];
41c49b06
SB
158
159 /* Get the thread id for the ptrace call. */
39f77062 160 tid = GET_THREAD_ID (inferior_ptid);
41c49b06
SB
161
162 /* Read the floating point state. */
cb587d83 163 ret = ptrace (PT_GETFPREGS, tid, 0, fp);
41c49b06
SB
164 if (ret < 0)
165 {
edefbb7c 166 warning (_("Unable to fetch the floating point registers."));
41c49b06
SB
167 return;
168 }
169
170 /* Store fpsr. */
672c9795
YQ
171 if (ARM_FPS_REGNUM == regno
172 && REG_VALID == regcache_register_status (regcache, ARM_FPS_REGNUM))
56be3814 173 regcache_raw_collect (regcache, ARM_FPS_REGNUM, fp + NWFPE_FPSR_OFFSET);
41c49b06
SB
174
175 /* Store the floating point register. */
34e8f22d 176 if (regno >= ARM_F0_REGNUM && regno <= ARM_F7_REGNUM)
56be3814 177 collect_nwfpe_register (regcache, regno, fp);
41c49b06 178
cb587d83 179 ret = ptrace (PTRACE_SETFPREGS, tid, 0, fp);
41c49b06
SB
180 if (ret < 0)
181 {
edefbb7c 182 warning (_("Unable to store floating point register."));
41c49b06
SB
183 return;
184 }
185}
186
ed9a39eb 187/* Save the whole floating point state of the process using
c6b92abd 188 the contents from regcache. */
ed9a39eb
JM
189
190static void
56be3814 191store_fpregs (const struct regcache *regcache)
ed9a39eb 192{
41c49b06 193 int ret, regno, tid;
cb587d83 194 gdb_byte fp[ARM_LINUX_SIZEOF_NWFPE];
ed9a39eb 195
41c49b06 196 /* Get the thread id for the ptrace call. */
39f77062 197 tid = GET_THREAD_ID (inferior_ptid);
41c49b06
SB
198
199 /* Read the floating point state. */
cb587d83 200 ret = ptrace (PT_GETFPREGS, tid, 0, fp);
41c49b06
SB
201 if (ret < 0)
202 {
edefbb7c 203 warning (_("Unable to fetch the floating point registers."));
41c49b06
SB
204 return;
205 }
206
ed9a39eb 207 /* Store fpsr. */
672c9795 208 if (REG_VALID == regcache_register_status (regcache, ARM_FPS_REGNUM))
56be3814 209 regcache_raw_collect (regcache, ARM_FPS_REGNUM, fp + NWFPE_FPSR_OFFSET);
ed9a39eb
JM
210
211 /* Store the floating point registers. */
34e8f22d 212 for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
672c9795 213 if (REG_VALID == regcache_register_status (regcache, regno))
56be3814 214 collect_nwfpe_register (regcache, regno, fp);
ed9a39eb 215
cb587d83 216 ret = ptrace (PTRACE_SETFPREGS, tid, 0, fp);
ed9a39eb
JM
217 if (ret < 0)
218 {
edefbb7c 219 warning (_("Unable to store floating point registers."));
ed9a39eb
JM
220 return;
221 }
222}
223
41c49b06 224/* Fetch a general register of the process and store into
c6b92abd 225 regcache. */
41c49b06
SB
226
227static void
56be3814 228fetch_register (struct regcache *regcache, int regno)
41c49b06
SB
229{
230 int ret, tid;
c2152441 231 elf_gregset_t regs;
41c49b06
SB
232
233 /* Get the thread id for the ptrace call. */
39f77062 234 tid = GET_THREAD_ID (inferior_ptid);
41c49b06
SB
235
236 ret = ptrace (PTRACE_GETREGS, tid, 0, &regs);
237 if (ret < 0)
238 {
edefbb7c 239 warning (_("Unable to fetch general register."));
41c49b06
SB
240 return;
241 }
242
34e8f22d 243 if (regno >= ARM_A1_REGNUM && regno < ARM_PC_REGNUM)
56be3814 244 regcache_raw_supply (regcache, regno, (char *) &regs[regno]);
41c49b06 245
34e8f22d 246 if (ARM_PS_REGNUM == regno)
41c49b06
SB
247 {
248 if (arm_apcs_32)
56be3814 249 regcache_raw_supply (regcache, ARM_PS_REGNUM,
17c12639 250 (char *) &regs[ARM_CPSR_GREGNUM]);
41c49b06 251 else
56be3814 252 regcache_raw_supply (regcache, ARM_PS_REGNUM,
23a6d369 253 (char *) &regs[ARM_PC_REGNUM]);
41c49b06
SB
254 }
255
34e8f22d 256 if (ARM_PC_REGNUM == regno)
41c49b06 257 {
bf6ae464 258 regs[ARM_PC_REGNUM] = gdbarch_addr_bits_remove
08790784
UW
259 (get_regcache_arch (regcache),
260 regs[ARM_PC_REGNUM]);
56be3814 261 regcache_raw_supply (regcache, ARM_PC_REGNUM,
23a6d369 262 (char *) &regs[ARM_PC_REGNUM]);
41c49b06
SB
263 }
264}
265
ed9a39eb 266/* Fetch all general registers of the process and store into
c6b92abd 267 regcache. */
ed9a39eb
JM
268
269static void
56be3814 270fetch_regs (struct regcache *regcache)
ed9a39eb 271{
41c49b06 272 int ret, regno, tid;
c2152441 273 elf_gregset_t regs;
ed9a39eb 274
41c49b06 275 /* Get the thread id for the ptrace call. */
39f77062 276 tid = GET_THREAD_ID (inferior_ptid);
41c49b06
SB
277
278 ret = ptrace (PTRACE_GETREGS, tid, 0, &regs);
ed9a39eb
JM
279 if (ret < 0)
280 {
edefbb7c 281 warning (_("Unable to fetch general registers."));
ed9a39eb
JM
282 return;
283 }
284
34e8f22d 285 for (regno = ARM_A1_REGNUM; regno < ARM_PC_REGNUM; regno++)
56be3814 286 regcache_raw_supply (regcache, regno, (char *) &regs[regno]);
ed9a39eb
JM
287
288 if (arm_apcs_32)
56be3814 289 regcache_raw_supply (regcache, ARM_PS_REGNUM,
17c12639 290 (char *) &regs[ARM_CPSR_GREGNUM]);
ed9a39eb 291 else
56be3814 292 regcache_raw_supply (regcache, ARM_PS_REGNUM,
23a6d369 293 (char *) &regs[ARM_PC_REGNUM]);
ed9a39eb 294
bf6ae464 295 regs[ARM_PC_REGNUM] = gdbarch_addr_bits_remove
08790784 296 (get_regcache_arch (regcache), regs[ARM_PC_REGNUM]);
56be3814 297 regcache_raw_supply (regcache, ARM_PC_REGNUM,
23a6d369 298 (char *) &regs[ARM_PC_REGNUM]);
ed9a39eb
JM
299}
300
301/* Store all general registers of the process from the values in
c6b92abd 302 regcache. */
ed9a39eb 303
41c49b06 304static void
56be3814 305store_register (const struct regcache *regcache, int regno)
41c49b06
SB
306{
307 int ret, tid;
c2152441 308 elf_gregset_t regs;
41c49b06 309
672c9795 310 if (REG_VALID != regcache_register_status (regcache, regno))
41c49b06
SB
311 return;
312
313 /* Get the thread id for the ptrace call. */
39f77062 314 tid = GET_THREAD_ID (inferior_ptid);
41c49b06
SB
315
316 /* Get the general registers from the process. */
317 ret = ptrace (PTRACE_GETREGS, tid, 0, &regs);
318 if (ret < 0)
319 {
edefbb7c 320 warning (_("Unable to fetch general registers."));
41c49b06
SB
321 return;
322 }
323
34e8f22d 324 if (regno >= ARM_A1_REGNUM && regno <= ARM_PC_REGNUM)
56be3814 325 regcache_raw_collect (regcache, regno, (char *) &regs[regno]);
adb8a87c 326 else if (arm_apcs_32 && regno == ARM_PS_REGNUM)
56be3814 327 regcache_raw_collect (regcache, regno,
17c12639 328 (char *) &regs[ARM_CPSR_GREGNUM]);
adb8a87c 329 else if (!arm_apcs_32 && regno == ARM_PS_REGNUM)
56be3814 330 regcache_raw_collect (regcache, ARM_PC_REGNUM,
adb8a87c 331 (char *) &regs[ARM_PC_REGNUM]);
41c49b06
SB
332
333 ret = ptrace (PTRACE_SETREGS, tid, 0, &regs);
334 if (ret < 0)
335 {
edefbb7c 336 warning (_("Unable to store general register."));
41c49b06
SB
337 return;
338 }
339}
340
ed9a39eb 341static void
56be3814 342store_regs (const struct regcache *regcache)
ed9a39eb 343{
41c49b06 344 int ret, regno, tid;
c2152441 345 elf_gregset_t regs;
ed9a39eb 346
41c49b06 347 /* Get the thread id for the ptrace call. */
39f77062 348 tid = GET_THREAD_ID (inferior_ptid);
41c49b06
SB
349
350 /* Fetch the general registers. */
351 ret = ptrace (PTRACE_GETREGS, tid, 0, &regs);
ed9a39eb
JM
352 if (ret < 0)
353 {
edefbb7c 354 warning (_("Unable to fetch general registers."));
ed9a39eb
JM
355 return;
356 }
357
34e8f22d 358 for (regno = ARM_A1_REGNUM; regno <= ARM_PC_REGNUM; regno++)
ed9a39eb 359 {
672c9795 360 if (REG_VALID == regcache_register_status (regcache, regno))
56be3814 361 regcache_raw_collect (regcache, regno, (char *) &regs[regno]);
ed9a39eb
JM
362 }
363
672c9795 364 if (arm_apcs_32 && REG_VALID == regcache_register_status (regcache, ARM_PS_REGNUM))
56be3814 365 regcache_raw_collect (regcache, ARM_PS_REGNUM,
17c12639 366 (char *) &regs[ARM_CPSR_GREGNUM]);
adb8a87c 367
41c49b06 368 ret = ptrace (PTRACE_SETREGS, tid, 0, &regs);
ed9a39eb
JM
369
370 if (ret < 0)
371 {
edefbb7c 372 warning (_("Unable to store general registers."));
ed9a39eb
JM
373 return;
374 }
375}
376
05a4558a
DJ
377/* Fetch all WMMX registers of the process and store into
378 regcache. */
379
380#define IWMMXT_REGS_SIZE (16 * 8 + 6 * 4)
381
382static void
56be3814 383fetch_wmmx_regs (struct regcache *regcache)
05a4558a
DJ
384{
385 char regbuf[IWMMXT_REGS_SIZE];
386 int ret, regno, tid;
387
388 /* Get the thread id for the ptrace call. */
389 tid = GET_THREAD_ID (inferior_ptid);
390
391 ret = ptrace (PTRACE_GETWMMXREGS, tid, 0, regbuf);
392 if (ret < 0)
393 {
394 warning (_("Unable to fetch WMMX registers."));
395 return;
396 }
397
398 for (regno = 0; regno < 16; regno++)
56be3814 399 regcache_raw_supply (regcache, regno + ARM_WR0_REGNUM,
05a4558a
DJ
400 &regbuf[regno * 8]);
401
402 for (regno = 0; regno < 2; regno++)
56be3814 403 regcache_raw_supply (regcache, regno + ARM_WCSSF_REGNUM,
05a4558a
DJ
404 &regbuf[16 * 8 + regno * 4]);
405
406 for (regno = 0; regno < 4; regno++)
56be3814 407 regcache_raw_supply (regcache, regno + ARM_WCGR0_REGNUM,
05a4558a
DJ
408 &regbuf[16 * 8 + 2 * 4 + regno * 4]);
409}
410
411static void
56be3814 412store_wmmx_regs (const struct regcache *regcache)
05a4558a
DJ
413{
414 char regbuf[IWMMXT_REGS_SIZE];
415 int ret, regno, tid;
416
417 /* Get the thread id for the ptrace call. */
418 tid = GET_THREAD_ID (inferior_ptid);
419
420 ret = ptrace (PTRACE_GETWMMXREGS, tid, 0, regbuf);
421 if (ret < 0)
422 {
423 warning (_("Unable to fetch WMMX registers."));
424 return;
425 }
426
427 for (regno = 0; regno < 16; regno++)
672c9795
YQ
428 if (REG_VALID == regcache_register_status (regcache,
429 regno + ARM_WR0_REGNUM))
56be3814 430 regcache_raw_collect (regcache, regno + ARM_WR0_REGNUM,
05a4558a
DJ
431 &regbuf[regno * 8]);
432
433 for (regno = 0; regno < 2; regno++)
672c9795
YQ
434 if (REG_VALID == regcache_register_status (regcache,
435 regno + ARM_WCSSF_REGNUM))
56be3814 436 regcache_raw_collect (regcache, regno + ARM_WCSSF_REGNUM,
05a4558a
DJ
437 &regbuf[16 * 8 + regno * 4]);
438
439 for (regno = 0; regno < 4; regno++)
672c9795
YQ
440 if (REG_VALID == regcache_register_status (regcache,
441 regno + ARM_WCGR0_REGNUM))
56be3814 442 regcache_raw_collect (regcache, regno + ARM_WCGR0_REGNUM,
05a4558a
DJ
443 &regbuf[16 * 8 + 2 * 4 + regno * 4]);
444
445 ret = ptrace (PTRACE_SETWMMXREGS, tid, 0, regbuf);
446
447 if (ret < 0)
448 {
449 warning (_("Unable to store WMMX registers."));
450 return;
451 }
452}
453
3b273a55
RE
454/* Fetch and store VFP Registers. The kernel object has space for 32
455 64-bit registers, and the FPSCR. This is even when on a VFPv2 or
456 VFPv3D16 target. */
457#define VFP_REGS_SIZE (32 * 8 + 4)
458
459static void
460fetch_vfp_regs (struct regcache *regcache)
461{
462 char regbuf[VFP_REGS_SIZE];
463 int ret, regno, tid;
464
465 /* Get the thread id for the ptrace call. */
466 tid = GET_THREAD_ID (inferior_ptid);
467
468 ret = ptrace (PTRACE_GETVFPREGS, tid, 0, regbuf);
469 if (ret < 0)
470 {
471 warning (_("Unable to fetch VFP registers."));
472 return;
473 }
474
475 for (regno = 0; regno < arm_linux_vfp_register_count; regno++)
476 regcache_raw_supply (regcache, regno + ARM_D0_REGNUM,
477 (char *) regbuf + regno * 8);
478
479 regcache_raw_supply (regcache, ARM_FPSCR_REGNUM,
480 (char *) regbuf + 32 * 8);
481}
482
483static void
484store_vfp_regs (const struct regcache *regcache)
485{
486 char regbuf[VFP_REGS_SIZE];
487 int ret, regno, tid;
488
489 /* Get the thread id for the ptrace call. */
490 tid = GET_THREAD_ID (inferior_ptid);
491
492 ret = ptrace (PTRACE_GETVFPREGS, tid, 0, regbuf);
493 if (ret < 0)
494 {
495 warning (_("Unable to fetch VFP registers (for update)."));
496 return;
497 }
498
499 for (regno = 0; regno < arm_linux_vfp_register_count; regno++)
500 regcache_raw_collect (regcache, regno + ARM_D0_REGNUM,
501 (char *) regbuf + regno * 8);
502
503 regcache_raw_collect (regcache, ARM_FPSCR_REGNUM,
504 (char *) regbuf + 32 * 8);
505
506 ret = ptrace (PTRACE_SETVFPREGS, tid, 0, regbuf);
507
508 if (ret < 0)
509 {
510 warning (_("Unable to store VFP registers."));
511 return;
512 }
513}
514
ed9a39eb
JM
515/* Fetch registers from the child process. Fetch all registers if
516 regno == -1, otherwise fetch all general registers or all floating
517 point registers depending upon the value of regno. */
518
10d6c8cd 519static void
28439f5e
PA
520arm_linux_fetch_inferior_registers (struct target_ops *ops,
521 struct regcache *regcache, int regno)
ed9a39eb 522{
41c49b06
SB
523 if (-1 == regno)
524 {
56be3814
UW
525 fetch_regs (regcache);
526 fetch_fpregs (regcache);
05a4558a 527 if (arm_linux_has_wmmx_registers)
56be3814 528 fetch_wmmx_regs (regcache);
3b273a55
RE
529 if (arm_linux_vfp_register_count > 0)
530 fetch_vfp_regs (regcache);
41c49b06
SB
531 }
532 else
533 {
05a4558a 534 if (regno < ARM_F0_REGNUM || regno == ARM_PS_REGNUM)
56be3814 535 fetch_register (regcache, regno);
05a4558a 536 else if (regno >= ARM_F0_REGNUM && regno <= ARM_FPS_REGNUM)
56be3814 537 fetch_fpregister (regcache, regno);
05a4558a
DJ
538 else if (arm_linux_has_wmmx_registers
539 && regno >= ARM_WR0_REGNUM && regno <= ARM_WCGR7_REGNUM)
56be3814 540 fetch_wmmx_regs (regcache);
3b273a55
RE
541 else if (arm_linux_vfp_register_count > 0
542 && regno >= ARM_D0_REGNUM
543 && regno <= ARM_D0_REGNUM + arm_linux_vfp_register_count)
544 fetch_vfp_regs (regcache);
41c49b06 545 }
ed9a39eb
JM
546}
547
548/* Store registers back into the inferior. Store all registers if
549 regno == -1, otherwise store all general registers or all floating
550 point registers depending upon the value of regno. */
551
10d6c8cd 552static void
28439f5e
PA
553arm_linux_store_inferior_registers (struct target_ops *ops,
554 struct regcache *regcache, int regno)
ed9a39eb 555{
41c49b06
SB
556 if (-1 == regno)
557 {
56be3814
UW
558 store_regs (regcache);
559 store_fpregs (regcache);
05a4558a 560 if (arm_linux_has_wmmx_registers)
56be3814 561 store_wmmx_regs (regcache);
3b273a55
RE
562 if (arm_linux_vfp_register_count > 0)
563 store_vfp_regs (regcache);
41c49b06
SB
564 }
565 else
566 {
05a4558a 567 if (regno < ARM_F0_REGNUM || regno == ARM_PS_REGNUM)
56be3814 568 store_register (regcache, regno);
05a4558a 569 else if ((regno >= ARM_F0_REGNUM) && (regno <= ARM_FPS_REGNUM))
56be3814 570 store_fpregister (regcache, regno);
05a4558a
DJ
571 else if (arm_linux_has_wmmx_registers
572 && regno >= ARM_WR0_REGNUM && regno <= ARM_WCGR7_REGNUM)
56be3814 573 store_wmmx_regs (regcache);
3b273a55
RE
574 else if (arm_linux_vfp_register_count > 0
575 && regno >= ARM_D0_REGNUM
576 && regno <= ARM_D0_REGNUM + arm_linux_vfp_register_count)
577 store_vfp_regs (regcache);
41c49b06 578 }
ed9a39eb
JM
579}
580
cb587d83
DJ
581/* Wrapper functions for the standard regset handling, used by
582 thread debugging. */
41c49b06
SB
583
584void
7f7fe91e
UW
585fill_gregset (const struct regcache *regcache,
586 gdb_gregset_t *gregsetp, int regno)
41c49b06 587{
7f7fe91e 588 arm_linux_collect_gregset (NULL, regcache, regno, gregsetp, 0);
41c49b06
SB
589}
590
41c49b06 591void
7f7fe91e 592supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
41c49b06 593{
7f7fe91e 594 arm_linux_supply_gregset (NULL, regcache, -1, gregsetp, 0);
41c49b06
SB
595}
596
41c49b06 597void
7f7fe91e
UW
598fill_fpregset (const struct regcache *regcache,
599 gdb_fpregset_t *fpregsetp, int regno)
41c49b06 600{
7f7fe91e 601 arm_linux_collect_nwfpe (NULL, regcache, regno, fpregsetp, 0);
41c49b06
SB
602}
603
604/* Fill GDB's register array with the floating-point register values
605 in *fpregsetp. */
606
607void
7f7fe91e 608supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
ed9a39eb 609{
7f7fe91e 610 arm_linux_supply_nwfpe (NULL, regcache, -1, fpregsetp, 0);
ed9a39eb
JM
611}
612
9308fc88
DJ
613/* Fetch the thread-local storage pointer for libthread_db. */
614
615ps_err_e
616ps_get_thread_area (const struct ps_prochandle *ph,
617 lwpid_t lwpid, int idx, void **base)
618{
619 if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
620 return PS_ERR;
621
622 /* IDX is the bias from the thread pointer to the beginning of the
623 thread descriptor. It has to be subtracted due to implementation
624 quirks in libthread_db. */
625 *base = (void *) ((char *)*base - idx);
626
627 return PS_OK;
628}
629
81adfced
DJ
630static const struct target_desc *
631arm_linux_read_description (struct target_ops *ops)
05a4558a 632{
3b273a55
RE
633 CORE_ADDR arm_hwcap = 0;
634 arm_linux_has_wmmx_registers = 0;
635 arm_linux_vfp_register_count = 0;
05a4558a 636
3b273a55
RE
637 if (target_auxv_search (ops, AT_HWCAP, &arm_hwcap) != 1)
638 {
639 return NULL;
640 }
81adfced 641
3b273a55
RE
642 if (arm_hwcap & HWCAP_IWMMXT)
643 {
644 arm_linux_has_wmmx_registers = 1;
3b273a55
RE
645 return tdesc_arm_with_iwmmxt;
646 }
647
648 if (arm_hwcap & HWCAP_VFP)
649 {
650 int pid;
651 char *buf;
652 const struct target_desc * result = NULL;
653
654 /* NEON implies VFPv3-D32 or no-VFP unit. Say that we only support
655 Neon with VFPv3-D32. */
656 if (arm_hwcap & HWCAP_NEON)
657 {
658 arm_linux_vfp_register_count = 32;
3b273a55
RE
659 result = tdesc_arm_with_neon;
660 }
661 else if ((arm_hwcap & (HWCAP_VFPv3 | HWCAP_VFPv3D16)) == HWCAP_VFPv3)
662 {
663 arm_linux_vfp_register_count = 32;
3b273a55
RE
664 result = tdesc_arm_with_vfpv3;
665 }
666 else
667 {
668 arm_linux_vfp_register_count = 16;
3b273a55
RE
669 result = tdesc_arm_with_vfpv2;
670 }
671
672 /* Now make sure that the kernel supports reading these
673 registers. Support was added in 2.6.30. */
dfd4cc63 674 pid = ptid_get_lwp (inferior_ptid);
3b273a55
RE
675 errno = 0;
676 buf = alloca (VFP_REGS_SIZE);
677 if (ptrace (PTRACE_GETVFPREGS, pid, 0, buf) < 0
678 && errno == EIO)
679 result = NULL;
680
681 return result;
682 }
683
684 return NULL;
05a4558a
DJ
685}
686
e3039479
UW
687/* Information describing the hardware breakpoint capabilities. */
688struct arm_linux_hwbp_cap
689{
690 gdb_byte arch;
691 gdb_byte max_wp_length;
692 gdb_byte wp_count;
693 gdb_byte bp_count;
694};
695
696/* Get hold of the Hardware Breakpoint information for the target we are
697 attached to. Returns NULL if the kernel doesn't support Hardware
698 breakpoints at all, or a pointer to the information structure. */
699static const struct arm_linux_hwbp_cap *
700arm_linux_get_hwbp_cap (void)
701{
702 /* The info structure we return. */
703 static struct arm_linux_hwbp_cap info;
704
705 /* Is INFO in a good state? -1 means that no attempt has been made to
706 initialize INFO; 0 means an attempt has been made, but it failed; 1
707 means INFO is in an initialized state. */
708 static int available = -1;
709
710 if (available == -1)
711 {
712 int tid;
713 unsigned int val;
714
715 tid = GET_THREAD_ID (inferior_ptid);
716 if (ptrace (PTRACE_GETHBPREGS, tid, 0, &val) < 0)
717 available = 0;
718 else
719 {
720 info.arch = (gdb_byte)((val >> 24) & 0xff);
721 info.max_wp_length = (gdb_byte)((val >> 16) & 0xff);
722 info.wp_count = (gdb_byte)((val >> 8) & 0xff);
723 info.bp_count = (gdb_byte)(val & 0xff);
724 available = (info.arch != 0);
725 }
726 }
727
728 return available == 1 ? &info : NULL;
729}
730
731/* How many hardware breakpoints are available? */
732static int
733arm_linux_get_hw_breakpoint_count (void)
734{
735 const struct arm_linux_hwbp_cap *cap = arm_linux_get_hwbp_cap ();
736 return cap != NULL ? cap->bp_count : 0;
737}
738
739/* How many hardware watchpoints are available? */
740static int
741arm_linux_get_hw_watchpoint_count (void)
742{
743 const struct arm_linux_hwbp_cap *cap = arm_linux_get_hwbp_cap ();
744 return cap != NULL ? cap->wp_count : 0;
745}
746
747/* Have we got a free break-/watch-point available for use? Returns -1 if
748 there is not an appropriate resource available, otherwise returns 1. */
749static int
5461485a
TT
750arm_linux_can_use_hw_breakpoint (struct target_ops *self,
751 int type, int cnt, int ot)
e3039479
UW
752{
753 if (type == bp_hardware_watchpoint || type == bp_read_watchpoint
754 || type == bp_access_watchpoint || type == bp_watchpoint)
755 {
756 if (cnt + ot > arm_linux_get_hw_watchpoint_count ())
757 return -1;
758 }
759 else if (type == bp_hardware_breakpoint)
760 {
761 if (cnt > arm_linux_get_hw_breakpoint_count ())
762 return -1;
763 }
764 else
765 gdb_assert (FALSE);
766
767 return 1;
768}
769
770/* Enum describing the different types of ARM hardware break-/watch-points. */
771typedef enum
772{
773 arm_hwbp_break = 0,
774 arm_hwbp_load = 1,
775 arm_hwbp_store = 2,
776 arm_hwbp_access = 3
777} arm_hwbp_type;
778
779/* Type describing an ARM Hardware Breakpoint Control register value. */
780typedef unsigned int arm_hwbp_control_t;
781
782/* Structure used to keep track of hardware break-/watch-points. */
783struct arm_linux_hw_breakpoint
784{
785 /* Address to break on, or being watched. */
786 unsigned int address;
787 /* Control register for break-/watch- point. */
788 arm_hwbp_control_t control;
789};
790
791/* Structure containing arrays of the break and watch points which are have
792 active in each thread.
793
794 The Linux ptrace interface to hardware break-/watch-points presents the
795 values in a vector centred around 0 (which is used fo generic information).
796 Positive indicies refer to breakpoint addresses/control registers, negative
797 indices to watchpoint addresses/control registers.
798
799 The Linux vector is indexed as follows:
800 -((i << 1) + 2): Control register for watchpoint i.
801 -((i << 1) + 1): Address register for watchpoint i.
802 0: Information register.
803 ((i << 1) + 1): Address register for breakpoint i.
804 ((i << 1) + 2): Control register for breakpoint i.
805
806 This structure is used as a per-thread cache of the state stored by the
807 kernel, so that we don't need to keep calling into the kernel to find a
808 free breakpoint.
809
810 We treat break-/watch-points with their enable bit clear as being deleted.
811 */
812typedef struct arm_linux_thread_points
813{
814 /* Thread ID. */
815 int tid;
816 /* Breakpoints for thread. */
817 struct arm_linux_hw_breakpoint *bpts;
818 /* Watchpoint for threads. */
819 struct arm_linux_hw_breakpoint *wpts;
820} *arm_linux_thread_points_p;
821DEF_VEC_P (arm_linux_thread_points_p);
822
823/* Vector of hardware breakpoints for each thread. */
824VEC(arm_linux_thread_points_p) *arm_threads = NULL;
825
826/* Find the list of hardware break-/watch-points for a thread with id TID.
827 If no list exists for TID we return NULL if ALLOC_NEW is 0, otherwise we
828 create a new list and return that. */
829static struct arm_linux_thread_points *
830arm_linux_find_breakpoints_by_tid (int tid, int alloc_new)
831{
832 int i;
833 struct arm_linux_thread_points *t;
834
835 for (i = 0; VEC_iterate (arm_linux_thread_points_p, arm_threads, i, t); ++i)
836 {
837 if (t->tid == tid)
838 return t;
839 }
840
841 t = NULL;
842
843 if (alloc_new)
844 {
845 t = xmalloc (sizeof (struct arm_linux_thread_points));
846 t->tid = tid;
847 t->bpts = xzalloc (arm_linux_get_hw_breakpoint_count ()
848 * sizeof (struct arm_linux_hw_breakpoint));
849 t->wpts = xzalloc (arm_linux_get_hw_watchpoint_count ()
850 * sizeof (struct arm_linux_hw_breakpoint));
851 VEC_safe_push (arm_linux_thread_points_p, arm_threads, t);
852 }
853
854 return t;
855}
856
857/* Initialize an ARM hardware break-/watch-point control register value.
858 BYTE_ADDRESS_SELECT is the mask of bytes to trigger on; HWBP_TYPE is the
859 type of break-/watch-point; ENABLE indicates whether the point is enabled.
860 */
861static arm_hwbp_control_t
862arm_hwbp_control_initialize (unsigned byte_address_select,
863 arm_hwbp_type hwbp_type,
864 int enable)
865{
866 gdb_assert ((byte_address_select & ~0xffU) == 0);
867 gdb_assert (hwbp_type != arm_hwbp_break
868 || ((byte_address_select & 0xfU) != 0));
869
870 return (byte_address_select << 5) | (hwbp_type << 3) | (3 << 1) | enable;
871}
872
873/* Does the breakpoint control value CONTROL have the enable bit set? */
874static int
875arm_hwbp_control_is_enabled (arm_hwbp_control_t control)
876{
877 return control & 0x1;
878}
879
880/* Change a breakpoint control word so that it is in the disabled state. */
881static arm_hwbp_control_t
882arm_hwbp_control_disable (arm_hwbp_control_t control)
883{
884 return control & ~0x1;
885}
886
887/* Initialise the hardware breakpoint structure P. The breakpoint will be
888 enabled, and will point to the placed address of BP_TGT. */
889static void
890arm_linux_hw_breakpoint_initialize (struct gdbarch *gdbarch,
891 struct bp_target_info *bp_tgt,
892 struct arm_linux_hw_breakpoint *p)
893{
894 unsigned mask;
895 CORE_ADDR address = bp_tgt->placed_address;
896
897 /* We have to create a mask for the control register which says which bits
898 of the word pointed to by address to break on. */
899 if (arm_pc_is_thumb (gdbarch, address))
fcf303ab
UW
900 {
901 mask = 0x3;
902 address &= ~1;
903 }
e3039479 904 else
fcf303ab
UW
905 {
906 mask = 0xf;
907 address &= ~3;
908 }
e3039479 909
fcf303ab 910 p->address = (unsigned int) address;
e3039479
UW
911 p->control = arm_hwbp_control_initialize (mask, arm_hwbp_break, 1);
912}
913
914/* Get the ARM hardware breakpoint type from the RW value we're given when
915 asked to set a watchpoint. */
916static arm_hwbp_type
917arm_linux_get_hwbp_type (int rw)
918{
919 if (rw == hw_read)
920 return arm_hwbp_load;
921 else if (rw == hw_write)
922 return arm_hwbp_store;
923 else
924 return arm_hwbp_access;
925}
926
927/* Initialize the hardware breakpoint structure P for a watchpoint at ADDR
928 to LEN. The type of watchpoint is given in RW. */
929static void
930arm_linux_hw_watchpoint_initialize (CORE_ADDR addr, int len, int rw,
931 struct arm_linux_hw_breakpoint *p)
932{
933 const struct arm_linux_hwbp_cap *cap = arm_linux_get_hwbp_cap ();
934 unsigned mask;
935
936 gdb_assert (cap != NULL);
937 gdb_assert (cap->max_wp_length != 0);
938
939 mask = (1 << len) - 1;
940
941 p->address = (unsigned int) addr;
942 p->control = arm_hwbp_control_initialize (mask,
943 arm_linux_get_hwbp_type (rw), 1);
944}
945
946/* Are two break-/watch-points equal? */
947static int
948arm_linux_hw_breakpoint_equal (const struct arm_linux_hw_breakpoint *p1,
949 const struct arm_linux_hw_breakpoint *p2)
950{
951 return p1->address == p2->address && p1->control == p2->control;
952}
953
954/* Insert the hardware breakpoint (WATCHPOINT = 0) or watchpoint (WATCHPOINT
955 =1) BPT for thread TID. */
956static void
957arm_linux_insert_hw_breakpoint1 (const struct arm_linux_hw_breakpoint* bpt,
958 int tid, int watchpoint)
959{
960 struct arm_linux_thread_points *t = arm_linux_find_breakpoints_by_tid (tid, 1);
961 gdb_byte count, i;
962 struct arm_linux_hw_breakpoint* bpts;
963 int dir;
964
965 gdb_assert (t != NULL);
966
967 if (watchpoint)
968 {
969 count = arm_linux_get_hw_watchpoint_count ();
970 bpts = t->wpts;
971 dir = -1;
972 }
973 else
974 {
975 count = arm_linux_get_hw_breakpoint_count ();
976 bpts = t->bpts;
977 dir = 1;
978 }
979
980 for (i = 0; i < count; ++i)
981 if (!arm_hwbp_control_is_enabled (bpts[i].control))
982 {
983 errno = 0;
984 if (ptrace (PTRACE_SETHBPREGS, tid, dir * ((i << 1) + 1),
985 &bpt->address) < 0)
986 perror_with_name (_("Unexpected error setting breakpoint address"));
987 if (ptrace (PTRACE_SETHBPREGS, tid, dir * ((i << 1) + 2),
988 &bpt->control) < 0)
989 perror_with_name (_("Unexpected error setting breakpoint"));
990
991 memcpy (bpts + i, bpt, sizeof (struct arm_linux_hw_breakpoint));
992 break;
993 }
994
995 gdb_assert (i != count);
996}
997
998/* Remove the hardware breakpoint (WATCHPOINT = 0) or watchpoint
999 (WATCHPOINT = 1) BPT for thread TID. */
1000static void
1001arm_linux_remove_hw_breakpoint1 (const struct arm_linux_hw_breakpoint *bpt,
1002 int tid, int watchpoint)
1003{
1004 struct arm_linux_thread_points *t = arm_linux_find_breakpoints_by_tid (tid, 0);
1005 gdb_byte count, i;
1006 struct arm_linux_hw_breakpoint *bpts;
1007 int dir;
1008
1009 gdb_assert (t != NULL);
1010
1011 if (watchpoint)
1012 {
1013 count = arm_linux_get_hw_watchpoint_count ();
1014 bpts = t->wpts;
1015 dir = -1;
1016 }
1017 else
1018 {
1019 count = arm_linux_get_hw_breakpoint_count ();
1020 bpts = t->bpts;
1021 dir = 1;
1022 }
1023
1024 for (i = 0; i < count; ++i)
1025 if (arm_linux_hw_breakpoint_equal (bpt, bpts + i))
1026 {
1027 errno = 0;
1028 bpts[i].control = arm_hwbp_control_disable (bpts[i].control);
1029 if (ptrace (PTRACE_SETHBPREGS, tid, dir * ((i << 1) + 2),
1030 &bpts[i].control) < 0)
1031 perror_with_name (_("Unexpected error clearing breakpoint"));
1032 break;
1033 }
1034
1035 gdb_assert (i != count);
1036}
1037
1038/* Insert a Hardware breakpoint. */
1039static int
23a26771
TT
1040arm_linux_insert_hw_breakpoint (struct target_ops *self,
1041 struct gdbarch *gdbarch,
e3039479
UW
1042 struct bp_target_info *bp_tgt)
1043{
e3039479
UW
1044 struct lwp_info *lp;
1045 struct arm_linux_hw_breakpoint p;
1046
1047 if (arm_linux_get_hw_breakpoint_count () == 0)
1048 return -1;
1049
1050 arm_linux_hw_breakpoint_initialize (gdbarch, bp_tgt, &p);
4c38200f 1051 ALL_LWPS (lp)
dfd4cc63 1052 arm_linux_insert_hw_breakpoint1 (&p, ptid_get_lwp (lp->ptid), 0);
e3039479
UW
1053
1054 return 0;
1055}
1056
1057/* Remove a hardware breakpoint. */
1058static int
1059arm_linux_remove_hw_breakpoint (struct gdbarch *gdbarch,
1060 struct bp_target_info *bp_tgt)
1061{
e3039479
UW
1062 struct lwp_info *lp;
1063 struct arm_linux_hw_breakpoint p;
1064
1065 if (arm_linux_get_hw_breakpoint_count () == 0)
1066 return -1;
1067
1068 arm_linux_hw_breakpoint_initialize (gdbarch, bp_tgt, &p);
4c38200f 1069 ALL_LWPS (lp)
dfd4cc63 1070 arm_linux_remove_hw_breakpoint1 (&p, ptid_get_lwp (lp->ptid), 0);
e3039479
UW
1071
1072 return 0;
1073}
1074
1075/* Are we able to use a hardware watchpoint for the LEN bytes starting at
1076 ADDR? */
1077static int
1078arm_linux_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
1079{
1080 const struct arm_linux_hwbp_cap *cap = arm_linux_get_hwbp_cap ();
1081 CORE_ADDR max_wp_length, aligned_addr;
1082
1083 /* Can not set watchpoints for zero or negative lengths. */
1084 if (len <= 0)
1085 return 0;
1086
1087 /* Need to be able to use the ptrace interface. */
1088 if (cap == NULL || cap->wp_count == 0)
1089 return 0;
1090
1091 /* Test that the range [ADDR, ADDR + LEN) fits into the largest address
1092 range covered by a watchpoint. */
1093 max_wp_length = (CORE_ADDR)cap->max_wp_length;
1094 aligned_addr = addr & ~(max_wp_length - 1);
1095
1096 if (aligned_addr + max_wp_length < addr + len)
1097 return 0;
1098
1099 /* The current ptrace interface can only handle watchpoints that are a
1100 power of 2. */
1101 if ((len & (len - 1)) != 0)
1102 return 0;
1103
1104 /* All tests passed so we must be able to set a watchpoint. */
1105 return 1;
1106}
1107
1108/* Insert a Hardware breakpoint. */
1109static int
1110arm_linux_insert_watchpoint (CORE_ADDR addr, int len, int rw,
1111 struct expression *cond)
1112{
e3039479
UW
1113 struct lwp_info *lp;
1114 struct arm_linux_hw_breakpoint p;
1115
1116 if (arm_linux_get_hw_watchpoint_count () == 0)
1117 return -1;
1118
1119 arm_linux_hw_watchpoint_initialize (addr, len, rw, &p);
4c38200f 1120 ALL_LWPS (lp)
dfd4cc63 1121 arm_linux_insert_hw_breakpoint1 (&p, ptid_get_lwp (lp->ptid), 1);
e3039479
UW
1122
1123 return 0;
1124}
1125
1126/* Remove a hardware breakpoint. */
1127static int
1128arm_linux_remove_watchpoint (CORE_ADDR addr, int len, int rw,
1129 struct expression *cond)
1130{
e3039479
UW
1131 struct lwp_info *lp;
1132 struct arm_linux_hw_breakpoint p;
1133
1134 if (arm_linux_get_hw_watchpoint_count () == 0)
1135 return -1;
1136
1137 arm_linux_hw_watchpoint_initialize (addr, len, rw, &p);
4c38200f 1138 ALL_LWPS (lp)
dfd4cc63 1139 arm_linux_remove_hw_breakpoint1 (&p, ptid_get_lwp (lp->ptid), 1);
e3039479
UW
1140
1141 return 0;
1142}
1143
1144/* What was the data address the target was stopped on accessing. */
1145static int
1146arm_linux_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p)
1147{
f865ee35
JK
1148 siginfo_t siginfo;
1149 int slot;
1150
1151 if (!linux_nat_get_siginfo (inferior_ptid, &siginfo))
1152 return 0;
e3039479
UW
1153
1154 /* This must be a hardware breakpoint. */
f865ee35
JK
1155 if (siginfo.si_signo != SIGTRAP
1156 || (siginfo.si_code & 0xffff) != 0x0004 /* TRAP_HWBKPT */)
e3039479
UW
1157 return 0;
1158
1159 /* We must be able to set hardware watchpoints. */
1160 if (arm_linux_get_hw_watchpoint_count () == 0)
1161 return 0;
1162
f865ee35
JK
1163 slot = siginfo.si_errno;
1164
e3039479
UW
1165 /* If we are in a positive slot then we're looking at a breakpoint and not
1166 a watchpoint. */
1167 if (slot >= 0)
1168 return 0;
1169
f865ee35 1170 *addr_p = (CORE_ADDR) (uintptr_t) siginfo.si_addr;
e3039479
UW
1171 return 1;
1172}
1173
1174/* Has the target been stopped by hitting a watchpoint? */
1175static int
6a109b6b 1176arm_linux_stopped_by_watchpoint (struct target_ops *ops)
e3039479
UW
1177{
1178 CORE_ADDR addr;
6a109b6b 1179 return arm_linux_stopped_data_address (ops, &addr);
e3039479
UW
1180}
1181
1182static int
1183arm_linux_watchpoint_addr_within_range (struct target_ops *target,
1184 CORE_ADDR addr,
1185 CORE_ADDR start, int length)
1186{
1187 return start <= addr && start + length - 1 >= addr;
1188}
1189
1190/* Handle thread creation. We need to copy the breakpoints and watchpoints
1191 in the parent thread to the child thread. */
1192static void
7b50312a 1193arm_linux_new_thread (struct lwp_info *lp)
e3039479 1194{
dfd4cc63 1195 int tid = ptid_get_lwp (lp->ptid);
e3039479
UW
1196 const struct arm_linux_hwbp_cap *info = arm_linux_get_hwbp_cap ();
1197
1198 if (info != NULL)
1199 {
1200 int i;
1201 struct arm_linux_thread_points *p;
1202 struct arm_linux_hw_breakpoint *bpts;
1203
1204 if (VEC_empty (arm_linux_thread_points_p, arm_threads))
1205 return;
1206
1207 /* Get a list of breakpoints from any thread. */
1208 p = VEC_last (arm_linux_thread_points_p, arm_threads);
1209
1210 /* Copy that thread's breakpoints and watchpoints to the new thread. */
1211 for (i = 0; i < info->bp_count; i++)
1212 if (arm_hwbp_control_is_enabled (p->bpts[i].control))
1213 arm_linux_insert_hw_breakpoint1 (p->bpts + i, tid, 0);
1214 for (i = 0; i < info->wp_count; i++)
1215 if (arm_hwbp_control_is_enabled (p->wpts[i].control))
1216 arm_linux_insert_hw_breakpoint1 (p->wpts + i, tid, 1);
1217 }
1218}
1219
1220/* Handle thread exit. Tidy up the memory that has been allocated for the
1221 thread. */
1222static void
1223arm_linux_thread_exit (struct thread_info *tp, int silent)
1224{
1225 const struct arm_linux_hwbp_cap *info = arm_linux_get_hwbp_cap ();
1226
1227 if (info != NULL)
1228 {
1229 int i;
dfd4cc63 1230 int tid = ptid_get_lwp (tp->ptid);
e3039479
UW
1231 struct arm_linux_thread_points *t = NULL, *p;
1232
1233 for (i = 0;
1234 VEC_iterate (arm_linux_thread_points_p, arm_threads, i, p); i++)
1235 {
1236 if (p->tid == tid)
1237 {
1238 t = p;
1239 break;
1240 }
1241 }
1242
1243 if (t == NULL)
1244 return;
1245
1246 VEC_unordered_remove (arm_linux_thread_points_p, arm_threads, i);
1247
1248 xfree (t->bpts);
1249 xfree (t->wpts);
1250 xfree (t);
1251 }
1252}
1253
10d6c8cd
DJ
1254void _initialize_arm_linux_nat (void);
1255
ed9a39eb
JM
1256void
1257_initialize_arm_linux_nat (void)
1258{
10d6c8cd
DJ
1259 struct target_ops *t;
1260
10d6c8cd
DJ
1261 /* Fill in the generic GNU/Linux methods. */
1262 t = linux_target ();
1263
1264 /* Add our register access methods. */
1265 t->to_fetch_registers = arm_linux_fetch_inferior_registers;
1266 t->to_store_registers = arm_linux_store_inferior_registers;
1267
e3039479
UW
1268 /* Add our hardware breakpoint and watchpoint implementation. */
1269 t->to_can_use_hw_breakpoint = arm_linux_can_use_hw_breakpoint;
1270 t->to_insert_hw_breakpoint = arm_linux_insert_hw_breakpoint;
1271 t->to_remove_hw_breakpoint = arm_linux_remove_hw_breakpoint;
1272 t->to_region_ok_for_hw_watchpoint = arm_linux_region_ok_for_hw_watchpoint;
1273 t->to_insert_watchpoint = arm_linux_insert_watchpoint;
1274 t->to_remove_watchpoint = arm_linux_remove_watchpoint;
1275 t->to_stopped_by_watchpoint = arm_linux_stopped_by_watchpoint;
1276 t->to_stopped_data_address = arm_linux_stopped_data_address;
1277 t->to_watchpoint_addr_within_range = arm_linux_watchpoint_addr_within_range;
1278
81adfced 1279 t->to_read_description = arm_linux_read_description;
05a4558a 1280
10d6c8cd 1281 /* Register the target. */
f973ed9c 1282 linux_nat_add_target (t);
e3039479
UW
1283
1284 /* Handle thread creation and exit */
1285 observer_attach_thread_exit (arm_linux_thread_exit);
1286 linux_nat_set_new_thread (t, arm_linux_new_thread);
ed9a39eb 1287}
This page took 0.848682 seconds and 4 git commands to generate.