1 /* Native-dependent code for PA-RISC HP-UX.
3 Copyright (C) 2004, 2005, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "gdb_assert.h"
27 #include <sys/ptrace.h>
28 #include <machine/save_state.h>
31 #include <sys/ttrace.h>
34 #include "hppa-tdep.h"
35 #include "inf-ptrace.h"
36 #include "inf-ttrace.h"
38 /* Non-zero if we should pretend not to be a runnable target. */
39 int child_suppress_run
= 0;
41 /* Return the offset of register REGNUM within `struct save_state'.
42 The offset returns depends on the flags in the "flags" register and
43 the register size (32-bit or 64-bit). These are taken from
47 hppa_hpux_save_state_offset (struct regcache
*regcache
, int regnum
)
51 if (regnum
== HPPA_FLAGS_REGNUM
)
52 return ssoff (ss_flags
);
54 if (HPPA_R0_REGNUM
< regnum
&& regnum
< HPPA_FP0_REGNUM
)
56 struct gdbarch
*arch
= get_regcache_arch (regcache
);
57 size_t size
= register_size (arch
, HPPA_R1_REGNUM
);
60 gdb_assert (size
== 4 || size
== 8);
62 regcache_cooked_read_unsigned (regcache
, HPPA_FLAGS_REGNUM
, &flags
);
63 if (flags
& SS_WIDEREGS
)
64 offset
= ssoff (ss_wide
) + (8 - size
) + (regnum
- HPPA_R0_REGNUM
) * 8;
66 offset
= ssoff (ss_narrow
) + (regnum
- HPPA_R1_REGNUM
) * 4;
70 struct gdbarch
*arch
= get_regcache_arch (regcache
);
71 size_t size
= register_size (arch
, HPPA_FP0_REGNUM
);
73 gdb_assert (size
== 4 || size
== 8);
74 gdb_assert (regnum
>= HPPA_FP0_REGNUM
);
75 offset
= ssoff(ss_fpblock
) + (regnum
- HPPA_FP0_REGNUM
) * size
;
78 gdb_assert (offset
< sizeof (save_state_t
));
82 /* Just in case a future version of PA-RISC HP-UX won't have ptrace(2)
84 #ifndef PTRACE_TYPE_RET
85 #define PTRACE_TYPE_RET void
89 hppa_hpux_fetch_register (struct regcache
*regcache
, int regnum
)
91 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
92 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
99 pid
= ptid_get_pid (inferior_ptid
);
101 /* This isn't really an address, but ptrace thinks of it as one. */
102 addr
= hppa_hpux_save_state_offset (regcache
, regnum
);
103 size
= register_size (gdbarch
, regnum
);
105 gdb_assert (size
== 4 || size
== 8);
110 lwpid_t lwp
= ptid_get_lwp (inferior_ptid
);
112 if (ttrace (TT_LWP_RUREGS
, pid
, lwp
, addr
, size
, (uintptr_t)buf
) == -1)
113 error (_("Couldn't read register %s (#%d): %s"),
114 gdbarch_register_name (gdbarch
, regnum
),
115 regnum
, safe_strerror (errno
));
121 /* Read the register contents from the inferior a chuck at the time. */
122 for (i
= 0; i
< size
/ sizeof (PTRACE_TYPE_RET
); i
++)
125 buf
[i
] = ptrace (PT_RUREGS
, pid
, (PTRACE_TYPE_ARG3
) addr
, 0, 0);
127 error (_("Couldn't read register %s (#%d): %s"),
128 gdbarch_register_name (gdbarch
, regnum
),
129 regnum
, safe_strerror (errno
));
131 addr
+= sizeof (PTRACE_TYPE_RET
);
136 /* Take care with the "flags" register. It's stored as an `int' in
137 `struct save_state', even for 64-bit code. */
138 if (regnum
== HPPA_FLAGS_REGNUM
&& size
== 8)
141 flags
= extract_unsigned_integer ((gdb_byte
*)buf
, 4, byte_order
);
142 store_unsigned_integer ((gdb_byte
*)buf
, 8, byte_order
, flags
);
145 regcache_raw_supply (regcache
, regnum
, buf
);
149 hppa_hpux_fetch_inferior_registers (struct target_ops
*ops
,
150 struct regcache
*regcache
, int regnum
)
154 regnum
< gdbarch_num_regs (get_regcache_arch (regcache
));
156 hppa_hpux_fetch_register (regcache
, regnum
);
158 hppa_hpux_fetch_register (regcache
, regnum
);
161 /* Store register REGNUM into the inferior. */
164 hppa_hpux_store_register (struct regcache
*regcache
, int regnum
)
166 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
167 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
170 PTRACE_TYPE_RET
*buf
;
173 pid
= ptid_get_pid (inferior_ptid
);
175 /* This isn't really an address, but ptrace thinks of it as one. */
176 addr
= hppa_hpux_save_state_offset (regcache
, regnum
);
177 size
= register_size (gdbarch
, regnum
);
179 gdb_assert (size
== 4 || size
== 8);
182 regcache_raw_collect (regcache
, regnum
, buf
);
184 /* Take care with the "flags" register. It's stored as an `int' in
185 `struct save_state', even for 64-bit code. */
186 if (regnum
== HPPA_FLAGS_REGNUM
&& size
== 8)
189 flags
= extract_unsigned_integer ((gdb_byte
*)buf
, 8, byte_order
);
190 store_unsigned_integer ((gdb_byte
*)buf
, 4, byte_order
, flags
);
196 lwpid_t lwp
= ptid_get_lwp (inferior_ptid
);
198 if (ttrace (TT_LWP_WUREGS
, pid
, lwp
, addr
, size
, (uintptr_t)buf
) == -1)
199 error (_("Couldn't write register %s (#%d): %s"),
200 gdbarch_register_name (gdbarch
, regnum
),
201 regnum
, safe_strerror (errno
));
207 /* Write the register contents into the inferior a chunk at the time. */
208 for (i
= 0; i
< size
/ sizeof (PTRACE_TYPE_RET
); i
++)
211 ptrace (PT_WUREGS
, pid
, (PTRACE_TYPE_ARG3
) addr
, buf
[i
], 0);
213 error (_("Couldn't write register %s (#%d): %s"),
214 gdbarch_register_name (gdbarch
, regnum
),
215 regnum
, safe_strerror (errno
));
217 addr
+= sizeof (PTRACE_TYPE_RET
);
223 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
224 this for all registers (including the floating point registers). */
227 hppa_hpux_store_inferior_registers (struct target_ops
*ops
,
228 struct regcache
*regcache
, int regnum
)
232 regnum
< gdbarch_num_regs (get_regcache_arch (regcache
));
234 hppa_hpux_store_register (regcache
, regnum
);
236 hppa_hpux_store_register (regcache
, regnum
);
240 hppa_hpux_child_can_run (void)
242 /* This variable is controlled by modules that layer their own
243 process structure atop that provided here. The code in
244 hpux-thread.c does this to support the HP-UX user-mode DCE
246 return !child_suppress_run
;
250 /* Prevent warning from -Wmissing-prototypes. */
251 void _initialize_hppa_hpux_nat (void);
254 _initialize_hppa_hpux_nat (void)
256 struct target_ops
*t
;
259 t
= inf_ttrace_target ();
261 t
= inf_ptrace_target ();
264 t
->to_fetch_registers
= hppa_hpux_fetch_inferior_registers
;
265 t
->to_store_registers
= hppa_hpux_store_inferior_registers
;
266 t
->to_can_run
= hppa_hpux_child_can_run
;