GDB (xrefs)
/tmp/gdb-7.10/gdb/s390-linux-nat.c
Go to the documentation of this file.
1 /* S390 native-dependent code for GDB, the GNU debugger.
2  Copyright (C) 2001-2015 Free Software Foundation, Inc.
3 
4  Contributed by D.J. Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
5  for IBM Deutschland Entwicklung GmbH, IBM Corporation.
6 
7  This file is part of GDB.
8 
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.
13 
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.
18 
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/>. */
21 
22 #include "defs.h"
23 #include "regcache.h"
24 #include "inferior.h"
25 #include "target.h"
26 #include "linux-nat.h"
27 #include "auxv.h"
28 #include "gregset.h"
29 #include "regset.h"
30 #include "nat/linux-ptrace.h"
31 
32 #include "s390-linux-tdep.h"
33 #include "elf/common.h"
34 
35 #include <asm/ptrace.h>
36 #include <sys/ptrace.h>
37 #include <asm/types.h>
38 #include <sys/procfs.h>
39 #include <sys/ucontext.h>
40 #include <elf.h>
41 
42 /* Per-thread arch-specific data. */
43 
44 struct arch_lwp_info
45 {
46  /* Non-zero if the thread's PER info must be re-written. */
48 };
49 
50 static int have_regset_last_break = 0;
51 static int have_regset_system_call = 0;
52 static int have_regset_tdb = 0;
53 static int have_regset_vxrs = 0;
54 
55 /* Register map for 32-bit executables running under a 64-bit
56  kernel. */
57 
58 #ifdef __s390x__
59 static const struct regcache_map_entry s390_64_regmap_gregset[] =
60  {
61  /* Skip PSWM and PSWA, since they must be handled specially. */
62  { 2, REGCACHE_MAP_SKIP, 8 },
63  { 1, S390_R0_UPPER_REGNUM, 4 }, { 1, S390_R0_REGNUM, 4 },
64  { 1, S390_R1_UPPER_REGNUM, 4 }, { 1, S390_R1_REGNUM, 4 },
65  { 1, S390_R2_UPPER_REGNUM, 4 }, { 1, S390_R2_REGNUM, 4 },
66  { 1, S390_R3_UPPER_REGNUM, 4 }, { 1, S390_R3_REGNUM, 4 },
67  { 1, S390_R4_UPPER_REGNUM, 4 }, { 1, S390_R4_REGNUM, 4 },
68  { 1, S390_R5_UPPER_REGNUM, 4 }, { 1, S390_R5_REGNUM, 4 },
69  { 1, S390_R6_UPPER_REGNUM, 4 }, { 1, S390_R6_REGNUM, 4 },
70  { 1, S390_R7_UPPER_REGNUM, 4 }, { 1, S390_R7_REGNUM, 4 },
71  { 1, S390_R8_UPPER_REGNUM, 4 }, { 1, S390_R8_REGNUM, 4 },
72  { 1, S390_R9_UPPER_REGNUM, 4 }, { 1, S390_R9_REGNUM, 4 },
73  { 1, S390_R10_UPPER_REGNUM, 4 }, { 1, S390_R10_REGNUM, 4 },
74  { 1, S390_R11_UPPER_REGNUM, 4 }, { 1, S390_R11_REGNUM, 4 },
75  { 1, S390_R12_UPPER_REGNUM, 4 }, { 1, S390_R12_REGNUM, 4 },
76  { 1, S390_R13_UPPER_REGNUM, 4 }, { 1, S390_R13_REGNUM, 4 },
77  { 1, S390_R14_UPPER_REGNUM, 4 }, { 1, S390_R14_REGNUM, 4 },
78  { 1, S390_R15_UPPER_REGNUM, 4 }, { 1, S390_R15_REGNUM, 4 },
79  { 16, S390_A0_REGNUM, 4 },
80  { 1, REGCACHE_MAP_SKIP, 4 }, { 1, S390_ORIG_R2_REGNUM, 4 },
81  { 0 }
82  };
83 
84 static const struct regset s390_64_gregset =
85  {
86  s390_64_regmap_gregset,
89  };
90 
91 #define S390_PSWM_OFFSET 0
92 #define S390_PSWA_OFFSET 8
93 #endif
94 
95 /* Fill GDB's register array with the general-purpose register values
96  in *REGP.
97 
98  When debugging a 32-bit executable running under a 64-bit kernel,
99  we have to fix up the 64-bit registers we get from the kernel to
100  make them look like 32-bit registers. */
101 
102 void
104 {
105 #ifdef __s390x__
106  struct gdbarch *gdbarch = get_regcache_arch (regcache);
107  if (gdbarch_ptr_bit (gdbarch) == 32)
108  {
109  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
110  ULONGEST pswm, pswa;
111  gdb_byte buf[4];
112 
113  regcache_supply_regset (&s390_64_gregset, regcache, -1,
114  regp, sizeof (gregset_t));
115  pswm = extract_unsigned_integer ((const gdb_byte *) regp
116  + S390_PSWM_OFFSET, 8, byte_order);
117  pswa = extract_unsigned_integer ((const gdb_byte *) regp
118  + S390_PSWA_OFFSET, 8, byte_order);
119  store_unsigned_integer (buf, 4, byte_order, (pswm >> 32) | 0x80000);
120  regcache_raw_supply (regcache, S390_PSWM_REGNUM, buf);
121  store_unsigned_integer (buf, 4, byte_order,
122  (pswa & 0x7fffffff) | (pswm & 0x80000000));
123  regcache_raw_supply (regcache, S390_PSWA_REGNUM, buf);
124  return;
125  }
126 #endif
127 
128  regcache_supply_regset (&s390_gregset, regcache, -1, regp,
129  sizeof (gregset_t));
130 }
131 
132 /* Fill register REGNO (if it is a general-purpose register) in
133  *REGP with the value in GDB's register array. If REGNO is -1,
134  do this for all registers. */
135 
136 void
137 fill_gregset (const struct regcache *regcache, gregset_t *regp, int regno)
138 {
139 #ifdef __s390x__
140  struct gdbarch *gdbarch = get_regcache_arch (regcache);
141  if (gdbarch_ptr_bit (gdbarch) == 32)
142  {
143  regcache_collect_regset (&s390_64_gregset, regcache, regno,
144  regp, sizeof (gregset_t));
145 
146  if (regno == -1
147  || regno == S390_PSWM_REGNUM || regno == S390_PSWA_REGNUM)
148  {
149  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
150  ULONGEST pswa, pswm;
151  gdb_byte buf[4];
152  gdb_byte *pswm_p = (gdb_byte *) regp + S390_PSWM_OFFSET;
153  gdb_byte *pswa_p = (gdb_byte *) regp + S390_PSWA_OFFSET;
154 
155  pswm = extract_unsigned_integer (pswm_p, 8, byte_order);
156 
157  if (regno == -1 || regno == S390_PSWM_REGNUM)
158  {
159  pswm &= 0x80000000;
160  regcache_raw_collect (regcache, S390_PSWM_REGNUM, buf);
161  pswm |= (extract_unsigned_integer (buf, 4, byte_order)
162  & 0xfff7ffff) << 32;
163  }
164 
165  if (regno == -1 || regno == S390_PSWA_REGNUM)
166  {
167  regcache_raw_collect (regcache, S390_PSWA_REGNUM, buf);
168  pswa = extract_unsigned_integer (buf, 4, byte_order);
169  pswm ^= (pswm ^ pswa) & 0x80000000;
170  pswa &= 0x7fffffff;
171  store_unsigned_integer (pswa_p, 8, byte_order, pswa);
172  }
173 
174  store_unsigned_integer (pswm_p, 8, byte_order, pswm);
175  }
176  return;
177  }
178 #endif
179 
180  regcache_collect_regset (&s390_gregset, regcache, regno, regp,
181  sizeof (gregset_t));
182 }
183 
184 /* Fill GDB's register array with the floating-point register values
185  in *REGP. */
186 void
188 {
189  regcache_supply_regset (&s390_fpregset, regcache, -1, regp,
190  sizeof (fpregset_t));
191 }
192 
193 /* Fill register REGNO (if it is a general-purpose register) in
194  *REGP with the value in GDB's register array. If REGNO is -1,
195  do this for all registers. */
196 void
197 fill_fpregset (const struct regcache *regcache, fpregset_t *regp, int regno)
198 {
199  regcache_collect_regset (&s390_fpregset, regcache, regno, regp,
200  sizeof (fpregset_t));
201 }
202 
203 /* Find the TID for the current inferior thread to use with ptrace. */
204 static int
206 {
207  /* GNU/Linux LWP ID's are process ID's. */
208  int tid = ptid_get_lwp (inferior_ptid);
209  if (tid == 0)
210  tid = ptid_get_pid (inferior_ptid); /* Not a threaded program. */
211 
212  return tid;
213 }
214 
215 /* Fetch all general-purpose registers from process/thread TID and
216  store their values in GDB's register cache. */
217 static void
218 fetch_regs (struct regcache *regcache, int tid)
219 {
220  gregset_t regs;
221  ptrace_area parea;
222 
223  parea.len = sizeof (regs);
224  parea.process_addr = (addr_t) &regs;
225  parea.kernel_addr = offsetof (struct user_regs_struct, psw);
226  if (ptrace (PTRACE_PEEKUSR_AREA, tid, (long) &parea) < 0)
227  perror_with_name (_("Couldn't get registers"));
228 
229  supply_gregset (regcache, (const gregset_t *) &regs);
230 }
231 
232 /* Store all valid general-purpose registers in GDB's register cache
233  into the process/thread specified by TID. */
234 static void
235 store_regs (const struct regcache *regcache, int tid, int regnum)
236 {
237  gregset_t regs;
238  ptrace_area parea;
239 
240  parea.len = sizeof (regs);
241  parea.process_addr = (addr_t) &regs;
242  parea.kernel_addr = offsetof (struct user_regs_struct, psw);
243  if (ptrace (PTRACE_PEEKUSR_AREA, tid, (long) &parea) < 0)
244  perror_with_name (_("Couldn't get registers"));
245 
246  fill_gregset (regcache, &regs, regnum);
247 
248  if (ptrace (PTRACE_POKEUSR_AREA, tid, (long) &parea) < 0)
249  perror_with_name (_("Couldn't write registers"));
250 }
251 
252 /* Fetch all floating-point registers from process/thread TID and store
253  their values in GDB's register cache. */
254 static void
255 fetch_fpregs (struct regcache *regcache, int tid)
256 {
257  fpregset_t fpregs;
258  ptrace_area parea;
259 
260  parea.len = sizeof (fpregs);
261  parea.process_addr = (addr_t) &fpregs;
262  parea.kernel_addr = offsetof (struct user_regs_struct, fp_regs);
263  if (ptrace (PTRACE_PEEKUSR_AREA, tid, (long) &parea) < 0)
264  perror_with_name (_("Couldn't get floating point status"));
265 
266  supply_fpregset (regcache, (const fpregset_t *) &fpregs);
267 }
268 
269 /* Store all valid floating-point registers in GDB's register cache
270  into the process/thread specified by TID. */
271 static void
272 store_fpregs (const struct regcache *regcache, int tid, int regnum)
273 {
274  fpregset_t fpregs;
275  ptrace_area parea;
276 
277  parea.len = sizeof (fpregs);
278  parea.process_addr = (addr_t) &fpregs;
279  parea.kernel_addr = offsetof (struct user_regs_struct, fp_regs);
280  if (ptrace (PTRACE_PEEKUSR_AREA, tid, (long) &parea) < 0)
281  perror_with_name (_("Couldn't get floating point status"));
282 
283  fill_fpregset (regcache, &fpregs, regnum);
284 
285  if (ptrace (PTRACE_POKEUSR_AREA, tid, (long) &parea) < 0)
286  perror_with_name (_("Couldn't write floating point status"));
287 }
288 
289 /* Fetch all registers in the kernel's register set whose number is
290  REGSET_ID, whose size is REGSIZE, and whose layout is described by
291  REGSET, from process/thread TID and store their values in GDB's
292  register cache. */
293 static void
294 fetch_regset (struct regcache *regcache, int tid,
295  int regset_id, int regsize, const struct regset *regset)
296 {
297  gdb_byte *buf = alloca (regsize);
298  struct iovec iov;
299 
300  iov.iov_base = buf;
301  iov.iov_len = regsize;
302 
303  if (ptrace (PTRACE_GETREGSET, tid, (long) regset_id, (long) &iov) < 0)
304  {
305  if (errno == ENODATA)
306  regcache_supply_regset (regset, regcache, -1, NULL, regsize);
307  else
308  perror_with_name (_("Couldn't get register set"));
309  }
310  else
311  regcache_supply_regset (regset, regcache, -1, buf, regsize);
312 }
313 
314 /* Store all registers in the kernel's register set whose number is
315  REGSET_ID, whose size is REGSIZE, and whose layout is described by
316  REGSET, from GDB's register cache back to process/thread TID. */
317 static void
318 store_regset (struct regcache *regcache, int tid,
319  int regset_id, int regsize, const struct regset *regset)
320 {
321  gdb_byte *buf = alloca (regsize);
322  struct iovec iov;
323 
324  iov.iov_base = buf;
325  iov.iov_len = regsize;
326 
327  if (ptrace (PTRACE_GETREGSET, tid, (long) regset_id, (long) &iov) < 0)
328  perror_with_name (_("Couldn't get register set"));
329 
330  regcache_collect_regset (regset, regcache, -1, buf, regsize);
331 
332  if (ptrace (PTRACE_SETREGSET, tid, (long) regset_id, (long) &iov) < 0)
333  perror_with_name (_("Couldn't set register set"));
334 }
335 
336 /* Check whether the kernel provides a register set with number REGSET
337  of size REGSIZE for process/thread TID. */
338 static int
339 check_regset (int tid, int regset, int regsize)
340 {
341  gdb_byte *buf = alloca (regsize);
342  struct iovec iov;
343 
344  iov.iov_base = buf;
345  iov.iov_len = regsize;
346 
347  if (ptrace (PTRACE_GETREGSET, tid, (long) regset, (long) &iov) >= 0
348  || errno == ENODATA)
349  return 1;
350  return 0;
351 }
352 
353 /* Fetch register REGNUM from the child process. If REGNUM is -1, do
354  this for all registers. */
355 static void
357  struct regcache *regcache, int regnum)
358 {
359  int tid = s390_inferior_tid ();
360 
361  if (regnum == -1 || S390_IS_GREGSET_REGNUM (regnum))
362  fetch_regs (regcache, tid);
363 
364  if (regnum == -1 || S390_IS_FPREGSET_REGNUM (regnum))
365  fetch_fpregs (regcache, tid);
366 
368  if (regnum == -1 || regnum == S390_LAST_BREAK_REGNUM)
369  fetch_regset (regcache, tid, NT_S390_LAST_BREAK, 8,
370  (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32
372 
374  if (regnum == -1 || regnum == S390_SYSTEM_CALL_REGNUM)
375  fetch_regset (regcache, tid, NT_S390_SYSTEM_CALL, 4,
377 
378  if (have_regset_tdb)
379  if (regnum == -1 || S390_IS_TDBREGSET_REGNUM (regnum))
380  fetch_regset (regcache, tid, NT_S390_TDB, s390_sizeof_tdbregset,
381  &s390_tdb_regset);
382 
383  if (have_regset_vxrs)
384  {
385  if (regnum == -1 || (regnum >= S390_V0_LOWER_REGNUM
386  && regnum <= S390_V15_LOWER_REGNUM))
387  fetch_regset (regcache, tid, NT_S390_VXRS_LOW, 16 * 8,
389  if (regnum == -1 || (regnum >= S390_V16_REGNUM
390  && regnum <= S390_V31_REGNUM))
391  fetch_regset (regcache, tid, NT_S390_VXRS_HIGH, 16 * 16,
393  }
394 }
395 
396 /* Store register REGNUM back into the child process. If REGNUM is
397  -1, do this for all registers. */
398 static void
400  struct regcache *regcache, int regnum)
401 {
402  int tid = s390_inferior_tid ();
403 
404  if (regnum == -1 || S390_IS_GREGSET_REGNUM (regnum))
405  store_regs (regcache, tid, regnum);
406 
407  if (regnum == -1 || S390_IS_FPREGSET_REGNUM (regnum))
408  store_fpregs (regcache, tid, regnum);
409 
410  /* S390_LAST_BREAK_REGNUM is read-only. */
411 
413  if (regnum == -1 || regnum == S390_SYSTEM_CALL_REGNUM)
414  store_regset (regcache, tid, NT_S390_SYSTEM_CALL, 4,
416 
417  if (have_regset_vxrs)
418  {
419  if (regnum == -1 || (regnum >= S390_V0_LOWER_REGNUM
420  && regnum <= S390_V15_LOWER_REGNUM))
421  store_regset (regcache, tid, NT_S390_VXRS_LOW, 16 * 8,
423  if (regnum == -1 || (regnum >= S390_V16_REGNUM
424  && regnum <= S390_V31_REGNUM))
425  store_regset (regcache, tid, NT_S390_VXRS_HIGH, 16 * 16,
427  }
428 }
429 
430 
431 /* Hardware-assisted watchpoint handling. */
432 
433 /* We maintain a list of all currently active watchpoints in order
434  to properly handle watchpoint removal.
435 
436  The only thing we actually need is the total address space area
437  spanned by the watchpoints. */
438 
440 {
441  struct watch_area *next;
444 };
445 
446 static struct watch_area *watch_base = NULL;
447 
448 static int
450 {
451  per_lowcore_bits per_lowcore;
452  ptrace_area parea;
453  int result;
454 
455  /* Speed up common case. */
456  if (!watch_base)
457  return 0;
458 
459  parea.len = sizeof (per_lowcore);
460  parea.process_addr = (addr_t) & per_lowcore;
461  parea.kernel_addr = offsetof (struct user_regs_struct, per_info.lowcore);
462  if (ptrace (PTRACE_PEEKUSR_AREA, s390_inferior_tid (), &parea) < 0)
463  perror_with_name (_("Couldn't retrieve watchpoint status"));
464 
465  result = (per_lowcore.perc_storage_alteration == 1
466  && per_lowcore.perc_store_real_address == 0);
467 
468  if (result)
469  {
470  /* Do not report this watchpoint again. */
471  memset (&per_lowcore, 0, sizeof (per_lowcore));
472  if (ptrace (PTRACE_POKEUSR_AREA, s390_inferior_tid (), &parea) < 0)
473  perror_with_name (_("Couldn't clear watchpoint status"));
474  }
475 
476  return result;
477 }
478 
479 /* Each time before resuming a thread, update its PER info. */
480 
481 static void
483 {
484  int tid;
485 
486  per_struct per_info;
487  ptrace_area parea;
488 
489  CORE_ADDR watch_lo_addr = (CORE_ADDR)-1, watch_hi_addr = 0;
490  struct watch_area *area;
491 
492  if (lp->arch_private == NULL
494  return;
495 
497 
498  tid = ptid_get_lwp (lp->ptid);
499  if (tid == 0)
500  tid = ptid_get_pid (lp->ptid);
501 
502  for (area = watch_base; area; area = area->next)
503  {
504  watch_lo_addr = min (watch_lo_addr, area->lo_addr);
505  watch_hi_addr = max (watch_hi_addr, area->hi_addr);
506  }
507 
508  parea.len = sizeof (per_info);
509  parea.process_addr = (addr_t) & per_info;
510  parea.kernel_addr = offsetof (struct user_regs_struct, per_info);
511  if (ptrace (PTRACE_PEEKUSR_AREA, tid, &parea) < 0)
512  perror_with_name (_("Couldn't retrieve watchpoint status"));
513 
514  if (watch_base)
515  {
516  per_info.control_regs.bits.em_storage_alteration = 1;
517  per_info.control_regs.bits.storage_alt_space_ctl = 1;
518  }
519  else
520  {
521  per_info.control_regs.bits.em_storage_alteration = 0;
522  per_info.control_regs.bits.storage_alt_space_ctl = 0;
523  }
524  per_info.starting_addr = watch_lo_addr;
525  per_info.ending_addr = watch_hi_addr;
526 
527  if (ptrace (PTRACE_POKEUSR_AREA, tid, &parea) < 0)
528  perror_with_name (_("Couldn't modify watchpoint status"));
529 }
530 
531 /* Make sure that LP is stopped and mark its PER info as changed, so
532  the next resume will update it. */
533 
534 static void
536 {
537  if (lp->arch_private == NULL)
538  lp->arch_private = XCNEW (struct arch_lwp_info);
539 
541 
542  if (!lp->stopped)
543  linux_stop_lwp (lp);
544 }
545 
546 /* When attaching to a new thread, mark its PER info as changed. */
547 
548 static void
550 {
551  lp->arch_private = XCNEW (struct arch_lwp_info);
553 }
554 
555 static int
557  CORE_ADDR addr, int len, int type,
558  struct expression *cond)
559 {
560  struct lwp_info *lp;
561  struct watch_area *area = xmalloc (sizeof (struct watch_area));
562 
563  if (!area)
564  return -1;
565 
566  area->lo_addr = addr;
567  area->hi_addr = addr + len - 1;
568 
569  area->next = watch_base;
570  watch_base = area;
571 
572  ALL_LWPS (lp)
574  return 0;
575 }
576 
577 static int
579  CORE_ADDR addr, int len, int type,
580  struct expression *cond)
581 {
582  struct lwp_info *lp;
583  struct watch_area *area, **parea;
584 
585  for (parea = &watch_base; *parea; parea = &(*parea)->next)
586  if ((*parea)->lo_addr == addr
587  && (*parea)->hi_addr == addr + len - 1)
588  break;
589 
590  if (!*parea)
591  {
593  "Attempt to remove nonexistent watchpoint.\n");
594  return -1;
595  }
596 
597  area = *parea;
598  *parea = area->next;
599  xfree (area);
600 
601  ALL_LWPS (lp)
603  return 0;
604 }
605 
606 static int
608  int type, int cnt, int othertype)
609 {
610  return type == bp_hardware_watchpoint;
611 }
612 
613 static int
615  CORE_ADDR addr, int cnt)
616 {
617  return 1;
618 }
619 
620 static int
622 {
623  int wordsize = 4;
624 
625  /* Check for 64-bit inferior process. This is the case when the host is
626  64-bit, and in addition bit 32 of the PSW mask is set. */
627 #ifdef __s390x__
628  long pswm;
629 
630  errno = 0;
631  pswm = (long) ptrace (PTRACE_PEEKUSER, s390_inferior_tid (), PT_PSWMASK, 0);
632  if (errno == 0 && (pswm & 0x100000000ul) != 0)
633  wordsize = 8;
634 #endif
635 
636  return wordsize;
637 }
638 
639 static int
640 s390_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
641  gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
642 {
643  int sizeof_auxv_field = s390_target_wordsize ();
644  enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
645  gdb_byte *ptr = *readptr;
646 
647  if (endptr == ptr)
648  return 0;
649 
650  if (endptr - ptr < sizeof_auxv_field * 2)
651  return -1;
652 
653  *typep = extract_unsigned_integer (ptr, sizeof_auxv_field, byte_order);
654  ptr += sizeof_auxv_field;
655  *valp = extract_unsigned_integer (ptr, sizeof_auxv_field, byte_order);
656  ptr += sizeof_auxv_field;
657 
658  *readptr = ptr;
659  return 1;
660 }
661 
662 static const struct target_desc *
664 {
665  int tid = s390_inferior_tid ();
666 
668  = check_regset (tid, NT_S390_LAST_BREAK, 8);
670  = check_regset (tid, NT_S390_SYSTEM_CALL, 4);
671 
672  /* If GDB itself is compiled as 64-bit, we are running on a machine in
673  z/Architecture mode. If the target is running in 64-bit addressing
674  mode, report s390x architecture. If the target is running in 31-bit
675  addressing mode, but the kernel supports using 64-bit registers in
676  that mode, report s390 architecture with 64-bit GPRs. */
677 #ifdef __s390x__
678  {
679  CORE_ADDR hwcap = 0;
680 
681  target_auxv_search (&current_target, AT_HWCAP, &hwcap);
682  have_regset_tdb = (hwcap & HWCAP_S390_TE)
683  && check_regset (tid, NT_S390_TDB, s390_sizeof_tdbregset);
684 
685  have_regset_vxrs = (hwcap & HWCAP_S390_VX)
686  && check_regset (tid, NT_S390_VXRS_LOW, 16 * 8)
687  && check_regset (tid, NT_S390_VXRS_HIGH, 16 * 16);
688 
689  if (s390_target_wordsize () == 8)
690  return (have_regset_vxrs ?
697 
698  if (hwcap & HWCAP_S390_HIGH_GPRS)
699  return (have_regset_vxrs ?
706  }
707 #endif
708 
709  /* If GDB itself is compiled as 31-bit, or if we're running a 31-bit inferior
710  on a 64-bit kernel that does not support using 64-bit registers in 31-bit
711  mode, report s390 architecture with 32-bit GPRs. */
715 }
716 
717 void _initialize_s390_nat (void);
718 
719 void
721 {
722  struct target_ops *t;
723 
724  /* Fill in the generic GNU/Linux methods. */
725  t = linux_target ();
726 
727  /* Add our register access methods. */
730 
731  /* Add our watchpoint methods. */
738 
739  /* Detect target architecture. */
742 
743  /* Register the target. */
747 }
struct gdbarch * target_gdbarch(void)
Definition: gdbarch.c:5143
static int s390_remove_watchpoint(struct target_ops *self, CORE_ADDR addr, int len, int type, struct expression *cond)
#define S390_V15_LOWER_REGNUM
void supply_fpregset(struct regcache *regcache, const fpregset_t *regp)
struct arch_lwp_info * arch_private
Definition: linux-nat.h:107
static int s390_target_wordsize(void)
static void fetch_fpregs(struct regcache *regcache, int tid)
ULONGEST extract_unsigned_integer(const gdb_byte *, int, enum bfd_endian)
Definition: findvar.c:84
static void fetch_regs(struct regcache *regcache, int tid)
static int have_regset_tdb
struct target_desc * tdesc_s390_vx_linux64
const struct target_desc *(* to_read_description)(struct target_ops *ops) TARGET_DEFAULT_RETURN(NULL)
Definition: target.h:769
#define S390_SYSTEM_CALL_REGNUM
struct target_desc * tdesc_s390_te_linux64
void fill_gregset(const struct regcache *regcache, gregset_t *regp, int regno)
bfd_vma CORE_ADDR
Definition: common-types.h:41
struct target_desc * tdesc_s390_linux32v1
Definition: s390-linux32v1.c:8
#define HWCAP_S390_TE
void linux_stop_lwp(struct lwp_info *lwp)
Definition: linux-nat.c:2378
static int s390_can_use_hw_breakpoint(struct target_ops *self, int type, int cnt, int othertype)
void xfree(void *)
Definition: common-utils.c:97
#define ALL_LWPS(LP)
Definition: linux-nat.h:123
struct gdbarch * get_regcache_arch(const struct regcache *regcache)
Definition: regcache.c:297
static const struct target_desc * s390_read_description(struct target_ops *ops)
void linux_nat_set_new_thread(struct target_ops *t, void(*new_thread)(struct lwp_info *))
Definition: linux-nat.c:5040
struct target_desc * tdesc_s390x_tevx_linux64
int gdbarch_ptr_bit(struct gdbarch *gdbarch)
Definition: gdbarch.c:1690
ptid_t ptid
Definition: linux-nat.h:34
static int have_regset_system_call
#define S390_R6_UPPER_REGNUM
#define S390_R6_REGNUM
#define S390_R9_REGNUM
static void s390_prepare_to_resume(struct lwp_info *lp)
#define S390_V31_REGNUM
void regcache_supply_regset(const struct regset *regset, struct regcache *regcache, int regnum, const void *buf, size_t size)
Definition: regcache.c:1149
#define S390_R2_UPPER_REGNUM
const struct regset s390_gregset
#define S390_V16_REGNUM
static int have_regset_last_break
struct target_desc * tdesc_s390_linux64v2
Definition: s390-linux64v2.c:8
struct target_desc * tdesc_s390_linux32v2
Definition: s390-linux32v2.c:8
int(* to_region_ok_for_hw_watchpoint)(struct target_ops *, CORE_ADDR, int) TARGET_DEFAULT_FUNC(default_region_ok_for_hw_watchpoint)
Definition: target.h:554
const struct regset s390_fpregset
struct watch_area * next
#define _(String)
Definition: gdb_locale.h:40
static int s390_insert_watchpoint(struct target_ops *self, CORE_ADDR addr, int len, int type, struct expression *cond)
#define S390_IS_GREGSET_REGNUM(i)
struct target_desc * tdesc_s390_tevx_linux64
#define S390_R11_UPPER_REGNUM
#define S390_R4_UPPER_REGNUM
void supply_gregset(struct regcache *regcache, const gregset_t *regp)
PTRACE_TYPE_RET ptrace()
void store_unsigned_integer(gdb_byte *, int, enum bfd_endian, ULONGEST)
Definition: findvar.c:212
Definition: regset.h:34
#define S390_R7_UPPER_REGNUM
#define S390_R11_REGNUM
int(* to_insert_watchpoint)(struct target_ops *, CORE_ADDR, int, int, struct expression *) TARGET_DEFAULT_RETURN(-1)
Definition: target.h:532
static void store_regset(struct regcache *regcache, int tid, int regset_id, int regsize, const struct regset *regset)
#define S390_R2_REGNUM
const struct regset s390_vxrs_low_regset
static int s390_inferior_tid(void)
#define S390_R4_REGNUM
struct target_ops current_target
static void s390_refresh_per_info(struct lwp_info *lp)
CORE_ADDR lo_addr
const struct regset s390_last_break_regset
int(* to_remove_watchpoint)(struct target_ops *, CORE_ADDR, int, int, struct expression *) TARGET_DEFAULT_RETURN(-1)
Definition: target.h:529
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2361
int target_auxv_search(struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp)
Definition: auxv.c:375
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1420
void linux_nat_set_prepare_to_resume(struct target_ops *t, void(*prepare_to_resume)(struct lwp_info *))
Definition: linux-nat.c:5094
#define S390_R1_REGNUM
#define S390_R0_UPPER_REGNUM
#define S390_LAST_BREAK_REGNUM
Definition: gdbtypes.h:749
void regcache_collect_regset(const struct regset *regset, const struct regcache *regcache, int regnum, void *buf, size_t size)
Definition: regcache.c:1162
static int s390_auxv_parse(struct target_ops *ops, gdb_byte **readptr, gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
#define S390_R13_UPPER_REGNUM
#define S390_R0_REGNUM
#define S390_R7_REGNUM
#define S390_R14_REGNUM
struct target_desc * tdesc_s390_linux64v1
Definition: s390-linux64v1.c:8
#define min(a, b)
Definition: defs.h:106
void linux_nat_add_target(struct target_ops *t)
Definition: linux-nat.c:4972
int stopped
Definition: linux-nat.h:50
#define PTRACE_SETREGSET
Definition: linux-ptrace.h:51
struct target_desc * tdesc_s390x_vx_linux64
#define S390_R3_REGNUM
const struct regset s390x_last_break_regset
int regnum
Definition: aarch64-tdep.c:69
static void s390_linux_store_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regnum)
#define S390_R10_REGNUM
const struct regset s390_system_call_regset
struct target_ops * linux_target(void)
Definition: linux-nat.c:4544
void * xmalloc(YYSIZE_T)
#define S390_PSWM_REGNUM
const struct regset s390_vxrs_high_regset
#define PTRACE_GETREGSET
Definition: linux-ptrace.h:47
Definition: regdef.h:22
void fill_fpregset(const struct regcache *regcache, fpregset_t *regp, int regno)
#define S390_A0_REGNUM
int ptid_get_pid(ptid_t ptid)
Definition: ptid.c:52
#define S390_ORIG_R2_REGNUM
int(* to_auxv_parse)(struct target_ops *ops, gdb_byte **readptr, gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp) TARGET_DEFAULT_FUNC(default_auxv_parse)
Definition: target.h:784
#define S390_R3_UPPER_REGNUM
static void s390_new_thread(struct lwp_info *lp)
bfd_byte gdb_byte
Definition: common-types.h:38
static int have_regset_vxrs
void(* to_fetch_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_IGNORE()
Definition: target.h:472
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
Definition: utils.c:979
#define max(a, b)
Definition: defs.h:109
struct target_desc * tdesc_s390x_linux64v2
int(* to_can_use_hw_breakpoint)(struct target_ops *, int, int, int) TARGET_DEFAULT_RETURN(0)
Definition: target.h:516
static void fetch_regset(struct regcache *regcache, int tid, int regset_id, int regsize, const struct regset *regset)
#define S390_PSWA_REGNUM
struct target_desc * tdesc_s390x_linux64v1
struct ui_file * gdb_stderr
Definition: main.c:72
#define S390_IS_FPREGSET_REGNUM(i)
ptid_t inferior_ptid
Definition: infcmd.c:124
const struct regset s390_tdb_regset
static struct watch_area * watch_base
static int check_regset(int tid, int regset, int regsize)
#define S390_R10_UPPER_REGNUM
CORE_ADDR hi_addr
#define S390_IS_TDBREGSET_REGNUM(i)
struct target_desc * tdesc_s390_linux32
Definition: s390-linux32.c:8
int(* to_stopped_by_watchpoint)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:542
#define S390_R5_UPPER_REGNUM
#define S390_R12_REGNUM
struct target_desc * tdesc_s390x_linux64
Definition: s390x-linux64.c:8
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1041
int to_have_continuable_watchpoint
Definition: target.h:545
#define S390_R15_UPPER_REGNUM
void _initialize_s390_nat(void)
unsigned long long ULONGEST
Definition: common-types.h:53
#define S390_R12_UPPER_REGNUM
static void store_fpregs(const struct regcache *regcache, int tid, int regnum)
long ptid_get_lwp(ptid_t ptid)
Definition: ptid.c:60
#define S390_V0_LOWER_REGNUM
#define S390_R8_UPPER_REGNUM
void regcache_raw_collect(const struct regcache *regcache, int regnum, void *buf)
Definition: regcache.c:1071
#define S390_R13_REGNUM
static int s390_region_ok_for_hw_watchpoint(struct target_ops *self, CORE_ADDR addr, int cnt)
#define S390_R14_UPPER_REGNUM
#define S390_R5_REGNUM
struct target_desc * tdesc_s390x_te_linux64
#define S390_R8_REGNUM
struct target_desc * tdesc_s390_linux64
Definition: s390-linux64.c:8
void(* to_store_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:474
#define s390_sizeof_tdbregset
enum bfd_endian byte_order
Definition: gdbarch.c:128
struct fpreg fpregset_t
Definition: alphabsd-nat.c:41
#define HWCAP_S390_HIGH_GPRS
#define S390_R1_UPPER_REGNUM
#define S390_R15_REGNUM
static void s390_linux_fetch_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regnum)
#define wordsize
Definition: regcache.h:167
static int s390_stopped_by_watchpoint(struct target_ops *ops)
#define HWCAP_S390_VX
#define S390_R9_UPPER_REGNUM
const ULONGEST const LONGEST len
Definition: target.h:309
static void store_regs(const struct regcache *regcache, int tid, int regnum)