1 /* Native-dependent code for PA-RISC HP-UX.
3 Copyright 2004 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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
27 #include "gdb_assert.h"
28 #include <sys/ptrace.h>
29 #include <machine/save_state.h>
32 #include <sys/ttrace.h>
35 #include "hppa-tdep.h"
36 #include "inf-ptrace.h"
37 #include "inf-ttrace.h"
39 /* Non-zero if we should pretend not to be a runnable target. */
40 int child_suppress_run
= 0;
42 /* Return the offset of register REGNUM within `struct save_state'.
43 The offset returns depends on the flags in the "flags" register and
44 the register size (32-bit or 64-bit). These are taken from
48 hppa_hpux_save_state_offset (struct regcache
*regcache
, int regnum
)
52 if (regnum
== HPPA_FLAGS_REGNUM
)
53 return ssoff (ss_flags
);
55 if (HPPA_R0_REGNUM
< regnum
&& regnum
< HPPA_FP0_REGNUM
)
57 struct gdbarch
*arch
= get_regcache_arch (regcache
);
58 size_t size
= register_size (arch
, HPPA_R1_REGNUM
);
61 gdb_assert (size
== 4 || size
== 8);
63 regcache_cooked_read_unsigned (regcache
, HPPA_FLAGS_REGNUM
, &flags
);
64 if (flags
& SS_WIDEREGS
)
65 offset
= ssoff (ss_wide
) + (8 - size
) + (regnum
- HPPA_R0_REGNUM
) * 8;
67 offset
= ssoff (ss_narrow
) + (regnum
- HPPA_R1_REGNUM
) * 4;
71 struct gdbarch
*arch
= get_regcache_arch (regcache
);
72 size_t size
= register_size (arch
, HPPA_FP0_REGNUM
);
74 gdb_assert (size
== 4 || size
== 8);
75 gdb_assert (regnum
>= HPPA_FP0_REGNUM
);
76 offset
= ssoff(ss_fpblock
) + (regnum
- HPPA_FP0_REGNUM
) * size
;
79 gdb_assert (offset
< sizeof (save_state_t
));
83 /* Just in case a future version of PA-RISC HP-UX won't have ptrace(2)
85 #ifndef PTRACE_TYPE_RET
86 #define PTRACE_TYPE_RET void
90 hppa_hpux_fetch_register (int regnum
)
98 pid
= ptid_get_pid (inferior_ptid
);
100 /* This isn't really an address, but ptrace thinks of it as one. */
101 addr
= hppa_hpux_save_state_offset(current_regcache
, regnum
);
102 size
= register_size (current_gdbarch
, regnum
);
104 gdb_assert (size
== 4 || size
== 8);
109 lwpid_t lwp
= ptid_get_lwp (inferior_ptid
);
111 if (ttrace (TT_LWP_RUREGS
, pid
, lwp
, addr
, size
, (uintptr_t)buf
) == -1)
112 error (_("Couldn't read register %s (#%d): %s"),
113 REGISTER_NAME (regnum
), regnum
, safe_strerror (errno
));
119 /* Read the register contents from the inferior a chuck at the time. */
120 for (i
= 0; i
< size
/ sizeof (PTRACE_TYPE_RET
); i
++)
123 buf
[i
] = ptrace (PT_RUREGS
, pid
, (PTRACE_TYPE_ARG3
) addr
, 0, 0);
125 error (_("Couldn't read register %s (#%d): %s"),
126 REGISTER_NAME (regnum
), regnum
, safe_strerror (errno
));
128 addr
+= sizeof (PTRACE_TYPE_RET
);
133 /* Take care with the "flags" register. It's stored as an `int' in
134 `struct save_state', even for 64-bit code. */
135 if (regnum
== HPPA_FLAGS_REGNUM
&& size
== 8)
137 ULONGEST flags
= extract_unsigned_integer (buf
, 4);
138 store_unsigned_integer (buf
, 8, flags
);
141 regcache_raw_supply (current_regcache
, regnum
, buf
);
145 hppa_hpux_fetch_inferior_registers (int regnum
)
148 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
149 hppa_hpux_fetch_register (regnum
);
151 hppa_hpux_fetch_register (regnum
);
154 /* Store register REGNUM into the inferior. */
157 hppa_hpux_store_register (int regnum
)
161 PTRACE_TYPE_RET
*buf
;
164 pid
= ptid_get_pid (inferior_ptid
);
166 /* This isn't really an address, but ptrace thinks of it as one. */
167 addr
= hppa_hpux_save_state_offset(current_regcache
, regnum
);
168 size
= register_size (current_gdbarch
, regnum
);
170 gdb_assert (size
== 4 || size
== 8);
173 regcache_raw_collect (current_regcache
, regnum
, buf
);
175 /* Take care with the "flags" register. It's stored as an `int' in
176 `struct save_state', even for 64-bit code. */
177 if (regnum
== HPPA_FLAGS_REGNUM
&& size
== 8)
179 ULONGEST flags
= extract_unsigned_integer (buf
, 8);
180 store_unsigned_integer (buf
, 4, flags
);
186 lwpid_t lwp
= ptid_get_lwp (inferior_ptid
);
188 if (ttrace (TT_LWP_WUREGS
, pid
, lwp
, addr
, size
, (uintptr_t)buf
) == -1)
189 error (_("Couldn't write register %s (#%d): %s"),
190 REGISTER_NAME (regnum
), regnum
, safe_strerror (errno
));
196 /* Write the register contents into the inferior a chunk at the time. */
197 for (i
= 0; i
< size
/ sizeof (PTRACE_TYPE_RET
); i
++)
200 ptrace (PT_WUREGS
, pid
, (PTRACE_TYPE_ARG3
) addr
, buf
[i
], 0);
202 error (_("Couldn't write register %s (#%d): %s"),
203 REGISTER_NAME (regnum
), regnum
, safe_strerror (errno
));
205 addr
+= sizeof (PTRACE_TYPE_RET
);
211 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
212 this for all registers (including the floating point registers). */
215 hppa_hpux_store_inferior_registers (int regnum
)
218 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
219 hppa_hpux_store_register (regnum
);
221 hppa_hpux_store_register (regnum
);
225 hppa_hpux_child_can_run (void)
227 /* This variable is controlled by modules that layer their own
228 process structure atop that provided here. The code in
229 hpux-thread.c does this to support the HP-UX user-mode DCE
231 return !child_suppress_run
;
235 /* Prevent warning from -Wmissing-prototypes. */
236 void _initialize_hppa_hpux_nat (void);
239 _initialize_hppa_hpux_nat (void)
241 struct target_ops
*t
;
244 t
= inf_ttrace_target ();
246 t
= inf_ptrace_target ();
249 t
->to_fetch_registers
= hppa_hpux_fetch_inferior_registers
;
250 t
->to_store_registers
= hppa_hpux_store_inferior_registers
;
251 t
->to_can_run
= hppa_hpux_child_can_run
;