1 /* Machine-dependent hooks for the unix child process stratum, for HPUX PA-RISC.
3 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993
4 Free Software Foundation, Inc.
6 Contributed by the Center for Software Science at the
7 University of Utah (pa-gdb-bugs@cs.utah.edu).
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 #include <sys/ptrace.h>
32 extern CORE_ADDR text_end
;
34 static void fetch_register
PARAMS ((int));
37 fetch_inferior_registers (regno
)
41 for (regno
= 0; regno
< NUM_REGS
; regno
++)
42 fetch_register (regno
);
44 fetch_register (regno
);
47 /* Store our register values back into the inferior.
48 If REGNO is -1, do this for all registers.
49 Otherwise, REGNO specifies which register (so we can save time). */
52 store_inferior_registers (regno
)
55 register unsigned int regaddr
;
57 extern char registers
[];
59 unsigned int offset
= U_REGS_OFFSET
;
64 if (CANNOT_STORE_REGISTER (regno
))
66 regaddr
= register_addr (regno
, offset
);
68 if (regno
== PCOQ_HEAD_REGNUM
|| regno
== PCOQ_TAIL_REGNUM
)
70 scratch
= *(int *) ®isters
[REGISTER_BYTE (regno
)] | 0x3;
71 call_ptrace (PT_WUREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
75 /* Error, even if attached. Failing to write these two
76 registers is pretty serious. */
77 sprintf (buf
, "writing register number %d", regno
);
78 perror_with_name (buf
);
82 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
85 call_ptrace (PT_WUREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
86 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
89 /* Warning, not error, in case we are attached; sometimes the
90 kernel doesn't let us at the registers. */
91 char *err
= safe_strerror (errno
);
92 char *msg
= alloca (strlen (err
) + 128);
93 sprintf (msg
, "writing register %s: %s",
94 reg_names
[regno
], err
);
98 regaddr
+= sizeof(int);
102 for (regno
= 0; regno
< NUM_REGS
; regno
++)
103 store_inferior_registers (regno
);
106 /* Fetch one register. */
109 fetch_register (regno
)
112 register unsigned int regaddr
;
113 char buf
[MAX_REGISTER_RAW_SIZE
];
116 /* Offset of registers within the u area. */
119 offset
= U_REGS_OFFSET
;
121 regaddr
= register_addr (regno
, offset
);
122 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
125 *(int *) &buf
[i
] = call_ptrace (PT_RUREGS
, inferior_pid
,
126 (PTRACE_ARG3_TYPE
) regaddr
, 0);
127 regaddr
+= sizeof (int);
130 /* Warning, not error, in case we are attached; sometimes the
131 kernel doesn't let us at the registers. */
132 char *err
= safe_strerror (errno
);
133 char *msg
= alloca (strlen (err
) + 128);
134 sprintf (msg
, "reading register %s: %s", reg_names
[regno
], err
);
139 if (regno
== PCOQ_HEAD_REGNUM
|| regno
== PCOQ_TAIL_REGNUM
)
141 supply_register (regno
, buf
);
145 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
146 to debugger memory starting at MYADDR. Copy to inferior if
149 Returns the length copied, which is either the LEN argument or zero.
150 This xfer function does not do partial moves, since child_ops
151 doesn't allow memory operations to cross below us in the target stack
155 child_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
160 struct target_ops
*target
; /* ignored */
163 /* Round starting address down to longword boundary. */
164 register CORE_ADDR addr
= memaddr
& - sizeof (int);
165 /* Round ending address up; get number of longwords that makes. */
167 = (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
168 /* Allocate buffer of that many longwords. */
169 register int *buffer
= (int *) alloca (count
* sizeof (int));
173 /* Fill start and end extra bytes of buffer with existing memory data. */
175 if (addr
!= memaddr
|| len
< (int)sizeof (int)) {
176 /* Need part of initial word -- fetch it. */
177 buffer
[0] = call_ptrace (addr
< text_end
? PT_RIUSER
: PT_RDUSER
,
178 inferior_pid
, (PTRACE_ARG3_TYPE
) addr
, 0);
181 if (count
> 1) /* FIXME, avoid if even boundary */
184 = call_ptrace (addr
< text_end
? PT_RIUSER
: PT_RDUSER
, inferior_pid
,
185 (PTRACE_ARG3_TYPE
) (addr
+ (count
- 1) * sizeof (int)),
189 /* Copy data to be written over corresponding part of buffer */
191 memcpy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
193 /* Write the entire buffer. */
195 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
197 /* The HP-UX kernel crashes if you use PT_WDUSER to write into the text
198 segment. FIXME -- does it work to write into the data segment using
199 WIUSER, or do these idiots really expect us to figure out which segment
200 the address is in, so we can use a separate system call for it??! */
202 call_ptrace (addr
< text_end
? PT_WIUSER
: PT_WDUSER
, inferior_pid
,
203 (PTRACE_ARG3_TYPE
) addr
,
211 /* Read all the longwords */
212 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
215 buffer
[i
] = call_ptrace (addr
< text_end
? PT_RIUSER
: PT_RDUSER
,
216 inferior_pid
, (PTRACE_ARG3_TYPE
) addr
, 0);
222 /* Copy appropriate bytes out of the buffer. */
223 memcpy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
This page took 0.033484 seconds and 4 git commands to generate.