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