1 /* PPC GNU/Linux native support.
3 Copyright (C) 1988-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
23 #include "gdbthread.h"
28 #include "linux-nat.h"
29 #include <sys/types.h>
32 #include <sys/ioctl.h>
34 #include "gdbsupport/gdb_wait.h"
36 #include <sys/procfs.h>
37 #include "nat/gdb_ptrace.h"
38 #include "nat/linux-ptrace.h"
39 #include "inf-ptrace.h"
41 #include <unordered_map>
44 /* Prototypes for supply_gregset etc. */
47 #include "ppc-linux-tdep.h"
49 /* Required when using the AUXV. */
50 #include "elf/common.h"
53 #include "arch/ppc-linux-common.h"
54 #include "arch/ppc-linux-tdesc.h"
55 #include "nat/ppc-linux.h"
56 #include "linux-tdep.h"
59 /* Similarly for the hardware watchpoint support. These requests are used
60 when the PowerPC HWDEBUG ptrace interface is not available. */
61 #ifndef PTRACE_GET_DEBUGREG
62 #define PTRACE_GET_DEBUGREG 25
64 #ifndef PTRACE_SET_DEBUGREG
65 #define PTRACE_SET_DEBUGREG 26
67 #ifndef PTRACE_GETSIGINFO
68 #define PTRACE_GETSIGINFO 0x4202
71 /* These requests are used when the PowerPC HWDEBUG ptrace interface is
72 available. It exposes the debug facilities of PowerPC processors, as well
73 as additional features of BookE processors, such as ranged breakpoints and
74 watchpoints and hardware-accelerated condition evaluation. */
75 #ifndef PPC_PTRACE_GETHWDBGINFO
77 /* Not having PPC_PTRACE_GETHWDBGINFO defined means that the PowerPC HWDEBUG
78 ptrace interface is not present in ptrace.h, so we'll have to pretty much
79 include it all here so that the code at least compiles on older systems. */
80 #define PPC_PTRACE_GETHWDBGINFO 0x89
81 #define PPC_PTRACE_SETHWDEBUG 0x88
82 #define PPC_PTRACE_DELHWDEBUG 0x87
86 uint32_t version
; /* Only version 1 exists to date. */
87 uint32_t num_instruction_bps
;
88 uint32_t num_data_bps
;
89 uint32_t num_condition_regs
;
90 uint32_t data_bp_alignment
;
91 uint32_t sizeof_condition
; /* size of the DVC register. */
95 /* Features will have bits indicating whether there is support for: */
96 #define PPC_DEBUG_FEATURE_INSN_BP_RANGE 0x1
97 #define PPC_DEBUG_FEATURE_INSN_BP_MASK 0x2
98 #define PPC_DEBUG_FEATURE_DATA_BP_RANGE 0x4
99 #define PPC_DEBUG_FEATURE_DATA_BP_MASK 0x8
101 struct ppc_hw_breakpoint
103 uint32_t version
; /* currently, version must be 1 */
104 uint32_t trigger_type
; /* only some combinations allowed */
105 uint32_t addr_mode
; /* address match mode */
106 uint32_t condition_mode
; /* break/watchpoint condition flags */
107 uint64_t addr
; /* break/watchpoint address */
108 uint64_t addr2
; /* range end or mask */
109 uint64_t condition_value
; /* contents of the DVC register */
113 #define PPC_BREAKPOINT_TRIGGER_EXECUTE 0x1
114 #define PPC_BREAKPOINT_TRIGGER_READ 0x2
115 #define PPC_BREAKPOINT_TRIGGER_WRITE 0x4
116 #define PPC_BREAKPOINT_TRIGGER_RW 0x6
119 #define PPC_BREAKPOINT_MODE_EXACT 0x0
120 #define PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE 0x1
121 #define PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE 0x2
122 #define PPC_BREAKPOINT_MODE_MASK 0x3
124 /* Condition mode. */
125 #define PPC_BREAKPOINT_CONDITION_NONE 0x0
126 #define PPC_BREAKPOINT_CONDITION_AND 0x1
127 #define PPC_BREAKPOINT_CONDITION_EXACT 0x1
128 #define PPC_BREAKPOINT_CONDITION_OR 0x2
129 #define PPC_BREAKPOINT_CONDITION_AND_OR 0x3
130 #define PPC_BREAKPOINT_CONDITION_BE_ALL 0x00ff0000
131 #define PPC_BREAKPOINT_CONDITION_BE_SHIFT 16
132 #define PPC_BREAKPOINT_CONDITION_BE(n) \
133 (1<<((n)+PPC_BREAKPOINT_CONDITION_BE_SHIFT))
134 #endif /* PPC_PTRACE_GETHWDBGINFO */
136 /* Feature defined on Linux kernel v3.9: DAWR interface, that enables wider
137 watchpoint (up to 512 bytes). */
138 #ifndef PPC_DEBUG_FEATURE_DATA_BP_DAWR
139 #define PPC_DEBUG_FEATURE_DATA_BP_DAWR 0x10
140 #endif /* PPC_DEBUG_FEATURE_DATA_BP_DAWR */
142 /* Feature defined on Linux kernel v5.1: Second watchpoint support. */
143 #ifndef PPC_DEBUG_FEATURE_DATA_BP_ARCH_31
144 #define PPC_DEBUG_FEATURE_DATA_BP_ARCH_31 0x20
145 #endif /* PPC_DEBUG_FEATURE_DATA_BP_ARCH_31 */
147 /* The version of the PowerPC HWDEBUG kernel interface that we will use, if
149 #define PPC_DEBUG_CURRENT_VERSION 1
151 /* Similarly for the general-purpose (gp0 -- gp31)
152 and floating-point registers (fp0 -- fp31). */
153 #ifndef PTRACE_GETREGS
154 #define PTRACE_GETREGS 12
156 #ifndef PTRACE_SETREGS
157 #define PTRACE_SETREGS 13
159 #ifndef PTRACE_GETFPREGS
160 #define PTRACE_GETFPREGS 14
162 #ifndef PTRACE_SETFPREGS
163 #define PTRACE_SETFPREGS 15
166 /* This oddity is because the Linux kernel defines elf_vrregset_t as
167 an array of 33 16 bytes long elements. I.e. it leaves out vrsave.
168 However the PTRACE_GETVRREGS and PTRACE_SETVRREGS requests return
169 the vrsave as an extra 4 bytes at the end. I opted for creating a
170 flat array of chars, so that it is easier to manipulate for gdb.
172 There are 32 vector registers 16 bytes longs, plus a VSCR register
173 which is only 4 bytes long, but is fetched as a 16 bytes
174 quantity. Up to here we have the elf_vrregset_t structure.
175 Appended to this there is space for the VRSAVE register: 4 bytes.
176 Even though this vrsave register is not included in the regset
177 typedef, it is handled by the ptrace requests.
179 The layout is like this (where x is the actual value of the vscr reg): */
184 |.|.|.|.|.....|.|.|.|.||.|.|.|x||.|
185 <-------> <-------><-------><->
188 |.|.|.|.|.....|.|.|.|.||X|.|.|.||.|
189 <-------> <-------><-------><->
194 typedef char gdb_vrregset_t
[PPC_LINUX_SIZEOF_VRREGSET
];
196 /* This is the layout of the POWER7 VSX registers and the way they overlap
197 with the existing FPR and VMX registers.
199 VSR doubleword 0 VSR doubleword 1
200 ----------------------------------------------------------------
202 ----------------------------------------------------------------
204 ----------------------------------------------------------------
207 ----------------------------------------------------------------
208 VSR[30] | FPR[30] | |
209 ----------------------------------------------------------------
210 VSR[31] | FPR[31] | |
211 ----------------------------------------------------------------
213 ----------------------------------------------------------------
215 ----------------------------------------------------------------
218 ----------------------------------------------------------------
220 ----------------------------------------------------------------
222 ----------------------------------------------------------------
224 VSX has 64 128bit registers. The first 32 registers overlap with
225 the FP registers (doubleword 0) and hence extend them with additional
226 64 bits (doubleword 1). The other 32 regs overlap with the VMX
228 typedef char gdb_vsxregset_t
[PPC_LINUX_SIZEOF_VSXREGSET
];
230 /* On PPC processors that support the Signal Processing Extension
231 (SPE) APU, the general-purpose registers are 64 bits long.
232 However, the ordinary Linux kernel PTRACE_PEEKUSER / PTRACE_POKEUSER
233 ptrace calls only access the lower half of each register, to allow
234 them to behave the same way they do on non-SPE systems. There's a
235 separate pair of calls, PTRACE_GETEVRREGS / PTRACE_SETEVRREGS, that
236 read and write the top halves of all the general-purpose registers
237 at once, along with some SPE-specific registers.
239 GDB itself continues to claim the general-purpose registers are 32
240 bits long. It has unnamed raw registers that hold the upper halves
241 of the gprs, and the full 64-bit SIMD views of the registers,
242 'ev0' -- 'ev31', are pseudo-registers that splice the top and
243 bottom halves together.
245 This is the structure filled in by PTRACE_GETEVRREGS and written to
246 the inferior's registers by PTRACE_SETEVRREGS. */
247 struct gdb_evrregset_t
249 unsigned long evr
[32];
250 unsigned long long acc
;
251 unsigned long spefscr
;
254 /* Non-zero if our kernel may support the PTRACE_GETVSXREGS and
255 PTRACE_SETVSXREGS requests, for reading and writing the VSX
256 POWER7 registers 0 through 31. Zero if we've tried one of them and
257 gotten an error. Note that VSX registers 32 through 63 overlap
258 with VR registers 0 through 31. */
259 int have_ptrace_getsetvsxregs
= 1;
261 /* Non-zero if our kernel may support the PTRACE_GETVRREGS and
262 PTRACE_SETVRREGS requests, for reading and writing the Altivec
263 registers. Zero if we've tried one of them and gotten an
265 int have_ptrace_getvrregs
= 1;
267 /* Non-zero if our kernel may support the PTRACE_GETEVRREGS and
268 PTRACE_SETEVRREGS requests, for reading and writing the SPE
269 registers. Zero if we've tried one of them and gotten an
271 int have_ptrace_getsetevrregs
= 1;
273 /* Non-zero if our kernel may support the PTRACE_GETREGS and
274 PTRACE_SETREGS requests, for reading and writing the
275 general-purpose registers. Zero if we've tried one of
276 them and gotten an error. */
277 int have_ptrace_getsetregs
= 1;
279 /* Non-zero if our kernel may support the PTRACE_GETFPREGS and
280 PTRACE_SETFPREGS requests, for reading and writing the
281 floating-pointers registers. Zero if we've tried one of
282 them and gotten an error. */
283 int have_ptrace_getsetfpregs
= 1;
285 /* Private arch info associated with each thread lwp_info object, used
286 for debug register handling. */
290 /* When true, indicates that the debug registers installed in the
291 thread no longer correspond to the watchpoints and breakpoints
293 bool debug_regs_stale
;
295 /* We need a back-reference to the PTID of the thread so that we can
296 cleanup the debug register state of the thread in
297 low_delete_thread. */
301 /* Class used to detect which set of ptrace requests that
302 ppc_linux_nat_target will use to install and remove hardware
303 breakpoints and watchpoints.
305 The interface is only detected once, testing the ptrace calls. The
306 result can indicate that no interface is available.
308 The Linux kernel provides two different sets of ptrace requests to
309 handle hardware watchpoints and breakpoints for Power:
311 - PPC_PTRACE_GETHWDBGINFO, PPC_PTRACE_SETHWDEBUG, and
312 PPC_PTRACE_DELHWDEBUG.
316 - PTRACE_SET_DEBUGREG and PTRACE_GET_DEBUGREG
318 The first set is the more flexible one and allows setting watchpoints
319 with a variable watched region length and, for BookE processors,
320 multiple types of debug registers (e.g. hardware breakpoints and
321 hardware-assisted conditions for watchpoints). The second one only
322 allows setting one debug register, a watchpoint, so we only use it if
323 the first one is not available. */
325 class ppc_linux_dreg_interface
329 ppc_linux_dreg_interface ()
330 : m_interface (), m_hwdebug_info ()
334 DISABLE_COPY_AND_ASSIGN (ppc_linux_dreg_interface
);
336 /* One and only one of these three functions returns true, indicating
337 whether the corresponding interface is the one we detected. The
338 interface must already have been detected as a precontidion. */
342 gdb_assert (detected_p ());
343 return *m_interface
== HWDEBUG
;
348 gdb_assert (detected_p ());
349 return *m_interface
== DEBUGREG
;
352 bool unavailable_p ()
354 gdb_assert (detected_p ());
355 return *m_interface
== UNAVAILABLE
;
358 /* Returns the debug register capabilities of the target. Should only
359 be called if the interface is HWDEBUG. */
360 const struct ppc_debug_info
&hwdebug_info ()
362 gdb_assert (hwdebug_p ());
364 return m_hwdebug_info
;
367 /* Returns true if the interface has already been detected. This is
368 useful for cases when we know there is no work to be done if the
369 interface hasn't been detected yet. */
372 return m_interface
.has_value ();
375 /* Detect the available interface, if any, if it hasn't been detected
376 before, using PTID for the necessary ptrace calls. */
378 void detect (const ptid_t
&ptid
)
380 if (m_interface
.has_value ())
383 gdb_assert (ptid
.lwp_p ());
385 bool no_features
= false;
387 if (ptrace (PPC_PTRACE_GETHWDBGINFO
, ptid
.lwp (), 0, &m_hwdebug_info
)
390 /* If there are no advertised features, we don't use the
391 HWDEBUG interface and try the DEBUGREG interface instead.
392 It shouldn't be necessary to do this, however, when the
393 kernel is configured without CONFIG_HW_BREAKPOINTS (selected
394 by CONFIG_PERF_EVENTS), there is a bug that causes
395 watchpoints installed with the HWDEBUG interface not to
396 trigger. When this is the case, features will be zero,
397 which we use as an indicator to fall back to the DEBUGREG
399 if (m_hwdebug_info
.features
!= 0)
401 m_interface
.emplace (HWDEBUG
);
408 /* EIO indicates that the request is invalid, so we try DEBUGREG
409 next. Technically, it can also indicate other failures, but we
410 can't differentiate those.
412 Other errors could happen for various reasons. We could get an
413 ESRCH if the traced thread was killed by a signal. Trying to
414 detect the interface with another thread in the future would be
415 complicated, as callers would have to handle an "unknown
416 interface" case. It's also unclear if raising an exception
419 Other errors, such as ENODEV, could be more permanent and cause
420 a failure for any thread.
422 For simplicity, with all errors other than EIO, we set the
423 interface to UNAVAILABLE and don't try DEBUGREG. If DEBUGREG
424 fails too, we'll also set the interface to UNAVAILABLE. It's
425 unlikely that trying the DEBUGREG interface with this same thread
426 would work, for errors other than EIO. This means that these
427 errors will cause hardware watchpoints and breakpoints to become
428 unavailable throughout a GDB session. */
430 if (no_features
|| errno
== EIO
)
434 if (ptrace (PTRACE_GET_DEBUGREG
, ptid
.lwp (), 0, &wp
) >= 0)
436 m_interface
.emplace (DEBUGREG
);
442 warning (_("Error when detecting the debug register interface. "
443 "Debug registers will be unavailable."));
445 m_interface
.emplace (UNAVAILABLE
);
451 /* HWDEBUG represents the set of calls PPC_PTRACE_GETHWDBGINFO,
452 PPC_PTRACE_SETHWDEBUG and PPC_PTRACE_DELHWDEBUG.
454 DEBUGREG represents the set of calls PTRACE_SET_DEBUGREG and
457 UNAVAILABLE can indicate that the kernel doesn't support any of the
458 two sets of requests or that there was an error when we tried to
459 detect wich interface is available. */
461 enum debug_reg_interface
468 /* The interface option. Initialized if has_value () returns true. */
469 gdb::optional
<enum debug_reg_interface
> m_interface
;
471 /* The info returned by the kernel with PPC_PTRACE_GETHWDBGINFO. Only
472 valid if we determined that the interface is HWDEBUG. */
473 struct ppc_debug_info m_hwdebug_info
;
476 /* Per-process information. This includes the hardware watchpoints and
477 breakpoints that GDB requested to this target. */
479 struct ppc_linux_process_info
481 /* The list of hardware watchpoints and breakpoints that GDB requested
484 Only used when the interface is HWDEBUG. */
485 std::list
<struct ppc_hw_breakpoint
> requested_hw_bps
;
487 /* The watchpoint value that GDB requested for this process.
489 Only used when the interface is DEBUGREG. */
490 gdb::optional
<long> requested_wp_val
;
493 struct ppc_linux_nat_target final
: public linux_nat_target
495 /* Add our register access methods. */
496 void fetch_registers (struct regcache
*, int) override
;
497 void store_registers (struct regcache
*, int) override
;
499 /* Add our breakpoint/watchpoint methods. */
500 int can_use_hw_breakpoint (enum bptype
, int, int) override
;
502 int insert_hw_breakpoint (struct gdbarch
*, struct bp_target_info
*)
505 int remove_hw_breakpoint (struct gdbarch
*, struct bp_target_info
*)
508 int region_ok_for_hw_watchpoint (CORE_ADDR
, int) override
;
510 int insert_watchpoint (CORE_ADDR
, int, enum target_hw_bp_type
,
511 struct expression
*) override
;
513 int remove_watchpoint (CORE_ADDR
, int, enum target_hw_bp_type
,
514 struct expression
*) override
;
516 int insert_mask_watchpoint (CORE_ADDR
, CORE_ADDR
, enum target_hw_bp_type
)
519 int remove_mask_watchpoint (CORE_ADDR
, CORE_ADDR
, enum target_hw_bp_type
)
522 bool watchpoint_addr_within_range (CORE_ADDR
, CORE_ADDR
, int) override
;
524 bool can_accel_watchpoint_condition (CORE_ADDR
, int, int, struct expression
*)
527 int masked_watch_num_registers (CORE_ADDR
, CORE_ADDR
) override
;
529 int ranged_break_num_registers () override
;
531 const struct target_desc
*read_description () override
;
533 int auxv_parse (gdb_byte
**readptr
,
534 gdb_byte
*endptr
, CORE_ADDR
*typep
, CORE_ADDR
*valp
)
537 /* Override linux_nat_target low methods. */
538 bool low_stopped_by_watchpoint () override
;
540 bool low_stopped_data_address (CORE_ADDR
*) override
;
542 void low_new_thread (struct lwp_info
*lp
) override
;
544 void low_delete_thread (arch_lwp_info
*) override
;
546 void low_new_fork (struct lwp_info
*, pid_t
) override
;
548 void low_new_clone (struct lwp_info
*, pid_t
) override
;
550 void low_forget_process (pid_t pid
) override
;
552 void low_prepare_to_resume (struct lwp_info
*) override
;
556 void copy_thread_dreg_state (const ptid_t
&parent_ptid
,
557 const ptid_t
&child_ptid
);
559 void mark_thread_stale (struct lwp_info
*lp
);
561 void mark_debug_registers_changed (pid_t pid
);
563 void register_hw_breakpoint (pid_t pid
,
564 const struct ppc_hw_breakpoint
&bp
);
566 void clear_hw_breakpoint (pid_t pid
,
567 const struct ppc_hw_breakpoint
&a
);
569 void register_wp (pid_t pid
, long wp_value
);
571 void clear_wp (pid_t pid
);
573 bool can_use_watchpoint_cond_accel (void);
575 void calculate_dvc (CORE_ADDR addr
, int len
,
576 CORE_ADDR data_value
,
577 uint32_t *condition_mode
,
578 uint64_t *condition_value
);
580 int check_condition (CORE_ADDR watch_addr
,
581 struct expression
*cond
,
582 CORE_ADDR
*data_value
, int *len
);
584 int num_memory_accesses (const std::vector
<value_ref_ptr
> &chain
);
586 int get_trigger_type (enum target_hw_bp_type type
);
588 void create_watchpoint_request (struct ppc_hw_breakpoint
*p
,
591 enum target_hw_bp_type type
,
592 struct expression
*cond
,
595 bool hwdebug_point_cmp (const struct ppc_hw_breakpoint
&a
,
596 const struct ppc_hw_breakpoint
&b
);
598 void init_arch_lwp_info (struct lwp_info
*lp
);
600 arch_lwp_info
*get_arch_lwp_info (struct lwp_info
*lp
);
602 /* The ptrace interface we'll use to install hardware watchpoints and
603 breakpoints (debug registers). */
604 ppc_linux_dreg_interface m_dreg_interface
;
606 /* A map from pids to structs containing info specific to each
608 std::unordered_map
<pid_t
, ppc_linux_process_info
> m_process_info
;
610 /* Callable object to hash ptids by their lwp number. */
613 std::size_t operator() (const ptid_t
&ptid
) const
615 return std::hash
<long>{} (ptid
.lwp ());
619 /* A map from ptid_t objects to a list of pairs of slots and hardware
620 breakpoint objects. This keeps track of which hardware breakpoints
621 and watchpoints were last installed in each slot of each thread.
623 Only used when the interface is HWDEBUG. */
624 std::unordered_map
<ptid_t
,
625 std::list
<std::pair
<long, ppc_hw_breakpoint
>>,
626 ptid_hash
> m_installed_hw_bps
;
629 static ppc_linux_nat_target the_ppc_linux_nat_target
;
632 /* registers layout, as presented by the ptrace interface:
633 PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5, PT_R6, PT_R7,
634 PT_R8, PT_R9, PT_R10, PT_R11, PT_R12, PT_R13, PT_R14, PT_R15,
635 PT_R16, PT_R17, PT_R18, PT_R19, PT_R20, PT_R21, PT_R22, PT_R23,
636 PT_R24, PT_R25, PT_R26, PT_R27, PT_R28, PT_R29, PT_R30, PT_R31,
637 PT_FPR0, PT_FPR0 + 2, PT_FPR0 + 4, PT_FPR0 + 6,
638 PT_FPR0 + 8, PT_FPR0 + 10, PT_FPR0 + 12, PT_FPR0 + 14,
639 PT_FPR0 + 16, PT_FPR0 + 18, PT_FPR0 + 20, PT_FPR0 + 22,
640 PT_FPR0 + 24, PT_FPR0 + 26, PT_FPR0 + 28, PT_FPR0 + 30,
641 PT_FPR0 + 32, PT_FPR0 + 34, PT_FPR0 + 36, PT_FPR0 + 38,
642 PT_FPR0 + 40, PT_FPR0 + 42, PT_FPR0 + 44, PT_FPR0 + 46,
643 PT_FPR0 + 48, PT_FPR0 + 50, PT_FPR0 + 52, PT_FPR0 + 54,
644 PT_FPR0 + 56, PT_FPR0 + 58, PT_FPR0 + 60, PT_FPR0 + 62,
645 PT_NIP, PT_MSR, PT_CCR, PT_LNK, PT_CTR, PT_XER, PT_MQ */
649 ppc_register_u_addr (struct gdbarch
*gdbarch
, int regno
)
652 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
653 /* NOTE: cagney/2003-11-25: This is the word size used by the ptrace
654 interface, and not the wordsize of the program's ABI. */
655 int wordsize
= sizeof (long);
657 /* General purpose registers occupy 1 slot each in the buffer. */
658 if (regno
>= tdep
->ppc_gp0_regnum
659 && regno
< tdep
->ppc_gp0_regnum
+ ppc_num_gprs
)
660 u_addr
= ((regno
- tdep
->ppc_gp0_regnum
+ PT_R0
) * wordsize
);
662 /* Floating point regs: eight bytes each in both 32- and 64-bit
663 ptrace interfaces. Thus, two slots each in 32-bit interface, one
664 slot each in 64-bit interface. */
665 if (tdep
->ppc_fp0_regnum
>= 0
666 && regno
>= tdep
->ppc_fp0_regnum
667 && regno
< tdep
->ppc_fp0_regnum
+ ppc_num_fprs
)
668 u_addr
= (PT_FPR0
* wordsize
) + ((regno
- tdep
->ppc_fp0_regnum
) * 8);
670 /* UISA special purpose registers: 1 slot each. */
671 if (regno
== gdbarch_pc_regnum (gdbarch
))
672 u_addr
= PT_NIP
* wordsize
;
673 if (regno
== tdep
->ppc_lr_regnum
)
674 u_addr
= PT_LNK
* wordsize
;
675 if (regno
== tdep
->ppc_cr_regnum
)
676 u_addr
= PT_CCR
* wordsize
;
677 if (regno
== tdep
->ppc_xer_regnum
)
678 u_addr
= PT_XER
* wordsize
;
679 if (regno
== tdep
->ppc_ctr_regnum
)
680 u_addr
= PT_CTR
* wordsize
;
682 if (regno
== tdep
->ppc_mq_regnum
)
683 u_addr
= PT_MQ
* wordsize
;
685 if (regno
== tdep
->ppc_ps_regnum
)
686 u_addr
= PT_MSR
* wordsize
;
687 if (regno
== PPC_ORIG_R3_REGNUM
)
688 u_addr
= PT_ORIG_R3
* wordsize
;
689 if (regno
== PPC_TRAP_REGNUM
)
690 u_addr
= PT_TRAP
* wordsize
;
691 if (tdep
->ppc_fpscr_regnum
>= 0
692 && regno
== tdep
->ppc_fpscr_regnum
)
694 /* NOTE: cagney/2005-02-08: On some 64-bit GNU/Linux systems the
695 kernel headers incorrectly contained the 32-bit definition of
696 PT_FPSCR. For the 32-bit definition, floating-point
697 registers occupy two 32-bit "slots", and the FPSCR lives in
698 the second half of such a slot-pair (hence +1). For 64-bit,
699 the FPSCR instead occupies the full 64-bit 2-word-slot and
700 hence no adjustment is necessary. Hack around this. */
701 if (wordsize
== 8 && PT_FPSCR
== (48 + 32 + 1))
702 u_addr
= (48 + 32) * wordsize
;
703 /* If the FPSCR is 64-bit wide, we need to fetch the whole 64-bit
704 slot and not just its second word. The PT_FPSCR supplied when
705 GDB is compiled as a 32-bit app doesn't reflect this. */
706 else if (wordsize
== 4 && register_size (gdbarch
, regno
) == 8
707 && PT_FPSCR
== (48 + 2*32 + 1))
708 u_addr
= (48 + 2*32) * wordsize
;
710 u_addr
= PT_FPSCR
* wordsize
;
715 /* The Linux kernel ptrace interface for POWER7 VSX registers uses the
716 registers set mechanism, as opposed to the interface for all the
717 other registers, that stores/fetches each register individually. */
719 fetch_vsx_registers (struct regcache
*regcache
, int tid
, int regno
)
722 gdb_vsxregset_t regs
;
723 const struct regset
*vsxregset
= ppc_linux_vsxregset ();
725 ret
= ptrace (PTRACE_GETVSXREGS
, tid
, 0, ®s
);
730 have_ptrace_getsetvsxregs
= 0;
733 perror_with_name (_("Unable to fetch VSX registers"));
736 vsxregset
->supply_regset (vsxregset
, regcache
, regno
, ®s
,
737 PPC_LINUX_SIZEOF_VSXREGSET
);
740 /* The Linux kernel ptrace interface for AltiVec registers uses the
741 registers set mechanism, as opposed to the interface for all the
742 other registers, that stores/fetches each register individually. */
744 fetch_altivec_registers (struct regcache
*regcache
, int tid
,
749 struct gdbarch
*gdbarch
= regcache
->arch ();
750 const struct regset
*vrregset
= ppc_linux_vrregset (gdbarch
);
752 ret
= ptrace (PTRACE_GETVRREGS
, tid
, 0, ®s
);
757 have_ptrace_getvrregs
= 0;
760 perror_with_name (_("Unable to fetch AltiVec registers"));
763 vrregset
->supply_regset (vrregset
, regcache
, regno
, ®s
,
764 PPC_LINUX_SIZEOF_VRREGSET
);
767 /* Fetch the top 32 bits of TID's general-purpose registers and the
768 SPE-specific registers, and place the results in EVRREGSET. If we
769 don't support PTRACE_GETEVRREGS, then just fill EVRREGSET with
772 All the logic to deal with whether or not the PTRACE_GETEVRREGS and
773 PTRACE_SETEVRREGS requests are supported is isolated here, and in
774 set_spe_registers. */
776 get_spe_registers (int tid
, struct gdb_evrregset_t
*evrregset
)
778 if (have_ptrace_getsetevrregs
)
780 if (ptrace (PTRACE_GETEVRREGS
, tid
, 0, evrregset
) >= 0)
784 /* EIO means that the PTRACE_GETEVRREGS request isn't supported;
785 we just return zeros. */
787 have_ptrace_getsetevrregs
= 0;
789 /* Anything else needs to be reported. */
790 perror_with_name (_("Unable to fetch SPE registers"));
794 memset (evrregset
, 0, sizeof (*evrregset
));
797 /* Supply values from TID for SPE-specific raw registers: the upper
798 halves of the GPRs, the accumulator, and the spefscr. REGNO must
799 be the number of an upper half register, acc, spefscr, or -1 to
800 supply the values of all registers. */
802 fetch_spe_register (struct regcache
*regcache
, int tid
, int regno
)
804 struct gdbarch
*gdbarch
= regcache
->arch ();
805 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
806 struct gdb_evrregset_t evrregs
;
808 gdb_assert (sizeof (evrregs
.evr
[0])
809 == register_size (gdbarch
, tdep
->ppc_ev0_upper_regnum
));
810 gdb_assert (sizeof (evrregs
.acc
)
811 == register_size (gdbarch
, tdep
->ppc_acc_regnum
));
812 gdb_assert (sizeof (evrregs
.spefscr
)
813 == register_size (gdbarch
, tdep
->ppc_spefscr_regnum
));
815 get_spe_registers (tid
, &evrregs
);
821 for (i
= 0; i
< ppc_num_gprs
; i
++)
822 regcache
->raw_supply (tdep
->ppc_ev0_upper_regnum
+ i
, &evrregs
.evr
[i
]);
824 else if (tdep
->ppc_ev0_upper_regnum
<= regno
825 && regno
< tdep
->ppc_ev0_upper_regnum
+ ppc_num_gprs
)
826 regcache
->raw_supply (regno
,
827 &evrregs
.evr
[regno
- tdep
->ppc_ev0_upper_regnum
]);
830 || regno
== tdep
->ppc_acc_regnum
)
831 regcache
->raw_supply (tdep
->ppc_acc_regnum
, &evrregs
.acc
);
834 || regno
== tdep
->ppc_spefscr_regnum
)
835 regcache
->raw_supply (tdep
->ppc_spefscr_regnum
, &evrregs
.spefscr
);
838 /* Use ptrace to fetch all registers from the register set with note
839 type REGSET_ID, size REGSIZE, and layout described by REGSET, from
840 process/thread TID and supply their values to REGCACHE. If ptrace
841 returns ENODATA to indicate the regset is unavailable, mark the
842 registers as unavailable in REGCACHE. */
845 fetch_regset (struct regcache
*regcache
, int tid
,
846 int regset_id
, int regsetsize
, const struct regset
*regset
)
848 void *buf
= alloca (regsetsize
);
852 iov
.iov_len
= regsetsize
;
854 if (ptrace (PTRACE_GETREGSET
, tid
, regset_id
, &iov
) < 0)
856 if (errno
== ENODATA
)
857 regset
->supply_regset (regset
, regcache
, -1, NULL
, regsetsize
);
859 perror_with_name (_("Couldn't get register set"));
862 regset
->supply_regset (regset
, regcache
, -1, buf
, regsetsize
);
865 /* Use ptrace to store register REGNUM of the regset with note type
866 REGSET_ID, size REGSETSIZE, and layout described by REGSET, from
867 REGCACHE back to process/thread TID. If REGNUM is -1 all registers
868 in the set are collected and stored. */
871 store_regset (const struct regcache
*regcache
, int tid
, int regnum
,
872 int regset_id
, int regsetsize
, const struct regset
*regset
)
874 void *buf
= alloca (regsetsize
);
878 iov
.iov_len
= regsetsize
;
880 /* Make sure that the buffer that will be stored has up to date values
881 for the registers that won't be collected. */
882 if (ptrace (PTRACE_GETREGSET
, tid
, regset_id
, &iov
) < 0)
883 perror_with_name (_("Couldn't get register set"));
885 regset
->collect_regset (regset
, regcache
, regnum
, buf
, regsetsize
);
887 if (ptrace (PTRACE_SETREGSET
, tid
, regset_id
, &iov
) < 0)
888 perror_with_name (_("Couldn't set register set"));
891 /* Check whether the kernel provides a register set with number
892 REGSET_ID of size REGSETSIZE for process/thread TID. */
895 check_regset (int tid
, int regset_id
, int regsetsize
)
897 void *buf
= alloca (regsetsize
);
901 iov
.iov_len
= regsetsize
;
903 if (ptrace (PTRACE_GETREGSET
, tid
, regset_id
, &iov
) >= 0
911 fetch_register (struct regcache
*regcache
, int tid
, int regno
)
913 struct gdbarch
*gdbarch
= regcache
->arch ();
914 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
915 /* This isn't really an address. But ptrace thinks of it as one. */
916 CORE_ADDR regaddr
= ppc_register_u_addr (gdbarch
, regno
);
917 int bytes_transferred
;
918 gdb_byte buf
[PPC_MAX_REGISTER_SIZE
];
920 if (altivec_register_p (gdbarch
, regno
))
922 /* If this is the first time through, or if it is not the first
923 time through, and we have confirmed that there is kernel
924 support for such a ptrace request, then go and fetch the
926 if (have_ptrace_getvrregs
)
928 fetch_altivec_registers (regcache
, tid
, regno
);
931 /* If we have discovered that there is no ptrace support for
932 AltiVec registers, fall through and return zeroes, because
933 regaddr will be -1 in this case. */
935 else if (vsx_register_p (gdbarch
, regno
))
937 if (have_ptrace_getsetvsxregs
)
939 fetch_vsx_registers (regcache
, tid
, regno
);
943 else if (spe_register_p (gdbarch
, regno
))
945 fetch_spe_register (regcache
, tid
, regno
);
948 else if (regno
== PPC_DSCR_REGNUM
)
950 gdb_assert (tdep
->ppc_dscr_regnum
!= -1);
952 fetch_regset (regcache
, tid
, NT_PPC_DSCR
,
953 PPC_LINUX_SIZEOF_DSCRREGSET
,
954 &ppc32_linux_dscrregset
);
957 else if (regno
== PPC_PPR_REGNUM
)
959 gdb_assert (tdep
->ppc_ppr_regnum
!= -1);
961 fetch_regset (regcache
, tid
, NT_PPC_PPR
,
962 PPC_LINUX_SIZEOF_PPRREGSET
,
963 &ppc32_linux_pprregset
);
966 else if (regno
== PPC_TAR_REGNUM
)
968 gdb_assert (tdep
->ppc_tar_regnum
!= -1);
970 fetch_regset (regcache
, tid
, NT_PPC_TAR
,
971 PPC_LINUX_SIZEOF_TARREGSET
,
972 &ppc32_linux_tarregset
);
975 else if (PPC_IS_EBB_REGNUM (regno
))
977 gdb_assert (tdep
->have_ebb
);
979 fetch_regset (regcache
, tid
, NT_PPC_EBB
,
980 PPC_LINUX_SIZEOF_EBBREGSET
,
981 &ppc32_linux_ebbregset
);
984 else if (PPC_IS_PMU_REGNUM (regno
))
986 gdb_assert (tdep
->ppc_mmcr0_regnum
!= -1);
988 fetch_regset (regcache
, tid
, NT_PPC_PMU
,
989 PPC_LINUX_SIZEOF_PMUREGSET
,
990 &ppc32_linux_pmuregset
);
993 else if (PPC_IS_TMSPR_REGNUM (regno
))
995 gdb_assert (tdep
->have_htm_spr
);
997 fetch_regset (regcache
, tid
, NT_PPC_TM_SPR
,
998 PPC_LINUX_SIZEOF_TM_SPRREGSET
,
999 &ppc32_linux_tm_sprregset
);
1002 else if (PPC_IS_CKPTGP_REGNUM (regno
))
1004 gdb_assert (tdep
->have_htm_core
);
1006 const struct regset
*cgprregset
= ppc_linux_cgprregset (gdbarch
);
1007 fetch_regset (regcache
, tid
, NT_PPC_TM_CGPR
,
1008 (tdep
->wordsize
== 4?
1009 PPC32_LINUX_SIZEOF_CGPRREGSET
1010 : PPC64_LINUX_SIZEOF_CGPRREGSET
),
1014 else if (PPC_IS_CKPTFP_REGNUM (regno
))
1016 gdb_assert (tdep
->have_htm_fpu
);
1018 fetch_regset (regcache
, tid
, NT_PPC_TM_CFPR
,
1019 PPC_LINUX_SIZEOF_CFPRREGSET
,
1020 &ppc32_linux_cfprregset
);
1023 else if (PPC_IS_CKPTVMX_REGNUM (regno
))
1025 gdb_assert (tdep
->have_htm_altivec
);
1027 const struct regset
*cvmxregset
= ppc_linux_cvmxregset (gdbarch
);
1028 fetch_regset (regcache
, tid
, NT_PPC_TM_CVMX
,
1029 PPC_LINUX_SIZEOF_CVMXREGSET
,
1033 else if (PPC_IS_CKPTVSX_REGNUM (regno
))
1035 gdb_assert (tdep
->have_htm_vsx
);
1037 fetch_regset (regcache
, tid
, NT_PPC_TM_CVSX
,
1038 PPC_LINUX_SIZEOF_CVSXREGSET
,
1039 &ppc32_linux_cvsxregset
);
1042 else if (regno
== PPC_CPPR_REGNUM
)
1044 gdb_assert (tdep
->ppc_cppr_regnum
!= -1);
1046 fetch_regset (regcache
, tid
, NT_PPC_TM_CPPR
,
1047 PPC_LINUX_SIZEOF_CPPRREGSET
,
1048 &ppc32_linux_cpprregset
);
1051 else if (regno
== PPC_CDSCR_REGNUM
)
1053 gdb_assert (tdep
->ppc_cdscr_regnum
!= -1);
1055 fetch_regset (regcache
, tid
, NT_PPC_TM_CDSCR
,
1056 PPC_LINUX_SIZEOF_CDSCRREGSET
,
1057 &ppc32_linux_cdscrregset
);
1060 else if (regno
== PPC_CTAR_REGNUM
)
1062 gdb_assert (tdep
->ppc_ctar_regnum
!= -1);
1064 fetch_regset (regcache
, tid
, NT_PPC_TM_CTAR
,
1065 PPC_LINUX_SIZEOF_CTARREGSET
,
1066 &ppc32_linux_ctarregset
);
1072 memset (buf
, '\0', register_size (gdbarch
, regno
)); /* Supply zeroes */
1073 regcache
->raw_supply (regno
, buf
);
1077 /* Read the raw register using sizeof(long) sized chunks. On a
1078 32-bit platform, 64-bit floating-point registers will require two
1080 for (bytes_transferred
= 0;
1081 bytes_transferred
< register_size (gdbarch
, regno
);
1082 bytes_transferred
+= sizeof (long))
1087 l
= ptrace (PTRACE_PEEKUSER
, tid
, (PTRACE_TYPE_ARG3
) regaddr
, 0);
1088 regaddr
+= sizeof (long);
1092 xsnprintf (message
, sizeof (message
), "reading register %s (#%d)",
1093 gdbarch_register_name (gdbarch
, regno
), regno
);
1094 perror_with_name (message
);
1096 memcpy (&buf
[bytes_transferred
], &l
, sizeof (l
));
1099 /* Now supply the register. Keep in mind that the regcache's idea
1100 of the register's size may not be a multiple of sizeof
1102 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_LITTLE
)
1104 /* Little-endian values are always found at the left end of the
1105 bytes transferred. */
1106 regcache
->raw_supply (regno
, buf
);
1108 else if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1110 /* Big-endian values are found at the right end of the bytes
1112 size_t padding
= (bytes_transferred
- register_size (gdbarch
, regno
));
1113 regcache
->raw_supply (regno
, buf
+ padding
);
1116 internal_error (__FILE__
, __LINE__
,
1117 _("fetch_register: unexpected byte order: %d"),
1118 gdbarch_byte_order (gdbarch
));
1121 /* This function actually issues the request to ptrace, telling
1122 it to get all general-purpose registers and put them into the
1125 If the ptrace request does not exist, this function returns 0
1126 and properly sets the have_ptrace_* flag. If the request fails,
1127 this function calls perror_with_name. Otherwise, if the request
1128 succeeds, then the regcache gets filled and 1 is returned. */
1130 fetch_all_gp_regs (struct regcache
*regcache
, int tid
)
1132 gdb_gregset_t gregset
;
1134 if (ptrace (PTRACE_GETREGS
, tid
, 0, (void *) &gregset
) < 0)
1138 have_ptrace_getsetregs
= 0;
1141 perror_with_name (_("Couldn't get general-purpose registers."));
1144 supply_gregset (regcache
, (const gdb_gregset_t
*) &gregset
);
1149 /* This is a wrapper for the fetch_all_gp_regs function. It is
1150 responsible for verifying if this target has the ptrace request
1151 that can be used to fetch all general-purpose registers at one
1152 shot. If it doesn't, then we should fetch them using the
1153 old-fashioned way, which is to iterate over the registers and
1154 request them one by one. */
1156 fetch_gp_regs (struct regcache
*regcache
, int tid
)
1158 struct gdbarch
*gdbarch
= regcache
->arch ();
1159 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
1162 if (have_ptrace_getsetregs
)
1163 if (fetch_all_gp_regs (regcache
, tid
))
1166 /* If we've hit this point, it doesn't really matter which
1167 architecture we are using. We just need to read the
1168 registers in the "old-fashioned way". */
1169 for (i
= 0; i
< ppc_num_gprs
; i
++)
1170 fetch_register (regcache
, tid
, tdep
->ppc_gp0_regnum
+ i
);
1173 /* This function actually issues the request to ptrace, telling
1174 it to get all floating-point registers and put them into the
1177 If the ptrace request does not exist, this function returns 0
1178 and properly sets the have_ptrace_* flag. If the request fails,
1179 this function calls perror_with_name. Otherwise, if the request
1180 succeeds, then the regcache gets filled and 1 is returned. */
1182 fetch_all_fp_regs (struct regcache
*regcache
, int tid
)
1184 gdb_fpregset_t fpregs
;
1186 if (ptrace (PTRACE_GETFPREGS
, tid
, 0, (void *) &fpregs
) < 0)
1190 have_ptrace_getsetfpregs
= 0;
1193 perror_with_name (_("Couldn't get floating-point registers."));
1196 supply_fpregset (regcache
, (const gdb_fpregset_t
*) &fpregs
);
1201 /* This is a wrapper for the fetch_all_fp_regs function. It is
1202 responsible for verifying if this target has the ptrace request
1203 that can be used to fetch all floating-point registers at one
1204 shot. If it doesn't, then we should fetch them using the
1205 old-fashioned way, which is to iterate over the registers and
1206 request them one by one. */
1208 fetch_fp_regs (struct regcache
*regcache
, int tid
)
1210 struct gdbarch
*gdbarch
= regcache
->arch ();
1211 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
1214 if (have_ptrace_getsetfpregs
)
1215 if (fetch_all_fp_regs (regcache
, tid
))
1218 /* If we've hit this point, it doesn't really matter which
1219 architecture we are using. We just need to read the
1220 registers in the "old-fashioned way". */
1221 for (i
= 0; i
< ppc_num_fprs
; i
++)
1222 fetch_register (regcache
, tid
, tdep
->ppc_fp0_regnum
+ i
);
1226 fetch_ppc_registers (struct regcache
*regcache
, int tid
)
1228 struct gdbarch
*gdbarch
= regcache
->arch ();
1229 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
1231 fetch_gp_regs (regcache
, tid
);
1232 if (tdep
->ppc_fp0_regnum
>= 0)
1233 fetch_fp_regs (regcache
, tid
);
1234 fetch_register (regcache
, tid
, gdbarch_pc_regnum (gdbarch
));
1235 if (tdep
->ppc_ps_regnum
!= -1)
1236 fetch_register (regcache
, tid
, tdep
->ppc_ps_regnum
);
1237 if (tdep
->ppc_cr_regnum
!= -1)
1238 fetch_register (regcache
, tid
, tdep
->ppc_cr_regnum
);
1239 if (tdep
->ppc_lr_regnum
!= -1)
1240 fetch_register (regcache
, tid
, tdep
->ppc_lr_regnum
);
1241 if (tdep
->ppc_ctr_regnum
!= -1)
1242 fetch_register (regcache
, tid
, tdep
->ppc_ctr_regnum
);
1243 if (tdep
->ppc_xer_regnum
!= -1)
1244 fetch_register (regcache
, tid
, tdep
->ppc_xer_regnum
);
1245 if (tdep
->ppc_mq_regnum
!= -1)
1246 fetch_register (regcache
, tid
, tdep
->ppc_mq_regnum
);
1247 if (ppc_linux_trap_reg_p (gdbarch
))
1249 fetch_register (regcache
, tid
, PPC_ORIG_R3_REGNUM
);
1250 fetch_register (regcache
, tid
, PPC_TRAP_REGNUM
);
1252 if (tdep
->ppc_fpscr_regnum
!= -1)
1253 fetch_register (regcache
, tid
, tdep
->ppc_fpscr_regnum
);
1254 if (have_ptrace_getvrregs
)
1255 if (tdep
->ppc_vr0_regnum
!= -1 && tdep
->ppc_vrsave_regnum
!= -1)
1256 fetch_altivec_registers (regcache
, tid
, -1);
1257 if (have_ptrace_getsetvsxregs
)
1258 if (tdep
->ppc_vsr0_upper_regnum
!= -1)
1259 fetch_vsx_registers (regcache
, tid
, -1);
1260 if (tdep
->ppc_ev0_upper_regnum
>= 0)
1261 fetch_spe_register (regcache
, tid
, -1);
1262 if (tdep
->ppc_ppr_regnum
!= -1)
1263 fetch_regset (regcache
, tid
, NT_PPC_PPR
,
1264 PPC_LINUX_SIZEOF_PPRREGSET
,
1265 &ppc32_linux_pprregset
);
1266 if (tdep
->ppc_dscr_regnum
!= -1)
1267 fetch_regset (regcache
, tid
, NT_PPC_DSCR
,
1268 PPC_LINUX_SIZEOF_DSCRREGSET
,
1269 &ppc32_linux_dscrregset
);
1270 if (tdep
->ppc_tar_regnum
!= -1)
1271 fetch_regset (regcache
, tid
, NT_PPC_TAR
,
1272 PPC_LINUX_SIZEOF_TARREGSET
,
1273 &ppc32_linux_tarregset
);
1275 fetch_regset (regcache
, tid
, NT_PPC_EBB
,
1276 PPC_LINUX_SIZEOF_EBBREGSET
,
1277 &ppc32_linux_ebbregset
);
1278 if (tdep
->ppc_mmcr0_regnum
!= -1)
1279 fetch_regset (regcache
, tid
, NT_PPC_PMU
,
1280 PPC_LINUX_SIZEOF_PMUREGSET
,
1281 &ppc32_linux_pmuregset
);
1282 if (tdep
->have_htm_spr
)
1283 fetch_regset (regcache
, tid
, NT_PPC_TM_SPR
,
1284 PPC_LINUX_SIZEOF_TM_SPRREGSET
,
1285 &ppc32_linux_tm_sprregset
);
1286 if (tdep
->have_htm_core
)
1288 const struct regset
*cgprregset
= ppc_linux_cgprregset (gdbarch
);
1289 fetch_regset (regcache
, tid
, NT_PPC_TM_CGPR
,
1290 (tdep
->wordsize
== 4?
1291 PPC32_LINUX_SIZEOF_CGPRREGSET
1292 : PPC64_LINUX_SIZEOF_CGPRREGSET
),
1295 if (tdep
->have_htm_fpu
)
1296 fetch_regset (regcache
, tid
, NT_PPC_TM_CFPR
,
1297 PPC_LINUX_SIZEOF_CFPRREGSET
,
1298 &ppc32_linux_cfprregset
);
1299 if (tdep
->have_htm_altivec
)
1301 const struct regset
*cvmxregset
= ppc_linux_cvmxregset (gdbarch
);
1302 fetch_regset (regcache
, tid
, NT_PPC_TM_CVMX
,
1303 PPC_LINUX_SIZEOF_CVMXREGSET
,
1306 if (tdep
->have_htm_vsx
)
1307 fetch_regset (regcache
, tid
, NT_PPC_TM_CVSX
,
1308 PPC_LINUX_SIZEOF_CVSXREGSET
,
1309 &ppc32_linux_cvsxregset
);
1310 if (tdep
->ppc_cppr_regnum
!= -1)
1311 fetch_regset (regcache
, tid
, NT_PPC_TM_CPPR
,
1312 PPC_LINUX_SIZEOF_CPPRREGSET
,
1313 &ppc32_linux_cpprregset
);
1314 if (tdep
->ppc_cdscr_regnum
!= -1)
1315 fetch_regset (regcache
, tid
, NT_PPC_TM_CDSCR
,
1316 PPC_LINUX_SIZEOF_CDSCRREGSET
,
1317 &ppc32_linux_cdscrregset
);
1318 if (tdep
->ppc_ctar_regnum
!= -1)
1319 fetch_regset (regcache
, tid
, NT_PPC_TM_CTAR
,
1320 PPC_LINUX_SIZEOF_CTARREGSET
,
1321 &ppc32_linux_ctarregset
);
1324 /* Fetch registers from the child process. Fetch all registers if
1325 regno == -1, otherwise fetch all general registers or all floating
1326 point registers depending upon the value of regno. */
1328 ppc_linux_nat_target::fetch_registers (struct regcache
*regcache
, int regno
)
1330 pid_t tid
= get_ptrace_pid (regcache
->ptid ());
1333 fetch_ppc_registers (regcache
, tid
);
1335 fetch_register (regcache
, tid
, regno
);
1339 store_vsx_registers (const struct regcache
*regcache
, int tid
, int regno
)
1342 gdb_vsxregset_t regs
;
1343 const struct regset
*vsxregset
= ppc_linux_vsxregset ();
1345 ret
= ptrace (PTRACE_GETVSXREGS
, tid
, 0, ®s
);
1350 have_ptrace_getsetvsxregs
= 0;
1353 perror_with_name (_("Unable to fetch VSX registers"));
1356 vsxregset
->collect_regset (vsxregset
, regcache
, regno
, ®s
,
1357 PPC_LINUX_SIZEOF_VSXREGSET
);
1359 ret
= ptrace (PTRACE_SETVSXREGS
, tid
, 0, ®s
);
1361 perror_with_name (_("Unable to store VSX registers"));
1365 store_altivec_registers (const struct regcache
*regcache
, int tid
,
1369 gdb_vrregset_t regs
;
1370 struct gdbarch
*gdbarch
= regcache
->arch ();
1371 const struct regset
*vrregset
= ppc_linux_vrregset (gdbarch
);
1373 ret
= ptrace (PTRACE_GETVRREGS
, tid
, 0, ®s
);
1378 have_ptrace_getvrregs
= 0;
1381 perror_with_name (_("Unable to fetch AltiVec registers"));
1384 vrregset
->collect_regset (vrregset
, regcache
, regno
, ®s
,
1385 PPC_LINUX_SIZEOF_VRREGSET
);
1387 ret
= ptrace (PTRACE_SETVRREGS
, tid
, 0, ®s
);
1389 perror_with_name (_("Unable to store AltiVec registers"));
1392 /* Assuming TID refers to an SPE process, set the top halves of TID's
1393 general-purpose registers and its SPE-specific registers to the
1394 values in EVRREGSET. If we don't support PTRACE_SETEVRREGS, do
1397 All the logic to deal with whether or not the PTRACE_GETEVRREGS and
1398 PTRACE_SETEVRREGS requests are supported is isolated here, and in
1399 get_spe_registers. */
1401 set_spe_registers (int tid
, struct gdb_evrregset_t
*evrregset
)
1403 if (have_ptrace_getsetevrregs
)
1405 if (ptrace (PTRACE_SETEVRREGS
, tid
, 0, evrregset
) >= 0)
1409 /* EIO means that the PTRACE_SETEVRREGS request isn't
1410 supported; we fail silently, and don't try the call
1413 have_ptrace_getsetevrregs
= 0;
1415 /* Anything else needs to be reported. */
1416 perror_with_name (_("Unable to set SPE registers"));
1421 /* Write GDB's value for the SPE-specific raw register REGNO to TID.
1422 If REGNO is -1, write the values of all the SPE-specific
1425 store_spe_register (const struct regcache
*regcache
, int tid
, int regno
)
1427 struct gdbarch
*gdbarch
= regcache
->arch ();
1428 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
1429 struct gdb_evrregset_t evrregs
;
1431 gdb_assert (sizeof (evrregs
.evr
[0])
1432 == register_size (gdbarch
, tdep
->ppc_ev0_upper_regnum
));
1433 gdb_assert (sizeof (evrregs
.acc
)
1434 == register_size (gdbarch
, tdep
->ppc_acc_regnum
));
1435 gdb_assert (sizeof (evrregs
.spefscr
)
1436 == register_size (gdbarch
, tdep
->ppc_spefscr_regnum
));
1439 /* Since we're going to write out every register, the code below
1440 should store to every field of evrregs; if that doesn't happen,
1441 make it obvious by initializing it with suspicious values. */
1442 memset (&evrregs
, 42, sizeof (evrregs
));
1444 /* We can only read and write the entire EVR register set at a
1445 time, so to write just a single register, we do a
1446 read-modify-write maneuver. */
1447 get_spe_registers (tid
, &evrregs
);
1453 for (i
= 0; i
< ppc_num_gprs
; i
++)
1454 regcache
->raw_collect (tdep
->ppc_ev0_upper_regnum
+ i
,
1457 else if (tdep
->ppc_ev0_upper_regnum
<= regno
1458 && regno
< tdep
->ppc_ev0_upper_regnum
+ ppc_num_gprs
)
1459 regcache
->raw_collect (regno
,
1460 &evrregs
.evr
[regno
- tdep
->ppc_ev0_upper_regnum
]);
1463 || regno
== tdep
->ppc_acc_regnum
)
1464 regcache
->raw_collect (tdep
->ppc_acc_regnum
,
1468 || regno
== tdep
->ppc_spefscr_regnum
)
1469 regcache
->raw_collect (tdep
->ppc_spefscr_regnum
,
1472 /* Write back the modified register set. */
1473 set_spe_registers (tid
, &evrregs
);
1477 store_register (const struct regcache
*regcache
, int tid
, int regno
)
1479 struct gdbarch
*gdbarch
= regcache
->arch ();
1480 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
1481 /* This isn't really an address. But ptrace thinks of it as one. */
1482 CORE_ADDR regaddr
= ppc_register_u_addr (gdbarch
, regno
);
1484 size_t bytes_to_transfer
;
1485 gdb_byte buf
[PPC_MAX_REGISTER_SIZE
];
1487 if (altivec_register_p (gdbarch
, regno
))
1489 store_altivec_registers (regcache
, tid
, regno
);
1492 else if (vsx_register_p (gdbarch
, regno
))
1494 store_vsx_registers (regcache
, tid
, regno
);
1497 else if (spe_register_p (gdbarch
, regno
))
1499 store_spe_register (regcache
, tid
, regno
);
1502 else if (regno
== PPC_DSCR_REGNUM
)
1504 gdb_assert (tdep
->ppc_dscr_regnum
!= -1);
1506 store_regset (regcache
, tid
, regno
, NT_PPC_DSCR
,
1507 PPC_LINUX_SIZEOF_DSCRREGSET
,
1508 &ppc32_linux_dscrregset
);
1511 else if (regno
== PPC_PPR_REGNUM
)
1513 gdb_assert (tdep
->ppc_ppr_regnum
!= -1);
1515 store_regset (regcache
, tid
, regno
, NT_PPC_PPR
,
1516 PPC_LINUX_SIZEOF_PPRREGSET
,
1517 &ppc32_linux_pprregset
);
1520 else if (regno
== PPC_TAR_REGNUM
)
1522 gdb_assert (tdep
->ppc_tar_regnum
!= -1);
1524 store_regset (regcache
, tid
, regno
, NT_PPC_TAR
,
1525 PPC_LINUX_SIZEOF_TARREGSET
,
1526 &ppc32_linux_tarregset
);
1529 else if (PPC_IS_EBB_REGNUM (regno
))
1531 gdb_assert (tdep
->have_ebb
);
1533 store_regset (regcache
, tid
, regno
, NT_PPC_EBB
,
1534 PPC_LINUX_SIZEOF_EBBREGSET
,
1535 &ppc32_linux_ebbregset
);
1538 else if (PPC_IS_PMU_REGNUM (regno
))
1540 gdb_assert (tdep
->ppc_mmcr0_regnum
!= -1);
1542 store_regset (regcache
, tid
, regno
, NT_PPC_PMU
,
1543 PPC_LINUX_SIZEOF_PMUREGSET
,
1544 &ppc32_linux_pmuregset
);
1547 else if (PPC_IS_TMSPR_REGNUM (regno
))
1549 gdb_assert (tdep
->have_htm_spr
);
1551 store_regset (regcache
, tid
, regno
, NT_PPC_TM_SPR
,
1552 PPC_LINUX_SIZEOF_TM_SPRREGSET
,
1553 &ppc32_linux_tm_sprregset
);
1556 else if (PPC_IS_CKPTGP_REGNUM (regno
))
1558 gdb_assert (tdep
->have_htm_core
);
1560 const struct regset
*cgprregset
= ppc_linux_cgprregset (gdbarch
);
1561 store_regset (regcache
, tid
, regno
, NT_PPC_TM_CGPR
,
1562 (tdep
->wordsize
== 4?
1563 PPC32_LINUX_SIZEOF_CGPRREGSET
1564 : PPC64_LINUX_SIZEOF_CGPRREGSET
),
1568 else if (PPC_IS_CKPTFP_REGNUM (regno
))
1570 gdb_assert (tdep
->have_htm_fpu
);
1572 store_regset (regcache
, tid
, regno
, NT_PPC_TM_CFPR
,
1573 PPC_LINUX_SIZEOF_CFPRREGSET
,
1574 &ppc32_linux_cfprregset
);
1577 else if (PPC_IS_CKPTVMX_REGNUM (regno
))
1579 gdb_assert (tdep
->have_htm_altivec
);
1581 const struct regset
*cvmxregset
= ppc_linux_cvmxregset (gdbarch
);
1582 store_regset (regcache
, tid
, regno
, NT_PPC_TM_CVMX
,
1583 PPC_LINUX_SIZEOF_CVMXREGSET
,
1587 else if (PPC_IS_CKPTVSX_REGNUM (regno
))
1589 gdb_assert (tdep
->have_htm_vsx
);
1591 store_regset (regcache
, tid
, regno
, NT_PPC_TM_CVSX
,
1592 PPC_LINUX_SIZEOF_CVSXREGSET
,
1593 &ppc32_linux_cvsxregset
);
1596 else if (regno
== PPC_CPPR_REGNUM
)
1598 gdb_assert (tdep
->ppc_cppr_regnum
!= -1);
1600 store_regset (regcache
, tid
, regno
, NT_PPC_TM_CPPR
,
1601 PPC_LINUX_SIZEOF_CPPRREGSET
,
1602 &ppc32_linux_cpprregset
);
1605 else if (regno
== PPC_CDSCR_REGNUM
)
1607 gdb_assert (tdep
->ppc_cdscr_regnum
!= -1);
1609 store_regset (regcache
, tid
, regno
, NT_PPC_TM_CDSCR
,
1610 PPC_LINUX_SIZEOF_CDSCRREGSET
,
1611 &ppc32_linux_cdscrregset
);
1614 else if (regno
== PPC_CTAR_REGNUM
)
1616 gdb_assert (tdep
->ppc_ctar_regnum
!= -1);
1618 store_regset (regcache
, tid
, regno
, NT_PPC_TM_CTAR
,
1619 PPC_LINUX_SIZEOF_CTARREGSET
,
1620 &ppc32_linux_ctarregset
);
1627 /* First collect the register. Keep in mind that the regcache's
1628 idea of the register's size may not be a multiple of sizeof
1630 memset (buf
, 0, sizeof buf
);
1631 bytes_to_transfer
= align_up (register_size (gdbarch
, regno
), sizeof (long));
1632 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_LITTLE
)
1634 /* Little-endian values always sit at the left end of the buffer. */
1635 regcache
->raw_collect (regno
, buf
);
1637 else if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1639 /* Big-endian values sit at the right end of the buffer. */
1640 size_t padding
= (bytes_to_transfer
- register_size (gdbarch
, regno
));
1641 regcache
->raw_collect (regno
, buf
+ padding
);
1644 for (i
= 0; i
< bytes_to_transfer
; i
+= sizeof (long))
1648 memcpy (&l
, &buf
[i
], sizeof (l
));
1650 ptrace (PTRACE_POKEUSER
, tid
, (PTRACE_TYPE_ARG3
) regaddr
, l
);
1651 regaddr
+= sizeof (long);
1654 && (regno
== tdep
->ppc_fpscr_regnum
1655 || regno
== PPC_ORIG_R3_REGNUM
1656 || regno
== PPC_TRAP_REGNUM
))
1658 /* Some older kernel versions don't allow fpscr, orig_r3
1659 or trap to be written. */
1666 xsnprintf (message
, sizeof (message
), "writing register %s (#%d)",
1667 gdbarch_register_name (gdbarch
, regno
), regno
);
1668 perror_with_name (message
);
1673 /* This function actually issues the request to ptrace, telling
1674 it to store all general-purpose registers present in the specified
1677 If the ptrace request does not exist, this function returns 0
1678 and properly sets the have_ptrace_* flag. If the request fails,
1679 this function calls perror_with_name. Otherwise, if the request
1680 succeeds, then the regcache is stored and 1 is returned. */
1682 store_all_gp_regs (const struct regcache
*regcache
, int tid
, int regno
)
1684 gdb_gregset_t gregset
;
1686 if (ptrace (PTRACE_GETREGS
, tid
, 0, (void *) &gregset
) < 0)
1690 have_ptrace_getsetregs
= 0;
1693 perror_with_name (_("Couldn't get general-purpose registers."));
1696 fill_gregset (regcache
, &gregset
, regno
);
1698 if (ptrace (PTRACE_SETREGS
, tid
, 0, (void *) &gregset
) < 0)
1702 have_ptrace_getsetregs
= 0;
1705 perror_with_name (_("Couldn't set general-purpose registers."));
1711 /* This is a wrapper for the store_all_gp_regs function. It is
1712 responsible for verifying if this target has the ptrace request
1713 that can be used to store all general-purpose registers at one
1714 shot. If it doesn't, then we should store them using the
1715 old-fashioned way, which is to iterate over the registers and
1716 store them one by one. */
1718 store_gp_regs (const struct regcache
*regcache
, int tid
, int regno
)
1720 struct gdbarch
*gdbarch
= regcache
->arch ();
1721 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
1724 if (have_ptrace_getsetregs
)
1725 if (store_all_gp_regs (regcache
, tid
, regno
))
1728 /* If we hit this point, it doesn't really matter which
1729 architecture we are using. We just need to store the
1730 registers in the "old-fashioned way". */
1731 for (i
= 0; i
< ppc_num_gprs
; i
++)
1732 store_register (regcache
, tid
, tdep
->ppc_gp0_regnum
+ i
);
1735 /* This function actually issues the request to ptrace, telling
1736 it to store all floating-point registers present in the specified
1739 If the ptrace request does not exist, this function returns 0
1740 and properly sets the have_ptrace_* flag. If the request fails,
1741 this function calls perror_with_name. Otherwise, if the request
1742 succeeds, then the regcache is stored and 1 is returned. */
1744 store_all_fp_regs (const struct regcache
*regcache
, int tid
, int regno
)
1746 gdb_fpregset_t fpregs
;
1748 if (ptrace (PTRACE_GETFPREGS
, tid
, 0, (void *) &fpregs
) < 0)
1752 have_ptrace_getsetfpregs
= 0;
1755 perror_with_name (_("Couldn't get floating-point registers."));
1758 fill_fpregset (regcache
, &fpregs
, regno
);
1760 if (ptrace (PTRACE_SETFPREGS
, tid
, 0, (void *) &fpregs
) < 0)
1764 have_ptrace_getsetfpregs
= 0;
1767 perror_with_name (_("Couldn't set floating-point registers."));
1773 /* This is a wrapper for the store_all_fp_regs function. It is
1774 responsible for verifying if this target has the ptrace request
1775 that can be used to store all floating-point registers at one
1776 shot. If it doesn't, then we should store them using the
1777 old-fashioned way, which is to iterate over the registers and
1778 store them one by one. */
1780 store_fp_regs (const struct regcache
*regcache
, int tid
, int regno
)
1782 struct gdbarch
*gdbarch
= regcache
->arch ();
1783 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
1786 if (have_ptrace_getsetfpregs
)
1787 if (store_all_fp_regs (regcache
, tid
, regno
))
1790 /* If we hit this point, it doesn't really matter which
1791 architecture we are using. We just need to store the
1792 registers in the "old-fashioned way". */
1793 for (i
= 0; i
< ppc_num_fprs
; i
++)
1794 store_register (regcache
, tid
, tdep
->ppc_fp0_regnum
+ i
);
1798 store_ppc_registers (const struct regcache
*regcache
, int tid
)
1800 struct gdbarch
*gdbarch
= regcache
->arch ();
1801 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
1803 store_gp_regs (regcache
, tid
, -1);
1804 if (tdep
->ppc_fp0_regnum
>= 0)
1805 store_fp_regs (regcache
, tid
, -1);
1806 store_register (regcache
, tid
, gdbarch_pc_regnum (gdbarch
));
1807 if (tdep
->ppc_ps_regnum
!= -1)
1808 store_register (regcache
, tid
, tdep
->ppc_ps_regnum
);
1809 if (tdep
->ppc_cr_regnum
!= -1)
1810 store_register (regcache
, tid
, tdep
->ppc_cr_regnum
);
1811 if (tdep
->ppc_lr_regnum
!= -1)
1812 store_register (regcache
, tid
, tdep
->ppc_lr_regnum
);
1813 if (tdep
->ppc_ctr_regnum
!= -1)
1814 store_register (regcache
, tid
, tdep
->ppc_ctr_regnum
);
1815 if (tdep
->ppc_xer_regnum
!= -1)
1816 store_register (regcache
, tid
, tdep
->ppc_xer_regnum
);
1817 if (tdep
->ppc_mq_regnum
!= -1)
1818 store_register (regcache
, tid
, tdep
->ppc_mq_regnum
);
1819 if (tdep
->ppc_fpscr_regnum
!= -1)
1820 store_register (regcache
, tid
, tdep
->ppc_fpscr_regnum
);
1821 if (ppc_linux_trap_reg_p (gdbarch
))
1823 store_register (regcache
, tid
, PPC_ORIG_R3_REGNUM
);
1824 store_register (regcache
, tid
, PPC_TRAP_REGNUM
);
1826 if (have_ptrace_getvrregs
)
1827 if (tdep
->ppc_vr0_regnum
!= -1 && tdep
->ppc_vrsave_regnum
!= -1)
1828 store_altivec_registers (regcache
, tid
, -1);
1829 if (have_ptrace_getsetvsxregs
)
1830 if (tdep
->ppc_vsr0_upper_regnum
!= -1)
1831 store_vsx_registers (regcache
, tid
, -1);
1832 if (tdep
->ppc_ev0_upper_regnum
>= 0)
1833 store_spe_register (regcache
, tid
, -1);
1834 if (tdep
->ppc_ppr_regnum
!= -1)
1835 store_regset (regcache
, tid
, -1, NT_PPC_PPR
,
1836 PPC_LINUX_SIZEOF_PPRREGSET
,
1837 &ppc32_linux_pprregset
);
1838 if (tdep
->ppc_dscr_regnum
!= -1)
1839 store_regset (regcache
, tid
, -1, NT_PPC_DSCR
,
1840 PPC_LINUX_SIZEOF_DSCRREGSET
,
1841 &ppc32_linux_dscrregset
);
1842 if (tdep
->ppc_tar_regnum
!= -1)
1843 store_regset (regcache
, tid
, -1, NT_PPC_TAR
,
1844 PPC_LINUX_SIZEOF_TARREGSET
,
1845 &ppc32_linux_tarregset
);
1847 if (tdep
->ppc_mmcr0_regnum
!= -1)
1848 store_regset (regcache
, tid
, -1, NT_PPC_PMU
,
1849 PPC_LINUX_SIZEOF_PMUREGSET
,
1850 &ppc32_linux_pmuregset
);
1852 if (tdep
->have_htm_spr
)
1853 store_regset (regcache
, tid
, -1, NT_PPC_TM_SPR
,
1854 PPC_LINUX_SIZEOF_TM_SPRREGSET
,
1855 &ppc32_linux_tm_sprregset
);
1857 /* Because the EBB and checkpointed HTM registers can be
1858 unavailable, attempts to store them here would cause this
1859 function to fail most of the time, so we ignore them. */
1863 ppc_linux_nat_target::store_registers (struct regcache
*regcache
, int regno
)
1865 pid_t tid
= get_ptrace_pid (regcache
->ptid ());
1868 store_register (regcache
, tid
, regno
);
1870 store_ppc_registers (regcache
, tid
);
1873 /* Functions for transferring registers between a gregset_t or fpregset_t
1874 (see sys/ucontext.h) and gdb's regcache. The word size is that used
1875 by the ptrace interface, not the current program's ABI. Eg. if a
1876 powerpc64-linux gdb is being used to debug a powerpc32-linux app, we
1877 read or write 64-bit gregsets. This is to suit the host libthread_db. */
1880 supply_gregset (struct regcache
*regcache
, const gdb_gregset_t
*gregsetp
)
1882 const struct regset
*regset
= ppc_linux_gregset (sizeof (long));
1884 ppc_supply_gregset (regset
, regcache
, -1, gregsetp
, sizeof (*gregsetp
));
1888 fill_gregset (const struct regcache
*regcache
,
1889 gdb_gregset_t
*gregsetp
, int regno
)
1891 const struct regset
*regset
= ppc_linux_gregset (sizeof (long));
1894 memset (gregsetp
, 0, sizeof (*gregsetp
));
1895 ppc_collect_gregset (regset
, regcache
, regno
, gregsetp
, sizeof (*gregsetp
));
1899 supply_fpregset (struct regcache
*regcache
, const gdb_fpregset_t
* fpregsetp
)
1901 const struct regset
*regset
= ppc_linux_fpregset ();
1903 ppc_supply_fpregset (regset
, regcache
, -1,
1904 fpregsetp
, sizeof (*fpregsetp
));
1908 fill_fpregset (const struct regcache
*regcache
,
1909 gdb_fpregset_t
*fpregsetp
, int regno
)
1911 const struct regset
*regset
= ppc_linux_fpregset ();
1913 ppc_collect_fpregset (regset
, regcache
, regno
,
1914 fpregsetp
, sizeof (*fpregsetp
));
1918 ppc_linux_nat_target::auxv_parse (gdb_byte
**readptr
,
1919 gdb_byte
*endptr
, CORE_ADDR
*typep
,
1922 int tid
= inferior_ptid
.lwp ();
1924 tid
= inferior_ptid
.pid ();
1926 int sizeof_auxv_field
= ppc_linux_target_wordsize (tid
);
1928 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch ());
1929 gdb_byte
*ptr
= *readptr
;
1934 if (endptr
- ptr
< sizeof_auxv_field
* 2)
1937 *typep
= extract_unsigned_integer (ptr
, sizeof_auxv_field
, byte_order
);
1938 ptr
+= sizeof_auxv_field
;
1939 *valp
= extract_unsigned_integer (ptr
, sizeof_auxv_field
, byte_order
);
1940 ptr
+= sizeof_auxv_field
;
1946 const struct target_desc
*
1947 ppc_linux_nat_target::read_description ()
1949 int tid
= inferior_ptid
.pid ();
1951 if (have_ptrace_getsetevrregs
)
1953 struct gdb_evrregset_t evrregset
;
1955 if (ptrace (PTRACE_GETEVRREGS
, tid
, 0, &evrregset
) >= 0)
1956 return tdesc_powerpc_e500l
;
1958 /* EIO means that the PTRACE_GETEVRREGS request isn't supported.
1959 Anything else needs to be reported. */
1960 else if (errno
!= EIO
)
1961 perror_with_name (_("Unable to fetch SPE registers"));
1964 struct ppc_linux_features features
= ppc_linux_no_features
;
1966 features
.wordsize
= ppc_linux_target_wordsize (tid
);
1968 CORE_ADDR hwcap
= linux_get_hwcap (current_inferior ()->top_target ());
1969 CORE_ADDR hwcap2
= linux_get_hwcap2 (current_inferior ()->top_target ());
1971 if (have_ptrace_getsetvsxregs
1972 && (hwcap
& PPC_FEATURE_HAS_VSX
))
1974 gdb_vsxregset_t vsxregset
;
1976 if (ptrace (PTRACE_GETVSXREGS
, tid
, 0, &vsxregset
) >= 0)
1977 features
.vsx
= true;
1979 /* EIO means that the PTRACE_GETVSXREGS request isn't supported.
1980 Anything else needs to be reported. */
1981 else if (errno
!= EIO
)
1982 perror_with_name (_("Unable to fetch VSX registers"));
1985 if (have_ptrace_getvrregs
1986 && (hwcap
& PPC_FEATURE_HAS_ALTIVEC
))
1988 gdb_vrregset_t vrregset
;
1990 if (ptrace (PTRACE_GETVRREGS
, tid
, 0, &vrregset
) >= 0)
1991 features
.altivec
= true;
1993 /* EIO means that the PTRACE_GETVRREGS request isn't supported.
1994 Anything else needs to be reported. */
1995 else if (errno
!= EIO
)
1996 perror_with_name (_("Unable to fetch AltiVec registers"));
1999 features
.isa205
= ppc_linux_has_isa205 (hwcap
);
2001 if ((hwcap2
& PPC_FEATURE2_DSCR
)
2002 && check_regset (tid
, NT_PPC_PPR
, PPC_LINUX_SIZEOF_PPRREGSET
)
2003 && check_regset (tid
, NT_PPC_DSCR
, PPC_LINUX_SIZEOF_DSCRREGSET
))
2005 features
.ppr_dscr
= true;
2006 if ((hwcap2
& PPC_FEATURE2_ARCH_2_07
)
2007 && (hwcap2
& PPC_FEATURE2_TAR
)
2008 && (hwcap2
& PPC_FEATURE2_EBB
)
2009 && check_regset (tid
, NT_PPC_TAR
, PPC_LINUX_SIZEOF_TARREGSET
)
2010 && check_regset (tid
, NT_PPC_EBB
, PPC_LINUX_SIZEOF_EBBREGSET
)
2011 && check_regset (tid
, NT_PPC_PMU
, PPC_LINUX_SIZEOF_PMUREGSET
))
2013 features
.isa207
= true;
2014 if ((hwcap2
& PPC_FEATURE2_HTM
)
2015 && check_regset (tid
, NT_PPC_TM_SPR
,
2016 PPC_LINUX_SIZEOF_TM_SPRREGSET
))
2017 features
.htm
= true;
2021 return ppc_linux_match_description (features
);
2024 /* Routines for installing hardware watchpoints and breakpoints. When
2025 GDB requests a hardware watchpoint or breakpoint to be installed, we
2026 register the request for the pid of inferior_ptid in a map with one
2027 entry per process. We then issue a stop request to all the threads of
2028 this process, and mark a per-thread flag indicating that their debug
2029 registers should be updated. Right before they are next resumed, we
2030 remove all previously installed debug registers and install all the
2031 ones GDB requested. We then update a map with one entry per thread
2032 that keeps track of what debug registers were last installed in each
2035 We use this second map to remove installed registers before installing
2036 the ones requested by GDB, and to copy the debug register state after
2037 a thread clones or forks, since depending on the kernel configuration,
2038 debug registers can be inherited. */
2040 /* Check if we support and have enough resources to install a hardware
2041 watchpoint or breakpoint. See the description in target.h. */
2044 ppc_linux_nat_target::can_use_hw_breakpoint (enum bptype type
, int cnt
,
2047 int total_hw_wp
, total_hw_bp
;
2049 m_dreg_interface
.detect (inferior_ptid
);
2051 if (m_dreg_interface
.unavailable_p ())
2054 if (m_dreg_interface
.hwdebug_p ())
2056 /* When PowerPC HWDEBUG ptrace interface is available, the number of
2057 available hardware watchpoints and breakpoints is stored at the
2058 hwdebug_info struct. */
2059 total_hw_bp
= m_dreg_interface
.hwdebug_info ().num_instruction_bps
;
2060 total_hw_wp
= m_dreg_interface
.hwdebug_info ().num_data_bps
;
2064 gdb_assert (m_dreg_interface
.debugreg_p ());
2066 /* With the DEBUGREG ptrace interface, we should consider having 1
2067 hardware watchpoint and no hardware breakpoints. */
2072 if (type
== bp_hardware_watchpoint
|| type
== bp_read_watchpoint
2073 || type
== bp_access_watchpoint
|| type
== bp_watchpoint
)
2075 if (total_hw_wp
== 0)
2077 else if (cnt
+ ot
> total_hw_wp
)
2082 else if (type
== bp_hardware_breakpoint
)
2084 if (total_hw_bp
== 0)
2086 else if (cnt
> total_hw_bp
)
2095 /* Returns 1 if we can watch LEN bytes at address ADDR, 0 otherwise. */
2098 ppc_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
2100 /* Handle sub-8-byte quantities. */
2104 m_dreg_interface
.detect (inferior_ptid
);
2106 if (m_dreg_interface
.unavailable_p ())
2109 /* The PowerPC HWDEBUG ptrace interface tells if there are alignment
2110 restrictions for watchpoints in the processors. In that case, we use that
2111 information to determine the hardcoded watchable region for
2113 if (m_dreg_interface
.hwdebug_p ())
2115 const struct ppc_debug_info
&hwdebug_info
= (m_dreg_interface
2117 int region_size
= hwdebug_info
.data_bp_alignment
;
2118 int region_align
= region_size
;
2120 /* Embedded DAC-based processors, like the PowerPC 440 have ranged
2121 watchpoints and can watch any access within an arbitrary memory
2122 region. This is useful to watch arrays and structs, for instance. It
2123 takes two hardware watchpoints though. */
2125 && hwdebug_info
.features
& PPC_DEBUG_FEATURE_DATA_BP_RANGE
2126 && (linux_get_hwcap (current_inferior ()->top_target ())
2127 & PPC_FEATURE_BOOKE
))
2129 /* Check if the processor provides DAWR interface. */
2130 if (hwdebug_info
.features
& PPC_DEBUG_FEATURE_DATA_BP_DAWR
)
2132 /* DAWR interface allows to watch up to 512 byte wide ranges. */
2134 /* DAWR interface allows to watch up to 512 byte wide ranges which
2135 can't cross a 512 byte bondary on machines that doesn't have a
2136 second DAWR (P9 or less). */
2137 if (!(hwdebug_info
.features
& PPC_DEBUG_FEATURE_DATA_BP_ARCH_31
))
2140 /* Server processors provide one hardware watchpoint and addr+len should
2141 fall in the watchable region provided by the ptrace interface. */
2143 && (addr
+ len
> (addr
& ~(region_align
- 1)) + region_size
))
2146 /* addr+len must fall in the 8 byte watchable region for DABR-based
2147 processors (i.e., server processors). Without the new PowerPC HWDEBUG
2148 ptrace interface, DAC-based processors (i.e., embedded processors) will
2149 use addresses aligned to 4-bytes due to the way the read/write flags are
2150 passed in the old ptrace interface. */
2153 gdb_assert (m_dreg_interface
.debugreg_p ());
2155 if (((linux_get_hwcap (current_inferior ()->top_target ())
2156 & PPC_FEATURE_BOOKE
)
2157 && (addr
+ len
) > (addr
& ~3) + 4)
2158 || (addr
+ len
) > (addr
& ~7) + 8)
2165 /* This function compares two ppc_hw_breakpoint structs
2169 ppc_linux_nat_target::hwdebug_point_cmp (const struct ppc_hw_breakpoint
&a
,
2170 const struct ppc_hw_breakpoint
&b
)
2172 return (a
.trigger_type
== b
.trigger_type
2173 && a
.addr_mode
== b
.addr_mode
2174 && a
.condition_mode
== b
.condition_mode
2176 && a
.addr2
== b
.addr2
2177 && a
.condition_value
== b
.condition_value
);
2180 /* Return the number of registers needed for a ranged breakpoint. */
2183 ppc_linux_nat_target::ranged_break_num_registers ()
2185 m_dreg_interface
.detect (inferior_ptid
);
2187 return ((m_dreg_interface
.hwdebug_p ()
2188 && (m_dreg_interface
.hwdebug_info ().features
2189 & PPC_DEBUG_FEATURE_INSN_BP_RANGE
))?
2193 /* Register the hardware breakpoint described by BP_TGT, to be inserted
2194 when the threads of inferior_ptid are resumed. Returns 0 for success,
2195 or -1 if the HWDEBUG interface that we need for hardware breakpoints
2196 is not available. */
2199 ppc_linux_nat_target::insert_hw_breakpoint (struct gdbarch
*gdbarch
,
2200 struct bp_target_info
*bp_tgt
)
2202 struct ppc_hw_breakpoint p
;
2204 m_dreg_interface
.detect (inferior_ptid
);
2206 if (!m_dreg_interface
.hwdebug_p ())
2209 p
.version
= PPC_DEBUG_CURRENT_VERSION
;
2210 p
.trigger_type
= PPC_BREAKPOINT_TRIGGER_EXECUTE
;
2211 p
.condition_mode
= PPC_BREAKPOINT_CONDITION_NONE
;
2212 p
.addr
= (uint64_t) (bp_tgt
->placed_address
= bp_tgt
->reqstd_address
);
2213 p
.condition_value
= 0;
2217 p
.addr_mode
= PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE
;
2219 /* The breakpoint will trigger if the address of the instruction is
2220 within the defined range, as follows: p.addr <= address < p.addr2. */
2221 p
.addr2
= (uint64_t) bp_tgt
->placed_address
+ bp_tgt
->length
;
2225 p
.addr_mode
= PPC_BREAKPOINT_MODE_EXACT
;
2229 register_hw_breakpoint (inferior_ptid
.pid (), p
);
2234 /* Clear a registration for the hardware breakpoint given by type BP_TGT.
2235 It will be removed from the threads of inferior_ptid when they are
2236 next resumed. Returns 0 for success, or -1 if the HWDEBUG interface
2237 that we need for hardware breakpoints is not available. */
2240 ppc_linux_nat_target::remove_hw_breakpoint (struct gdbarch
*gdbarch
,
2241 struct bp_target_info
*bp_tgt
)
2243 struct ppc_hw_breakpoint p
;
2245 m_dreg_interface
.detect (inferior_ptid
);
2247 if (!m_dreg_interface
.hwdebug_p ())
2250 p
.version
= PPC_DEBUG_CURRENT_VERSION
;
2251 p
.trigger_type
= PPC_BREAKPOINT_TRIGGER_EXECUTE
;
2252 p
.condition_mode
= PPC_BREAKPOINT_CONDITION_NONE
;
2253 p
.addr
= (uint64_t) bp_tgt
->placed_address
;
2254 p
.condition_value
= 0;
2258 p
.addr_mode
= PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE
;
2260 /* The breakpoint will trigger if the address of the instruction is within
2261 the defined range, as follows: p.addr <= address < p.addr2. */
2262 p
.addr2
= (uint64_t) bp_tgt
->placed_address
+ bp_tgt
->length
;
2266 p
.addr_mode
= PPC_BREAKPOINT_MODE_EXACT
;
2270 clear_hw_breakpoint (inferior_ptid
.pid (), p
);
2275 /* Return the trigger value to set in a ppc_hw_breakpoint object for a
2276 given hardware watchpoint TYPE. We assume type is not hw_execute. */
2279 ppc_linux_nat_target::get_trigger_type (enum target_hw_bp_type type
)
2283 if (type
== hw_read
)
2284 t
= PPC_BREAKPOINT_TRIGGER_READ
;
2285 else if (type
== hw_write
)
2286 t
= PPC_BREAKPOINT_TRIGGER_WRITE
;
2288 t
= PPC_BREAKPOINT_TRIGGER_READ
| PPC_BREAKPOINT_TRIGGER_WRITE
;
2293 /* Register a new masked watchpoint at ADDR using the mask MASK, to be
2294 inserted when the threads of inferior_ptid are resumed. RW may be
2295 hw_read for a read watchpoint, hw_write for a write watchpoint or
2296 hw_access for an access watchpoint. */
2299 ppc_linux_nat_target::insert_mask_watchpoint (CORE_ADDR addr
, CORE_ADDR mask
,
2300 target_hw_bp_type rw
)
2302 struct ppc_hw_breakpoint p
;
2304 gdb_assert (m_dreg_interface
.hwdebug_p ());
2306 p
.version
= PPC_DEBUG_CURRENT_VERSION
;
2307 p
.trigger_type
= get_trigger_type (rw
);
2308 p
.addr_mode
= PPC_BREAKPOINT_MODE_MASK
;
2309 p
.condition_mode
= PPC_BREAKPOINT_CONDITION_NONE
;
2312 p
.condition_value
= 0;
2314 register_hw_breakpoint (inferior_ptid
.pid (), p
);
2319 /* Clear a registration for a masked watchpoint at ADDR with the mask
2320 MASK. It will be removed from the threads of inferior_ptid when they
2321 are next resumed. RW may be hw_read for a read watchpoint, hw_write
2322 for a write watchpoint or hw_access for an access watchpoint. */
2325 ppc_linux_nat_target::remove_mask_watchpoint (CORE_ADDR addr
, CORE_ADDR mask
,
2326 target_hw_bp_type rw
)
2328 struct ppc_hw_breakpoint p
;
2330 gdb_assert (m_dreg_interface
.hwdebug_p ());
2332 p
.version
= PPC_DEBUG_CURRENT_VERSION
;
2333 p
.trigger_type
= get_trigger_type (rw
);
2334 p
.addr_mode
= PPC_BREAKPOINT_MODE_MASK
;
2335 p
.condition_mode
= PPC_BREAKPOINT_CONDITION_NONE
;
2338 p
.condition_value
= 0;
2340 clear_hw_breakpoint (inferior_ptid
.pid (), p
);
2345 /* Check whether we have at least one free DVC register for the threads
2346 of the pid of inferior_ptid. */
2349 ppc_linux_nat_target::can_use_watchpoint_cond_accel (void)
2351 m_dreg_interface
.detect (inferior_ptid
);
2353 if (!m_dreg_interface
.hwdebug_p ())
2356 int cnt
= m_dreg_interface
.hwdebug_info ().num_condition_regs
;
2361 auto process_it
= m_process_info
.find (inferior_ptid
.pid ());
2363 /* No breakpoints or watchpoints have been requested for this process,
2364 we have at least one free DVC register. */
2365 if (process_it
== m_process_info
.end ())
2368 for (const ppc_hw_breakpoint
&bp
: process_it
->second
.requested_hw_bps
)
2369 if (bp
.condition_mode
!= PPC_BREAKPOINT_CONDITION_NONE
)
2378 /* Calculate the enable bits and the contents of the Data Value Compare
2379 debug register present in BookE processors.
2381 ADDR is the address to be watched, LEN is the length of watched data
2382 and DATA_VALUE is the value which will trigger the watchpoint.
2383 On exit, CONDITION_MODE will hold the enable bits for the DVC, and
2384 CONDITION_VALUE will hold the value which should be put in the
2388 ppc_linux_nat_target::calculate_dvc (CORE_ADDR addr
, int len
,
2389 CORE_ADDR data_value
,
2390 uint32_t *condition_mode
,
2391 uint64_t *condition_value
)
2393 const struct ppc_debug_info
&hwdebug_info
= (m_dreg_interface
.
2396 int i
, num_byte_enable
, align_offset
, num_bytes_off_dvc
,
2397 rightmost_enabled_byte
;
2398 CORE_ADDR addr_end_data
, addr_end_dvc
;
2400 /* The DVC register compares bytes within fixed-length windows which
2401 are word-aligned, with length equal to that of the DVC register.
2402 We need to calculate where our watch region is relative to that
2403 window and enable comparison of the bytes which fall within it. */
2405 align_offset
= addr
% hwdebug_info
.sizeof_condition
;
2406 addr_end_data
= addr
+ len
;
2407 addr_end_dvc
= (addr
- align_offset
2408 + hwdebug_info
.sizeof_condition
);
2409 num_bytes_off_dvc
= (addr_end_data
> addr_end_dvc
)?
2410 addr_end_data
- addr_end_dvc
: 0;
2411 num_byte_enable
= len
- num_bytes_off_dvc
;
2412 /* Here, bytes are numbered from right to left. */
2413 rightmost_enabled_byte
= (addr_end_data
< addr_end_dvc
)?
2414 addr_end_dvc
- addr_end_data
: 0;
2416 *condition_mode
= PPC_BREAKPOINT_CONDITION_AND
;
2417 for (i
= 0; i
< num_byte_enable
; i
++)
2419 |= PPC_BREAKPOINT_CONDITION_BE (i
+ rightmost_enabled_byte
);
2421 /* Now we need to match the position within the DVC of the comparison
2422 value with where the watch region is relative to the window
2423 (i.e., the ALIGN_OFFSET). */
2425 *condition_value
= ((uint64_t) data_value
>> num_bytes_off_dvc
* 8
2426 << rightmost_enabled_byte
* 8);
2429 /* Return the number of memory locations that need to be accessed to
2430 evaluate the expression which generated the given value chain.
2431 Returns -1 if there's any register access involved, or if there are
2432 other kinds of values which are not acceptable in a condition
2433 expression (e.g., lval_computed or lval_internalvar). */
2436 ppc_linux_nat_target::num_memory_accesses (const std::vector
<value_ref_ptr
>
2439 int found_memory_cnt
= 0;
2441 /* The idea here is that evaluating an expression generates a series
2442 of values, one holding the value of every subexpression. (The
2443 expression a*b+c has five subexpressions: a, b, a*b, c, and
2444 a*b+c.) GDB's values hold almost enough information to establish
2445 the criteria given above --- they identify memory lvalues,
2446 register lvalues, computed values, etcetera. So we can evaluate
2447 the expression, and then scan the chain of values that leaves
2448 behind to determine the memory locations involved in the evaluation
2451 However, I don't think that the values returned by inferior
2452 function calls are special in any way. So this function may not
2453 notice that an expression contains an inferior function call.
2456 for (const value_ref_ptr
&iter
: chain
)
2458 struct value
*v
= iter
.get ();
2460 /* Constants and values from the history are fine. */
2461 if (VALUE_LVAL (v
) == not_lval
|| deprecated_value_modifiable (v
) == 0)
2463 else if (VALUE_LVAL (v
) == lval_memory
)
2465 /* A lazy memory lvalue is one that GDB never needed to fetch;
2466 we either just used its address (e.g., `a' in `a.b') or
2467 we never needed it at all (e.g., `a' in `a,b'). */
2468 if (!value_lazy (v
))
2471 /* Other kinds of values are not fine. */
2476 return found_memory_cnt
;
2479 /* Verifies whether the expression COND can be implemented using the
2480 DVC (Data Value Compare) register in BookE processors. The expression
2481 must test the watch value for equality with a constant expression.
2482 If the function returns 1, DATA_VALUE will contain the constant against
2483 which the watch value should be compared and LEN will contain the size
2487 ppc_linux_nat_target::check_condition (CORE_ADDR watch_addr
,
2488 struct expression
*cond
,
2489 CORE_ADDR
*data_value
, int *len
)
2491 int num_accesses_left
, num_accesses_right
;
2492 struct value
*left_val
, *right_val
;
2493 std::vector
<value_ref_ptr
> left_chain
, right_chain
;
2495 expr::equal_operation
*eqop
2496 = dynamic_cast<expr::equal_operation
*> (cond
->op
.get ());
2497 if (eqop
== nullptr)
2499 expr::operation
*lhs
= eqop
->get_lhs ();
2500 expr::operation
*rhs
= eqop
->get_rhs ();
2502 fetch_subexp_value (cond
, lhs
, &left_val
, NULL
, &left_chain
, false);
2503 num_accesses_left
= num_memory_accesses (left_chain
);
2505 if (left_val
== NULL
|| num_accesses_left
< 0)
2508 fetch_subexp_value (cond
, rhs
, &right_val
, NULL
, &right_chain
, false);
2509 num_accesses_right
= num_memory_accesses (right_chain
);
2511 if (right_val
== NULL
|| num_accesses_right
< 0)
2514 if (num_accesses_left
== 1 && num_accesses_right
== 0
2515 && VALUE_LVAL (left_val
) == lval_memory
2516 && value_address (left_val
) == watch_addr
)
2518 *data_value
= value_as_long (right_val
);
2520 /* DATA_VALUE is the constant in RIGHT_VAL, but actually has
2521 the same type as the memory region referenced by LEFT_VAL. */
2522 *len
= TYPE_LENGTH (check_typedef (value_type (left_val
)));
2524 else if (num_accesses_left
== 0 && num_accesses_right
== 1
2525 && VALUE_LVAL (right_val
) == lval_memory
2526 && value_address (right_val
) == watch_addr
)
2528 *data_value
= value_as_long (left_val
);
2530 /* DATA_VALUE is the constant in LEFT_VAL, but actually has
2531 the same type as the memory region referenced by RIGHT_VAL. */
2532 *len
= TYPE_LENGTH (check_typedef (value_type (right_val
)));
2540 /* Return true if the target is capable of using hardware to evaluate the
2541 condition expression, thus only triggering the watchpoint when it is
2545 ppc_linux_nat_target::can_accel_watchpoint_condition (CORE_ADDR addr
,
2547 struct expression
*cond
)
2549 CORE_ADDR data_value
;
2551 m_dreg_interface
.detect (inferior_ptid
);
2553 return (m_dreg_interface
.hwdebug_p ()
2554 && (m_dreg_interface
.hwdebug_info ().num_condition_regs
> 0)
2555 && check_condition (addr
, cond
, &data_value
, &len
));
2558 /* Set up P with the parameters necessary to request a watchpoint covering
2559 LEN bytes starting at ADDR and if possible with condition expression COND
2560 evaluated by hardware. INSERT tells if we are creating a request for
2561 inserting or removing the watchpoint. */
2564 ppc_linux_nat_target::create_watchpoint_request (struct ppc_hw_breakpoint
*p
,
2565 CORE_ADDR addr
, int len
,
2566 enum target_hw_bp_type type
,
2567 struct expression
*cond
,
2570 const struct ppc_debug_info
&hwdebug_info
= (m_dreg_interface
2574 || !(hwdebug_info
.features
& PPC_DEBUG_FEATURE_DATA_BP_RANGE
))
2577 CORE_ADDR data_value
;
2579 use_condition
= (insert
? can_use_watchpoint_cond_accel ()
2580 : hwdebug_info
.num_condition_regs
> 0);
2581 if (cond
&& use_condition
&& check_condition (addr
, cond
,
2583 calculate_dvc (addr
, len
, data_value
, &p
->condition_mode
,
2584 &p
->condition_value
);
2587 p
->condition_mode
= PPC_BREAKPOINT_CONDITION_NONE
;
2588 p
->condition_value
= 0;
2591 p
->addr_mode
= PPC_BREAKPOINT_MODE_EXACT
;
2596 p
->addr_mode
= PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE
;
2597 p
->condition_mode
= PPC_BREAKPOINT_CONDITION_NONE
;
2598 p
->condition_value
= 0;
2600 /* The watchpoint will trigger if the address of the memory access is
2601 within the defined range, as follows: p->addr <= address < p->addr2.
2603 Note that the above sentence just documents how ptrace interprets
2604 its arguments; the watchpoint is set to watch the range defined by
2605 the user _inclusively_, as specified by the user interface. */
2606 p
->addr2
= (uint64_t) addr
+ len
;
2609 p
->version
= PPC_DEBUG_CURRENT_VERSION
;
2610 p
->trigger_type
= get_trigger_type (type
);
2611 p
->addr
= (uint64_t) addr
;
2614 /* Register a watchpoint, to be inserted when the threads of the group of
2615 inferior_ptid are next resumed. Returns 0 on success, and -1 if there
2616 is no ptrace interface available to install the watchpoint. */
2619 ppc_linux_nat_target::insert_watchpoint (CORE_ADDR addr
, int len
,
2620 enum target_hw_bp_type type
,
2621 struct expression
*cond
)
2623 m_dreg_interface
.detect (inferior_ptid
);
2625 if (m_dreg_interface
.unavailable_p ())
2628 if (m_dreg_interface
.hwdebug_p ())
2630 struct ppc_hw_breakpoint p
;
2632 create_watchpoint_request (&p
, addr
, len
, type
, cond
, 1);
2634 register_hw_breakpoint (inferior_ptid
.pid (), p
);
2638 gdb_assert (m_dreg_interface
.debugreg_p ());
2641 long read_mode
, write_mode
;
2643 if (linux_get_hwcap (current_inferior ()->top_target ())
2644 & PPC_FEATURE_BOOKE
)
2646 /* PowerPC 440 requires only the read/write flags to be passed
2653 /* PowerPC 970 and other DABR-based processors are required to pass
2654 the Breakpoint Translation bit together with the flags. */
2659 wp_value
= addr
& ~(read_mode
| write_mode
);
2663 /* Set read and translate bits. */
2664 wp_value
|= read_mode
;
2667 /* Set write and translate bits. */
2668 wp_value
|= write_mode
;
2671 /* Set read, write and translate bits. */
2672 wp_value
|= read_mode
| write_mode
;
2676 register_wp (inferior_ptid
.pid (), wp_value
);
2682 /* Clear a registration for a hardware watchpoint. It will be removed
2683 from the threads of the group of inferior_ptid when they are next
2687 ppc_linux_nat_target::remove_watchpoint (CORE_ADDR addr
, int len
,
2688 enum target_hw_bp_type type
,
2689 struct expression
*cond
)
2691 gdb_assert (!m_dreg_interface
.unavailable_p ());
2693 if (m_dreg_interface
.hwdebug_p ())
2695 struct ppc_hw_breakpoint p
;
2697 create_watchpoint_request (&p
, addr
, len
, type
, cond
, 0);
2699 clear_hw_breakpoint (inferior_ptid
.pid (), p
);
2703 gdb_assert (m_dreg_interface
.debugreg_p ());
2705 clear_wp (inferior_ptid
.pid ());
2711 /* Clean up the per-process info associated with PID. When using the
2712 HWDEBUG interface, we also erase the per-thread state of installed
2713 debug registers for all the threads that belong to the group of PID.
2715 Usually the thread state is cleaned up by low_delete_thread. We also
2716 do it here because low_new_thread is not called for the initial LWP,
2717 so low_delete_thread won't be able to clean up this state. */
2720 ppc_linux_nat_target::low_forget_process (pid_t pid
)
2722 if ((!m_dreg_interface
.detected_p ())
2723 || (m_dreg_interface
.unavailable_p ()))
2726 ptid_t
pid_ptid (pid
, 0, 0);
2728 m_process_info
.erase (pid
);
2730 if (m_dreg_interface
.hwdebug_p ())
2732 for (auto it
= m_installed_hw_bps
.begin ();
2733 it
!= m_installed_hw_bps
.end ();)
2735 if (it
->first
.matches (pid_ptid
))
2736 it
= m_installed_hw_bps
.erase (it
);
2743 /* Copy the per-process state associated with the pid of PARENT to the
2744 sate of CHILD_PID. GDB expects that a forked process will have the
2745 same hardware breakpoints and watchpoints as the parent.
2747 If we're using the HWDEBUG interface, also copy the thread debug
2748 register state for the ptid of PARENT to the state for CHILD_PID.
2750 Like for clone events, we assume the kernel will copy the debug
2751 registers from the parent thread to the child. The
2752 low_prepare_to_resume function is made to work even if it doesn't.
2754 We copy the thread state here and not in low_new_thread since we don't
2755 have the pid of the parent in low_new_thread. Even if we did,
2756 low_new_thread might not be called immediately after the fork event is
2757 detected. For instance, with the checkpointing system (see
2758 linux-fork.c), the thread won't be added until GDB decides to switch
2759 to a new checkpointed process. At that point, the debug register
2760 state of the parent thread is unlikely to correspond to the state it
2761 had at the point when it forked. */
2764 ppc_linux_nat_target::low_new_fork (struct lwp_info
*parent
,
2767 if ((!m_dreg_interface
.detected_p ())
2768 || (m_dreg_interface
.unavailable_p ()))
2771 auto process_it
= m_process_info
.find (parent
->ptid
.pid ());
2773 if (process_it
!= m_process_info
.end ())
2774 m_process_info
[child_pid
] = m_process_info
[parent
->ptid
.pid ()];
2776 if (m_dreg_interface
.hwdebug_p ())
2778 ptid_t
child_ptid (child_pid
, child_pid
, 0);
2780 copy_thread_dreg_state (parent
->ptid
, child_ptid
);
2784 /* Copy the thread debug register state from the PARENT thread to the the
2785 state for CHILD_LWP, if we're using the HWDEBUG interface. We assume
2786 the kernel copies the debug registers from one thread to another after
2787 a clone event. The low_prepare_to_resume function is made to work
2788 even if it doesn't. */
2791 ppc_linux_nat_target::low_new_clone (struct lwp_info
*parent
,
2794 if ((!m_dreg_interface
.detected_p ())
2795 || (m_dreg_interface
.unavailable_p ()))
2798 if (m_dreg_interface
.hwdebug_p ())
2800 ptid_t
child_ptid (parent
->ptid
.pid (), child_lwp
, 0);
2802 copy_thread_dreg_state (parent
->ptid
, child_ptid
);
2806 /* Initialize the arch-specific thread state for LP so that it contains
2807 the ptid for lp, so that we can use it in low_delete_thread. Mark the
2808 new thread LP as stale so that we update its debug registers before
2809 resuming it. This is not called for the initial thread. */
2812 ppc_linux_nat_target::low_new_thread (struct lwp_info
*lp
)
2814 init_arch_lwp_info (lp
);
2816 mark_thread_stale (lp
);
2819 /* Delete the per-thread debug register stale flag. */
2822 ppc_linux_nat_target::low_delete_thread (struct arch_lwp_info
2825 if (lp_arch_info
!= NULL
)
2827 if (m_dreg_interface
.detected_p ()
2828 && m_dreg_interface
.hwdebug_p ())
2829 m_installed_hw_bps
.erase (lp_arch_info
->lwp_ptid
);
2831 xfree (lp_arch_info
);
2835 /* Install or delete debug registers in thread LP so that it matches what
2836 GDB requested before it is resumed. */
2839 ppc_linux_nat_target::low_prepare_to_resume (struct lwp_info
*lp
)
2841 if ((!m_dreg_interface
.detected_p ())
2842 || (m_dreg_interface
.unavailable_p ()))
2845 /* We have to re-install or clear the debug registers if we set the
2848 In addition, some kernels configurations can disable a hardware
2849 watchpoint after it is hit. Usually, GDB will remove and re-install
2850 a hardware watchpoint when the thread stops if "breakpoint
2851 always-inserted" is off, or to single-step a watchpoint. But so
2852 that we don't rely on this behavior, if we stop due to a hardware
2853 breakpoint or watchpoint, we also refresh our debug registers. */
2855 arch_lwp_info
*lp_arch_info
= get_arch_lwp_info (lp
);
2857 bool stale_dregs
= (lp
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
2858 || lp
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
2859 || lp_arch_info
->debug_regs_stale
);
2864 gdb_assert (lp
->ptid
.lwp_p ());
2866 auto process_it
= m_process_info
.find (lp
->ptid
.pid ());
2868 if (m_dreg_interface
.hwdebug_p ())
2870 /* First, delete any hardware watchpoint or breakpoint installed in
2871 the inferior and update the thread state. */
2872 auto installed_it
= m_installed_hw_bps
.find (lp
->ptid
);
2874 if (installed_it
!= m_installed_hw_bps
.end ())
2876 auto &bp_list
= installed_it
->second
;
2878 for (auto bp_it
= bp_list
.begin (); bp_it
!= bp_list
.end ();)
2880 /* We ignore ENOENT to account for various possible kernel
2881 behaviors, e.g. the kernel might or might not copy debug
2882 registers across forks and clones, and we always copy
2883 the debug register state when fork and clone events are
2885 if (ptrace (PPC_PTRACE_DELHWDEBUG
, lp
->ptid
.lwp (), 0,
2887 if (errno
!= ENOENT
)
2888 perror_with_name (_("Error deleting hardware "
2889 "breakpoint or watchpoint"));
2891 /* We erase the entries one at a time after successfuly
2892 removing the corresponding slot form the thread so that
2893 if we throw an exception above in a future iteration the
2894 map remains consistent. */
2895 bp_it
= bp_list
.erase (bp_it
);
2898 gdb_assert (bp_list
.empty ());
2901 /* Now we install all the requested hardware breakpoints and
2902 watchpoints and update the thread state. */
2904 if (process_it
!= m_process_info
.end ())
2906 auto &bp_list
= m_installed_hw_bps
[lp
->ptid
];
2908 for (ppc_hw_breakpoint bp
2909 : process_it
->second
.requested_hw_bps
)
2911 long slot
= ptrace (PPC_PTRACE_SETHWDEBUG
, lp
->ptid
.lwp (),
2915 perror_with_name (_("Error setting hardware "
2916 "breakpoint or watchpoint"));
2918 /* Keep track of which slots we installed in this
2920 bp_list
.emplace (bp_list
.begin (), slot
, bp
);
2926 gdb_assert (m_dreg_interface
.debugreg_p ());
2928 /* Passing 0 to PTRACE_SET_DEBUGREG will clear the watchpoint. We
2929 always clear the watchpoint instead of just overwriting it, in
2930 case there is a request for a new watchpoint, because on some
2931 older kernel versions and configurations simply overwriting the
2932 watchpoint after it was hit would not re-enable it. */
2933 if (ptrace (PTRACE_SET_DEBUGREG
, lp
->ptid
.lwp (), 0, 0) < 0)
2934 perror_with_name (_("Error clearing hardware watchpoint"));
2936 /* GDB requested a watchpoint to be installed. */
2937 if (process_it
!= m_process_info
.end ()
2938 && process_it
->second
.requested_wp_val
.has_value ())
2940 long wp
= *(process_it
->second
.requested_wp_val
);
2942 if (ptrace (PTRACE_SET_DEBUGREG
, lp
->ptid
.lwp (), 0, wp
) < 0)
2943 perror_with_name (_("Error setting hardware watchpoint"));
2947 lp_arch_info
->debug_regs_stale
= false;
2950 /* Return true if INFERIOR_PTID is known to have been stopped by a
2951 hardware watchpoint, false otherwise. If true is returned, write the
2952 address that the kernel reported as causing the SIGTRAP in ADDR_P. */
2955 ppc_linux_nat_target::low_stopped_data_address (CORE_ADDR
*addr_p
)
2959 if (!linux_nat_get_siginfo (inferior_ptid
, &siginfo
))
2962 if (siginfo
.si_signo
!= SIGTRAP
2963 || (siginfo
.si_code
& 0xffff) != 0x0004 /* TRAP_HWBKPT */)
2966 gdb_assert (!m_dreg_interface
.unavailable_p ());
2968 /* Check if this signal corresponds to a hardware breakpoint. We only
2969 need to check this if we're using the HWDEBUG interface, since the
2970 DEBUGREG interface only allows setting one hardware watchpoint. */
2971 if (m_dreg_interface
.hwdebug_p ())
2973 /* The index (or slot) of the *point is passed in the si_errno
2974 field. Currently, this is only the case if the kernel was
2975 configured with CONFIG_PPC_ADV_DEBUG_REGS. If not, we assume
2976 the kernel will set si_errno to a value that doesn't correspond
2977 to any real slot. */
2978 int slot
= siginfo
.si_errno
;
2980 auto installed_it
= m_installed_hw_bps
.find (inferior_ptid
);
2982 /* We must have installed slots for the thread if it got a
2983 TRAP_HWBKPT signal. */
2984 gdb_assert (installed_it
!= m_installed_hw_bps
.end ());
2986 for (const auto & slot_bp_pair
: installed_it
->second
)
2987 if (slot_bp_pair
.first
== slot
2988 && (slot_bp_pair
.second
.trigger_type
2989 == PPC_BREAKPOINT_TRIGGER_EXECUTE
))
2993 *addr_p
= (CORE_ADDR
) (uintptr_t) siginfo
.si_addr
;
2997 /* Return true if INFERIOR_PTID is known to have been stopped by a
2998 hardware watchpoint, false otherwise. */
3001 ppc_linux_nat_target::low_stopped_by_watchpoint ()
3004 return low_stopped_data_address (&addr
);
3008 ppc_linux_nat_target::watchpoint_addr_within_range (CORE_ADDR addr
,
3012 gdb_assert (!m_dreg_interface
.unavailable_p ());
3016 if (m_dreg_interface
.hwdebug_p ()
3017 && (linux_get_hwcap (current_inferior ()->top_target ())
3018 & PPC_FEATURE_BOOKE
))
3019 return start
<= addr
&& start
+ length
>= addr
;
3020 else if (linux_get_hwcap (current_inferior ()->top_target ())
3021 & PPC_FEATURE_BOOKE
)
3028 /* Check whether [start, start+length-1] intersects [addr, addr+mask]. */
3029 return start
<= addr
+ mask
&& start
+ length
- 1 >= addr
;
3032 /* Return the number of registers needed for a masked hardware watchpoint. */
3035 ppc_linux_nat_target::masked_watch_num_registers (CORE_ADDR addr
,
3038 m_dreg_interface
.detect (inferior_ptid
);
3040 if (!m_dreg_interface
.hwdebug_p ()
3041 || (m_dreg_interface
.hwdebug_info ().features
3042 & PPC_DEBUG_FEATURE_DATA_BP_MASK
) == 0)
3044 else if ((mask
& 0xC0000000) != 0xC0000000)
3046 warning (_("The given mask covers kernel address space "
3047 "and cannot be used.\n"));
3055 /* Copy the per-thread debug register state, if any, from thread
3056 PARENT_PTID to thread CHILD_PTID, if the debug register being used is
3060 ppc_linux_nat_target::copy_thread_dreg_state (const ptid_t
&parent_ptid
,
3061 const ptid_t
&child_ptid
)
3063 gdb_assert (m_dreg_interface
.hwdebug_p ());
3065 auto installed_it
= m_installed_hw_bps
.find (parent_ptid
);
3067 if (installed_it
!= m_installed_hw_bps
.end ())
3068 m_installed_hw_bps
[child_ptid
] = m_installed_hw_bps
[parent_ptid
];
3071 /* Mark the debug register stale flag for the new thread, if we have
3072 already detected which debug register interface we use. */
3075 ppc_linux_nat_target::mark_thread_stale (struct lwp_info
*lp
)
3077 if ((!m_dreg_interface
.detected_p ())
3078 || (m_dreg_interface
.unavailable_p ()))
3081 arch_lwp_info
*lp_arch_info
= get_arch_lwp_info (lp
);
3083 lp_arch_info
->debug_regs_stale
= true;
3086 /* Mark all the threads of the group of PID as stale with respect to
3087 debug registers and issue a stop request to each such thread that
3088 isn't already stopped. */
3091 ppc_linux_nat_target::mark_debug_registers_changed (pid_t pid
)
3093 /* We do this in two passes to make sure all threads are marked even if
3094 we get an exception when stopping one of them. */
3096 iterate_over_lwps (ptid_t (pid
),
3097 [this] (struct lwp_info
*lp
) -> int {
3098 this->mark_thread_stale (lp
);
3102 iterate_over_lwps (ptid_t (pid
),
3103 [] (struct lwp_info
*lp
) -> int {
3104 if (!lwp_is_stopped (lp
))
3105 linux_stop_lwp (lp
);
3110 /* Register a hardware breakpoint or watchpoint BP for the pid PID, then
3111 mark the stale flag for all threads of the group of PID, and issue a
3112 stop request for them. The breakpoint or watchpoint will be installed
3113 the next time each thread is resumed. Should only be used if the
3114 debug register interface is HWDEBUG. */
3117 ppc_linux_nat_target::register_hw_breakpoint (pid_t pid
,
3119 ppc_hw_breakpoint
&bp
)
3121 gdb_assert (m_dreg_interface
.hwdebug_p ());
3123 m_process_info
[pid
].requested_hw_bps
.push_back (bp
);
3125 mark_debug_registers_changed (pid
);
3128 /* Clear a registration for a hardware breakpoint or watchpoint BP for
3129 the pid PID, then mark the stale flag for all threads of the group of
3130 PID, and issue a stop request for them. The breakpoint or watchpoint
3131 will be removed the next time each thread is resumed. Should only be
3132 used if the debug register interface is HWDEBUG. */
3135 ppc_linux_nat_target::clear_hw_breakpoint (pid_t pid
,
3136 const struct ppc_hw_breakpoint
&bp
)
3138 gdb_assert (m_dreg_interface
.hwdebug_p ());
3140 auto process_it
= m_process_info
.find (pid
);
3142 gdb_assert (process_it
!= m_process_info
.end ());
3144 auto bp_it
= std::find_if (process_it
->second
.requested_hw_bps
.begin (),
3145 process_it
->second
.requested_hw_bps
.end (),
3147 (const struct ppc_hw_breakpoint
&curr
)
3148 { return hwdebug_point_cmp (bp
, curr
); }
3151 /* If GDB is removing a watchpoint, it must have been inserted. */
3152 gdb_assert (bp_it
!= process_it
->second
.requested_hw_bps
.end ());
3154 process_it
->second
.requested_hw_bps
.erase (bp_it
);
3156 mark_debug_registers_changed (pid
);
3159 /* Register the hardware watchpoint value WP_VALUE for the pid PID,
3160 then mark the stale flag for all threads of the group of PID, and
3161 issue a stop request for them. The breakpoint or watchpoint will be
3162 installed the next time each thread is resumed. Should only be used
3163 if the debug register interface is DEBUGREG. */
3166 ppc_linux_nat_target::register_wp (pid_t pid
, long wp_value
)
3168 gdb_assert (m_dreg_interface
.debugreg_p ());
3170 /* Our other functions should have told GDB that we only have one
3171 hardware watchpoint with this interface. */
3172 gdb_assert (!m_process_info
[pid
].requested_wp_val
.has_value ());
3174 m_process_info
[pid
].requested_wp_val
.emplace (wp_value
);
3176 mark_debug_registers_changed (pid
);
3179 /* Clear the hardware watchpoint registration for the pid PID, then mark
3180 the stale flag for all threads of the group of PID, and issue a stop
3181 request for them. The breakpoint or watchpoint will be installed the
3182 next time each thread is resumed. Should only be used if the debug
3183 register interface is DEBUGREG. */
3186 ppc_linux_nat_target::clear_wp (pid_t pid
)
3188 gdb_assert (m_dreg_interface
.debugreg_p ());
3190 auto process_it
= m_process_info
.find (pid
);
3192 gdb_assert (process_it
!= m_process_info
.end ());
3193 gdb_assert (process_it
->second
.requested_wp_val
.has_value ());
3195 process_it
->second
.requested_wp_val
.reset ();
3197 mark_debug_registers_changed (pid
);
3200 /* Initialize the arch-specific thread state for LWP, if it not already
3204 ppc_linux_nat_target::init_arch_lwp_info (struct lwp_info
*lp
)
3206 if (lwp_arch_private_info (lp
) == NULL
)
3208 lwp_set_arch_private_info (lp
, XCNEW (struct arch_lwp_info
));
3209 lwp_arch_private_info (lp
)->debug_regs_stale
= false;
3210 lwp_arch_private_info (lp
)->lwp_ptid
= lp
->ptid
;
3214 /* Get the arch-specific thread state for LWP, creating it if
3218 ppc_linux_nat_target::get_arch_lwp_info (struct lwp_info
*lp
)
3220 init_arch_lwp_info (lp
);
3222 return lwp_arch_private_info (lp
);
3225 void _initialize_ppc_linux_nat ();
3227 _initialize_ppc_linux_nat ()
3229 linux_target
= &the_ppc_linux_nat_target
;
3231 /* Register the target. */
3232 add_inf_child_target (linux_target
);