]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Native support code for HPUX PA-RISC. |
b83266a0 | 2 | Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1998, 1999 |
c906108c SS |
3 | Free Software Foundation, Inc. |
4 | ||
5 | Contributed by the Center for Software Science at the | |
6 | University of Utah ([email protected]). | |
7 | ||
c5aa993b | 8 | This file is part of GDB. |
c906108c | 9 | |
c5aa993b JM |
10 | This program is free software; you can redistribute it and/or modify |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2 of the License, or | |
13 | (at your option) any later version. | |
c906108c | 14 | |
c5aa993b JM |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
c906108c | 19 | |
c5aa993b JM |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program; if not, write to the Free Software | |
22 | Foundation, Inc., 59 Temple Place - Suite 330, | |
23 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
24 | |
25 | ||
26 | #include "defs.h" | |
27 | #include "inferior.h" | |
28 | #include "target.h" | |
29 | #include <sys/ptrace.h> | |
30 | #include "gdbcore.h" | |
a526d713 | 31 | #include "gdb_wait.h" |
c906108c SS |
32 | #include <signal.h> |
33 | ||
34 | extern CORE_ADDR text_end; | |
35 | ||
a14ed312 | 36 | static void fetch_register (int); |
c906108c SS |
37 | |
38 | void | |
fba45db2 | 39 | fetch_inferior_registers (int regno) |
c906108c SS |
40 | { |
41 | if (regno == -1) | |
42 | for (regno = 0; regno < NUM_REGS; regno++) | |
43 | fetch_register (regno); | |
44 | else | |
45 | fetch_register (regno); | |
46 | } | |
47 | ||
7be570e7 JM |
48 | /* Our own version of the offsetof macro, since we can't assume ANSI C. */ |
49 | #define HPPAH_OFFSETOF(type, member) ((int) (&((type *) 0)->member)) | |
50 | ||
c906108c SS |
51 | /* Store our register values back into the inferior. |
52 | If REGNO is -1, do this for all registers. | |
53 | Otherwise, REGNO specifies which register (so we can save time). */ | |
54 | ||
55 | void | |
fba45db2 | 56 | store_inferior_registers (int regno) |
c906108c SS |
57 | { |
58 | register unsigned int regaddr; | |
59 | char buf[80]; | |
c906108c SS |
60 | register int i; |
61 | unsigned int offset = U_REGS_OFFSET; | |
62 | int scratch; | |
63 | ||
64 | if (regno >= 0) | |
65 | { | |
7be570e7 JM |
66 | unsigned int addr, len, offset; |
67 | ||
c906108c SS |
68 | if (CANNOT_STORE_REGISTER (regno)) |
69 | return; | |
7be570e7 JM |
70 | |
71 | offset = 0; | |
72 | len = REGISTER_RAW_SIZE (regno); | |
73 | ||
74 | /* Requests for register zero actually want the save_state's | |
75 | ss_flags member. As RM says: "Oh, what a hack!" */ | |
76 | if (regno == 0) | |
b83266a0 | 77 | { |
7be570e7 JM |
78 | save_state_t ss; |
79 | addr = HPPAH_OFFSETOF (save_state_t, ss_flags); | |
80 | len = sizeof (ss.ss_flags); | |
81 | ||
82 | /* Note that ss_flags is always an int, no matter what | |
83 | REGISTER_RAW_SIZE(0) says. Assuming all HP-UX PA machines | |
84 | are big-endian, put it at the least significant end of the | |
85 | value, and zap the rest of the buffer. */ | |
86 | offset = REGISTER_RAW_SIZE (0) - len; | |
87 | } | |
88 | ||
89 | /* Floating-point registers come from the ss_fpblock area. */ | |
90 | else if (regno >= FP0_REGNUM) | |
91 | addr = (HPPAH_OFFSETOF (save_state_t, ss_fpblock) | |
92 | + (REGISTER_BYTE (regno) - REGISTER_BYTE (FP0_REGNUM))); | |
93 | ||
94 | /* Wide registers come from the ss_wide area. | |
95 | I think it's more PC to test (ss_flags & SS_WIDEREGS) to select | |
96 | between ss_wide and ss_narrow than to use the raw register size. | |
97 | But checking ss_flags would require an extra ptrace call for | |
98 | every register reference. Bleah. */ | |
99 | else if (len == 8) | |
100 | addr = (HPPAH_OFFSETOF (save_state_t, ss_wide) | |
101 | + REGISTER_BYTE (regno)); | |
102 | ||
103 | /* Narrow registers come from the ss_narrow area. Note that | |
104 | ss_narrow starts with gr1, not gr0. */ | |
105 | else if (len == 4) | |
106 | addr = (HPPAH_OFFSETOF (save_state_t, ss_narrow) | |
107 | + (REGISTER_BYTE (regno) - REGISTER_BYTE (1))); | |
108 | else | |
109 | internal_error ("hppah-nat.c (write_register): unexpected register size"); | |
110 | ||
111 | #ifdef GDB_TARGET_IS_HPPA_20W | |
112 | /* Unbelieveable. The PC head and tail must be written in 64bit hunks | |
113 | or we will get an error. Worse yet, the oddball ptrace/ttrace | |
114 | layering will not allow us to perform a 64bit register store. | |
115 | ||
116 | What a crock. */ | |
117 | if (regno == PCOQ_HEAD_REGNUM || regno == PCOQ_TAIL_REGNUM && len == 8) | |
118 | { | |
119 | CORE_ADDR temp; | |
120 | ||
121 | temp = *(CORE_ADDR *)®isters[REGISTER_BYTE (regno)]; | |
122 | ||
123 | /* Set the priv level (stored in the low two bits of the PC. */ | |
124 | temp |= 0x3; | |
125 | ||
126 | ttrace_write_reg_64 (inferior_pid, (CORE_ADDR)addr, (CORE_ADDR)&temp); | |
127 | ||
128 | /* If we fail to write the PC, give a true error instead of | |
129 | just a warning. */ | |
b83266a0 SS |
130 | if (errno != 0) |
131 | { | |
7be570e7 JM |
132 | char *err = safe_strerror (errno); |
133 | char *msg = alloca (strlen (err) + 128); | |
134 | sprintf (msg, "writing `%s' register: %s", | |
135 | REGISTER_NAME (regno), err); | |
136 | perror_with_name (msg); | |
b83266a0 | 137 | } |
7be570e7 | 138 | return; |
b83266a0 | 139 | } |
53a5351d JM |
140 | |
141 | /* Another crock. HPUX complains if you write a nonzero value to | |
142 | the high part of IPSW. What will it take for HP to catch a | |
143 | clue about building sensible interfaces? */ | |
144 | if (regno == IPSW_REGNUM && len == 8) | |
145 | *(int *)®isters[REGISTER_BYTE (regno)] = 0; | |
7be570e7 JM |
146 | #endif |
147 | ||
148 | for (i = 0; i < len; i += sizeof (int)) | |
149 | { | |
150 | errno = 0; | |
151 | call_ptrace (PT_WUREGS, inferior_pid, (PTRACE_ARG3_TYPE) addr + i, | |
152 | *(int *) ®isters[REGISTER_BYTE (regno) + i]); | |
153 | if (errno != 0) | |
154 | { | |
155 | /* Warning, not error, in case we are attached; sometimes | |
156 | the kernel doesn't let us at the registers. */ | |
157 | char *err = safe_strerror (errno); | |
158 | char *msg = alloca (strlen (err) + 128); | |
53a5351d | 159 | sprintf (msg, "writing `%s' register: %s", |
7be570e7 JM |
160 | REGISTER_NAME (regno), err); |
161 | /* If we fail to write the PC, give a true error instead of | |
162 | just a warning. */ | |
163 | if (regno == PCOQ_HEAD_REGNUM || regno == PCOQ_TAIL_REGNUM) | |
164 | perror_with_name (msg); | |
165 | else | |
c906108c | 166 | warning (msg); |
7be570e7 JM |
167 | return; |
168 | } | |
169 | } | |
c906108c SS |
170 | } |
171 | else | |
172 | for (regno = 0; regno < NUM_REGS; regno++) | |
173 | store_inferior_registers (regno); | |
174 | } | |
175 | ||
c906108c | 176 | |
adf40b2e | 177 | /* Fetch a register's value from the process's U area. */ |
c906108c | 178 | static void |
fba45db2 | 179 | fetch_register (int regno) |
c906108c | 180 | { |
c906108c | 181 | char buf[MAX_REGISTER_RAW_SIZE]; |
adf40b2e JM |
182 | unsigned int addr, len, offset; |
183 | int i; | |
c906108c | 184 | |
adf40b2e JM |
185 | offset = 0; |
186 | len = REGISTER_RAW_SIZE (regno); | |
187 | ||
188 | /* Requests for register zero actually want the save_state's | |
189 | ss_flags member. As RM says: "Oh, what a hack!" */ | |
190 | if (regno == 0) | |
191 | { | |
192 | save_state_t ss; | |
193 | addr = HPPAH_OFFSETOF (save_state_t, ss_flags); | |
194 | len = sizeof (ss.ss_flags); | |
195 | ||
196 | /* Note that ss_flags is always an int, no matter what | |
197 | REGISTER_RAW_SIZE(0) says. Assuming all HP-UX PA machines | |
198 | are big-endian, put it at the least significant end of the | |
199 | value, and zap the rest of the buffer. */ | |
200 | offset = REGISTER_RAW_SIZE (0) - len; | |
201 | memset (buf, 0, sizeof (buf)); | |
202 | } | |
c906108c | 203 | |
adf40b2e JM |
204 | /* Floating-point registers come from the ss_fpblock area. */ |
205 | else if (regno >= FP0_REGNUM) | |
206 | addr = (HPPAH_OFFSETOF (save_state_t, ss_fpblock) | |
207 | + (REGISTER_BYTE (regno) - REGISTER_BYTE (FP0_REGNUM))); | |
208 | ||
209 | /* Wide registers come from the ss_wide area. | |
210 | I think it's more PC to test (ss_flags & SS_WIDEREGS) to select | |
211 | between ss_wide and ss_narrow than to use the raw register size. | |
212 | But checking ss_flags would require an extra ptrace call for | |
213 | every register reference. Bleah. */ | |
214 | else if (len == 8) | |
215 | addr = (HPPAH_OFFSETOF (save_state_t, ss_wide) | |
216 | + REGISTER_BYTE (regno)); | |
217 | ||
218 | /* Narrow registers come from the ss_narrow area. Note that | |
219 | ss_narrow starts with gr1, not gr0. */ | |
220 | else if (len == 4) | |
221 | addr = (HPPAH_OFFSETOF (save_state_t, ss_narrow) | |
222 | + (REGISTER_BYTE (regno) - REGISTER_BYTE (1))); | |
c906108c | 223 | |
adf40b2e | 224 | else |
96baa820 | 225 | internal_error ("hppa-nat.c (fetch_register): unexpected register size"); |
adf40b2e JM |
226 | |
227 | for (i = 0; i < len; i += sizeof (int)) | |
c906108c SS |
228 | { |
229 | errno = 0; | |
adf40b2e JM |
230 | /* Copy an int from the U area to buf. Fill the least |
231 | significant end if len != raw_size. */ | |
232 | * (int *) &buf[offset + i] = | |
233 | call_ptrace (PT_RUREGS, inferior_pid, | |
234 | (PTRACE_ARG3_TYPE) addr + i, 0); | |
c906108c SS |
235 | if (errno != 0) |
236 | { | |
adf40b2e JM |
237 | /* Warning, not error, in case we are attached; sometimes |
238 | the kernel doesn't let us at the registers. */ | |
c906108c SS |
239 | char *err = safe_strerror (errno); |
240 | char *msg = alloca (strlen (err) + 128); | |
adf40b2e JM |
241 | sprintf (msg, "reading `%s' register: %s", |
242 | REGISTER_NAME (regno), err); | |
c906108c | 243 | warning (msg); |
adf40b2e | 244 | return; |
c906108c SS |
245 | } |
246 | } | |
adf40b2e JM |
247 | |
248 | /* If we're reading an address from the instruction address queue, | |
249 | mask out the bottom two bits --- they contain the privilege | |
250 | level. */ | |
c906108c | 251 | if (regno == PCOQ_HEAD_REGNUM || regno == PCOQ_TAIL_REGNUM) |
adf40b2e JM |
252 | buf[len - 1] &= ~0x3; |
253 | ||
c906108c | 254 | supply_register (regno, buf); |
c906108c SS |
255 | } |
256 | ||
adf40b2e | 257 | |
c906108c SS |
258 | /* Copy LEN bytes to or from inferior's memory starting at MEMADDR |
259 | to debugger memory starting at MYADDR. Copy to inferior if | |
260 | WRITE is nonzero. | |
c5aa993b | 261 | |
c906108c SS |
262 | Returns the length copied, which is either the LEN argument or zero. |
263 | This xfer function does not do partial moves, since child_ops | |
264 | doesn't allow memory operations to cross below us in the target stack | |
265 | anyway. */ | |
266 | ||
267 | int | |
268 | child_xfer_memory (memaddr, myaddr, len, write, target) | |
269 | CORE_ADDR memaddr; | |
270 | char *myaddr; | |
271 | int len; | |
272 | int write; | |
c5aa993b | 273 | struct target_ops *target; /* ignored */ |
c906108c SS |
274 | { |
275 | register int i; | |
276 | /* Round starting address down to longword boundary. */ | |
a0b3c4fd | 277 | register CORE_ADDR addr = memaddr & - (CORE_ADDR)(sizeof (int)); |
c906108c SS |
278 | /* Round ending address up; get number of longwords that makes. */ |
279 | register int count | |
c5aa993b | 280 | = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int); |
c906108c | 281 | |
b83266a0 SS |
282 | /* Allocate buffer of that many longwords. |
283 | Note -- do not use alloca to allocate this buffer since there is no | |
284 | guarantee of when the buffer will actually be deallocated. | |
285 | ||
286 | This routine can be called over and over with the same call chain; | |
287 | this (in effect) would pile up all those alloca requests until a call | |
288 | to alloca was made from a point higher than this routine in the | |
289 | call chain. */ | |
c906108c SS |
290 | register int *buffer = (int *) xmalloc (count * sizeof (int)); |
291 | ||
292 | if (write) | |
293 | { | |
294 | /* Fill start and end extra bytes of buffer with existing memory data. */ | |
c5aa993b | 295 | if (addr != memaddr || len < (int) sizeof (int)) |
b83266a0 SS |
296 | { |
297 | /* Need part of initial word -- fetch it. */ | |
c5aa993b | 298 | buffer[0] = call_ptrace (addr < text_end ? PT_RIUSER : PT_RDUSER, |
b83266a0 SS |
299 | inferior_pid, (PTRACE_ARG3_TYPE) addr, 0); |
300 | } | |
c906108c SS |
301 | |
302 | if (count > 1) /* FIXME, avoid if even boundary */ | |
303 | { | |
304 | buffer[count - 1] | |
b83266a0 SS |
305 | = call_ptrace (addr < text_end ? PT_RIUSER : PT_RDUSER, |
306 | inferior_pid, | |
307 | (PTRACE_ARG3_TYPE) (addr | |
308 | + (count - 1) * sizeof (int)), | |
309 | 0); | |
c906108c SS |
310 | } |
311 | ||
312 | /* Copy data to be written over corresponding part of buffer */ | |
c906108c SS |
313 | memcpy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len); |
314 | ||
315 | /* Write the entire buffer. */ | |
c906108c SS |
316 | for (i = 0; i < count; i++, addr += sizeof (int)) |
317 | { | |
b83266a0 SS |
318 | int pt_status; |
319 | int pt_request; | |
320 | /* The HP-UX kernel crashes if you use PT_WDUSER to write into the | |
321 | text segment. FIXME -- does it work to write into the data | |
322 | segment using WIUSER, or do these idiots really expect us to | |
323 | figure out which segment the address is in, so we can use a | |
324 | separate system call for it??! */ | |
c906108c | 325 | errno = 0; |
b83266a0 | 326 | pt_request = (addr < text_end) ? PT_WIUSER : PT_WDUSER; |
c906108c | 327 | pt_status = call_ptrace (pt_request, |
c5aa993b | 328 | inferior_pid, |
b83266a0 SS |
329 | (PTRACE_ARG3_TYPE) addr, |
330 | buffer[i]); | |
331 | ||
332 | /* Did we fail? Might we've guessed wrong about which | |
333 | segment this address resides in? Try the other request, | |
334 | and see if that works... */ | |
335 | if ((pt_status == -1) && errno) | |
336 | { | |
337 | errno = 0; | |
338 | pt_request = (pt_request == PT_WIUSER) ? PT_WDUSER : PT_WIUSER; | |
339 | pt_status = call_ptrace (pt_request, | |
c5aa993b | 340 | inferior_pid, |
b83266a0 SS |
341 | (PTRACE_ARG3_TYPE) addr, |
342 | buffer[i]); | |
343 | ||
344 | /* No, we still fail. Okay, time to punt. */ | |
345 | if ((pt_status == -1) && errno) | |
346 | { | |
c5aa993b | 347 | free (buffer); |
b83266a0 SS |
348 | return 0; |
349 | } | |
350 | } | |
c906108c SS |
351 | } |
352 | } | |
353 | else | |
354 | { | |
355 | /* Read all the longwords */ | |
356 | for (i = 0; i < count; i++, addr += sizeof (int)) | |
357 | { | |
358 | errno = 0; | |
c5aa993b | 359 | buffer[i] = call_ptrace (addr < text_end ? PT_RIUSER : PT_RDUSER, |
b83266a0 SS |
360 | inferior_pid, (PTRACE_ARG3_TYPE) addr, 0); |
361 | if (errno) | |
362 | { | |
c5aa993b | 363 | free (buffer); |
b83266a0 SS |
364 | return 0; |
365 | } | |
c906108c SS |
366 | QUIT; |
367 | } | |
368 | ||
369 | /* Copy appropriate bytes out of the buffer. */ | |
370 | memcpy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len); | |
371 | } | |
c5aa993b | 372 | free (buffer); |
c906108c SS |
373 | return len; |
374 | } | |
375 | ||
376 | ||
377 | void | |
fba45db2 | 378 | child_post_follow_inferior_by_clone (void) |
c906108c | 379 | { |
b83266a0 | 380 | int status; |
c906108c SS |
381 | |
382 | /* This function is used when following both the parent and child | |
383 | of a fork. In this case, the debugger clones itself. The original | |
384 | debugger follows the parent, the clone follows the child. The | |
385 | original detaches from the child, delivering a SIGSTOP to it to | |
386 | keep it from running away until the clone can attach itself. | |
387 | ||
388 | At this point, the clone has attached to the child. Because of | |
389 | the SIGSTOP, we must now deliver a SIGCONT to the child, or it | |
390 | won't behave properly. */ | |
391 | status = kill (inferior_pid, SIGCONT); | |
392 | } | |
393 | ||
394 | ||
395 | void | |
fba45db2 KB |
396 | child_post_follow_vfork (int parent_pid, int followed_parent, int child_pid, |
397 | int followed_child) | |
c906108c | 398 | { |
c906108c SS |
399 | /* Are we a debugger that followed the parent of a vfork? If so, |
400 | then recall that the child's vfork event was delivered to us | |
401 | first. And, that the parent was suspended by the OS until the | |
402 | child's exec or exit events were received. | |
403 | ||
404 | Upon receiving that child vfork, then, we were forced to remove | |
405 | all breakpoints in the child and continue it so that it could | |
406 | reach the exec or exit point. | |
407 | ||
408 | But also recall that the parent and child of a vfork share the | |
409 | same address space. Thus, removing bp's in the child also | |
410 | removed them from the parent. | |
411 | ||
412 | Now that the child has safely exec'd or exited, we must restore | |
413 | the parent's breakpoints before we continue it. Else, we may | |
414 | cause it run past expected stopping points. */ | |
415 | if (followed_parent) | |
416 | { | |
417 | reattach_breakpoints (parent_pid); | |
418 | } | |
419 | ||
420 | /* Are we a debugger that followed the child of a vfork? If so, | |
421 | then recall that we don't actually acquire control of the child | |
b83266a0 | 422 | until after it has exec'd or exited. */ |
c906108c SS |
423 | if (followed_child) |
424 | { | |
425 | /* If the child has exited, then there's nothing for us to do. | |
c5aa993b JM |
426 | In the case of an exec event, we'll let that be handled by |
427 | the normal mechanism that notices and handles exec events, in | |
428 | resume(). */ | |
c906108c SS |
429 | } |
430 | } | |
431 | ||
b83266a0 SS |
432 | /* Format a process id, given PID. Be sure to terminate |
433 | this with a null--it's going to be printed via a "%s". */ | |
c906108c | 434 | char * |
fba45db2 | 435 | child_pid_to_str (pid_t pid) |
c906108c | 436 | { |
c5aa993b JM |
437 | /* Static because address returned */ |
438 | static char buf[30]; | |
c906108c | 439 | |
c5aa993b JM |
440 | /* Extra NULLs for paranoia's sake */ |
441 | sprintf (buf, "process %d\0\0\0\0", pid); | |
442 | ||
443 | return buf; | |
c906108c SS |
444 | } |
445 | ||
b83266a0 SS |
446 | /* Format a thread id, given TID. Be sure to terminate |
447 | this with a null--it's going to be printed via a "%s". | |
448 | ||
449 | Note: This is a core-gdb tid, not the actual system tid. | |
c5aa993b | 450 | See infttrace.c for details. */ |
c906108c | 451 | char * |
fba45db2 | 452 | hppa_tid_to_str (pid_t tid) |
c906108c | 453 | { |
c5aa993b JM |
454 | /* Static because address returned */ |
455 | static char buf[30]; | |
456 | ||
457 | /* Extra NULLs for paranoia's sake */ | |
458 | sprintf (buf, "system thread %d\0\0\0\0", tid); | |
c906108c | 459 | |
c5aa993b | 460 | return buf; |
c906108c SS |
461 | } |
462 | ||
463 | #if !defined (GDB_NATIVE_HPUX_11) | |
464 | ||
465 | /* The following code is a substitute for the infttrace.c versions used | |
466 | with ttrace() in HPUX 11. */ | |
467 | ||
468 | /* This value is an arbitrary integer. */ | |
469 | #define PT_VERSION 123456 | |
470 | ||
471 | /* This semaphore is used to coordinate the child and parent processes | |
472 | after a fork(), and before an exec() by the child. See | |
473 | parent_attach_all for details. */ | |
474 | ||
c5aa993b JM |
475 | typedef struct |
476 | { | |
477 | int parent_channel[2]; /* Parent "talks" to [1], child "listens" to [0] */ | |
478 | int child_channel[2]; /* Child "talks" to [1], parent "listens" to [0] */ | |
479 | } | |
480 | startup_semaphore_t; | |
c906108c SS |
481 | |
482 | #define SEM_TALK (1) | |
483 | #define SEM_LISTEN (0) | |
484 | ||
c5aa993b | 485 | static startup_semaphore_t startup_semaphore; |
c906108c | 486 | |
a14ed312 | 487 | extern int parent_attach_all (int, PTRACE_ARG3_TYPE, int); |
c906108c SS |
488 | |
489 | #ifdef PT_SETTRC | |
490 | /* This function causes the caller's process to be traced by its | |
491 | parent. This is intended to be called after GDB forks itself, | |
492 | and before the child execs the target. | |
493 | ||
494 | Note that HP-UX ptrace is rather funky in how this is done. | |
495 | If the parent wants to get the initial exec event of a child, | |
496 | it must set the ptrace event mask of the child to include execs. | |
497 | (The child cannot do this itself.) This must be done after the | |
498 | child is forked, but before it execs. | |
499 | ||
500 | To coordinate the parent and child, we implement a semaphore using | |
501 | pipes. After SETTRC'ing itself, the child tells the parent that | |
502 | it is now traceable by the parent, and waits for the parent's | |
503 | acknowledgement. The parent can then set the child's event mask, | |
504 | and notify the child that it can now exec. | |
505 | ||
506 | (The acknowledgement by parent happens as a result of a call to | |
507 | child_acknowledge_created_inferior.) */ | |
508 | ||
509 | int | |
fba45db2 | 510 | parent_attach_all (int pid, PTRACE_ARG3_TYPE addr, int data) |
c906108c SS |
511 | { |
512 | int pt_status = 0; | |
513 | ||
514 | /* We need a memory home for a constant. */ | |
515 | int tc_magic_child = PT_VERSION; | |
516 | int tc_magic_parent = 0; | |
517 | ||
518 | /* The remainder of this function is only useful for HPUX 10.0 and | |
519 | later, as it depends upon the ability to request notification | |
520 | of specific kinds of events by the kernel. */ | |
521 | #if defined(PT_SET_EVENT_MASK) | |
522 | ||
523 | /* Notify the parent that we're potentially ready to exec(). */ | |
524 | write (startup_semaphore.child_channel[SEM_TALK], | |
b83266a0 SS |
525 | &tc_magic_child, |
526 | sizeof (tc_magic_child)); | |
c906108c SS |
527 | |
528 | /* Wait for acknowledgement from the parent. */ | |
529 | read (startup_semaphore.parent_channel[SEM_LISTEN], | |
b83266a0 SS |
530 | &tc_magic_parent, |
531 | sizeof (tc_magic_parent)); | |
c906108c | 532 | if (tc_magic_child != tc_magic_parent) |
c5aa993b | 533 | warning ("mismatched semaphore magic"); |
c906108c SS |
534 | |
535 | /* Discard our copy of the semaphore. */ | |
536 | (void) close (startup_semaphore.parent_channel[SEM_LISTEN]); | |
537 | (void) close (startup_semaphore.parent_channel[SEM_TALK]); | |
538 | (void) close (startup_semaphore.child_channel[SEM_LISTEN]); | |
539 | (void) close (startup_semaphore.child_channel[SEM_TALK]); | |
540 | #endif | |
c5aa993b | 541 | |
c906108c SS |
542 | return 0; |
543 | } | |
544 | #endif | |
545 | ||
546 | int | |
fba45db2 | 547 | hppa_require_attach (int pid) |
c906108c SS |
548 | { |
549 | int pt_status; | |
b83266a0 SS |
550 | CORE_ADDR pc; |
551 | CORE_ADDR pc_addr; | |
c906108c SS |
552 | unsigned int regs_offset; |
553 | ||
554 | /* Are we already attached? There appears to be no explicit way to | |
555 | answer this via ptrace, so we try something which should be | |
556 | innocuous if we are attached. If that fails, then we assume | |
557 | we're not attached, and so attempt to make it so. */ | |
558 | ||
559 | errno = 0; | |
560 | regs_offset = U_REGS_OFFSET; | |
561 | pc_addr = register_addr (PC_REGNUM, regs_offset); | |
562 | pc = call_ptrace (PT_READ_U, pid, (PTRACE_ARG3_TYPE) pc_addr, 0); | |
563 | ||
564 | if (errno) | |
565 | { | |
566 | errno = 0; | |
567 | pt_status = call_ptrace (PT_ATTACH, pid, (PTRACE_ARG3_TYPE) 0, 0); | |
568 | ||
569 | if (errno) | |
b83266a0 | 570 | return -1; |
c906108c SS |
571 | |
572 | /* Now we really are attached. */ | |
573 | errno = 0; | |
574 | } | |
575 | attach_flag = 1; | |
576 | return pid; | |
577 | } | |
578 | ||
579 | int | |
fba45db2 | 580 | hppa_require_detach (int pid, int signal) |
c906108c SS |
581 | { |
582 | errno = 0; | |
583 | call_ptrace (PT_DETACH, pid, (PTRACE_ARG3_TYPE) 1, signal); | |
c5aa993b | 584 | errno = 0; /* Ignore any errors. */ |
c906108c SS |
585 | return pid; |
586 | } | |
587 | ||
588 | /* Since ptrace doesn't support memory page-protection events, which | |
589 | are used to implement "hardware" watchpoints on HP-UX, these are | |
590 | dummy versions, which perform no useful work. */ | |
591 | ||
592 | void | |
fba45db2 | 593 | hppa_enable_page_protection_events (int pid) |
c906108c SS |
594 | { |
595 | } | |
596 | ||
597 | void | |
fba45db2 | 598 | hppa_disable_page_protection_events (int pid) |
c906108c SS |
599 | { |
600 | } | |
601 | ||
602 | int | |
fba45db2 | 603 | hppa_insert_hw_watchpoint (int pid, CORE_ADDR start, LONGEST len, int type) |
c906108c SS |
604 | { |
605 | error ("Hardware watchpoints not implemented on this platform."); | |
606 | } | |
607 | ||
608 | int | |
fba45db2 KB |
609 | hppa_remove_hw_watchpoint (int pid, CORE_ADDR start, LONGEST len, |
610 | enum bptype type) | |
c906108c SS |
611 | { |
612 | error ("Hardware watchpoints not implemented on this platform."); | |
613 | } | |
614 | ||
615 | int | |
fba45db2 | 616 | hppa_can_use_hw_watchpoint (enum bptype type, int cnt, enum bptype ot) |
c906108c SS |
617 | { |
618 | return 0; | |
619 | } | |
620 | ||
621 | int | |
fba45db2 | 622 | hppa_range_profitable_for_hw_watchpoint (int pid, CORE_ADDR start, LONGEST len) |
c906108c SS |
623 | { |
624 | error ("Hardware watchpoints not implemented on this platform."); | |
625 | } | |
626 | ||
627 | char * | |
fba45db2 | 628 | hppa_pid_or_tid_to_str (pid_t id) |
c906108c SS |
629 | { |
630 | /* In the ptrace world, there are only processes. */ | |
ed9a39eb | 631 | return child_pid_to_str (id); |
c906108c SS |
632 | } |
633 | ||
634 | /* This function has no meaning in a non-threaded world. Thus, we | |
635 | return 0 (FALSE). See the use of "hppa_prepare_to_proceed" in | |
636 | hppa-tdep.c. */ | |
637 | ||
638 | pid_t | |
fba45db2 | 639 | hppa_switched_threads (pid_t pid) |
c906108c SS |
640 | { |
641 | return (pid_t) 0; | |
642 | } | |
643 | ||
644 | void | |
fba45db2 | 645 | hppa_ensure_vforking_parent_remains_stopped (int pid) |
c906108c SS |
646 | { |
647 | /* This assumes that the vforked parent is presently stopped, and | |
648 | that the vforked child has just delivered its first exec event. | |
649 | Calling kill() this way will cause the SIGTRAP to be delivered as | |
650 | soon as the parent is resumed, which happens as soon as the | |
651 | vforked child is resumed. See wait_for_inferior for the use of | |
652 | this function. */ | |
653 | kill (pid, SIGTRAP); | |
654 | } | |
655 | ||
656 | int | |
fba45db2 | 657 | hppa_resume_execd_vforking_child_to_get_parent_vfork (void) |
c906108c | 658 | { |
c5aa993b | 659 | return 1; /* Yes, the child must be resumed. */ |
c906108c SS |
660 | } |
661 | ||
662 | void | |
fba45db2 | 663 | require_notification_of_events (int pid) |
c906108c SS |
664 | { |
665 | #if defined(PT_SET_EVENT_MASK) | |
666 | int pt_status; | |
667 | ptrace_event_t ptrace_events; | |
c2d11a7d JM |
668 | int nsigs; |
669 | int signum; | |
c906108c SS |
670 | |
671 | /* Instruct the kernel as to the set of events we wish to be | |
672 | informed of. (This support does not exist before HPUX 10.0. | |
673 | We'll assume if PT_SET_EVENT_MASK has not been defined by | |
b83266a0 | 674 | <sys/ptrace.h>, then we're being built on pre-10.0.) */ |
c906108c SS |
675 | memset (&ptrace_events, 0, sizeof (ptrace_events)); |
676 | ||
677 | /* Note: By default, all signals are visible to us. If we wish | |
678 | the kernel to keep certain signals hidden from us, we do it | |
679 | by calling sigdelset (ptrace_events.pe_signals, signal) for | |
b83266a0 | 680 | each such signal here, before doing PT_SET_EVENT_MASK. */ |
c2d11a7d JM |
681 | /* RM: The above comment is no longer true. We start with ignoring |
682 | all signals, and then add the ones we are interested in. We could | |
683 | do it the other way: start by looking at all signals and then | |
684 | deleting the ones that we aren't interested in, except that | |
685 | multiple gdb signals may be mapped to the same host signal | |
686 | (eg. TARGET_SIGNAL_IO and TARGET_SIGNAL_POLL both get mapped to | |
687 | signal 22 on HPUX 10.20) We want to be notified if we are | |
688 | interested in either signal. */ | |
689 | sigfillset (&ptrace_events.pe_signals); | |
690 | ||
691 | /* RM: Let's not bother with signals we don't care about */ | |
692 | nsigs = (int) TARGET_SIGNAL_LAST; | |
693 | for (signum = nsigs; signum > 0; signum--) | |
694 | { | |
695 | if ((signal_stop_state (signum)) || | |
696 | (signal_print_state (signum)) || | |
697 | (!signal_pass_state (signum))) | |
698 | { | |
699 | if (target_signal_to_host_p (signum)) | |
700 | sigdelset (&ptrace_events.pe_signals, | |
701 | target_signal_to_host (signum)); | |
702 | } | |
703 | } | |
c906108c SS |
704 | |
705 | ptrace_events.pe_set_event = 0; | |
706 | ||
707 | ptrace_events.pe_set_event |= PTRACE_SIGNAL; | |
708 | ptrace_events.pe_set_event |= PTRACE_EXEC; | |
709 | ptrace_events.pe_set_event |= PTRACE_FORK; | |
710 | ptrace_events.pe_set_event |= PTRACE_VFORK; | |
711 | /* ??rehrauer: Add this one when we're prepared to catch it... | |
c5aa993b JM |
712 | ptrace_events.pe_set_event |= PTRACE_EXIT; |
713 | */ | |
c906108c SS |
714 | |
715 | errno = 0; | |
716 | pt_status = call_ptrace (PT_SET_EVENT_MASK, | |
c5aa993b JM |
717 | pid, |
718 | (PTRACE_ARG3_TYPE) & ptrace_events, | |
719 | sizeof (ptrace_events)); | |
c906108c SS |
720 | if (errno) |
721 | perror_with_name ("ptrace"); | |
722 | if (pt_status < 0) | |
723 | return; | |
724 | #endif | |
725 | } | |
726 | ||
727 | void | |
fba45db2 | 728 | require_notification_of_exec_events (int pid) |
c906108c SS |
729 | { |
730 | #if defined(PT_SET_EVENT_MASK) | |
731 | int pt_status; | |
732 | ptrace_event_t ptrace_events; | |
733 | ||
734 | /* Instruct the kernel as to the set of events we wish to be | |
735 | informed of. (This support does not exist before HPUX 10.0. | |
736 | We'll assume if PT_SET_EVENT_MASK has not been defined by | |
b83266a0 | 737 | <sys/ptrace.h>, then we're being built on pre-10.0.) */ |
c906108c SS |
738 | memset (&ptrace_events, 0, sizeof (ptrace_events)); |
739 | ||
740 | /* Note: By default, all signals are visible to us. If we wish | |
741 | the kernel to keep certain signals hidden from us, we do it | |
742 | by calling sigdelset (ptrace_events.pe_signals, signal) for | |
b83266a0 | 743 | each such signal here, before doing PT_SET_EVENT_MASK. */ |
c906108c SS |
744 | sigemptyset (&ptrace_events.pe_signals); |
745 | ||
746 | ptrace_events.pe_set_event = 0; | |
747 | ||
748 | ptrace_events.pe_set_event |= PTRACE_EXEC; | |
749 | /* ??rehrauer: Add this one when we're prepared to catch it... | |
c5aa993b JM |
750 | ptrace_events.pe_set_event |= PTRACE_EXIT; |
751 | */ | |
c906108c SS |
752 | |
753 | errno = 0; | |
754 | pt_status = call_ptrace (PT_SET_EVENT_MASK, | |
c5aa993b JM |
755 | pid, |
756 | (PTRACE_ARG3_TYPE) & ptrace_events, | |
757 | sizeof (ptrace_events)); | |
c906108c SS |
758 | if (errno) |
759 | perror_with_name ("ptrace"); | |
760 | if (pt_status < 0) | |
761 | return; | |
762 | #endif | |
763 | } | |
764 | ||
765 | /* This function is called by the parent process, with pid being the | |
766 | ID of the child process, after the debugger has forked. */ | |
767 | ||
768 | void | |
fba45db2 | 769 | child_acknowledge_created_inferior (int pid) |
c906108c SS |
770 | { |
771 | /* We need a memory home for a constant. */ | |
772 | int tc_magic_parent = PT_VERSION; | |
773 | int tc_magic_child = 0; | |
774 | ||
b83266a0 SS |
775 | /* The remainder of this function is only useful for HPUX 10.0 and |
776 | later, as it depends upon the ability to request notification | |
777 | of specific kinds of events by the kernel. */ | |
778 | #if defined(PT_SET_EVENT_MASK) | |
c906108c SS |
779 | /* Wait for the child to tell us that it has forked. */ |
780 | read (startup_semaphore.child_channel[SEM_LISTEN], | |
b83266a0 | 781 | &tc_magic_child, |
c5aa993b | 782 | sizeof (tc_magic_child)); |
c906108c SS |
783 | |
784 | /* Notify the child that it can exec. | |
785 | ||
786 | In the infttrace.c variant of this function, we set the child's | |
787 | event mask after the fork but before the exec. In the ptrace | |
788 | world, it seems we can't set the event mask until after the exec. */ | |
c906108c | 789 | write (startup_semaphore.parent_channel[SEM_TALK], |
b83266a0 SS |
790 | &tc_magic_parent, |
791 | sizeof (tc_magic_parent)); | |
c906108c SS |
792 | |
793 | /* We'd better pause a bit before trying to set the event mask, | |
794 | though, to ensure that the exec has happened. We don't want to | |
795 | wait() on the child, because that'll screw up the upper layers | |
796 | of gdb's execution control that expect to see the exec event. | |
797 | ||
798 | After an exec, the child is no longer executing gdb code. Hence, | |
799 | we can't have yet another synchronization via the pipes. We'll | |
800 | just sleep for a second, and hope that's enough delay... */ | |
c906108c SS |
801 | sleep (1); |
802 | ||
803 | /* Instruct the kernel as to the set of events we wish to be | |
804 | informed of. */ | |
c906108c SS |
805 | require_notification_of_exec_events (pid); |
806 | ||
807 | /* Discard our copy of the semaphore. */ | |
808 | (void) close (startup_semaphore.parent_channel[SEM_LISTEN]); | |
809 | (void) close (startup_semaphore.parent_channel[SEM_TALK]); | |
810 | (void) close (startup_semaphore.child_channel[SEM_LISTEN]); | |
811 | (void) close (startup_semaphore.child_channel[SEM_TALK]); | |
b83266a0 | 812 | #endif |
c906108c SS |
813 | } |
814 | ||
815 | void | |
fba45db2 | 816 | child_post_startup_inferior (int pid) |
c906108c SS |
817 | { |
818 | require_notification_of_events (pid); | |
819 | } | |
820 | ||
821 | void | |
fba45db2 | 822 | child_post_attach (int pid) |
c906108c SS |
823 | { |
824 | require_notification_of_events (pid); | |
825 | } | |
826 | ||
827 | int | |
fba45db2 | 828 | child_insert_fork_catchpoint (int pid) |
c906108c SS |
829 | { |
830 | /* This request is only available on HPUX 10.0 and later. */ | |
831 | #if !defined(PT_SET_EVENT_MASK) | |
832 | error ("Unable to catch forks prior to HPUX 10.0"); | |
833 | #else | |
834 | /* Enable reporting of fork events from the kernel. */ | |
835 | /* ??rehrauer: For the moment, we're always enabling these events, | |
b83266a0 | 836 | and just ignoring them if there's no catchpoint to catch them. */ |
c906108c SS |
837 | return 0; |
838 | #endif | |
839 | } | |
840 | ||
841 | int | |
fba45db2 | 842 | child_remove_fork_catchpoint (int pid) |
c906108c SS |
843 | { |
844 | /* This request is only available on HPUX 10.0 and later. */ | |
845 | #if !defined(PT_SET_EVENT_MASK) | |
846 | error ("Unable to catch forks prior to HPUX 10.0"); | |
847 | #else | |
848 | /* Disable reporting of fork events from the kernel. */ | |
849 | /* ??rehrauer: For the moment, we're always enabling these events, | |
850 | and just ignoring them if there's no catchpoint to catch them. */ | |
851 | return 0; | |
852 | #endif | |
853 | } | |
854 | ||
855 | int | |
fba45db2 | 856 | child_insert_vfork_catchpoint (int pid) |
c906108c SS |
857 | { |
858 | /* This request is only available on HPUX 10.0 and later. */ | |
859 | #if !defined(PT_SET_EVENT_MASK) | |
860 | error ("Unable to catch vforks prior to HPUX 10.0"); | |
861 | #else | |
862 | /* Enable reporting of vfork events from the kernel. */ | |
863 | /* ??rehrauer: For the moment, we're always enabling these events, | |
864 | and just ignoring them if there's no catchpoint to catch them. */ | |
865 | return 0; | |
866 | #endif | |
867 | } | |
868 | ||
869 | int | |
fba45db2 | 870 | child_remove_vfork_catchpoint (int pid) |
c906108c SS |
871 | { |
872 | /* This request is only available on HPUX 10.0 and later. */ | |
873 | #if !defined(PT_SET_EVENT_MASK) | |
874 | error ("Unable to catch vforks prior to HPUX 10.0"); | |
875 | #else | |
876 | /* Disable reporting of vfork events from the kernel. */ | |
877 | /* ??rehrauer: For the moment, we're always enabling these events, | |
878 | and just ignoring them if there's no catchpoint to catch them. */ | |
879 | return 0; | |
880 | #endif | |
881 | } | |
882 | ||
883 | int | |
fba45db2 | 884 | child_has_forked (int pid, int *childpid) |
c906108c SS |
885 | { |
886 | /* This request is only available on HPUX 10.0 and later. */ | |
887 | #if !defined(PT_GET_PROCESS_STATE) | |
888 | *childpid = 0; | |
889 | return 0; | |
890 | #else | |
891 | int pt_status; | |
c5aa993b | 892 | ptrace_state_t ptrace_state; |
c906108c SS |
893 | |
894 | errno = 0; | |
895 | pt_status = call_ptrace (PT_GET_PROCESS_STATE, | |
b83266a0 | 896 | pid, |
c5aa993b | 897 | (PTRACE_ARG3_TYPE) & ptrace_state, |
b83266a0 | 898 | sizeof (ptrace_state)); |
c906108c SS |
899 | if (errno) |
900 | perror_with_name ("ptrace"); | |
901 | if (pt_status < 0) | |
902 | return 0; | |
903 | ||
904 | if (ptrace_state.pe_report_event & PTRACE_FORK) | |
905 | { | |
906 | *childpid = ptrace_state.pe_other_pid; | |
907 | return 1; | |
908 | } | |
909 | ||
910 | return 0; | |
911 | #endif | |
912 | } | |
913 | ||
914 | int | |
fba45db2 | 915 | child_has_vforked (int pid, int *childpid) |
c906108c SS |
916 | { |
917 | /* This request is only available on HPUX 10.0 and later. */ | |
918 | #if !defined(PT_GET_PROCESS_STATE) | |
919 | *childpid = 0; | |
920 | return 0; | |
921 | ||
922 | #else | |
923 | int pt_status; | |
c5aa993b | 924 | ptrace_state_t ptrace_state; |
c906108c SS |
925 | |
926 | errno = 0; | |
927 | pt_status = call_ptrace (PT_GET_PROCESS_STATE, | |
b83266a0 | 928 | pid, |
c5aa993b | 929 | (PTRACE_ARG3_TYPE) & ptrace_state, |
b83266a0 | 930 | sizeof (ptrace_state)); |
c906108c SS |
931 | if (errno) |
932 | perror_with_name ("ptrace"); | |
933 | if (pt_status < 0) | |
934 | return 0; | |
935 | ||
936 | if (ptrace_state.pe_report_event & PTRACE_VFORK) | |
937 | { | |
938 | *childpid = ptrace_state.pe_other_pid; | |
939 | return 1; | |
940 | } | |
941 | ||
942 | return 0; | |
943 | #endif | |
944 | } | |
945 | ||
946 | int | |
fba45db2 | 947 | child_can_follow_vfork_prior_to_exec (void) |
c906108c SS |
948 | { |
949 | /* ptrace doesn't allow this. */ | |
950 | return 0; | |
951 | } | |
952 | ||
953 | int | |
fba45db2 | 954 | child_insert_exec_catchpoint (int pid) |
c906108c | 955 | { |
b83266a0 | 956 | /* This request is only available on HPUX 10.0 and later. */ |
c906108c SS |
957 | #if !defined(PT_SET_EVENT_MASK) |
958 | error ("Unable to catch execs prior to HPUX 10.0"); | |
959 | ||
960 | #else | |
b83266a0 | 961 | /* Enable reporting of exec events from the kernel. */ |
c906108c | 962 | /* ??rehrauer: For the moment, we're always enabling these events, |
b83266a0 | 963 | and just ignoring them if there's no catchpoint to catch them. */ |
c906108c SS |
964 | return 0; |
965 | #endif | |
966 | } | |
967 | ||
968 | int | |
fba45db2 | 969 | child_remove_exec_catchpoint (int pid) |
c906108c | 970 | { |
b83266a0 | 971 | /* This request is only available on HPUX 10.0 and later. */ |
c906108c SS |
972 | #if !defined(PT_SET_EVENT_MASK) |
973 | error ("Unable to catch execs prior to HPUX 10.0"); | |
974 | ||
975 | #else | |
976 | /* Disable reporting of exec events from the kernel. */ | |
977 | /* ??rehrauer: For the moment, we're always enabling these events, | |
b83266a0 | 978 | and just ignoring them if there's no catchpoint to catch them. */ |
c906108c SS |
979 | return 0; |
980 | #endif | |
981 | } | |
982 | ||
983 | int | |
fba45db2 | 984 | child_has_execd (int pid, char **execd_pathname) |
c906108c | 985 | { |
b83266a0 | 986 | /* This request is only available on HPUX 10.0 and later. */ |
c906108c SS |
987 | #if !defined(PT_GET_PROCESS_STATE) |
988 | *execd_pathname = NULL; | |
989 | return 0; | |
990 | ||
991 | #else | |
992 | int pt_status; | |
c5aa993b | 993 | ptrace_state_t ptrace_state; |
c906108c SS |
994 | |
995 | errno = 0; | |
996 | pt_status = call_ptrace (PT_GET_PROCESS_STATE, | |
b83266a0 | 997 | pid, |
c5aa993b | 998 | (PTRACE_ARG3_TYPE) & ptrace_state, |
b83266a0 | 999 | sizeof (ptrace_state)); |
c906108c SS |
1000 | if (errno) |
1001 | perror_with_name ("ptrace"); | |
1002 | if (pt_status < 0) | |
1003 | return 0; | |
1004 | ||
1005 | if (ptrace_state.pe_report_event & PTRACE_EXEC) | |
1006 | { | |
c5aa993b | 1007 | char *exec_file = target_pid_to_exec_file (pid); |
c906108c SS |
1008 | *execd_pathname = savestring (exec_file, strlen (exec_file)); |
1009 | return 1; | |
1010 | } | |
1011 | ||
1012 | return 0; | |
1013 | #endif | |
1014 | } | |
1015 | ||
1016 | int | |
fba45db2 | 1017 | child_reported_exec_events_per_exec_call (void) |
c906108c | 1018 | { |
c5aa993b | 1019 | return 2; /* ptrace reports the event twice per call. */ |
c906108c SS |
1020 | } |
1021 | ||
1022 | int | |
fba45db2 | 1023 | child_has_syscall_event (int pid, enum target_waitkind *kind, int *syscall_id) |
c906108c SS |
1024 | { |
1025 | /* This request is only available on HPUX 10.30 and later, via | |
1026 | the ttrace interface. */ | |
1027 | ||
1028 | *kind = TARGET_WAITKIND_SPURIOUS; | |
1029 | *syscall_id = -1; | |
1030 | return 0; | |
1031 | } | |
1032 | ||
1033 | char * | |
fba45db2 | 1034 | child_pid_to_exec_file (int pid) |
c906108c | 1035 | { |
b83266a0 | 1036 | static char exec_file_buffer[1024]; |
c906108c | 1037 | int pt_status; |
b83266a0 SS |
1038 | CORE_ADDR top_of_stack; |
1039 | char four_chars[4]; | |
c906108c SS |
1040 | int name_index; |
1041 | int i; | |
1042 | int saved_inferior_pid; | |
b83266a0 | 1043 | boolean done; |
c5aa993b | 1044 | |
c906108c SS |
1045 | #ifdef PT_GET_PROCESS_PATHNAME |
1046 | /* As of 10.x HP-UX, there's an explicit request to get the pathname. */ | |
1047 | pt_status = call_ptrace (PT_GET_PROCESS_PATHNAME, | |
b83266a0 SS |
1048 | pid, |
1049 | (PTRACE_ARG3_TYPE) exec_file_buffer, | |
1050 | sizeof (exec_file_buffer) - 1); | |
c906108c SS |
1051 | if (pt_status == 0) |
1052 | return exec_file_buffer; | |
1053 | #endif | |
1054 | ||
1055 | /* It appears that this request is broken prior to 10.30. | |
1056 | If it fails, try a really, truly amazingly gross hack | |
1057 | that DDE uses, of pawing through the process' data | |
1058 | segment to find the pathname. */ | |
1059 | ||
1060 | top_of_stack = 0x7b03a000; | |
1061 | name_index = 0; | |
1062 | done = 0; | |
1063 | ||
1064 | /* On the chance that pid != inferior_pid, set inferior_pid | |
1065 | to pid, so that (grrrr!) implicit uses of inferior_pid get | |
1066 | the right id. */ | |
1067 | ||
1068 | saved_inferior_pid = inferior_pid; | |
1069 | inferior_pid = pid; | |
1070 | ||
1071 | /* Try to grab a null-terminated string. */ | |
c5aa993b | 1072 | while (!done) |
c906108c SS |
1073 | { |
1074 | if (target_read_memory (top_of_stack, four_chars, 4) != 0) | |
1075 | { | |
1076 | inferior_pid = saved_inferior_pid; | |
1077 | return NULL; | |
1078 | } | |
1079 | for (i = 0; i < 4; i++) | |
1080 | { | |
1081 | exec_file_buffer[name_index++] = four_chars[i]; | |
1082 | done = (four_chars[i] == '\0'); | |
1083 | if (done) | |
1084 | break; | |
1085 | } | |
1086 | top_of_stack += 4; | |
1087 | } | |
1088 | ||
1089 | if (exec_file_buffer[0] == '\0') | |
1090 | { | |
1091 | inferior_pid = saved_inferior_pid; | |
1092 | return NULL; | |
1093 | } | |
1094 | ||
1095 | inferior_pid = saved_inferior_pid; | |
1096 | return exec_file_buffer; | |
1097 | } | |
1098 | ||
1099 | void | |
fba45db2 | 1100 | pre_fork_inferior (void) |
c906108c SS |
1101 | { |
1102 | int status; | |
1103 | ||
1104 | status = pipe (startup_semaphore.parent_channel); | |
1105 | if (status < 0) | |
1106 | { | |
1107 | warning ("error getting parent pipe for startup semaphore"); | |
1108 | return; | |
1109 | } | |
1110 | ||
1111 | status = pipe (startup_semaphore.child_channel); | |
1112 | if (status < 0) | |
1113 | { | |
1114 | warning ("error getting child pipe for startup semaphore"); | |
1115 | return; | |
1116 | } | |
1117 | } | |
c906108c | 1118 | \f |
c5aa993b | 1119 | |
c906108c SS |
1120 | /* Check to see if the given thread is alive. |
1121 | ||
1122 | This is a no-op, as ptrace doesn't support threads, so we just | |
1123 | return "TRUE". */ | |
1124 | ||
1125 | int | |
fba45db2 | 1126 | child_thread_alive (int pid) |
c906108c | 1127 | { |
c5aa993b | 1128 | return 1; |
c906108c SS |
1129 | } |
1130 | ||
1131 | #endif /* ! GDB_NATIVE_HPUX_11 */ |