1 /* S390 native-dependent code for GDB, the GNU debugger.
2 Copyright (C) 2001-2016 Free Software Foundation, Inc.
4 Contributed by D.J. Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
5 for IBM Deutschland Entwicklung GmbH, IBM Corporation.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "linux-nat.h"
30 #include "nat/linux-ptrace.h"
33 #include "s390-linux-tdep.h"
34 #include "elf/common.h"
36 #include <asm/ptrace.h>
37 #include "nat/gdb_ptrace.h"
38 #include <asm/types.h>
39 #include <sys/procfs.h>
40 #include <sys/ucontext.h>
43 /* Per-thread arch-specific data. */
47 /* Non-zero if the thread's PER info must be re-written. */
51 static int have_regset_last_break
= 0;
52 static int have_regset_system_call
= 0;
53 static int have_regset_tdb
= 0;
54 static int have_regset_vxrs
= 0;
56 /* Register map for 32-bit executables running under a 64-bit
60 static const struct regcache_map_entry s390_64_regmap_gregset
[] =
62 /* Skip PSWM and PSWA, since they must be handled specially. */
63 { 2, REGCACHE_MAP_SKIP
, 8 },
64 { 1, S390_R0_UPPER_REGNUM
, 4 }, { 1, S390_R0_REGNUM
, 4 },
65 { 1, S390_R1_UPPER_REGNUM
, 4 }, { 1, S390_R1_REGNUM
, 4 },
66 { 1, S390_R2_UPPER_REGNUM
, 4 }, { 1, S390_R2_REGNUM
, 4 },
67 { 1, S390_R3_UPPER_REGNUM
, 4 }, { 1, S390_R3_REGNUM
, 4 },
68 { 1, S390_R4_UPPER_REGNUM
, 4 }, { 1, S390_R4_REGNUM
, 4 },
69 { 1, S390_R5_UPPER_REGNUM
, 4 }, { 1, S390_R5_REGNUM
, 4 },
70 { 1, S390_R6_UPPER_REGNUM
, 4 }, { 1, S390_R6_REGNUM
, 4 },
71 { 1, S390_R7_UPPER_REGNUM
, 4 }, { 1, S390_R7_REGNUM
, 4 },
72 { 1, S390_R8_UPPER_REGNUM
, 4 }, { 1, S390_R8_REGNUM
, 4 },
73 { 1, S390_R9_UPPER_REGNUM
, 4 }, { 1, S390_R9_REGNUM
, 4 },
74 { 1, S390_R10_UPPER_REGNUM
, 4 }, { 1, S390_R10_REGNUM
, 4 },
75 { 1, S390_R11_UPPER_REGNUM
, 4 }, { 1, S390_R11_REGNUM
, 4 },
76 { 1, S390_R12_UPPER_REGNUM
, 4 }, { 1, S390_R12_REGNUM
, 4 },
77 { 1, S390_R13_UPPER_REGNUM
, 4 }, { 1, S390_R13_REGNUM
, 4 },
78 { 1, S390_R14_UPPER_REGNUM
, 4 }, { 1, S390_R14_REGNUM
, 4 },
79 { 1, S390_R15_UPPER_REGNUM
, 4 }, { 1, S390_R15_REGNUM
, 4 },
80 { 16, S390_A0_REGNUM
, 4 },
81 { 1, REGCACHE_MAP_SKIP
, 4 }, { 1, S390_ORIG_R2_REGNUM
, 4 },
85 static const struct regset s390_64_gregset
=
87 s390_64_regmap_gregset
,
88 regcache_supply_regset
,
89 regcache_collect_regset
92 #define S390_PSWM_OFFSET 0
93 #define S390_PSWA_OFFSET 8
96 /* Fill GDB's register array with the general-purpose register values
99 When debugging a 32-bit executable running under a 64-bit kernel,
100 we have to fix up the 64-bit registers we get from the kernel to
101 make them look like 32-bit registers. */
104 supply_gregset (struct regcache
*regcache
, const gregset_t
*regp
)
107 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
108 if (gdbarch_ptr_bit (gdbarch
) == 32)
110 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
114 regcache_supply_regset (&s390_64_gregset
, regcache
, -1,
115 regp
, sizeof (gregset_t
));
116 pswm
= extract_unsigned_integer ((const gdb_byte
*) regp
117 + S390_PSWM_OFFSET
, 8, byte_order
);
118 pswa
= extract_unsigned_integer ((const gdb_byte
*) regp
119 + S390_PSWA_OFFSET
, 8, byte_order
);
120 store_unsigned_integer (buf
, 4, byte_order
, (pswm
>> 32) | 0x80000);
121 regcache_raw_supply (regcache
, S390_PSWM_REGNUM
, buf
);
122 store_unsigned_integer (buf
, 4, byte_order
,
123 (pswa
& 0x7fffffff) | (pswm
& 0x80000000));
124 regcache_raw_supply (regcache
, S390_PSWA_REGNUM
, buf
);
129 regcache_supply_regset (&s390_gregset
, regcache
, -1, regp
,
133 /* Fill register REGNO (if it is a general-purpose register) in
134 *REGP with the value in GDB's register array. If REGNO is -1,
135 do this for all registers. */
138 fill_gregset (const struct regcache
*regcache
, gregset_t
*regp
, int regno
)
141 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
142 if (gdbarch_ptr_bit (gdbarch
) == 32)
144 regcache_collect_regset (&s390_64_gregset
, regcache
, regno
,
145 regp
, sizeof (gregset_t
));
148 || regno
== S390_PSWM_REGNUM
|| regno
== S390_PSWA_REGNUM
)
150 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
153 gdb_byte
*pswm_p
= (gdb_byte
*) regp
+ S390_PSWM_OFFSET
;
154 gdb_byte
*pswa_p
= (gdb_byte
*) regp
+ S390_PSWA_OFFSET
;
156 pswm
= extract_unsigned_integer (pswm_p
, 8, byte_order
);
158 if (regno
== -1 || regno
== S390_PSWM_REGNUM
)
161 regcache_raw_collect (regcache
, S390_PSWM_REGNUM
, buf
);
162 pswm
|= (extract_unsigned_integer (buf
, 4, byte_order
)
166 if (regno
== -1 || regno
== S390_PSWA_REGNUM
)
168 regcache_raw_collect (regcache
, S390_PSWA_REGNUM
, buf
);
169 pswa
= extract_unsigned_integer (buf
, 4, byte_order
);
170 pswm
^= (pswm
^ pswa
) & 0x80000000;
172 store_unsigned_integer (pswa_p
, 8, byte_order
, pswa
);
175 store_unsigned_integer (pswm_p
, 8, byte_order
, pswm
);
181 regcache_collect_regset (&s390_gregset
, regcache
, regno
, regp
,
185 /* Fill GDB's register array with the floating-point register values
188 supply_fpregset (struct regcache
*regcache
, const fpregset_t
*regp
)
190 regcache_supply_regset (&s390_fpregset
, regcache
, -1, regp
,
191 sizeof (fpregset_t
));
194 /* Fill register REGNO (if it is a general-purpose register) in
195 *REGP with the value in GDB's register array. If REGNO is -1,
196 do this for all registers. */
198 fill_fpregset (const struct regcache
*regcache
, fpregset_t
*regp
, int regno
)
200 regcache_collect_regset (&s390_fpregset
, regcache
, regno
, regp
,
201 sizeof (fpregset_t
));
204 /* Find the TID for the current inferior thread to use with ptrace. */
206 s390_inferior_tid (void)
208 /* GNU/Linux LWP ID's are process ID's. */
209 int tid
= ptid_get_lwp (inferior_ptid
);
211 tid
= ptid_get_pid (inferior_ptid
); /* Not a threaded program. */
216 /* Fetch all general-purpose registers from process/thread TID and
217 store their values in GDB's register cache. */
219 fetch_regs (struct regcache
*regcache
, int tid
)
224 parea
.len
= sizeof (regs
);
225 parea
.process_addr
= (addr_t
) ®s
;
226 parea
.kernel_addr
= offsetof (struct user_regs_struct
, psw
);
227 if (ptrace (PTRACE_PEEKUSR_AREA
, tid
, (long) &parea
, 0) < 0)
228 perror_with_name (_("Couldn't get registers"));
230 supply_gregset (regcache
, (const gregset_t
*) ®s
);
233 /* Store all valid general-purpose registers in GDB's register cache
234 into the process/thread specified by TID. */
236 store_regs (const struct regcache
*regcache
, int tid
, int regnum
)
241 parea
.len
= sizeof (regs
);
242 parea
.process_addr
= (addr_t
) ®s
;
243 parea
.kernel_addr
= offsetof (struct user_regs_struct
, psw
);
244 if (ptrace (PTRACE_PEEKUSR_AREA
, tid
, (long) &parea
, 0) < 0)
245 perror_with_name (_("Couldn't get registers"));
247 fill_gregset (regcache
, ®s
, regnum
);
249 if (ptrace (PTRACE_POKEUSR_AREA
, tid
, (long) &parea
, 0) < 0)
250 perror_with_name (_("Couldn't write registers"));
253 /* Fetch all floating-point registers from process/thread TID and store
254 their values in GDB's register cache. */
256 fetch_fpregs (struct regcache
*regcache
, int tid
)
261 parea
.len
= sizeof (fpregs
);
262 parea
.process_addr
= (addr_t
) &fpregs
;
263 parea
.kernel_addr
= offsetof (struct user_regs_struct
, fp_regs
);
264 if (ptrace (PTRACE_PEEKUSR_AREA
, tid
, (long) &parea
, 0) < 0)
265 perror_with_name (_("Couldn't get floating point status"));
267 supply_fpregset (regcache
, (const fpregset_t
*) &fpregs
);
270 /* Store all valid floating-point registers in GDB's register cache
271 into the process/thread specified by TID. */
273 store_fpregs (const struct regcache
*regcache
, int tid
, int regnum
)
278 parea
.len
= sizeof (fpregs
);
279 parea
.process_addr
= (addr_t
) &fpregs
;
280 parea
.kernel_addr
= offsetof (struct user_regs_struct
, fp_regs
);
281 if (ptrace (PTRACE_PEEKUSR_AREA
, tid
, (long) &parea
, 0) < 0)
282 perror_with_name (_("Couldn't get floating point status"));
284 fill_fpregset (regcache
, &fpregs
, regnum
);
286 if (ptrace (PTRACE_POKEUSR_AREA
, tid
, (long) &parea
, 0) < 0)
287 perror_with_name (_("Couldn't write floating point status"));
290 /* Fetch all registers in the kernel's register set whose number is
291 REGSET_ID, whose size is REGSIZE, and whose layout is described by
292 REGSET, from process/thread TID and store their values in GDB's
295 fetch_regset (struct regcache
*regcache
, int tid
,
296 int regset_id
, int regsize
, const struct regset
*regset
)
298 void *buf
= alloca (regsize
);
302 iov
.iov_len
= regsize
;
304 if (ptrace (PTRACE_GETREGSET
, tid
, (long) regset_id
, (long) &iov
) < 0)
306 if (errno
== ENODATA
)
307 regcache_supply_regset (regset
, regcache
, -1, NULL
, regsize
);
309 perror_with_name (_("Couldn't get register set"));
312 regcache_supply_regset (regset
, regcache
, -1, buf
, regsize
);
315 /* Store all registers in the kernel's register set whose number is
316 REGSET_ID, whose size is REGSIZE, and whose layout is described by
317 REGSET, from GDB's register cache back to process/thread TID. */
319 store_regset (struct regcache
*regcache
, int tid
,
320 int regset_id
, int regsize
, const struct regset
*regset
)
322 void *buf
= alloca (regsize
);
326 iov
.iov_len
= regsize
;
328 if (ptrace (PTRACE_GETREGSET
, tid
, (long) regset_id
, (long) &iov
) < 0)
329 perror_with_name (_("Couldn't get register set"));
331 regcache_collect_regset (regset
, regcache
, -1, buf
, regsize
);
333 if (ptrace (PTRACE_SETREGSET
, tid
, (long) regset_id
, (long) &iov
) < 0)
334 perror_with_name (_("Couldn't set register set"));
337 /* Check whether the kernel provides a register set with number REGSET
338 of size REGSIZE for process/thread TID. */
340 check_regset (int tid
, int regset
, int regsize
)
342 void *buf
= alloca (regsize
);
346 iov
.iov_len
= regsize
;
348 if (ptrace (PTRACE_GETREGSET
, tid
, (long) regset
, (long) &iov
) >= 0
354 /* Fetch register REGNUM from the child process. If REGNUM is -1, do
355 this for all registers. */
357 s390_linux_fetch_inferior_registers (struct target_ops
*ops
,
358 struct regcache
*regcache
, int regnum
)
360 int tid
= s390_inferior_tid ();
362 if (regnum
== -1 || S390_IS_GREGSET_REGNUM (regnum
))
363 fetch_regs (regcache
, tid
);
365 if (regnum
== -1 || S390_IS_FPREGSET_REGNUM (regnum
))
366 fetch_fpregs (regcache
, tid
);
368 if (have_regset_last_break
)
369 if (regnum
== -1 || regnum
== S390_LAST_BREAK_REGNUM
)
370 fetch_regset (regcache
, tid
, NT_S390_LAST_BREAK
, 8,
371 (gdbarch_ptr_bit (get_regcache_arch (regcache
)) == 32
372 ? &s390_last_break_regset
: &s390x_last_break_regset
));
374 if (have_regset_system_call
)
375 if (regnum
== -1 || regnum
== S390_SYSTEM_CALL_REGNUM
)
376 fetch_regset (regcache
, tid
, NT_S390_SYSTEM_CALL
, 4,
377 &s390_system_call_regset
);
380 if (regnum
== -1 || S390_IS_TDBREGSET_REGNUM (regnum
))
381 fetch_regset (regcache
, tid
, NT_S390_TDB
, s390_sizeof_tdbregset
,
384 if (have_regset_vxrs
)
386 if (regnum
== -1 || (regnum
>= S390_V0_LOWER_REGNUM
387 && regnum
<= S390_V15_LOWER_REGNUM
))
388 fetch_regset (regcache
, tid
, NT_S390_VXRS_LOW
, 16 * 8,
389 &s390_vxrs_low_regset
);
390 if (regnum
== -1 || (regnum
>= S390_V16_REGNUM
391 && regnum
<= S390_V31_REGNUM
))
392 fetch_regset (regcache
, tid
, NT_S390_VXRS_HIGH
, 16 * 16,
393 &s390_vxrs_high_regset
);
397 /* Store register REGNUM back into the child process. If REGNUM is
398 -1, do this for all registers. */
400 s390_linux_store_inferior_registers (struct target_ops
*ops
,
401 struct regcache
*regcache
, int regnum
)
403 int tid
= s390_inferior_tid ();
405 if (regnum
== -1 || S390_IS_GREGSET_REGNUM (regnum
))
406 store_regs (regcache
, tid
, regnum
);
408 if (regnum
== -1 || S390_IS_FPREGSET_REGNUM (regnum
))
409 store_fpregs (regcache
, tid
, regnum
);
411 /* S390_LAST_BREAK_REGNUM is read-only. */
413 if (have_regset_system_call
)
414 if (regnum
== -1 || regnum
== S390_SYSTEM_CALL_REGNUM
)
415 store_regset (regcache
, tid
, NT_S390_SYSTEM_CALL
, 4,
416 &s390_system_call_regset
);
418 if (have_regset_vxrs
)
420 if (regnum
== -1 || (regnum
>= S390_V0_LOWER_REGNUM
421 && regnum
<= S390_V15_LOWER_REGNUM
))
422 store_regset (regcache
, tid
, NT_S390_VXRS_LOW
, 16 * 8,
423 &s390_vxrs_low_regset
);
424 if (regnum
== -1 || (regnum
>= S390_V16_REGNUM
425 && regnum
<= S390_V31_REGNUM
))
426 store_regset (regcache
, tid
, NT_S390_VXRS_HIGH
, 16 * 16,
427 &s390_vxrs_high_regset
);
432 /* Hardware-assisted watchpoint handling. */
434 /* For each process we maintain a list of all currently active
435 watchpoints, in order to properly handle watchpoint removal.
437 The only thing we actually need is the total address space area
438 spanned by the watchpoints. */
440 typedef struct watch_area
446 DEF_VEC_O (s390_watch_area
);
448 /* Hardware debug state. */
450 struct s390_debug_reg_state
452 VEC_s390_watch_area
*watch_areas
;
455 /* Per-process data. */
457 struct s390_process_info
459 struct s390_process_info
*next
;
461 struct s390_debug_reg_state state
;
464 static struct s390_process_info
*s390_process_list
= NULL
;
466 /* Find process data for process PID. */
468 static struct s390_process_info
*
469 s390_find_process_pid (pid_t pid
)
471 struct s390_process_info
*proc
;
473 for (proc
= s390_process_list
; proc
; proc
= proc
->next
)
474 if (proc
->pid
== pid
)
480 /* Add process data for process PID. Returns newly allocated info
483 static struct s390_process_info
*
484 s390_add_process (pid_t pid
)
486 struct s390_process_info
*proc
= XCNEW (struct s390_process_info
);
489 proc
->next
= s390_process_list
;
490 s390_process_list
= proc
;
495 /* Get data specific info for process PID, creating it if necessary.
496 Never returns NULL. */
498 static struct s390_process_info
*
499 s390_process_info_get (pid_t pid
)
501 struct s390_process_info
*proc
;
503 proc
= s390_find_process_pid (pid
);
505 proc
= s390_add_process (pid
);
510 /* Get hardware debug state for process PID. */
512 static struct s390_debug_reg_state
*
513 s390_get_debug_reg_state (pid_t pid
)
515 return &s390_process_info_get (pid
)->state
;
518 /* Called whenever GDB is no longer debugging process PID. It deletes
519 data structures that keep track of hardware debug state. */
522 s390_forget_process (pid_t pid
)
524 struct s390_process_info
*proc
, **proc_link
;
526 proc
= s390_process_list
;
527 proc_link
= &s390_process_list
;
531 if (proc
->pid
== pid
)
533 VEC_free (s390_watch_area
, proc
->state
.watch_areas
);
534 *proc_link
= proc
->next
;
539 proc_link
= &proc
->next
;
544 /* linux_nat_new_fork hook. */
547 s390_linux_new_fork (struct lwp_info
*parent
, pid_t child_pid
)
550 struct s390_debug_reg_state
*parent_state
;
551 struct s390_debug_reg_state
*child_state
;
553 /* NULL means no watchpoint has ever been set in the parent. In
554 that case, there's nothing to do. */
555 if (lwp_arch_private_info (parent
) == NULL
)
558 /* GDB core assumes the child inherits the watchpoints/hw breakpoints of
559 the parent. So copy the debug state from parent to child. */
561 parent_pid
= ptid_get_pid (parent
->ptid
);
562 parent_state
= s390_get_debug_reg_state (parent_pid
);
563 child_state
= s390_get_debug_reg_state (child_pid
);
565 child_state
->watch_areas
= VEC_copy (s390_watch_area
,
566 parent_state
->watch_areas
);
569 /* Dump PER state. */
572 s390_show_debug_regs (int tid
, const char *where
)
577 parea
.len
= sizeof (per_info
);
578 parea
.process_addr
= (addr_t
) &per_info
;
579 parea
.kernel_addr
= offsetof (struct user_regs_struct
, per_info
);
581 if (ptrace (PTRACE_PEEKUSR_AREA
, tid
, &parea
, 0) < 0)
582 perror_with_name (_("Couldn't retrieve debug regs"));
584 debug_printf ("PER (debug) state for %d -- %s\n"
585 " cr9-11: %lx %lx %lx\n"
586 " start, end: %lx %lx\n"
587 " code/ATMID: %x address: %lx PAID: %x\n",
590 per_info
.control_regs
.words
.cr
[0],
591 per_info
.control_regs
.words
.cr
[1],
592 per_info
.control_regs
.words
.cr
[2],
593 per_info
.starting_addr
,
594 per_info
.ending_addr
,
595 per_info
.lowcore
.words
.perc_atmid
,
596 per_info
.lowcore
.words
.address
,
597 per_info
.lowcore
.words
.access_id
);
601 s390_stopped_by_watchpoint (struct target_ops
*ops
)
603 struct s390_debug_reg_state
*state
604 = s390_get_debug_reg_state (ptid_get_pid (inferior_ptid
));
605 per_lowcore_bits per_lowcore
;
610 s390_show_debug_regs (s390_inferior_tid (), "stop");
612 /* Speed up common case. */
613 if (VEC_empty (s390_watch_area
, state
->watch_areas
))
616 parea
.len
= sizeof (per_lowcore
);
617 parea
.process_addr
= (addr_t
) & per_lowcore
;
618 parea
.kernel_addr
= offsetof (struct user_regs_struct
, per_info
.lowcore
);
619 if (ptrace (PTRACE_PEEKUSR_AREA
, s390_inferior_tid (), &parea
, 0) < 0)
620 perror_with_name (_("Couldn't retrieve watchpoint status"));
622 result
= (per_lowcore
.perc_storage_alteration
== 1
623 && per_lowcore
.perc_store_real_address
== 0);
627 /* Do not report this watchpoint again. */
628 memset (&per_lowcore
, 0, sizeof (per_lowcore
));
629 if (ptrace (PTRACE_POKEUSR_AREA
, s390_inferior_tid (), &parea
, 0) < 0)
630 perror_with_name (_("Couldn't clear watchpoint status"));
636 /* Each time before resuming a thread, update its PER info. */
639 s390_prepare_to_resume (struct lwp_info
*lp
)
642 pid_t pid
= ptid_get_pid (ptid_of_lwp (lp
));
647 CORE_ADDR watch_lo_addr
= (CORE_ADDR
)-1, watch_hi_addr
= 0;
649 s390_watch_area
*area
;
650 struct arch_lwp_info
*lp_priv
= lwp_arch_private_info (lp
);
651 struct s390_debug_reg_state
*state
= s390_get_debug_reg_state (pid
);
653 if (lp_priv
== NULL
|| !lp_priv
->per_info_changed
)
656 lp_priv
->per_info_changed
= 0;
658 tid
= ptid_get_lwp (ptid_of_lwp (lp
));
662 parea
.len
= sizeof (per_info
);
663 parea
.process_addr
= (addr_t
) & per_info
;
664 parea
.kernel_addr
= offsetof (struct user_regs_struct
, per_info
);
665 if (ptrace (PTRACE_PEEKUSR_AREA
, tid
, &parea
, 0) < 0)
666 perror_with_name (_("Couldn't retrieve watchpoint status"));
668 if (!VEC_empty (s390_watch_area
, state
->watch_areas
))
671 VEC_iterate (s390_watch_area
, state
->watch_areas
, ix
, area
);
674 watch_lo_addr
= min (watch_lo_addr
, area
->lo_addr
);
675 watch_hi_addr
= max (watch_hi_addr
, area
->hi_addr
);
678 per_info
.control_regs
.bits
.em_storage_alteration
= 1;
679 per_info
.control_regs
.bits
.storage_alt_space_ctl
= 1;
683 per_info
.control_regs
.bits
.em_storage_alteration
= 0;
684 per_info
.control_regs
.bits
.storage_alt_space_ctl
= 0;
686 per_info
.starting_addr
= watch_lo_addr
;
687 per_info
.ending_addr
= watch_hi_addr
;
689 if (ptrace (PTRACE_POKEUSR_AREA
, tid
, &parea
, 0) < 0)
690 perror_with_name (_("Couldn't modify watchpoint status"));
693 s390_show_debug_regs (tid
, "resume");
696 /* Mark the PER info as changed, so the next resume will update it. */
699 s390_mark_per_info_changed (struct lwp_info
*lp
)
701 if (lwp_arch_private_info (lp
) == NULL
)
702 lwp_set_arch_private_info (lp
, XCNEW (struct arch_lwp_info
));
704 lwp_arch_private_info (lp
)->per_info_changed
= 1;
707 /* When attaching to a new thread, mark its PER info as changed. */
710 s390_new_thread (struct lwp_info
*lp
)
712 s390_mark_per_info_changed (lp
);
715 /* Iterator callback for s390_refresh_per_info. */
718 s390_refresh_per_info_cb (struct lwp_info
*lp
, void *arg
)
720 s390_mark_per_info_changed (lp
);
722 if (!lwp_is_stopped (lp
))
727 /* Make sure that threads are stopped and mark PER info as changed. */
730 s390_refresh_per_info (void)
732 ptid_t pid_ptid
= pid_to_ptid (ptid_get_pid (current_lwp_ptid ()));
734 iterate_over_lwps (pid_ptid
, s390_refresh_per_info_cb
, NULL
);
739 s390_insert_watchpoint (struct target_ops
*self
,
740 CORE_ADDR addr
, int len
, enum target_hw_bp_type type
,
741 struct expression
*cond
)
743 s390_watch_area area
;
744 struct s390_debug_reg_state
*state
745 = s390_get_debug_reg_state (ptid_get_pid (inferior_ptid
));
748 area
.hi_addr
= addr
+ len
- 1;
749 VEC_safe_push (s390_watch_area
, state
->watch_areas
, &area
);
751 return s390_refresh_per_info ();
755 s390_remove_watchpoint (struct target_ops
*self
,
756 CORE_ADDR addr
, int len
, enum target_hw_bp_type type
,
757 struct expression
*cond
)
760 s390_watch_area
*area
;
761 struct s390_debug_reg_state
*state
762 = s390_get_debug_reg_state (ptid_get_pid (inferior_ptid
));
765 VEC_iterate (s390_watch_area
, state
->watch_areas
, ix
, area
);
768 if (area
->lo_addr
== addr
&& area
->hi_addr
== addr
+ len
- 1)
770 VEC_unordered_remove (s390_watch_area
, state
->watch_areas
, ix
);
771 return s390_refresh_per_info ();
775 fprintf_unfiltered (gdb_stderr
,
776 "Attempt to remove nonexistent watchpoint.\n");
781 s390_can_use_hw_breakpoint (struct target_ops
*self
,
782 enum bptype type
, int cnt
, int othertype
)
784 return type
== bp_hardware_watchpoint
;
788 s390_region_ok_for_hw_watchpoint (struct target_ops
*self
,
789 CORE_ADDR addr
, int cnt
)
795 s390_target_wordsize (void)
799 /* Check for 64-bit inferior process. This is the case when the host is
800 64-bit, and in addition bit 32 of the PSW mask is set. */
805 pswm
= (long) ptrace (PTRACE_PEEKUSER
, s390_inferior_tid (), PT_PSWMASK
, 0);
806 if (errno
== 0 && (pswm
& 0x100000000ul
) != 0)
814 s390_auxv_parse (struct target_ops
*ops
, gdb_byte
**readptr
,
815 gdb_byte
*endptr
, CORE_ADDR
*typep
, CORE_ADDR
*valp
)
817 int sizeof_auxv_field
= s390_target_wordsize ();
818 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch ());
819 gdb_byte
*ptr
= *readptr
;
824 if (endptr
- ptr
< sizeof_auxv_field
* 2)
827 *typep
= extract_unsigned_integer (ptr
, sizeof_auxv_field
, byte_order
);
828 ptr
+= sizeof_auxv_field
;
829 *valp
= extract_unsigned_integer (ptr
, sizeof_auxv_field
, byte_order
);
830 ptr
+= sizeof_auxv_field
;
836 static const struct target_desc
*
837 s390_read_description (struct target_ops
*ops
)
839 int tid
= s390_inferior_tid ();
841 have_regset_last_break
842 = check_regset (tid
, NT_S390_LAST_BREAK
, 8);
843 have_regset_system_call
844 = check_regset (tid
, NT_S390_SYSTEM_CALL
, 4);
846 /* If GDB itself is compiled as 64-bit, we are running on a machine in
847 z/Architecture mode. If the target is running in 64-bit addressing
848 mode, report s390x architecture. If the target is running in 31-bit
849 addressing mode, but the kernel supports using 64-bit registers in
850 that mode, report s390 architecture with 64-bit GPRs. */
855 target_auxv_search (¤t_target
, AT_HWCAP
, &hwcap
);
856 have_regset_tdb
= (hwcap
& HWCAP_S390_TE
)
857 && check_regset (tid
, NT_S390_TDB
, s390_sizeof_tdbregset
);
859 have_regset_vxrs
= (hwcap
& HWCAP_S390_VX
)
860 && check_regset (tid
, NT_S390_VXRS_LOW
, 16 * 8)
861 && check_regset (tid
, NT_S390_VXRS_HIGH
, 16 * 16);
863 if (s390_target_wordsize () == 8)
864 return (have_regset_vxrs
?
865 (have_regset_tdb
? tdesc_s390x_tevx_linux64
:
866 tdesc_s390x_vx_linux64
) :
867 have_regset_tdb
? tdesc_s390x_te_linux64
:
868 have_regset_system_call
? tdesc_s390x_linux64v2
:
869 have_regset_last_break
? tdesc_s390x_linux64v1
:
870 tdesc_s390x_linux64
);
872 if (hwcap
& HWCAP_S390_HIGH_GPRS
)
873 return (have_regset_vxrs
?
874 (have_regset_tdb
? tdesc_s390_tevx_linux64
:
875 tdesc_s390_vx_linux64
) :
876 have_regset_tdb
? tdesc_s390_te_linux64
:
877 have_regset_system_call
? tdesc_s390_linux64v2
:
878 have_regset_last_break
? tdesc_s390_linux64v1
:
883 /* If GDB itself is compiled as 31-bit, or if we're running a 31-bit inferior
884 on a 64-bit kernel that does not support using 64-bit registers in 31-bit
885 mode, report s390 architecture with 32-bit GPRs. */
886 return (have_regset_system_call
? tdesc_s390_linux32v2
:
887 have_regset_last_break
? tdesc_s390_linux32v1
:
891 void _initialize_s390_nat (void);
894 _initialize_s390_nat (void)
896 struct target_ops
*t
;
898 /* Fill in the generic GNU/Linux methods. */
901 /* Add our register access methods. */
902 t
->to_fetch_registers
= s390_linux_fetch_inferior_registers
;
903 t
->to_store_registers
= s390_linux_store_inferior_registers
;
905 /* Add our watchpoint methods. */
906 t
->to_can_use_hw_breakpoint
= s390_can_use_hw_breakpoint
;
907 t
->to_region_ok_for_hw_watchpoint
= s390_region_ok_for_hw_watchpoint
;
908 t
->to_have_continuable_watchpoint
= 1;
909 t
->to_stopped_by_watchpoint
= s390_stopped_by_watchpoint
;
910 t
->to_insert_watchpoint
= s390_insert_watchpoint
;
911 t
->to_remove_watchpoint
= s390_remove_watchpoint
;
913 /* Detect target architecture. */
914 t
->to_read_description
= s390_read_description
;
915 t
->to_auxv_parse
= s390_auxv_parse
;
917 /* Register the target. */
918 linux_nat_add_target (t
);
919 linux_nat_set_new_thread (t
, s390_new_thread
);
920 linux_nat_set_prepare_to_resume (t
, s390_prepare_to_resume
);
921 linux_nat_set_forget_process (t
, s390_forget_process
);
922 linux_nat_set_new_fork (t
, s390_linux_new_fork
);
924 /* A maintenance command to enable showing the PER state. */
925 add_setshow_boolean_cmd ("show-debug-regs", class_maintenance
,
926 &show_debug_regs
, _("\
927 Set whether to show the PER (debug) hardware state."), _("\
928 Show whether to show the PER (debug) hardware state."), _("\
929 Use \"on\" to enable, \"off\" to disable.\n\
930 If enabled, the PER state is shown after it is changed by GDB,\n\
931 and when the inferior triggers a breakpoint or watchpoint."),
934 &maintenance_set_cmdlist
,
935 &maintenance_show_cmdlist
);