procfs.c: iterate_over_mappings callback has wrong profile.
[deliverable/binutils-gdb.git] / gdb / procfs.c
1 /* Machine independent support for SVR4 /proc (process file system) for GDB.
2
3 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5
6 Written by Michael Snyder at Cygnus Solutions.
7 Based on work by Fred Fish, Stu Grossman, Geoff Noer, and others.
8
9 This file is part of GDB.
10
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 3 of the License, or
14 (at your option) any later version.
15
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.
20
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23
24 #include "defs.h"
25 #include "inferior.h"
26 #include "target.h"
27 #include "gdbcore.h"
28 #include "elf-bfd.h" /* for elfcore_write_* */
29 #include "gdbcmd.h"
30 #include "gdbthread.h"
31 #include "regcache.h"
32 #include "inf-child.h"
33
34 #if defined (NEW_PROC_API)
35 #define _STRUCTURED_PROC 1 /* Should be done by configure script. */
36 #endif
37
38 #include <sys/procfs.h>
39 #ifdef HAVE_SYS_FAULT_H
40 #include <sys/fault.h>
41 #endif
42 #ifdef HAVE_SYS_SYSCALL_H
43 #include <sys/syscall.h>
44 #endif
45 #include <sys/errno.h>
46 #include "gdb_wait.h"
47 #include <signal.h>
48 #include <ctype.h>
49 #include "gdb_string.h"
50 #include "gdb_assert.h"
51 #include "inflow.h"
52 #include "auxv.h"
53 #include "procfs.h"
54 #include "observer.h"
55
56 /*
57 * PROCFS.C
58 *
59 * This module provides the interface between GDB and the
60 * /proc file system, which is used on many versions of Unix
61 * as a means for debuggers to control other processes.
62 * Examples of the systems that use this interface are:
63 * Irix
64 * Solaris
65 * OSF
66 * Unixware
67 * AIX5
68 *
69 * /proc works by imitating a file system: you open a simulated file
70 * that represents the process you wish to interact with, and
71 * perform operations on that "file" in order to examine or change
72 * the state of the other process.
73 *
74 * The most important thing to know about /proc and this module
75 * is that there are two very different interfaces to /proc:
76 * One that uses the ioctl system call, and
77 * another that uses read and write system calls.
78 * This module has to support both /proc interfaces. This means
79 * that there are two different ways of doing every basic operation.
80 *
81 * In order to keep most of the code simple and clean, I have
82 * defined an interface "layer" which hides all these system calls.
83 * An ifdef (NEW_PROC_API) determines which interface we are using,
84 * and most or all occurrances of this ifdef should be confined to
85 * this interface layer.
86 */
87
88
89 /* Determine which /proc API we are using:
90 The ioctl API defines PIOCSTATUS, while
91 the read/write (multiple fd) API never does. */
92
93 #ifdef NEW_PROC_API
94 #include <sys/types.h>
95 #include "gdb_dirent.h" /* opendir/readdir, for listing the LWP's */
96 #endif
97
98 #include <fcntl.h> /* for O_RDONLY */
99 #include <unistd.h> /* for "X_OK" */
100 #include "gdb_stat.h" /* for struct stat */
101
102 /* Note: procfs-utils.h must be included after the above system header
103 files, because it redefines various system calls using macros.
104 This may be incompatible with the prototype declarations. */
105
106 #include "proc-utils.h"
107
108 /* Prototypes for supply_gregset etc. */
109 #include "gregset.h"
110
111 /* =================== TARGET_OPS "MODULE" =================== */
112
113 /*
114 * This module defines the GDB target vector and its methods.
115 */
116
117 static void procfs_attach (struct target_ops *, char *, int);
118 static void procfs_detach (struct target_ops *, char *, int);
119 static void procfs_resume (struct target_ops *,
120 ptid_t, int, enum target_signal);
121 static void procfs_stop (ptid_t);
122 static void procfs_files_info (struct target_ops *);
123 static void procfs_fetch_registers (struct target_ops *,
124 struct regcache *, int);
125 static void procfs_store_registers (struct target_ops *,
126 struct regcache *, int);
127 static void procfs_notice_signals (ptid_t);
128 static void procfs_kill_inferior (struct target_ops *ops);
129 static void procfs_mourn_inferior (struct target_ops *ops);
130 static void procfs_create_inferior (struct target_ops *, char *,
131 char *, char **, int);
132 static ptid_t procfs_wait (struct target_ops *,
133 ptid_t, struct target_waitstatus *, int);
134 static int procfs_xfer_memory (CORE_ADDR, gdb_byte *, int, int,
135 struct mem_attrib *attrib,
136 struct target_ops *);
137 static LONGEST procfs_xfer_partial (struct target_ops *ops,
138 enum target_object object,
139 const char *annex,
140 gdb_byte *readbuf, const gdb_byte *writebuf,
141 ULONGEST offset, LONGEST len);
142
143 static int procfs_thread_alive (struct target_ops *ops, ptid_t);
144
145 void procfs_find_new_threads (struct target_ops *ops);
146 char *procfs_pid_to_str (struct target_ops *, ptid_t);
147
148 static int proc_find_memory_regions (int (*) (CORE_ADDR,
149 unsigned long,
150 int, int, int,
151 void *),
152 void *);
153
154 static char * procfs_make_note_section (bfd *, int *);
155
156 static int procfs_can_use_hw_breakpoint (int, int, int);
157
158 #if defined (PR_MODEL_NATIVE) && (PR_MODEL_NATIVE == PR_MODEL_LP64)
159 /* When GDB is built as 64-bit application on Solaris, the auxv data is
160 presented in 64-bit format. We need to provide a custom parser to handle
161 that. */
162 static int
163 procfs_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
164 gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
165 {
166 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
167 gdb_byte *ptr = *readptr;
168
169 if (endptr == ptr)
170 return 0;
171
172 if (endptr - ptr < 8 * 2)
173 return -1;
174
175 *typep = extract_unsigned_integer (ptr, 4, byte_order);
176 ptr += 8;
177 /* The size of data is always 64-bit. If the application is 32-bit,
178 it will be zero extended, as expected. */
179 *valp = extract_unsigned_integer (ptr, 8, byte_order);
180 ptr += 8;
181
182 *readptr = ptr;
183 return 1;
184 }
185 #endif
186
187 struct target_ops *
188 procfs_target (void)
189 {
190 struct target_ops *t = inf_child_target ();
191
192 t->to_shortname = "procfs";
193 t->to_longname = "Unix /proc child process";
194 t->to_doc =
195 "Unix /proc child process (started by the \"run\" command).";
196 t->to_create_inferior = procfs_create_inferior;
197 t->to_kill = procfs_kill_inferior;
198 t->to_mourn_inferior = procfs_mourn_inferior;
199 t->to_attach = procfs_attach;
200 t->to_detach = procfs_detach;
201 t->to_wait = procfs_wait;
202 t->to_resume = procfs_resume;
203 t->to_fetch_registers = procfs_fetch_registers;
204 t->to_store_registers = procfs_store_registers;
205 t->to_xfer_partial = procfs_xfer_partial;
206 t->deprecated_xfer_memory = procfs_xfer_memory;
207 t->to_notice_signals = procfs_notice_signals;
208 t->to_files_info = procfs_files_info;
209 t->to_stop = procfs_stop;
210
211 t->to_find_new_threads = procfs_find_new_threads;
212 t->to_thread_alive = procfs_thread_alive;
213 t->to_pid_to_str = procfs_pid_to_str;
214
215 t->to_has_thread_control = tc_schedlock;
216 t->to_find_memory_regions = proc_find_memory_regions;
217 t->to_make_corefile_notes = procfs_make_note_section;
218
219 #if defined(PR_MODEL_NATIVE) && (PR_MODEL_NATIVE == PR_MODEL_LP64)
220 t->to_auxv_parse = procfs_auxv_parse;
221 #endif
222
223 t->to_magic = OPS_MAGIC;
224
225 return t;
226 }
227
228 /* =================== END, TARGET_OPS "MODULE" =================== */
229
230 /*
231 * World Unification:
232 *
233 * Put any typedefs, defines etc. here that are required for
234 * the unification of code that handles different versions of /proc.
235 */
236
237 #ifdef NEW_PROC_API /* Solaris 7 && 8 method for watchpoints */
238 #ifdef WA_READ
239 enum { READ_WATCHFLAG = WA_READ,
240 WRITE_WATCHFLAG = WA_WRITE,
241 EXEC_WATCHFLAG = WA_EXEC,
242 AFTER_WATCHFLAG = WA_TRAPAFTER
243 };
244 #endif
245 #else /* Irix method for watchpoints */
246 enum { READ_WATCHFLAG = MA_READ,
247 WRITE_WATCHFLAG = MA_WRITE,
248 EXEC_WATCHFLAG = MA_EXEC,
249 AFTER_WATCHFLAG = 0 /* trapafter not implemented */
250 };
251 #endif
252
253 /* gdb_sigset_t */
254 #ifdef HAVE_PR_SIGSET_T
255 typedef pr_sigset_t gdb_sigset_t;
256 #else
257 typedef sigset_t gdb_sigset_t;
258 #endif
259
260 /* sigaction */
261 #ifdef HAVE_PR_SIGACTION64_T
262 typedef pr_sigaction64_t gdb_sigaction_t;
263 #else
264 typedef struct sigaction gdb_sigaction_t;
265 #endif
266
267 /* siginfo */
268 #ifdef HAVE_PR_SIGINFO64_T
269 typedef pr_siginfo64_t gdb_siginfo_t;
270 #else
271 typedef struct siginfo gdb_siginfo_t;
272 #endif
273
274 /* On mips-irix, praddset and prdelset are defined in such a way that
275 they return a value, which causes GCC to emit a -Wunused error
276 because the returned value is not used. Prevent this warning
277 by casting the return value to void. On sparc-solaris, this issue
278 does not exist because the definition of these macros already include
279 that cast to void. */
280 #define gdb_praddset(sp, flag) ((void) praddset (sp, flag))
281 #define gdb_prdelset(sp, flag) ((void) prdelset (sp, flag))
282
283 /* gdb_premptysysset */
284 #ifdef premptysysset
285 #define gdb_premptysysset premptysysset
286 #else
287 #define gdb_premptysysset premptyset
288 #endif
289
290 /* praddsysset */
291 #ifdef praddsysset
292 #define gdb_praddsysset praddsysset
293 #else
294 #define gdb_praddsysset gdb_praddset
295 #endif
296
297 /* prdelsysset */
298 #ifdef prdelsysset
299 #define gdb_prdelsysset prdelsysset
300 #else
301 #define gdb_prdelsysset gdb_prdelset
302 #endif
303
304 /* prissyssetmember */
305 #ifdef prissyssetmember
306 #define gdb_pr_issyssetmember prissyssetmember
307 #else
308 #define gdb_pr_issyssetmember prismember
309 #endif
310
311 /* As a feature test, saying ``#if HAVE_PRSYSENT_T'' everywhere isn't
312 as intuitively descriptive as it could be, so we'll define
313 DYNAMIC_SYSCALLS to mean the same thing. Anyway, at the time of
314 this writing, this feature is only found on AIX5 systems and
315 basically means that the set of syscalls is not fixed. I.e,
316 there's no nice table that one can #include to get all of the
317 syscall numbers. Instead, they're stored in /proc/PID/sysent
318 for each process. We are at least guaranteed that they won't
319 change over the lifetime of the process. But each process could
320 (in theory) have different syscall numbers.
321 */
322 #ifdef HAVE_PRSYSENT_T
323 #define DYNAMIC_SYSCALLS
324 #endif
325
326
327
328 /* =================== STRUCT PROCINFO "MODULE" =================== */
329
330 /* FIXME: this comment will soon be out of date W.R.T. threads. */
331
332 /* The procinfo struct is a wrapper to hold all the state information
333 concerning a /proc process. There should be exactly one procinfo
334 for each process, and since GDB currently can debug only one
335 process at a time, that means there should be only one procinfo.
336 All of the LWP's of a process can be accessed indirectly thru the
337 single process procinfo.
338
339 However, against the day when GDB may debug more than one process,
340 this data structure is kept in a list (which for now will hold no
341 more than one member), and many functions will have a pointer to a
342 procinfo as an argument.
343
344 There will be a separate procinfo structure for use by the (not yet
345 implemented) "info proc" command, so that we can print useful
346 information about any random process without interfering with the
347 inferior's procinfo information. */
348
349 #ifdef NEW_PROC_API
350 /* format strings for /proc paths */
351 # ifndef CTL_PROC_NAME_FMT
352 # define MAIN_PROC_NAME_FMT "/proc/%d"
353 # define CTL_PROC_NAME_FMT "/proc/%d/ctl"
354 # define AS_PROC_NAME_FMT "/proc/%d/as"
355 # define MAP_PROC_NAME_FMT "/proc/%d/map"
356 # define STATUS_PROC_NAME_FMT "/proc/%d/status"
357 # define MAX_PROC_NAME_SIZE sizeof("/proc/99999/lwp/8096/lstatus")
358 # endif
359 /* the name of the proc status struct depends on the implementation */
360 typedef pstatus_t gdb_prstatus_t;
361 typedef lwpstatus_t gdb_lwpstatus_t;
362 #else /* ! NEW_PROC_API */
363 /* format strings for /proc paths */
364 # ifndef CTL_PROC_NAME_FMT
365 # define MAIN_PROC_NAME_FMT "/proc/%05d"
366 # define CTL_PROC_NAME_FMT "/proc/%05d"
367 # define AS_PROC_NAME_FMT "/proc/%05d"
368 # define MAP_PROC_NAME_FMT "/proc/%05d"
369 # define STATUS_PROC_NAME_FMT "/proc/%05d"
370 # define MAX_PROC_NAME_SIZE sizeof("/proc/ttttppppp")
371 # endif
372 /* the name of the proc status struct depends on the implementation */
373 typedef prstatus_t gdb_prstatus_t;
374 typedef prstatus_t gdb_lwpstatus_t;
375 #endif /* NEW_PROC_API */
376
377 typedef struct procinfo {
378 struct procinfo *next;
379 int pid; /* Process ID */
380 int tid; /* Thread/LWP id */
381
382 /* process state */
383 int was_stopped;
384 int ignore_next_sigstop;
385
386 /* The following four fd fields may be identical, or may contain
387 several different fd's, depending on the version of /proc
388 (old ioctl or new read/write). */
389
390 int ctl_fd; /* File descriptor for /proc control file */
391 /*
392 * The next three file descriptors are actually only needed in the
393 * read/write, multiple-file-descriptor implemenation (NEW_PROC_API).
394 * However, to avoid a bunch of #ifdefs in the code, we will use
395 * them uniformly by (in the case of the ioctl single-file-descriptor
396 * implementation) filling them with copies of the control fd.
397 */
398 int status_fd; /* File descriptor for /proc status file */
399 int as_fd; /* File descriptor for /proc as file */
400
401 char pathname[MAX_PROC_NAME_SIZE]; /* Pathname to /proc entry */
402
403 fltset_t saved_fltset; /* Saved traced hardware fault set */
404 gdb_sigset_t saved_sigset; /* Saved traced signal set */
405 gdb_sigset_t saved_sighold; /* Saved held signal set */
406 sysset_t *saved_exitset; /* Saved traced system call exit set */
407 sysset_t *saved_entryset; /* Saved traced system call entry set */
408
409 gdb_prstatus_t prstatus; /* Current process status info */
410
411 #ifndef NEW_PROC_API
412 gdb_fpregset_t fpregset; /* Current floating point registers */
413 #endif
414
415 #ifdef DYNAMIC_SYSCALLS
416 int num_syscalls; /* Total number of syscalls */
417 char **syscall_names; /* Syscall number to name map */
418 #endif
419
420 struct procinfo *thread_list;
421
422 int status_valid : 1;
423 int gregs_valid : 1;
424 int fpregs_valid : 1;
425 int threads_valid: 1;
426 } procinfo;
427
428 static char errmsg[128]; /* shared error msg buffer */
429
430 /* Function prototypes for procinfo module: */
431
432 static procinfo *find_procinfo_or_die (int pid, int tid);
433 static procinfo *find_procinfo (int pid, int tid);
434 static procinfo *create_procinfo (int pid, int tid);
435 static void destroy_procinfo (procinfo * p);
436 static void do_destroy_procinfo_cleanup (void *);
437 static void dead_procinfo (procinfo * p, char *msg, int killp);
438 static int open_procinfo_files (procinfo * p, int which);
439 static void close_procinfo_files (procinfo * p);
440 static int sysset_t_size (procinfo *p);
441 static sysset_t *sysset_t_alloc (procinfo * pi);
442 #ifdef DYNAMIC_SYSCALLS
443 static void load_syscalls (procinfo *pi);
444 static void free_syscalls (procinfo *pi);
445 static int find_syscall (procinfo *pi, char *name);
446 #endif /* DYNAMIC_SYSCALLS */
447
448 /* A function type used as a callback back iterate_over_mappings. */
449 typedef int (iterate_over_mappings_cb_ftype)
450 (CORE_ADDR vaddr, unsigned long size, int read, int write, int execute,
451 void *data);
452
453 static int iterate_over_mappings
454 (procinfo *pi,
455 iterate_over_mappings_cb_ftype *child_func,
456 void *data,
457 int (*func) (struct prmap *map,
458 iterate_over_mappings_cb_ftype *child_func,
459 void *data));
460
461 /* The head of the procinfo list: */
462 static procinfo * procinfo_list;
463
464 /*
465 * Function: find_procinfo
466 *
467 * Search the procinfo list.
468 *
469 * Returns: pointer to procinfo, or NULL if not found.
470 */
471
472 static procinfo *
473 find_procinfo (int pid, int tid)
474 {
475 procinfo *pi;
476
477 for (pi = procinfo_list; pi; pi = pi->next)
478 if (pi->pid == pid)
479 break;
480
481 if (pi)
482 if (tid)
483 {
484 /* Don't check threads_valid. If we're updating the
485 thread_list, we want to find whatever threads are already
486 here. This means that in general it is the caller's
487 responsibility to check threads_valid and update before
488 calling find_procinfo, if the caller wants to find a new
489 thread. */
490
491 for (pi = pi->thread_list; pi; pi = pi->next)
492 if (pi->tid == tid)
493 break;
494 }
495
496 return pi;
497 }
498
499 /*
500 * Function: find_procinfo_or_die
501 *
502 * Calls find_procinfo, but errors on failure.
503 */
504
505 static procinfo *
506 find_procinfo_or_die (int pid, int tid)
507 {
508 procinfo *pi = find_procinfo (pid, tid);
509
510 if (pi == NULL)
511 {
512 if (tid)
513 error (_("procfs: couldn't find pid %d (kernel thread %d) in procinfo list."),
514 pid, tid);
515 else
516 error (_("procfs: couldn't find pid %d in procinfo list."), pid);
517 }
518 return pi;
519 }
520
521 /* open_with_retry() is a wrapper for open(). The appropriate
522 open() call is attempted; if unsuccessful, it will be retried as
523 many times as needed for the EAGAIN and EINTR conditions.
524
525 For other conditions, open_with_retry() will retry the open() a
526 limited number of times. In addition, a short sleep is imposed
527 prior to retrying the open(). The reason for this sleep is to give
528 the kernel a chance to catch up and create the file in question in
529 the event that GDB "wins" the race to open a file before the kernel
530 has created it. */
531
532 static int
533 open_with_retry (const char *pathname, int flags)
534 {
535 int retries_remaining, status;
536
537 retries_remaining = 2;
538
539 while (1)
540 {
541 status = open (pathname, flags);
542
543 if (status >= 0 || retries_remaining == 0)
544 break;
545 else if (errno != EINTR && errno != EAGAIN)
546 {
547 retries_remaining--;
548 sleep (1);
549 }
550 }
551
552 return status;
553 }
554
555 /*
556 * Function: open_procinfo_files
557 *
558 * Open the file descriptor for the process or LWP.
559 * ifdef NEW_PROC_API, we only open the control file descriptor;
560 * the others are opened lazily as needed.
561 * else (if not NEW_PROC_API), there is only one real
562 * file descriptor, but we keep multiple copies of it so that
563 * the code that uses them does not have to be #ifdef'd.
564 *
565 * Return: file descriptor, or zero for failure.
566 */
567
568 enum { FD_CTL, FD_STATUS, FD_AS };
569
570 static int
571 open_procinfo_files (procinfo *pi, int which)
572 {
573 #ifdef NEW_PROC_API
574 char tmp[MAX_PROC_NAME_SIZE];
575 #endif
576 int fd;
577
578 /*
579 * This function is getting ALMOST long enough to break up into several.
580 * Here is some rationale:
581 *
582 * NEW_PROC_API (Solaris 2.6, Solaris 2.7, Unixware):
583 * There are several file descriptors that may need to be open
584 * for any given process or LWP. The ones we're intereted in are:
585 * - control (ctl) write-only change the state
586 * - status (status) read-only query the state
587 * - address space (as) read/write access memory
588 * - map (map) read-only virtual addr map
589 * Most of these are opened lazily as they are needed.
590 * The pathnames for the 'files' for an LWP look slightly
591 * different from those of a first-class process:
592 * Pathnames for a process (<proc-id>):
593 * /proc/<proc-id>/ctl
594 * /proc/<proc-id>/status
595 * /proc/<proc-id>/as
596 * /proc/<proc-id>/map
597 * Pathnames for an LWP (lwp-id):
598 * /proc/<proc-id>/lwp/<lwp-id>/lwpctl
599 * /proc/<proc-id>/lwp/<lwp-id>/lwpstatus
600 * An LWP has no map or address space file descriptor, since
601 * the memory map and address space are shared by all LWPs.
602 *
603 * Everyone else (Solaris 2.5, Irix, OSF)
604 * There is only one file descriptor for each process or LWP.
605 * For convenience, we copy the same file descriptor into all
606 * three fields of the procinfo struct (ctl_fd, status_fd, and
607 * as_fd, see NEW_PROC_API above) so that code that uses them
608 * doesn't need any #ifdef's.
609 * Pathname for all:
610 * /proc/<proc-id>
611 *
612 * Solaris 2.5 LWP's:
613 * Each LWP has an independent file descriptor, but these
614 * are not obtained via the 'open' system call like the rest:
615 * instead, they're obtained thru an ioctl call (PIOCOPENLWP)
616 * to the file descriptor of the parent process.
617 *
618 * OSF threads:
619 * These do not even have their own independent file descriptor.
620 * All operations are carried out on the file descriptor of the
621 * parent process. Therefore we just call open again for each
622 * thread, getting a new handle for the same 'file'.
623 */
624
625 #ifdef NEW_PROC_API
626 /*
627 * In this case, there are several different file descriptors that
628 * we might be asked to open. The control file descriptor will be
629 * opened early, but the others will be opened lazily as they are
630 * needed.
631 */
632
633 strcpy (tmp, pi->pathname);
634 switch (which) { /* which file descriptor to open? */
635 case FD_CTL:
636 if (pi->tid)
637 strcat (tmp, "/lwpctl");
638 else
639 strcat (tmp, "/ctl");
640 fd = open_with_retry (tmp, O_WRONLY);
641 if (fd <= 0)
642 return 0; /* fail */
643 pi->ctl_fd = fd;
644 break;
645 case FD_AS:
646 if (pi->tid)
647 return 0; /* there is no 'as' file descriptor for an lwp */
648 strcat (tmp, "/as");
649 fd = open_with_retry (tmp, O_RDWR);
650 if (fd <= 0)
651 return 0; /* fail */
652 pi->as_fd = fd;
653 break;
654 case FD_STATUS:
655 if (pi->tid)
656 strcat (tmp, "/lwpstatus");
657 else
658 strcat (tmp, "/status");
659 fd = open_with_retry (tmp, O_RDONLY);
660 if (fd <= 0)
661 return 0; /* fail */
662 pi->status_fd = fd;
663 break;
664 default:
665 return 0; /* unknown file descriptor */
666 }
667 #else /* not NEW_PROC_API */
668 /*
669 * In this case, there is only one file descriptor for each procinfo
670 * (ie. each process or LWP). In fact, only the file descriptor for
671 * the process can actually be opened by an 'open' system call.
672 * The ones for the LWPs have to be obtained thru an IOCTL call
673 * on the process's file descriptor.
674 *
675 * For convenience, we copy each procinfo's single file descriptor
676 * into all of the fields occupied by the several file descriptors
677 * of the NEW_PROC_API implementation. That way, the code that uses
678 * them can be written without ifdefs.
679 */
680
681
682 #ifdef PIOCTSTATUS /* OSF */
683 /* Only one FD; just open it. */
684 if ((fd = open_with_retry (pi->pathname, O_RDWR)) == 0)
685 return 0;
686 #else /* Sol 2.5, Irix, other? */
687 if (pi->tid == 0) /* Master procinfo for the process */
688 {
689 fd = open_with_retry (pi->pathname, O_RDWR);
690 if (fd <= 0)
691 return 0; /* fail */
692 }
693 else /* LWP thread procinfo */
694 {
695 #ifdef PIOCOPENLWP /* Sol 2.5, thread/LWP */
696 procinfo *process;
697 int lwpid = pi->tid;
698
699 /* Find the procinfo for the entire process. */
700 if ((process = find_procinfo (pi->pid, 0)) == NULL)
701 return 0; /* fail */
702
703 /* Now obtain the file descriptor for the LWP. */
704 if ((fd = ioctl (process->ctl_fd, PIOCOPENLWP, &lwpid)) <= 0)
705 return 0; /* fail */
706 #else /* Irix, other? */
707 return 0; /* Don't know how to open threads */
708 #endif /* Sol 2.5 PIOCOPENLWP */
709 }
710 #endif /* OSF PIOCTSTATUS */
711 pi->ctl_fd = pi->as_fd = pi->status_fd = fd;
712 #endif /* NEW_PROC_API */
713
714 return 1; /* success */
715 }
716
717 /*
718 * Function: create_procinfo
719 *
720 * Allocate a data structure and link it into the procinfo list.
721 * (First tries to find a pre-existing one (FIXME: why?)
722 *
723 * Return: pointer to new procinfo struct.
724 */
725
726 static procinfo *
727 create_procinfo (int pid, int tid)
728 {
729 procinfo *pi, *parent = NULL;
730
731 if ((pi = find_procinfo (pid, tid)))
732 return pi; /* Already exists, nothing to do. */
733
734 /* find parent before doing malloc, to save having to cleanup */
735 if (tid != 0)
736 parent = find_procinfo_or_die (pid, 0); /* FIXME: should I
737 create it if it
738 doesn't exist yet? */
739
740 pi = (procinfo *) xmalloc (sizeof (procinfo));
741 memset (pi, 0, sizeof (procinfo));
742 pi->pid = pid;
743 pi->tid = tid;
744
745 #ifdef DYNAMIC_SYSCALLS
746 load_syscalls (pi);
747 #endif
748
749 pi->saved_entryset = sysset_t_alloc (pi);
750 pi->saved_exitset = sysset_t_alloc (pi);
751
752 /* Chain into list. */
753 if (tid == 0)
754 {
755 sprintf (pi->pathname, MAIN_PROC_NAME_FMT, pid);
756 pi->next = procinfo_list;
757 procinfo_list = pi;
758 }
759 else
760 {
761 #ifdef NEW_PROC_API
762 sprintf (pi->pathname, "/proc/%05d/lwp/%d", pid, tid);
763 #else
764 sprintf (pi->pathname, MAIN_PROC_NAME_FMT, pid);
765 #endif
766 pi->next = parent->thread_list;
767 parent->thread_list = pi;
768 }
769 return pi;
770 }
771
772 /*
773 * Function: close_procinfo_files
774 *
775 * Close all file descriptors associated with the procinfo
776 */
777
778 static void
779 close_procinfo_files (procinfo *pi)
780 {
781 if (pi->ctl_fd > 0)
782 close (pi->ctl_fd);
783 #ifdef NEW_PROC_API
784 if (pi->as_fd > 0)
785 close (pi->as_fd);
786 if (pi->status_fd > 0)
787 close (pi->status_fd);
788 #endif
789 pi->ctl_fd = pi->as_fd = pi->status_fd = 0;
790 }
791
792 /*
793 * Function: destroy_procinfo
794 *
795 * Destructor function. Close, unlink and deallocate the object.
796 */
797
798 static void
799 destroy_one_procinfo (procinfo **list, procinfo *pi)
800 {
801 procinfo *ptr;
802
803 /* Step one: unlink the procinfo from its list */
804 if (pi == *list)
805 *list = pi->next;
806 else
807 for (ptr = *list; ptr; ptr = ptr->next)
808 if (ptr->next == pi)
809 {
810 ptr->next = pi->next;
811 break;
812 }
813
814 /* Step two: close any open file descriptors */
815 close_procinfo_files (pi);
816
817 /* Step three: free the memory. */
818 #ifdef DYNAMIC_SYSCALLS
819 free_syscalls (pi);
820 #endif
821 xfree (pi->saved_entryset);
822 xfree (pi->saved_exitset);
823 xfree (pi);
824 }
825
826 static void
827 destroy_procinfo (procinfo *pi)
828 {
829 procinfo *tmp;
830
831 if (pi->tid != 0) /* destroy a thread procinfo */
832 {
833 tmp = find_procinfo (pi->pid, 0); /* find the parent process */
834 destroy_one_procinfo (&tmp->thread_list, pi);
835 }
836 else /* destroy a process procinfo and all its threads */
837 {
838 /* First destroy the children, if any; */
839 while (pi->thread_list != NULL)
840 destroy_one_procinfo (&pi->thread_list, pi->thread_list);
841 /* Then destroy the parent. Genocide!!! */
842 destroy_one_procinfo (&procinfo_list, pi);
843 }
844 }
845
846 static void
847 do_destroy_procinfo_cleanup (void *pi)
848 {
849 destroy_procinfo (pi);
850 }
851
852 enum { NOKILL, KILL };
853
854 /*
855 * Function: dead_procinfo
856 *
857 * To be called on a non_recoverable error for a procinfo.
858 * Prints error messages, optionally sends a SIGKILL to the process,
859 * then destroys the data structure.
860 */
861
862 static void
863 dead_procinfo (procinfo *pi, char *msg, int kill_p)
864 {
865 char procfile[80];
866
867 if (pi->pathname)
868 {
869 print_sys_errmsg (pi->pathname, errno);
870 }
871 else
872 {
873 sprintf (procfile, "process %d", pi->pid);
874 print_sys_errmsg (procfile, errno);
875 }
876 if (kill_p == KILL)
877 kill (pi->pid, SIGKILL);
878
879 destroy_procinfo (pi);
880 error ("%s", msg);
881 }
882
883 /*
884 * Function: sysset_t_size
885 *
886 * Returns the (complete) size of a sysset_t struct. Normally, this
887 * is just sizeof (syset_t), but in the case of Monterey/64, the actual
888 * size of sysset_t isn't known until runtime.
889 */
890
891 static int
892 sysset_t_size (procinfo * pi)
893 {
894 #ifndef DYNAMIC_SYSCALLS
895 return sizeof (sysset_t);
896 #else
897 return sizeof (sysset_t) - sizeof (uint64_t)
898 + sizeof (uint64_t) * ((pi->num_syscalls + (8 * sizeof (uint64_t) - 1))
899 / (8 * sizeof (uint64_t)));
900 #endif
901 }
902
903 /* Function: sysset_t_alloc
904
905 Allocate and (partially) initialize a sysset_t struct. */
906
907 static sysset_t *
908 sysset_t_alloc (procinfo * pi)
909 {
910 sysset_t *ret;
911 int size = sysset_t_size (pi);
912 ret = xmalloc (size);
913 #ifdef DYNAMIC_SYSCALLS
914 ret->pr_size = (pi->num_syscalls + (8 * sizeof (uint64_t) - 1))
915 / (8 * sizeof (uint64_t));
916 #endif
917 return ret;
918 }
919
920 #ifdef DYNAMIC_SYSCALLS
921
922 /* Function: load_syscalls
923
924 Extract syscall numbers and names from /proc/<pid>/sysent. Initialize
925 pi->num_syscalls with the number of syscalls and pi->syscall_names
926 with the names. (Certain numbers may be skipped in which case the
927 names for these numbers will be left as NULL.) */
928
929 #define MAX_SYSCALL_NAME_LENGTH 256
930 #define MAX_SYSCALLS 65536
931
932 static void
933 load_syscalls (procinfo *pi)
934 {
935 char pathname[MAX_PROC_NAME_SIZE];
936 int sysent_fd;
937 prsysent_t header;
938 prsyscall_t *syscalls;
939 int i, size, maxcall;
940
941 pi->num_syscalls = 0;
942 pi->syscall_names = 0;
943
944 /* Open the file descriptor for the sysent file */
945 sprintf (pathname, "/proc/%d/sysent", pi->pid);
946 sysent_fd = open_with_retry (pathname, O_RDONLY);
947 if (sysent_fd < 0)
948 {
949 error (_("load_syscalls: Can't open /proc/%d/sysent"), pi->pid);
950 }
951
952 size = sizeof header - sizeof (prsyscall_t);
953 if (read (sysent_fd, &header, size) != size)
954 {
955 error (_("load_syscalls: Error reading /proc/%d/sysent"), pi->pid);
956 }
957
958 if (header.pr_nsyscalls == 0)
959 {
960 error (_("load_syscalls: /proc/%d/sysent contains no syscalls!"), pi->pid);
961 }
962
963 size = header.pr_nsyscalls * sizeof (prsyscall_t);
964 syscalls = xmalloc (size);
965
966 if (read (sysent_fd, syscalls, size) != size)
967 {
968 xfree (syscalls);
969 error (_("load_syscalls: Error reading /proc/%d/sysent"), pi->pid);
970 }
971
972 /* Find maximum syscall number. This may not be the same as
973 pr_nsyscalls since that value refers to the number of entries
974 in the table. (Also, the docs indicate that some system
975 call numbers may be skipped.) */
976
977 maxcall = syscalls[0].pr_number;
978
979 for (i = 1; i < header.pr_nsyscalls; i++)
980 if (syscalls[i].pr_number > maxcall
981 && syscalls[i].pr_nameoff > 0
982 && syscalls[i].pr_number < MAX_SYSCALLS)
983 maxcall = syscalls[i].pr_number;
984
985 pi->num_syscalls = maxcall+1;
986 pi->syscall_names = xmalloc (pi->num_syscalls * sizeof (char *));
987
988 for (i = 0; i < pi->num_syscalls; i++)
989 pi->syscall_names[i] = NULL;
990
991 /* Read the syscall names in */
992 for (i = 0; i < header.pr_nsyscalls; i++)
993 {
994 char namebuf[MAX_SYSCALL_NAME_LENGTH];
995 int nread;
996 int callnum;
997
998 if (syscalls[i].pr_number >= MAX_SYSCALLS
999 || syscalls[i].pr_number < 0
1000 || syscalls[i].pr_nameoff <= 0
1001 || (lseek (sysent_fd, (off_t) syscalls[i].pr_nameoff, SEEK_SET)
1002 != (off_t) syscalls[i].pr_nameoff))
1003 continue;
1004
1005 nread = read (sysent_fd, namebuf, sizeof namebuf);
1006 if (nread <= 0)
1007 continue;
1008
1009 callnum = syscalls[i].pr_number;
1010
1011 if (pi->syscall_names[callnum] != NULL)
1012 {
1013 /* FIXME: Generate warning */
1014 continue;
1015 }
1016
1017 namebuf[nread-1] = '\0';
1018 size = strlen (namebuf) + 1;
1019 pi->syscall_names[callnum] = xmalloc (size);
1020 strncpy (pi->syscall_names[callnum], namebuf, size-1);
1021 pi->syscall_names[callnum][size-1] = '\0';
1022 }
1023
1024 close (sysent_fd);
1025 xfree (syscalls);
1026 }
1027
1028 /* Function: free_syscalls
1029
1030 Free the space allocated for the syscall names from the procinfo
1031 structure. */
1032
1033 static void
1034 free_syscalls (procinfo *pi)
1035 {
1036 if (pi->syscall_names)
1037 {
1038 int i;
1039
1040 for (i = 0; i < pi->num_syscalls; i++)
1041 if (pi->syscall_names[i] != NULL)
1042 xfree (pi->syscall_names[i]);
1043
1044 xfree (pi->syscall_names);
1045 pi->syscall_names = 0;
1046 }
1047 }
1048
1049 /* Function: find_syscall
1050
1051 Given a name, look up (and return) the corresponding syscall number.
1052 If no match is found, return -1. */
1053
1054 static int
1055 find_syscall (procinfo *pi, char *name)
1056 {
1057 int i;
1058 for (i = 0; i < pi->num_syscalls; i++)
1059 {
1060 if (pi->syscall_names[i] && strcmp (name, pi->syscall_names[i]) == 0)
1061 return i;
1062 }
1063 return -1;
1064 }
1065 #endif
1066
1067 /* =================== END, STRUCT PROCINFO "MODULE" =================== */
1068
1069 /* =================== /proc "MODULE" =================== */
1070
1071 /*
1072 * This "module" is the interface layer between the /proc system API
1073 * and the gdb target vector functions. This layer consists of
1074 * access functions that encapsulate each of the basic operations
1075 * that we need to use from the /proc API.
1076 *
1077 * The main motivation for this layer is to hide the fact that
1078 * there are two very different implementations of the /proc API.
1079 * Rather than have a bunch of #ifdefs all thru the gdb target vector
1080 * functions, we do our best to hide them all in here.
1081 */
1082
1083 int proc_get_status (procinfo * pi);
1084 long proc_flags (procinfo * pi);
1085 int proc_why (procinfo * pi);
1086 int proc_what (procinfo * pi);
1087 int proc_set_run_on_last_close (procinfo * pi);
1088 int proc_unset_run_on_last_close (procinfo * pi);
1089 int proc_set_inherit_on_fork (procinfo * pi);
1090 int proc_unset_inherit_on_fork (procinfo * pi);
1091 int proc_set_async (procinfo * pi);
1092 int proc_unset_async (procinfo * pi);
1093 int proc_stop_process (procinfo * pi);
1094 int proc_trace_signal (procinfo * pi, int signo);
1095 int proc_ignore_signal (procinfo * pi, int signo);
1096 int proc_clear_current_fault (procinfo * pi);
1097 int proc_set_current_signal (procinfo * pi, int signo);
1098 int proc_clear_current_signal (procinfo * pi);
1099 int proc_set_gregs (procinfo * pi);
1100 int proc_set_fpregs (procinfo * pi);
1101 int proc_wait_for_stop (procinfo * pi);
1102 int proc_run_process (procinfo * pi, int step, int signo);
1103 int proc_kill (procinfo * pi, int signo);
1104 int proc_parent_pid (procinfo * pi);
1105 int proc_get_nthreads (procinfo * pi);
1106 int proc_get_current_thread (procinfo * pi);
1107 int proc_set_held_signals (procinfo * pi, gdb_sigset_t * sighold);
1108 int proc_set_traced_sysexit (procinfo * pi, sysset_t * sysset);
1109 int proc_set_traced_sysentry (procinfo * pi, sysset_t * sysset);
1110 int proc_set_traced_faults (procinfo * pi, fltset_t * fltset);
1111 int proc_set_traced_signals (procinfo * pi, gdb_sigset_t * sigset);
1112
1113 int proc_update_threads (procinfo * pi);
1114 int proc_iterate_over_threads (procinfo * pi,
1115 int (*func) (procinfo *, procinfo *, void *),
1116 void *ptr);
1117
1118 gdb_gregset_t *proc_get_gregs (procinfo * pi);
1119 gdb_fpregset_t *proc_get_fpregs (procinfo * pi);
1120 sysset_t *proc_get_traced_sysexit (procinfo * pi, sysset_t * save);
1121 sysset_t *proc_get_traced_sysentry (procinfo * pi, sysset_t * save);
1122 fltset_t *proc_get_traced_faults (procinfo * pi, fltset_t * save);
1123 gdb_sigset_t *proc_get_traced_signals (procinfo * pi, gdb_sigset_t * save);
1124 gdb_sigset_t *proc_get_held_signals (procinfo * pi, gdb_sigset_t * save);
1125 gdb_sigset_t *proc_get_pending_signals (procinfo * pi, gdb_sigset_t * save);
1126 gdb_sigaction_t *proc_get_signal_actions (procinfo * pi, gdb_sigaction_t *save);
1127
1128 void proc_warn (procinfo * pi, char *func, int line);
1129 void proc_error (procinfo * pi, char *func, int line);
1130
1131 void
1132 proc_warn (procinfo *pi, char *func, int line)
1133 {
1134 sprintf (errmsg, "procfs: %s line %d, %s", func, line, pi->pathname);
1135 print_sys_errmsg (errmsg, errno);
1136 }
1137
1138 void
1139 proc_error (procinfo *pi, char *func, int line)
1140 {
1141 sprintf (errmsg, "procfs: %s line %d, %s", func, line, pi->pathname);
1142 perror_with_name (errmsg);
1143 }
1144
1145 /*
1146 * Function: proc_get_status
1147 *
1148 * Updates the status struct in the procinfo.
1149 * There is a 'valid' flag, to let other functions know when
1150 * this function needs to be called (so the status is only
1151 * read when it is needed). The status file descriptor is
1152 * also only opened when it is needed.
1153 *
1154 * Return: non-zero for success, zero for failure.
1155 */
1156
1157 int
1158 proc_get_status (procinfo *pi)
1159 {
1160 /* Status file descriptor is opened "lazily" */
1161 if (pi->status_fd == 0 &&
1162 open_procinfo_files (pi, FD_STATUS) == 0)
1163 {
1164 pi->status_valid = 0;
1165 return 0;
1166 }
1167
1168 #ifdef NEW_PROC_API
1169 if (lseek (pi->status_fd, 0, SEEK_SET) < 0)
1170 pi->status_valid = 0; /* fail */
1171 else
1172 {
1173 /* Sigh... I have to read a different data structure,
1174 depending on whether this is a main process or an LWP. */
1175 if (pi->tid)
1176 pi->status_valid = (read (pi->status_fd,
1177 (char *) &pi->prstatus.pr_lwp,
1178 sizeof (lwpstatus_t))
1179 == sizeof (lwpstatus_t));
1180 else
1181 {
1182 pi->status_valid = (read (pi->status_fd,
1183 (char *) &pi->prstatus,
1184 sizeof (gdb_prstatus_t))
1185 == sizeof (gdb_prstatus_t));
1186 #if 0 /*def UNIXWARE*/
1187 if (pi->status_valid &&
1188 (pi->prstatus.pr_lwp.pr_flags & PR_ISTOP) &&
1189 pi->prstatus.pr_lwp.pr_why == PR_REQUESTED)
1190 /* Unixware peculiarity -- read the damn thing again! */
1191 pi->status_valid = (read (pi->status_fd,
1192 (char *) &pi->prstatus,
1193 sizeof (gdb_prstatus_t))
1194 == sizeof (gdb_prstatus_t));
1195 #endif /* UNIXWARE */
1196 }
1197 }
1198 #else /* ioctl method */
1199 #ifdef PIOCTSTATUS /* osf */
1200 if (pi->tid == 0) /* main process */
1201 {
1202 /* Just read the danged status. Now isn't that simple? */
1203 pi->status_valid =
1204 (ioctl (pi->status_fd, PIOCSTATUS, &pi->prstatus) >= 0);
1205 }
1206 else
1207 {
1208 int win;
1209 struct {
1210 long pr_count;
1211 tid_t pr_error_thread;
1212 struct prstatus status;
1213 } thread_status;
1214
1215 thread_status.pr_count = 1;
1216 thread_status.status.pr_tid = pi->tid;
1217 win = (ioctl (pi->status_fd, PIOCTSTATUS, &thread_status) >= 0);
1218 if (win)
1219 {
1220 memcpy (&pi->prstatus, &thread_status.status,
1221 sizeof (pi->prstatus));
1222 pi->status_valid = 1;
1223 }
1224 }
1225 #else
1226 /* Just read the danged status. Now isn't that simple? */
1227 pi->status_valid = (ioctl (pi->status_fd, PIOCSTATUS, &pi->prstatus) >= 0);
1228 #endif
1229 #endif
1230
1231 if (pi->status_valid)
1232 {
1233 PROC_PRETTYFPRINT_STATUS (proc_flags (pi),
1234 proc_why (pi),
1235 proc_what (pi),
1236 proc_get_current_thread (pi));
1237 }
1238
1239 /* The status struct includes general regs, so mark them valid too */
1240 pi->gregs_valid = pi->status_valid;
1241 #ifdef NEW_PROC_API
1242 /* In the read/write multiple-fd model,
1243 the status struct includes the fp regs too, so mark them valid too */
1244 pi->fpregs_valid = pi->status_valid;
1245 #endif
1246 return pi->status_valid; /* True if success, false if failure. */
1247 }
1248
1249 /*
1250 * Function: proc_flags
1251 *
1252 * returns the process flags (pr_flags field).
1253 */
1254
1255 long
1256 proc_flags (procinfo *pi)
1257 {
1258 if (!pi->status_valid)
1259 if (!proc_get_status (pi))
1260 return 0; /* FIXME: not a good failure value (but what is?) */
1261
1262 #ifdef NEW_PROC_API
1263 # ifdef UNIXWARE
1264 /* UnixWare 7.1 puts process status flags, e.g. PR_ASYNC, in
1265 pstatus_t and LWP status flags, e.g. PR_STOPPED, in lwpstatus_t.
1266 The two sets of flags don't overlap. */
1267 return pi->prstatus.pr_flags | pi->prstatus.pr_lwp.pr_flags;
1268 # else
1269 return pi->prstatus.pr_lwp.pr_flags;
1270 # endif
1271 #else
1272 return pi->prstatus.pr_flags;
1273 #endif
1274 }
1275
1276 /*
1277 * Function: proc_why
1278 *
1279 * returns the pr_why field (why the process stopped).
1280 */
1281
1282 int
1283 proc_why (procinfo *pi)
1284 {
1285 if (!pi->status_valid)
1286 if (!proc_get_status (pi))
1287 return 0; /* FIXME: not a good failure value (but what is?) */
1288
1289 #ifdef NEW_PROC_API
1290 return pi->prstatus.pr_lwp.pr_why;
1291 #else
1292 return pi->prstatus.pr_why;
1293 #endif
1294 }
1295
1296 /*
1297 * Function: proc_what
1298 *
1299 * returns the pr_what field (details of why the process stopped).
1300 */
1301
1302 int
1303 proc_what (procinfo *pi)
1304 {
1305 if (!pi->status_valid)
1306 if (!proc_get_status (pi))
1307 return 0; /* FIXME: not a good failure value (but what is?) */
1308
1309 #ifdef NEW_PROC_API
1310 return pi->prstatus.pr_lwp.pr_what;
1311 #else
1312 return pi->prstatus.pr_what;
1313 #endif
1314 }
1315
1316 #ifndef PIOCSSPCACT /* The following is not supported on OSF. */
1317 /*
1318 * Function: proc_nsysarg
1319 *
1320 * returns the pr_nsysarg field (number of args to the current syscall).
1321 */
1322
1323 int
1324 proc_nsysarg (procinfo *pi)
1325 {
1326 if (!pi->status_valid)
1327 if (!proc_get_status (pi))
1328 return 0;
1329
1330 #ifdef NEW_PROC_API
1331 return pi->prstatus.pr_lwp.pr_nsysarg;
1332 #else
1333 return pi->prstatus.pr_nsysarg;
1334 #endif
1335 }
1336
1337 /*
1338 * Function: proc_sysargs
1339 *
1340 * returns the pr_sysarg field (pointer to the arguments of current syscall).
1341 */
1342
1343 long *
1344 proc_sysargs (procinfo *pi)
1345 {
1346 if (!pi->status_valid)
1347 if (!proc_get_status (pi))
1348 return NULL;
1349
1350 #ifdef NEW_PROC_API
1351 return (long *) &pi->prstatus.pr_lwp.pr_sysarg;
1352 #else
1353 return (long *) &pi->prstatus.pr_sysarg;
1354 #endif
1355 }
1356
1357 /*
1358 * Function: proc_syscall
1359 *
1360 * returns the pr_syscall field (id of current syscall if we are in one).
1361 */
1362
1363 int
1364 proc_syscall (procinfo *pi)
1365 {
1366 if (!pi->status_valid)
1367 if (!proc_get_status (pi))
1368 return 0;
1369
1370 #ifdef NEW_PROC_API
1371 return pi->prstatus.pr_lwp.pr_syscall;
1372 #else
1373 return pi->prstatus.pr_syscall;
1374 #endif
1375 }
1376 #endif /* PIOCSSPCACT */
1377
1378 /*
1379 * Function: proc_cursig:
1380 *
1381 * returns the pr_cursig field (current signal).
1382 */
1383
1384 long
1385 proc_cursig (struct procinfo *pi)
1386 {
1387 if (!pi->status_valid)
1388 if (!proc_get_status (pi))
1389 return 0; /* FIXME: not a good failure value (but what is?) */
1390
1391 #ifdef NEW_PROC_API
1392 return pi->prstatus.pr_lwp.pr_cursig;
1393 #else
1394 return pi->prstatus.pr_cursig;
1395 #endif
1396 }
1397
1398 /*
1399 * Function: proc_modify_flag
1400 *
1401 * === I appologize for the messiness of this function.
1402 * === This is an area where the different versions of
1403 * === /proc are more inconsistent than usual. MVS
1404 *
1405 * Set or reset any of the following process flags:
1406 * PR_FORK -- forked child will inherit trace flags
1407 * PR_RLC -- traced process runs when last /proc file closed.
1408 * PR_KLC -- traced process is killed when last /proc file closed.
1409 * PR_ASYNC -- LWP's get to run/stop independently.
1410 *
1411 * There are three methods for doing this function:
1412 * 1) Newest: read/write [PCSET/PCRESET/PCUNSET]
1413 * [Sol6, Sol7, UW]
1414 * 2) Middle: PIOCSET/PIOCRESET
1415 * [Irix, Sol5]
1416 * 3) Oldest: PIOCSFORK/PIOCRFORK/PIOCSRLC/PIOCRRLC
1417 * [OSF, Sol5]
1418 *
1419 * Note: Irix does not define PR_ASYNC.
1420 * Note: OSF does not define PR_KLC.
1421 * Note: OSF is the only one that can ONLY use the oldest method.
1422 *
1423 * Arguments:
1424 * pi -- the procinfo
1425 * flag -- one of PR_FORK, PR_RLC, or PR_ASYNC
1426 * mode -- 1 for set, 0 for reset.
1427 *
1428 * Returns non-zero for success, zero for failure.
1429 */
1430
1431 enum { FLAG_RESET, FLAG_SET };
1432
1433 static int
1434 proc_modify_flag (procinfo *pi, long flag, long mode)
1435 {
1436 long win = 0; /* default to fail */
1437
1438 /*
1439 * These operations affect the process as a whole, and applying
1440 * them to an individual LWP has the same meaning as applying them
1441 * to the main process. Therefore, if we're ever called with a
1442 * pointer to an LWP's procinfo, let's substitute the process's
1443 * procinfo and avoid opening the LWP's file descriptor
1444 * unnecessarily.
1445 */
1446
1447 if (pi->pid != 0)
1448 pi = find_procinfo_or_die (pi->pid, 0);
1449
1450 #ifdef NEW_PROC_API /* Newest method: UnixWare and newer Solarii */
1451 /* First normalize the PCUNSET/PCRESET command opcode
1452 (which for no obvious reason has a different definition
1453 from one operating system to the next...) */
1454 #ifdef PCUNSET
1455 #define GDBRESET PCUNSET
1456 #else
1457 #ifdef PCRESET
1458 #define GDBRESET PCRESET
1459 #endif
1460 #endif
1461 {
1462 procfs_ctl_t arg[2];
1463
1464 if (mode == FLAG_SET) /* Set the flag (RLC, FORK, or ASYNC) */
1465 arg[0] = PCSET;
1466 else /* Reset the flag */
1467 arg[0] = GDBRESET;
1468
1469 arg[1] = flag;
1470 win = (write (pi->ctl_fd, (void *) &arg, sizeof (arg)) == sizeof (arg));
1471 }
1472 #else
1473 #ifdef PIOCSET /* Irix/Sol5 method */
1474 if (mode == FLAG_SET) /* Set the flag (hopefully RLC, FORK, or ASYNC) */
1475 {
1476 win = (ioctl (pi->ctl_fd, PIOCSET, &flag) >= 0);
1477 }
1478 else /* Reset the flag */
1479 {
1480 win = (ioctl (pi->ctl_fd, PIOCRESET, &flag) >= 0);
1481 }
1482
1483 #else
1484 #ifdef PIOCSRLC /* Oldest method: OSF */
1485 switch (flag) {
1486 case PR_RLC:
1487 if (mode == FLAG_SET) /* Set run-on-last-close */
1488 {
1489 win = (ioctl (pi->ctl_fd, PIOCSRLC, NULL) >= 0);
1490 }
1491 else /* Clear run-on-last-close */
1492 {
1493 win = (ioctl (pi->ctl_fd, PIOCRRLC, NULL) >= 0);
1494 }
1495 break;
1496 case PR_FORK:
1497 if (mode == FLAG_SET) /* Set inherit-on-fork */
1498 {
1499 win = (ioctl (pi->ctl_fd, PIOCSFORK, NULL) >= 0);
1500 }
1501 else /* Clear inherit-on-fork */
1502 {
1503 win = (ioctl (pi->ctl_fd, PIOCRFORK, NULL) >= 0);
1504 }
1505 break;
1506 default:
1507 win = 0; /* fail -- unknown flag (can't do PR_ASYNC) */
1508 break;
1509 }
1510 #endif
1511 #endif
1512 #endif
1513 #undef GDBRESET
1514 /* The above operation renders the procinfo's cached pstatus obsolete. */
1515 pi->status_valid = 0;
1516
1517 if (!win)
1518 warning (_("procfs: modify_flag failed to turn %s %s"),
1519 flag == PR_FORK ? "PR_FORK" :
1520 flag == PR_RLC ? "PR_RLC" :
1521 #ifdef PR_ASYNC
1522 flag == PR_ASYNC ? "PR_ASYNC" :
1523 #endif
1524 #ifdef PR_KLC
1525 flag == PR_KLC ? "PR_KLC" :
1526 #endif
1527 "<unknown flag>",
1528 mode == FLAG_RESET ? "off" : "on");
1529
1530 return win;
1531 }
1532
1533 /*
1534 * Function: proc_set_run_on_last_close
1535 *
1536 * Set the run_on_last_close flag.
1537 * Process with all threads will become runnable
1538 * when debugger closes all /proc fds.
1539 *
1540 * Returns non-zero for success, zero for failure.
1541 */
1542
1543 int
1544 proc_set_run_on_last_close (procinfo *pi)
1545 {
1546 return proc_modify_flag (pi, PR_RLC, FLAG_SET);
1547 }
1548
1549 /*
1550 * Function: proc_unset_run_on_last_close
1551 *
1552 * Reset the run_on_last_close flag.
1553 * Process will NOT become runnable
1554 * when debugger closes its file handles.
1555 *
1556 * Returns non-zero for success, zero for failure.
1557 */
1558
1559 int
1560 proc_unset_run_on_last_close (procinfo *pi)
1561 {
1562 return proc_modify_flag (pi, PR_RLC, FLAG_RESET);
1563 }
1564
1565 #ifdef PR_KLC
1566 /*
1567 * Function: proc_set_kill_on_last_close
1568 *
1569 * Set the kill_on_last_close flag.
1570 * Process with all threads will be killed when debugger
1571 * closes all /proc fds (or debugger exits or dies).
1572 *
1573 * Returns non-zero for success, zero for failure.
1574 */
1575
1576 int
1577 proc_set_kill_on_last_close (procinfo *pi)
1578 {
1579 return proc_modify_flag (pi, PR_KLC, FLAG_SET);
1580 }
1581
1582 /*
1583 * Function: proc_unset_kill_on_last_close
1584 *
1585 * Reset the kill_on_last_close flag.
1586 * Process will NOT be killed when debugger
1587 * closes its file handles (or exits or dies).
1588 *
1589 * Returns non-zero for success, zero for failure.
1590 */
1591
1592 int
1593 proc_unset_kill_on_last_close (procinfo *pi)
1594 {
1595 return proc_modify_flag (pi, PR_KLC, FLAG_RESET);
1596 }
1597 #endif /* PR_KLC */
1598
1599 /*
1600 * Function: proc_set_inherit_on_fork
1601 *
1602 * Set inherit_on_fork flag.
1603 * If the process forks a child while we are registered for events
1604 * in the parent, then we will also recieve events from the child.
1605 *
1606 * Returns non-zero for success, zero for failure.
1607 */
1608
1609 int
1610 proc_set_inherit_on_fork (procinfo *pi)
1611 {
1612 return proc_modify_flag (pi, PR_FORK, FLAG_SET);
1613 }
1614
1615 /*
1616 * Function: proc_unset_inherit_on_fork
1617 *
1618 * Reset inherit_on_fork flag.
1619 * If the process forks a child while we are registered for events
1620 * in the parent, then we will NOT recieve events from the child.
1621 *
1622 * Returns non-zero for success, zero for failure.
1623 */
1624
1625 int
1626 proc_unset_inherit_on_fork (procinfo *pi)
1627 {
1628 return proc_modify_flag (pi, PR_FORK, FLAG_RESET);
1629 }
1630
1631 #ifdef PR_ASYNC
1632 /*
1633 * Function: proc_set_async
1634 *
1635 * Set PR_ASYNC flag.
1636 * If one LWP stops because of a debug event (signal etc.),
1637 * the remaining LWPs will continue to run.
1638 *
1639 * Returns non-zero for success, zero for failure.
1640 */
1641
1642 int
1643 proc_set_async (procinfo *pi)
1644 {
1645 return proc_modify_flag (pi, PR_ASYNC, FLAG_SET);
1646 }
1647
1648 /*
1649 * Function: proc_unset_async
1650 *
1651 * Reset PR_ASYNC flag.
1652 * If one LWP stops because of a debug event (signal etc.),
1653 * then all other LWPs will stop as well.
1654 *
1655 * Returns non-zero for success, zero for failure.
1656 */
1657
1658 int
1659 proc_unset_async (procinfo *pi)
1660 {
1661 return proc_modify_flag (pi, PR_ASYNC, FLAG_RESET);
1662 }
1663 #endif /* PR_ASYNC */
1664
1665 /*
1666 * Function: proc_stop_process
1667 *
1668 * Request the process/LWP to stop. Does not wait.
1669 * Returns non-zero for success, zero for failure.
1670 */
1671
1672 int
1673 proc_stop_process (procinfo *pi)
1674 {
1675 int win;
1676
1677 /*
1678 * We might conceivably apply this operation to an LWP, and
1679 * the LWP's ctl file descriptor might not be open.
1680 */
1681
1682 if (pi->ctl_fd == 0 &&
1683 open_procinfo_files (pi, FD_CTL) == 0)
1684 return 0;
1685 else
1686 {
1687 #ifdef NEW_PROC_API
1688 procfs_ctl_t cmd = PCSTOP;
1689 win = (write (pi->ctl_fd, (char *) &cmd, sizeof (cmd)) == sizeof (cmd));
1690 #else /* ioctl method */
1691 win = (ioctl (pi->ctl_fd, PIOCSTOP, &pi->prstatus) >= 0);
1692 /* Note: the call also reads the prstatus. */
1693 if (win)
1694 {
1695 pi->status_valid = 1;
1696 PROC_PRETTYFPRINT_STATUS (proc_flags (pi),
1697 proc_why (pi),
1698 proc_what (pi),
1699 proc_get_current_thread (pi));
1700 }
1701 #endif
1702 }
1703
1704 return win;
1705 }
1706
1707 /*
1708 * Function: proc_wait_for_stop
1709 *
1710 * Wait for the process or LWP to stop (block until it does).
1711 * Returns non-zero for success, zero for failure.
1712 */
1713
1714 int
1715 proc_wait_for_stop (procinfo *pi)
1716 {
1717 int win;
1718
1719 /*
1720 * We should never have to apply this operation to any procinfo
1721 * except the one for the main process. If that ever changes
1722 * for any reason, then take out the following clause and
1723 * replace it with one that makes sure the ctl_fd is open.
1724 */
1725
1726 if (pi->tid != 0)
1727 pi = find_procinfo_or_die (pi->pid, 0);
1728
1729 #ifdef NEW_PROC_API
1730 {
1731 procfs_ctl_t cmd = PCWSTOP;
1732 win = (write (pi->ctl_fd, (char *) &cmd, sizeof (cmd)) == sizeof (cmd));
1733 /* We been runnin' and we stopped -- need to update status. */
1734 pi->status_valid = 0;
1735 }
1736 #else /* ioctl method */
1737 win = (ioctl (pi->ctl_fd, PIOCWSTOP, &pi->prstatus) >= 0);
1738 /* Above call also refreshes the prstatus. */
1739 if (win)
1740 {
1741 pi->status_valid = 1;
1742 PROC_PRETTYFPRINT_STATUS (proc_flags (pi),
1743 proc_why (pi),
1744 proc_what (pi),
1745 proc_get_current_thread (pi));
1746 }
1747 #endif
1748
1749 return win;
1750 }
1751
1752 /*
1753 * Function: proc_run_process
1754 *
1755 * Make the process or LWP runnable.
1756 * Options (not all are implemented):
1757 * - single-step
1758 * - clear current fault
1759 * - clear current signal
1760 * - abort the current system call
1761 * - stop as soon as finished with system call
1762 * - (ioctl): set traced signal set
1763 * - (ioctl): set held signal set
1764 * - (ioctl): set traced fault set
1765 * - (ioctl): set start pc (vaddr)
1766 * Always clear the current fault.
1767 * Clear the current signal if 'signo' is zero.
1768 *
1769 * Arguments:
1770 * pi the process or LWP to operate on.
1771 * step if true, set the process or LWP to trap after one instr.
1772 * signo if zero, clear the current signal if any.
1773 * if non-zero, set the current signal to this one.
1774 *
1775 * Returns non-zero for success, zero for failure.
1776 */
1777
1778 int
1779 proc_run_process (procinfo *pi, int step, int signo)
1780 {
1781 int win;
1782 int runflags;
1783
1784 /*
1785 * We will probably have to apply this operation to individual threads,
1786 * so make sure the control file descriptor is open.
1787 */
1788
1789 if (pi->ctl_fd == 0 &&
1790 open_procinfo_files (pi, FD_CTL) == 0)
1791 {
1792 return 0;
1793 }
1794
1795 runflags = PRCFAULT; /* always clear current fault */
1796 if (step)
1797 runflags |= PRSTEP;
1798 if (signo == 0)
1799 runflags |= PRCSIG;
1800 else if (signo != -1) /* -1 means do nothing W.R.T. signals */
1801 proc_set_current_signal (pi, signo);
1802
1803 #ifdef NEW_PROC_API
1804 {
1805 procfs_ctl_t cmd[2];
1806
1807 cmd[0] = PCRUN;
1808 cmd[1] = runflags;
1809 win = (write (pi->ctl_fd, (char *) &cmd, sizeof (cmd)) == sizeof (cmd));
1810 }
1811 #else /* ioctl method */
1812 {
1813 prrun_t prrun;
1814
1815 memset (&prrun, 0, sizeof (prrun));
1816 prrun.pr_flags = runflags;
1817 win = (ioctl (pi->ctl_fd, PIOCRUN, &prrun) >= 0);
1818 }
1819 #endif
1820
1821 return win;
1822 }
1823
1824 /*
1825 * Function: proc_set_traced_signals
1826 *
1827 * Register to trace signals in the process or LWP.
1828 * Returns non-zero for success, zero for failure.
1829 */
1830
1831 int
1832 proc_set_traced_signals (procinfo *pi, gdb_sigset_t *sigset)
1833 {
1834 int win;
1835
1836 /*
1837 * We should never have to apply this operation to any procinfo
1838 * except the one for the main process. If that ever changes
1839 * for any reason, then take out the following clause and
1840 * replace it with one that makes sure the ctl_fd is open.
1841 */
1842
1843 if (pi->tid != 0)
1844 pi = find_procinfo_or_die (pi->pid, 0);
1845
1846 #ifdef NEW_PROC_API
1847 {
1848 struct {
1849 procfs_ctl_t cmd;
1850 /* Use char array to avoid alignment issues. */
1851 char sigset[sizeof (gdb_sigset_t)];
1852 } arg;
1853
1854 arg.cmd = PCSTRACE;
1855 memcpy (&arg.sigset, sigset, sizeof (gdb_sigset_t));
1856
1857 win = (write (pi->ctl_fd, (char *) &arg, sizeof (arg)) == sizeof (arg));
1858 }
1859 #else /* ioctl method */
1860 win = (ioctl (pi->ctl_fd, PIOCSTRACE, sigset) >= 0);
1861 #endif
1862 /* The above operation renders the procinfo's cached pstatus obsolete. */
1863 pi->status_valid = 0;
1864
1865 if (!win)
1866 warning (_("procfs: set_traced_signals failed"));
1867 return win;
1868 }
1869
1870 /*
1871 * Function: proc_set_traced_faults
1872 *
1873 * Register to trace hardware faults in the process or LWP.
1874 * Returns non-zero for success, zero for failure.
1875 */
1876
1877 int
1878 proc_set_traced_faults (procinfo *pi, fltset_t *fltset)
1879 {
1880 int win;
1881
1882 /*
1883 * We should never have to apply this operation to any procinfo
1884 * except the one for the main process. If that ever changes
1885 * for any reason, then take out the following clause and
1886 * replace it with one that makes sure the ctl_fd is open.
1887 */
1888
1889 if (pi->tid != 0)
1890 pi = find_procinfo_or_die (pi->pid, 0);
1891
1892 #ifdef NEW_PROC_API
1893 {
1894 struct {
1895 procfs_ctl_t cmd;
1896 /* Use char array to avoid alignment issues. */
1897 char fltset[sizeof (fltset_t)];
1898 } arg;
1899
1900 arg.cmd = PCSFAULT;
1901 memcpy (&arg.fltset, fltset, sizeof (fltset_t));
1902
1903 win = (write (pi->ctl_fd, (char *) &arg, sizeof (arg)) == sizeof (arg));
1904 }
1905 #else /* ioctl method */
1906 win = (ioctl (pi->ctl_fd, PIOCSFAULT, fltset) >= 0);
1907 #endif
1908 /* The above operation renders the procinfo's cached pstatus obsolete. */
1909 pi->status_valid = 0;
1910
1911 return win;
1912 }
1913
1914 /*
1915 * Function: proc_set_traced_sysentry
1916 *
1917 * Register to trace entry to system calls in the process or LWP.
1918 * Returns non-zero for success, zero for failure.
1919 */
1920
1921 int
1922 proc_set_traced_sysentry (procinfo *pi, sysset_t *sysset)
1923 {
1924 int win;
1925
1926 /*
1927 * We should never have to apply this operation to any procinfo
1928 * except the one for the main process. If that ever changes
1929 * for any reason, then take out the following clause and
1930 * replace it with one that makes sure the ctl_fd is open.
1931 */
1932
1933 if (pi->tid != 0)
1934 pi = find_procinfo_or_die (pi->pid, 0);
1935
1936 #ifdef NEW_PROC_API
1937 {
1938 struct gdb_proc_ctl_pcsentry {
1939 procfs_ctl_t cmd;
1940 /* Use char array to avoid alignment issues. */
1941 char sysset[sizeof (sysset_t)];
1942 } *argp;
1943 int argp_size = sizeof (struct gdb_proc_ctl_pcsentry)
1944 - sizeof (sysset_t)
1945 + sysset_t_size (pi);
1946
1947 argp = xmalloc (argp_size);
1948
1949 argp->cmd = PCSENTRY;
1950 memcpy (&argp->sysset, sysset, sysset_t_size (pi));
1951
1952 win = (write (pi->ctl_fd, (char *) argp, argp_size) == argp_size);
1953 xfree (argp);
1954 }
1955 #else /* ioctl method */
1956 win = (ioctl (pi->ctl_fd, PIOCSENTRY, sysset) >= 0);
1957 #endif
1958 /* The above operation renders the procinfo's cached pstatus obsolete. */
1959 pi->status_valid = 0;
1960
1961 return win;
1962 }
1963
1964 /*
1965 * Function: proc_set_traced_sysexit
1966 *
1967 * Register to trace exit from system calls in the process or LWP.
1968 * Returns non-zero for success, zero for failure.
1969 */
1970
1971 int
1972 proc_set_traced_sysexit (procinfo *pi, sysset_t *sysset)
1973 {
1974 int win;
1975
1976 /*
1977 * We should never have to apply this operation to any procinfo
1978 * except the one for the main process. If that ever changes
1979 * for any reason, then take out the following clause and
1980 * replace it with one that makes sure the ctl_fd is open.
1981 */
1982
1983 if (pi->tid != 0)
1984 pi = find_procinfo_or_die (pi->pid, 0);
1985
1986 #ifdef NEW_PROC_API
1987 {
1988 struct gdb_proc_ctl_pcsexit {
1989 procfs_ctl_t cmd;
1990 /* Use char array to avoid alignment issues. */
1991 char sysset[sizeof (sysset_t)];
1992 } *argp;
1993 int argp_size = sizeof (struct gdb_proc_ctl_pcsexit)
1994 - sizeof (sysset_t)
1995 + sysset_t_size (pi);
1996
1997 argp = xmalloc (argp_size);
1998
1999 argp->cmd = PCSEXIT;
2000 memcpy (&argp->sysset, sysset, sysset_t_size (pi));
2001
2002 win = (write (pi->ctl_fd, (char *) argp, argp_size) == argp_size);
2003 xfree (argp);
2004 }
2005 #else /* ioctl method */
2006 win = (ioctl (pi->ctl_fd, PIOCSEXIT, sysset) >= 0);
2007 #endif
2008 /* The above operation renders the procinfo's cached pstatus obsolete. */
2009 pi->status_valid = 0;
2010
2011 return win;
2012 }
2013
2014 /*
2015 * Function: proc_set_held_signals
2016 *
2017 * Specify the set of blocked / held signals in the process or LWP.
2018 * Returns non-zero for success, zero for failure.
2019 */
2020
2021 int
2022 proc_set_held_signals (procinfo *pi, gdb_sigset_t *sighold)
2023 {
2024 int win;
2025
2026 /*
2027 * We should never have to apply this operation to any procinfo
2028 * except the one for the main process. If that ever changes
2029 * for any reason, then take out the following clause and
2030 * replace it with one that makes sure the ctl_fd is open.
2031 */
2032
2033 if (pi->tid != 0)
2034 pi = find_procinfo_or_die (pi->pid, 0);
2035
2036 #ifdef NEW_PROC_API
2037 {
2038 struct {
2039 procfs_ctl_t cmd;
2040 /* Use char array to avoid alignment issues. */
2041 char hold[sizeof (gdb_sigset_t)];
2042 } arg;
2043
2044 arg.cmd = PCSHOLD;
2045 memcpy (&arg.hold, sighold, sizeof (gdb_sigset_t));
2046 win = (write (pi->ctl_fd, (void *) &arg, sizeof (arg)) == sizeof (arg));
2047 }
2048 #else
2049 win = (ioctl (pi->ctl_fd, PIOCSHOLD, sighold) >= 0);
2050 #endif
2051 /* The above operation renders the procinfo's cached pstatus obsolete. */
2052 pi->status_valid = 0;
2053
2054 return win;
2055 }
2056
2057 /*
2058 * Function: proc_get_pending_signals
2059 *
2060 * returns the set of signals that are pending in the process or LWP.
2061 * Will also copy the sigset if 'save' is non-zero.
2062 */
2063
2064 gdb_sigset_t *
2065 proc_get_pending_signals (procinfo *pi, gdb_sigset_t *save)
2066 {
2067 gdb_sigset_t *ret = NULL;
2068
2069 /*
2070 * We should never have to apply this operation to any procinfo
2071 * except the one for the main process. If that ever changes
2072 * for any reason, then take out the following clause and
2073 * replace it with one that makes sure the ctl_fd is open.
2074 */
2075
2076 if (pi->tid != 0)
2077 pi = find_procinfo_or_die (pi->pid, 0);
2078
2079 if (!pi->status_valid)
2080 if (!proc_get_status (pi))
2081 return NULL;
2082
2083 #ifdef NEW_PROC_API
2084 ret = &pi->prstatus.pr_lwp.pr_lwppend;
2085 #else
2086 ret = &pi->prstatus.pr_sigpend;
2087 #endif
2088 if (save && ret)
2089 memcpy (save, ret, sizeof (gdb_sigset_t));
2090
2091 return ret;
2092 }
2093
2094 /*
2095 * Function: proc_get_signal_actions
2096 *
2097 * returns the set of signal actions.
2098 * Will also copy the sigactionset if 'save' is non-zero.
2099 */
2100
2101 gdb_sigaction_t *
2102 proc_get_signal_actions (procinfo *pi, gdb_sigaction_t *save)
2103 {
2104 gdb_sigaction_t *ret = NULL;
2105
2106 /*
2107 * We should never have to apply this operation to any procinfo
2108 * except the one for the main process. If that ever changes
2109 * for any reason, then take out the following clause and
2110 * replace it with one that makes sure the ctl_fd is open.
2111 */
2112
2113 if (pi->tid != 0)
2114 pi = find_procinfo_or_die (pi->pid, 0);
2115
2116 if (!pi->status_valid)
2117 if (!proc_get_status (pi))
2118 return NULL;
2119
2120 #ifdef NEW_PROC_API
2121 ret = &pi->prstatus.pr_lwp.pr_action;
2122 #else
2123 ret = &pi->prstatus.pr_action;
2124 #endif
2125 if (save && ret)
2126 memcpy (save, ret, sizeof (gdb_sigaction_t));
2127
2128 return ret;
2129 }
2130
2131 /*
2132 * Function: proc_get_held_signals
2133 *
2134 * returns the set of signals that are held / blocked.
2135 * Will also copy the sigset if 'save' is non-zero.
2136 */
2137
2138 gdb_sigset_t *
2139 proc_get_held_signals (procinfo *pi, gdb_sigset_t *save)
2140 {
2141 gdb_sigset_t *ret = NULL;
2142
2143 /*
2144 * We should never have to apply this operation to any procinfo
2145 * except the one for the main process. If that ever changes
2146 * for any reason, then take out the following clause and
2147 * replace it with one that makes sure the ctl_fd is open.
2148 */
2149
2150 if (pi->tid != 0)
2151 pi = find_procinfo_or_die (pi->pid, 0);
2152
2153 #ifdef NEW_PROC_API
2154 if (!pi->status_valid)
2155 if (!proc_get_status (pi))
2156 return NULL;
2157
2158 #ifdef UNIXWARE
2159 ret = &pi->prstatus.pr_lwp.pr_context.uc_sigmask;
2160 #else
2161 ret = &pi->prstatus.pr_lwp.pr_lwphold;
2162 #endif /* UNIXWARE */
2163 #else /* not NEW_PROC_API */
2164 {
2165 static gdb_sigset_t sigheld;
2166
2167 if (ioctl (pi->ctl_fd, PIOCGHOLD, &sigheld) >= 0)
2168 ret = &sigheld;
2169 }
2170 #endif /* NEW_PROC_API */
2171 if (save && ret)
2172 memcpy (save, ret, sizeof (gdb_sigset_t));
2173
2174 return ret;
2175 }
2176
2177 /*
2178 * Function: proc_get_traced_signals
2179 *
2180 * returns the set of signals that are traced / debugged.
2181 * Will also copy the sigset if 'save' is non-zero.
2182 */
2183
2184 gdb_sigset_t *
2185 proc_get_traced_signals (procinfo *pi, gdb_sigset_t *save)
2186 {
2187 gdb_sigset_t *ret = NULL;
2188
2189 /*
2190 * We should never have to apply this operation to any procinfo
2191 * except the one for the main process. If that ever changes
2192 * for any reason, then take out the following clause and
2193 * replace it with one that makes sure the ctl_fd is open.
2194 */
2195
2196 if (pi->tid != 0)
2197 pi = find_procinfo_or_die (pi->pid, 0);
2198
2199 #ifdef NEW_PROC_API
2200 if (!pi->status_valid)
2201 if (!proc_get_status (pi))
2202 return NULL;
2203
2204 ret = &pi->prstatus.pr_sigtrace;
2205 #else
2206 {
2207 static gdb_sigset_t sigtrace;
2208
2209 if (ioctl (pi->ctl_fd, PIOCGTRACE, &sigtrace) >= 0)
2210 ret = &sigtrace;
2211 }
2212 #endif
2213 if (save && ret)
2214 memcpy (save, ret, sizeof (gdb_sigset_t));
2215
2216 return ret;
2217 }
2218
2219 /*
2220 * Function: proc_trace_signal
2221 *
2222 * Add 'signo' to the set of signals that are traced.
2223 * Returns non-zero for success, zero for failure.
2224 */
2225
2226 int
2227 proc_trace_signal (procinfo *pi, int signo)
2228 {
2229 gdb_sigset_t temp;
2230
2231 /*
2232 * We should never have to apply this operation to any procinfo
2233 * except the one for the main process. If that ever changes
2234 * for any reason, then take out the following clause and
2235 * replace it with one that makes sure the ctl_fd is open.
2236 */
2237
2238 if (pi->tid != 0)
2239 pi = find_procinfo_or_die (pi->pid, 0);
2240
2241 if (pi)
2242 {
2243 if (proc_get_traced_signals (pi, &temp))
2244 {
2245 gdb_praddset (&temp, signo);
2246 return proc_set_traced_signals (pi, &temp);
2247 }
2248 }
2249
2250 return 0; /* failure */
2251 }
2252
2253 /*
2254 * Function: proc_ignore_signal
2255 *
2256 * Remove 'signo' from the set of signals that are traced.
2257 * Returns non-zero for success, zero for failure.
2258 */
2259
2260 int
2261 proc_ignore_signal (procinfo *pi, int signo)
2262 {
2263 gdb_sigset_t temp;
2264
2265 /*
2266 * We should never have to apply this operation to any procinfo
2267 * except the one for the main process. If that ever changes
2268 * for any reason, then take out the following clause and
2269 * replace it with one that makes sure the ctl_fd is open.
2270 */
2271
2272 if (pi->tid != 0)
2273 pi = find_procinfo_or_die (pi->pid, 0);
2274
2275 if (pi)
2276 {
2277 if (proc_get_traced_signals (pi, &temp))
2278 {
2279 gdb_prdelset (&temp, signo);
2280 return proc_set_traced_signals (pi, &temp);
2281 }
2282 }
2283
2284 return 0; /* failure */
2285 }
2286
2287 /*
2288 * Function: proc_get_traced_faults
2289 *
2290 * returns the set of hardware faults that are traced /debugged.
2291 * Will also copy the faultset if 'save' is non-zero.
2292 */
2293
2294 fltset_t *
2295 proc_get_traced_faults (procinfo *pi, fltset_t *save)
2296 {
2297 fltset_t *ret = NULL;
2298
2299 /*
2300 * We should never have to apply this operation to any procinfo
2301 * except the one for the main process. If that ever changes
2302 * for any reason, then take out the following clause and
2303 * replace it with one that makes sure the ctl_fd is open.
2304 */
2305
2306 if (pi->tid != 0)
2307 pi = find_procinfo_or_die (pi->pid, 0);
2308
2309 #ifdef NEW_PROC_API
2310 if (!pi->status_valid)
2311 if (!proc_get_status (pi))
2312 return NULL;
2313
2314 ret = &pi->prstatus.pr_flttrace;
2315 #else
2316 {
2317 static fltset_t flttrace;
2318
2319 if (ioctl (pi->ctl_fd, PIOCGFAULT, &flttrace) >= 0)
2320 ret = &flttrace;
2321 }
2322 #endif
2323 if (save && ret)
2324 memcpy (save, ret, sizeof (fltset_t));
2325
2326 return ret;
2327 }
2328
2329 /*
2330 * Function: proc_get_traced_sysentry
2331 *
2332 * returns the set of syscalls that are traced /debugged on entry.
2333 * Will also copy the syscall set if 'save' is non-zero.
2334 */
2335
2336 sysset_t *
2337 proc_get_traced_sysentry (procinfo *pi, sysset_t *save)
2338 {
2339 sysset_t *ret = NULL;
2340
2341 /*
2342 * We should never have to apply this operation to any procinfo
2343 * except the one for the main process. If that ever changes
2344 * for any reason, then take out the following clause and
2345 * replace it with one that makes sure the ctl_fd is open.
2346 */
2347
2348 if (pi->tid != 0)
2349 pi = find_procinfo_or_die (pi->pid, 0);
2350
2351 #ifdef NEW_PROC_API
2352 if (!pi->status_valid)
2353 if (!proc_get_status (pi))
2354 return NULL;
2355
2356 #ifndef DYNAMIC_SYSCALLS
2357 ret = &pi->prstatus.pr_sysentry;
2358 #else /* DYNAMIC_SYSCALLS */
2359 {
2360 static sysset_t *sysentry;
2361 size_t size;
2362
2363 if (!sysentry)
2364 sysentry = sysset_t_alloc (pi);
2365 ret = sysentry;
2366 if (pi->status_fd == 0 && open_procinfo_files (pi, FD_STATUS) == 0)
2367 return NULL;
2368 if (pi->prstatus.pr_sysentry_offset == 0)
2369 {
2370 gdb_premptysysset (sysentry);
2371 }
2372 else
2373 {
2374 int rsize;
2375
2376 if (lseek (pi->status_fd, (off_t) pi->prstatus.pr_sysentry_offset,
2377 SEEK_SET)
2378 != (off_t) pi->prstatus.pr_sysentry_offset)
2379 return NULL;
2380 size = sysset_t_size (pi);
2381 gdb_premptysysset (sysentry);
2382 rsize = read (pi->status_fd, sysentry, size);
2383 if (rsize < 0)
2384 return NULL;
2385 }
2386 }
2387 #endif /* DYNAMIC_SYSCALLS */
2388 #else /* !NEW_PROC_API */
2389 {
2390 static sysset_t sysentry;
2391
2392 if (ioctl (pi->ctl_fd, PIOCGENTRY, &sysentry) >= 0)
2393 ret = &sysentry;
2394 }
2395 #endif /* NEW_PROC_API */
2396 if (save && ret)
2397 memcpy (save, ret, sysset_t_size (pi));
2398
2399 return ret;
2400 }
2401
2402 /*
2403 * Function: proc_get_traced_sysexit
2404 *
2405 * returns the set of syscalls that are traced /debugged on exit.
2406 * Will also copy the syscall set if 'save' is non-zero.
2407 */
2408
2409 sysset_t *
2410 proc_get_traced_sysexit (procinfo *pi, sysset_t *save)
2411 {
2412 sysset_t * ret = NULL;
2413
2414 /*
2415 * We should never have to apply this operation to any procinfo
2416 * except the one for the main process. If that ever changes
2417 * for any reason, then take out the following clause and
2418 * replace it with one that makes sure the ctl_fd is open.
2419 */
2420
2421 if (pi->tid != 0)
2422 pi = find_procinfo_or_die (pi->pid, 0);
2423
2424 #ifdef NEW_PROC_API
2425 if (!pi->status_valid)
2426 if (!proc_get_status (pi))
2427 return NULL;
2428
2429 #ifndef DYNAMIC_SYSCALLS
2430 ret = &pi->prstatus.pr_sysexit;
2431 #else /* DYNAMIC_SYSCALLS */
2432 {
2433 static sysset_t *sysexit;
2434 size_t size;
2435
2436 if (!sysexit)
2437 sysexit = sysset_t_alloc (pi);
2438 ret = sysexit;
2439 if (pi->status_fd == 0 && open_procinfo_files (pi, FD_STATUS) == 0)
2440 return NULL;
2441 if (pi->prstatus.pr_sysexit_offset == 0)
2442 {
2443 gdb_premptysysset (sysexit);
2444 }
2445 else
2446 {
2447 int rsize;
2448
2449 if (lseek (pi->status_fd, (off_t) pi->prstatus.pr_sysexit_offset, SEEK_SET)
2450 != (off_t) pi->prstatus.pr_sysexit_offset)
2451 return NULL;
2452 size = sysset_t_size (pi);
2453 gdb_premptysysset (sysexit);
2454 rsize = read (pi->status_fd, sysexit, size);
2455 if (rsize < 0)
2456 return NULL;
2457 }
2458 }
2459 #endif /* DYNAMIC_SYSCALLS */
2460 #else
2461 {
2462 static sysset_t sysexit;
2463
2464 if (ioctl (pi->ctl_fd, PIOCGEXIT, &sysexit) >= 0)
2465 ret = &sysexit;
2466 }
2467 #endif
2468 if (save && ret)
2469 memcpy (save, ret, sysset_t_size (pi));
2470
2471 return ret;
2472 }
2473
2474 /*
2475 * Function: proc_clear_current_fault
2476 *
2477 * The current fault (if any) is cleared; the associated signal
2478 * will not be sent to the process or LWP when it resumes.
2479 * Returns non-zero for success, zero for failure.
2480 */
2481
2482 int
2483 proc_clear_current_fault (procinfo *pi)
2484 {
2485 int win;
2486
2487 /*
2488 * We should never have to apply this operation to any procinfo
2489 * except the one for the main process. If that ever changes
2490 * for any reason, then take out the following clause and
2491 * replace it with one that makes sure the ctl_fd is open.
2492 */
2493
2494 if (pi->tid != 0)
2495 pi = find_procinfo_or_die (pi->pid, 0);
2496
2497 #ifdef NEW_PROC_API
2498 {
2499 procfs_ctl_t cmd = PCCFAULT;
2500 win = (write (pi->ctl_fd, (void *) &cmd, sizeof (cmd)) == sizeof (cmd));
2501 }
2502 #else
2503 win = (ioctl (pi->ctl_fd, PIOCCFAULT, 0) >= 0);
2504 #endif
2505
2506 return win;
2507 }
2508
2509 /*
2510 * Function: proc_set_current_signal
2511 *
2512 * Set the "current signal" that will be delivered next to the process.
2513 * NOTE: semantics are different from those of KILL.
2514 * This signal will be delivered to the process or LWP
2515 * immediately when it is resumed (even if the signal is held/blocked);
2516 * it will NOT immediately cause another event of interest, and will NOT
2517 * first trap back to the debugger.
2518 *
2519 * Returns non-zero for success, zero for failure.
2520 */
2521
2522 int
2523 proc_set_current_signal (procinfo *pi, int signo)
2524 {
2525 int win;
2526 struct {
2527 procfs_ctl_t cmd;
2528 /* Use char array to avoid alignment issues. */
2529 char sinfo[sizeof (gdb_siginfo_t)];
2530 } arg;
2531 gdb_siginfo_t mysinfo;
2532 ptid_t wait_ptid;
2533 struct target_waitstatus wait_status;
2534
2535 /*
2536 * We should never have to apply this operation to any procinfo
2537 * except the one for the main process. If that ever changes
2538 * for any reason, then take out the following clause and
2539 * replace it with one that makes sure the ctl_fd is open.
2540 */
2541
2542 if (pi->tid != 0)
2543 pi = find_procinfo_or_die (pi->pid, 0);
2544
2545 #ifdef PROCFS_DONT_PIOCSSIG_CURSIG
2546 /* With Alpha OSF/1 procfs, the kernel gets really confused if it
2547 * receives a PIOCSSIG with a signal identical to the current signal,
2548 * it messes up the current signal. Work around the kernel bug.
2549 */
2550 if (signo > 0 &&
2551 signo == proc_cursig (pi))
2552 return 1; /* I assume this is a success? */
2553 #endif
2554
2555 /* The pointer is just a type alias. */
2556 get_last_target_status (&wait_ptid, &wait_status);
2557 if (ptid_equal (wait_ptid, inferior_ptid)
2558 && wait_status.kind == TARGET_WAITKIND_STOPPED
2559 && wait_status.value.sig == target_signal_from_host (signo)
2560 && proc_get_status (pi)
2561 #ifdef NEW_PROC_API
2562 && pi->prstatus.pr_lwp.pr_info.si_signo == signo
2563 #else
2564 && pi->prstatus.pr_info.si_signo == signo
2565 #endif
2566 )
2567 /* Use the siginfo associated with the signal being
2568 redelivered. */
2569 #ifdef NEW_PROC_API
2570 memcpy (arg.sinfo, &pi->prstatus.pr_lwp.pr_info, sizeof (gdb_siginfo_t));
2571 #else
2572 memcpy (arg.sinfo, &pi->prstatus.pr_info, sizeof (gdb_siginfo_t));
2573 #endif
2574 else
2575 {
2576 mysinfo.si_signo = signo;
2577 mysinfo.si_code = 0;
2578 mysinfo.si_pid = getpid (); /* ?why? */
2579 mysinfo.si_uid = getuid (); /* ?why? */
2580 memcpy (arg.sinfo, &mysinfo, sizeof (gdb_siginfo_t));
2581 }
2582
2583 #ifdef NEW_PROC_API
2584 arg.cmd = PCSSIG;
2585 win = (write (pi->ctl_fd, (void *) &arg, sizeof (arg)) == sizeof (arg));
2586 #else
2587 win = (ioctl (pi->ctl_fd, PIOCSSIG, (void *) &arg.sinfo) >= 0);
2588 #endif
2589
2590 return win;
2591 }
2592
2593 /*
2594 * Function: proc_clear_current_signal
2595 *
2596 * The current signal (if any) is cleared, and
2597 * is not sent to the process or LWP when it resumes.
2598 * Returns non-zero for success, zero for failure.
2599 */
2600
2601 int
2602 proc_clear_current_signal (procinfo *pi)
2603 {
2604 int win;
2605
2606 /*
2607 * We should never have to apply this operation to any procinfo
2608 * except the one for the main process. If that ever changes
2609 * for any reason, then take out the following clause and
2610 * replace it with one that makes sure the ctl_fd is open.
2611 */
2612
2613 if (pi->tid != 0)
2614 pi = find_procinfo_or_die (pi->pid, 0);
2615
2616 #ifdef NEW_PROC_API
2617 {
2618 struct {
2619 procfs_ctl_t cmd;
2620 /* Use char array to avoid alignment issues. */
2621 char sinfo[sizeof (gdb_siginfo_t)];
2622 } arg;
2623 gdb_siginfo_t mysinfo;
2624
2625 arg.cmd = PCSSIG;
2626 /* The pointer is just a type alias. */
2627 mysinfo.si_signo = 0;
2628 mysinfo.si_code = 0;
2629 mysinfo.si_errno = 0;
2630 mysinfo.si_pid = getpid (); /* ?why? */
2631 mysinfo.si_uid = getuid (); /* ?why? */
2632 memcpy (arg.sinfo, &mysinfo, sizeof (gdb_siginfo_t));
2633
2634 win = (write (pi->ctl_fd, (void *) &arg, sizeof (arg)) == sizeof (arg));
2635 }
2636 #else
2637 win = (ioctl (pi->ctl_fd, PIOCSSIG, 0) >= 0);
2638 #endif
2639
2640 return win;
2641 }
2642
2643 /* Return the general-purpose registers for the process or LWP
2644 corresponding to PI. Upon failure, return NULL. */
2645
2646 gdb_gregset_t *
2647 proc_get_gregs (procinfo *pi)
2648 {
2649 if (!pi->status_valid || !pi->gregs_valid)
2650 if (!proc_get_status (pi))
2651 return NULL;
2652
2653 /* OK, sorry about the ifdef's. There's three cases instead of two,
2654 because in this case Unixware and Solaris/RW differ. */
2655
2656 #ifdef NEW_PROC_API
2657 # ifdef UNIXWARE /* FIXME: Should be autoconfigured. */
2658 return &pi->prstatus.pr_lwp.pr_context.uc_mcontext.gregs;
2659 # else
2660 return &pi->prstatus.pr_lwp.pr_reg;
2661 # endif
2662 #else
2663 return &pi->prstatus.pr_reg;
2664 #endif
2665 }
2666
2667 /* Return the general-purpose registers for the process or LWP
2668 corresponding to PI. Upon failure, return NULL. */
2669
2670 gdb_fpregset_t *
2671 proc_get_fpregs (procinfo *pi)
2672 {
2673 #ifdef NEW_PROC_API
2674 if (!pi->status_valid || !pi->fpregs_valid)
2675 if (!proc_get_status (pi))
2676 return NULL;
2677
2678 # ifdef UNIXWARE /* FIXME: Should be autoconfigured. */
2679 return &pi->prstatus.pr_lwp.pr_context.uc_mcontext.fpregs;
2680 # else
2681 return &pi->prstatus.pr_lwp.pr_fpreg;
2682 # endif
2683
2684 #else /* not NEW_PROC_API */
2685 if (pi->fpregs_valid)
2686 return &pi->fpregset; /* Already got 'em. */
2687 else
2688 {
2689 if (pi->ctl_fd == 0 && open_procinfo_files (pi, FD_CTL) == 0)
2690 {
2691 return NULL;
2692 }
2693 else
2694 {
2695 # ifdef PIOCTGFPREG
2696 struct {
2697 long pr_count;
2698 tid_t pr_error_thread;
2699 tfpregset_t thread_1;
2700 } thread_fpregs;
2701
2702 thread_fpregs.pr_count = 1;
2703 thread_fpregs.thread_1.tid = pi->tid;
2704
2705 if (pi->tid == 0
2706 && ioctl (pi->ctl_fd, PIOCGFPREG, &pi->fpregset) >= 0)
2707 {
2708 pi->fpregs_valid = 1;
2709 return &pi->fpregset; /* Got 'em now! */
2710 }
2711 else if (pi->tid != 0
2712 && ioctl (pi->ctl_fd, PIOCTGFPREG, &thread_fpregs) >= 0)
2713 {
2714 memcpy (&pi->fpregset, &thread_fpregs.thread_1.pr_fpregs,
2715 sizeof (pi->fpregset));
2716 pi->fpregs_valid = 1;
2717 return &pi->fpregset; /* Got 'em now! */
2718 }
2719 else
2720 {
2721 return NULL;
2722 }
2723 # else
2724 if (ioctl (pi->ctl_fd, PIOCGFPREG, &pi->fpregset) >= 0)
2725 {
2726 pi->fpregs_valid = 1;
2727 return &pi->fpregset; /* Got 'em now! */
2728 }
2729 else
2730 {
2731 return NULL;
2732 }
2733 # endif
2734 }
2735 }
2736 #endif /* NEW_PROC_API */
2737 }
2738
2739 /* Write the general-purpose registers back to the process or LWP
2740 corresponding to PI. Return non-zero for success, zero for
2741 failure. */
2742
2743 int
2744 proc_set_gregs (procinfo *pi)
2745 {
2746 gdb_gregset_t *gregs;
2747 int win;
2748
2749 gregs = proc_get_gregs (pi);
2750 if (gregs == NULL)
2751 return 0; /* proc_get_regs has already warned. */
2752
2753 if (pi->ctl_fd == 0 && open_procinfo_files (pi, FD_CTL) == 0)
2754 {
2755 return 0;
2756 }
2757 else
2758 {
2759 #ifdef NEW_PROC_API
2760 struct {
2761 procfs_ctl_t cmd;
2762 /* Use char array to avoid alignment issues. */
2763 char gregs[sizeof (gdb_gregset_t)];
2764 } arg;
2765
2766 arg.cmd = PCSREG;
2767 memcpy (&arg.gregs, gregs, sizeof (arg.gregs));
2768 win = (write (pi->ctl_fd, (void *) &arg, sizeof (arg)) == sizeof (arg));
2769 #else
2770 win = (ioctl (pi->ctl_fd, PIOCSREG, gregs) >= 0);
2771 #endif
2772 }
2773
2774 /* Policy: writing the registers invalidates our cache. */
2775 pi->gregs_valid = 0;
2776 return win;
2777 }
2778
2779 /* Write the floating-pointer registers back to the process or LWP
2780 corresponding to PI. Return non-zero for success, zero for
2781 failure. */
2782
2783 int
2784 proc_set_fpregs (procinfo *pi)
2785 {
2786 gdb_fpregset_t *fpregs;
2787 int win;
2788
2789 fpregs = proc_get_fpregs (pi);
2790 if (fpregs == NULL)
2791 return 0; /* proc_get_fpregs has already warned. */
2792
2793 if (pi->ctl_fd == 0 && open_procinfo_files (pi, FD_CTL) == 0)
2794 {
2795 return 0;
2796 }
2797 else
2798 {
2799 #ifdef NEW_PROC_API
2800 struct {
2801 procfs_ctl_t cmd;
2802 /* Use char array to avoid alignment issues. */
2803 char fpregs[sizeof (gdb_fpregset_t)];
2804 } arg;
2805
2806 arg.cmd = PCSFPREG;
2807 memcpy (&arg.fpregs, fpregs, sizeof (arg.fpregs));
2808 win = (write (pi->ctl_fd, (void *) &arg, sizeof (arg)) == sizeof (arg));
2809 #else
2810 # ifdef PIOCTSFPREG
2811 if (pi->tid == 0)
2812 win = (ioctl (pi->ctl_fd, PIOCSFPREG, fpregs) >= 0);
2813 else
2814 {
2815 struct {
2816 long pr_count;
2817 tid_t pr_error_thread;
2818 tfpregset_t thread_1;
2819 } thread_fpregs;
2820
2821 thread_fpregs.pr_count = 1;
2822 thread_fpregs.thread_1.tid = pi->tid;
2823 memcpy (&thread_fpregs.thread_1.pr_fpregs, fpregs,
2824 sizeof (*fpregs));
2825 win = (ioctl (pi->ctl_fd, PIOCTSFPREG, &thread_fpregs) >= 0);
2826 }
2827 # else
2828 win = (ioctl (pi->ctl_fd, PIOCSFPREG, fpregs) >= 0);
2829 # endif
2830 #endif /* NEW_PROC_API */
2831 }
2832
2833 /* Policy: writing the registers invalidates our cache. */
2834 pi->fpregs_valid = 0;
2835 return win;
2836 }
2837
2838 /*
2839 * Function: proc_kill
2840 *
2841 * Send a signal to the proc or lwp with the semantics of "kill()".
2842 * Returns non-zero for success, zero for failure.
2843 */
2844
2845 int
2846 proc_kill (procinfo *pi, int signo)
2847 {
2848 int win;
2849
2850 /*
2851 * We might conceivably apply this operation to an LWP, and
2852 * the LWP's ctl file descriptor might not be open.
2853 */
2854
2855 if (pi->ctl_fd == 0 &&
2856 open_procinfo_files (pi, FD_CTL) == 0)
2857 {
2858 return 0;
2859 }
2860 else
2861 {
2862 #ifdef NEW_PROC_API
2863 procfs_ctl_t cmd[2];
2864
2865 cmd[0] = PCKILL;
2866 cmd[1] = signo;
2867 win = (write (pi->ctl_fd, (char *) &cmd, sizeof (cmd)) == sizeof (cmd));
2868 #else /* ioctl method */
2869 /* FIXME: do I need the Alpha OSF fixups present in
2870 procfs.c/unconditionally_kill_inferior? Perhaps only for SIGKILL? */
2871 win = (ioctl (pi->ctl_fd, PIOCKILL, &signo) >= 0);
2872 #endif
2873 }
2874
2875 return win;
2876 }
2877
2878 /*
2879 * Function: proc_parent_pid
2880 *
2881 * Find the pid of the process that started this one.
2882 * Returns the parent process pid, or zero.
2883 */
2884
2885 int
2886 proc_parent_pid (procinfo *pi)
2887 {
2888 /*
2889 * We should never have to apply this operation to any procinfo
2890 * except the one for the main process. If that ever changes
2891 * for any reason, then take out the following clause and
2892 * replace it with one that makes sure the ctl_fd is open.
2893 */
2894
2895 if (pi->tid != 0)
2896 pi = find_procinfo_or_die (pi->pid, 0);
2897
2898 if (!pi->status_valid)
2899 if (!proc_get_status (pi))
2900 return 0;
2901
2902 return pi->prstatus.pr_ppid;
2903 }
2904
2905
2906 /* Convert a target address (a.k.a. CORE_ADDR) into a host address
2907 (a.k.a void pointer)! */
2908
2909 static void *
2910 procfs_address_to_host_pointer (CORE_ADDR addr)
2911 {
2912 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
2913 void *ptr;
2914
2915 gdb_assert (sizeof (ptr) == TYPE_LENGTH (ptr_type));
2916 gdbarch_address_to_pointer (target_gdbarch, ptr_type,
2917 (gdb_byte *) &ptr, addr);
2918 return ptr;
2919 }
2920
2921 /*
2922 * Function: proc_set_watchpoint
2923 *
2924 */
2925
2926 int
2927 proc_set_watchpoint (procinfo *pi, CORE_ADDR addr, int len, int wflags)
2928 {
2929 #if !defined (PCWATCH) && !defined (PIOCSWATCH)
2930 /* If neither or these is defined, we can't support watchpoints.
2931 This just avoids possibly failing to compile the below on such
2932 systems. */
2933 return 0;
2934 #else
2935 /* Horrible hack! Detect Solaris 2.5, because this doesn't work on 2.5 */
2936 #if defined (PIOCOPENLWP) || defined (UNIXWARE) /* Solaris 2.5: bail out */
2937 return 0;
2938 #else
2939 struct {
2940 procfs_ctl_t cmd;
2941 char watch[sizeof (prwatch_t)];
2942 } arg;
2943 prwatch_t pwatch;
2944
2945 /* NOTE: cagney/2003-02-01: Even more horrible hack. Need to
2946 convert a target address into something that can be stored in a
2947 native data structure. */
2948 #ifdef PCAGENT /* Horrible hack: only defined on Solaris 2.6+ */
2949 pwatch.pr_vaddr = (uintptr_t) procfs_address_to_host_pointer (addr);
2950 #else
2951 pwatch.pr_vaddr = (caddr_t) procfs_address_to_host_pointer (addr);
2952 #endif
2953 pwatch.pr_size = len;
2954 pwatch.pr_wflags = wflags;
2955 #if defined(NEW_PROC_API) && defined (PCWATCH)
2956 arg.cmd = PCWATCH;
2957 memcpy (arg.watch, &pwatch, sizeof (prwatch_t));
2958 return (write (pi->ctl_fd, &arg, sizeof (arg)) == sizeof (arg));
2959 #else
2960 #if defined (PIOCSWATCH)
2961 return (ioctl (pi->ctl_fd, PIOCSWATCH, &pwatch) >= 0);
2962 #else
2963 return 0; /* Fail */
2964 #endif
2965 #endif
2966 #endif
2967 #endif
2968 }
2969
2970 #if (defined(__i386__) || defined(__x86_64__)) && defined (sun)
2971
2972 #include <sys/sysi86.h>
2973
2974 /*
2975 * Function: proc_get_LDT_entry
2976 *
2977 * Inputs:
2978 * procinfo *pi;
2979 * int key;
2980 *
2981 * The 'key' is actually the value of the lower 16 bits of
2982 * the GS register for the LWP that we're interested in.
2983 *
2984 * Return: matching ssh struct (LDT entry).
2985 */
2986
2987 struct ssd *
2988 proc_get_LDT_entry (procinfo *pi, int key)
2989 {
2990 static struct ssd *ldt_entry = NULL;
2991 #ifdef NEW_PROC_API
2992 char pathname[MAX_PROC_NAME_SIZE];
2993 struct cleanup *old_chain = NULL;
2994 int fd;
2995
2996 /* Allocate space for one LDT entry.
2997 This alloc must persist, because we return a pointer to it. */
2998 if (ldt_entry == NULL)
2999 ldt_entry = (struct ssd *) xmalloc (sizeof (struct ssd));
3000
3001 /* Open the file descriptor for the LDT table. */
3002 sprintf (pathname, "/proc/%d/ldt", pi->pid);
3003 if ((fd = open_with_retry (pathname, O_RDONLY)) < 0)
3004 {
3005 proc_warn (pi, "proc_get_LDT_entry (open)", __LINE__);
3006 return NULL;
3007 }
3008 /* Make sure it gets closed again! */
3009 old_chain = make_cleanup_close (fd);
3010
3011 /* Now 'read' thru the table, find a match and return it. */
3012 while (read (fd, ldt_entry, sizeof (struct ssd)) == sizeof (struct ssd))
3013 {
3014 if (ldt_entry->sel == 0 &&
3015 ldt_entry->bo == 0 &&
3016 ldt_entry->acc1 == 0 &&
3017 ldt_entry->acc2 == 0)
3018 break; /* end of table */
3019 /* If key matches, return this entry. */
3020 if (ldt_entry->sel == key)
3021 return ldt_entry;
3022 }
3023 /* Loop ended, match not found. */
3024 return NULL;
3025 #else
3026 int nldt, i;
3027 static int nalloc = 0;
3028
3029 /* Get the number of LDT entries. */
3030 if (ioctl (pi->ctl_fd, PIOCNLDT, &nldt) < 0)
3031 {
3032 proc_warn (pi, "proc_get_LDT_entry (PIOCNLDT)", __LINE__);
3033 return NULL;
3034 }
3035
3036 /* Allocate space for the number of LDT entries. */
3037 /* This alloc has to persist, 'cause we return a pointer to it. */
3038 if (nldt > nalloc)
3039 {
3040 ldt_entry = (struct ssd *)
3041 xrealloc (ldt_entry, (nldt + 1) * sizeof (struct ssd));
3042 nalloc = nldt;
3043 }
3044
3045 /* Read the whole table in one gulp. */
3046 if (ioctl (pi->ctl_fd, PIOCLDT, ldt_entry) < 0)
3047 {
3048 proc_warn (pi, "proc_get_LDT_entry (PIOCLDT)", __LINE__);
3049 return NULL;
3050 }
3051
3052 /* Search the table and return the (first) entry matching 'key'. */
3053 for (i = 0; i < nldt; i++)
3054 if (ldt_entry[i].sel == key)
3055 return &ldt_entry[i];
3056
3057 /* Loop ended, match not found. */
3058 return NULL;
3059 #endif
3060 }
3061
3062 /*
3063 * Function: procfs_find_LDT_entry
3064 *
3065 * Input:
3066 * ptid_t ptid; // The GDB-style pid-plus-LWP.
3067 *
3068 * Return:
3069 * pointer to the corresponding LDT entry.
3070 */
3071
3072 struct ssd *
3073 procfs_find_LDT_entry (ptid_t ptid)
3074 {
3075 gdb_gregset_t *gregs;
3076 int key;
3077 procinfo *pi;
3078
3079 /* Find procinfo for the lwp. */
3080 if ((pi = find_procinfo (PIDGET (ptid), TIDGET (ptid))) == NULL)
3081 {
3082 warning (_("procfs_find_LDT_entry: could not find procinfo for %d:%ld."),
3083 PIDGET (ptid), TIDGET (ptid));
3084 return NULL;
3085 }
3086 /* get its general registers. */
3087 if ((gregs = proc_get_gregs (pi)) == NULL)
3088 {
3089 warning (_("procfs_find_LDT_entry: could not read gregs for %d:%ld."),
3090 PIDGET (ptid), TIDGET (ptid));
3091 return NULL;
3092 }
3093 /* Now extract the GS register's lower 16 bits. */
3094 key = (*gregs)[GS] & 0xffff;
3095
3096 /* Find the matching entry and return it. */
3097 return proc_get_LDT_entry (pi, key);
3098 }
3099
3100 #endif
3101
3102 /* =============== END, non-thread part of /proc "MODULE" =============== */
3103
3104 /* =================== Thread "MODULE" =================== */
3105
3106 /* NOTE: you'll see more ifdefs and duplication of functions here,
3107 since there is a different way to do threads on every OS. */
3108
3109 /*
3110 * Function: proc_get_nthreads
3111 *
3112 * Return the number of threads for the process
3113 */
3114
3115 #if defined (PIOCNTHR) && defined (PIOCTLIST)
3116 /*
3117 * OSF version
3118 */
3119 int
3120 proc_get_nthreads (procinfo *pi)
3121 {
3122 int nthreads = 0;
3123
3124 if (ioctl (pi->ctl_fd, PIOCNTHR, &nthreads) < 0)
3125 proc_warn (pi, "procfs: PIOCNTHR failed", __LINE__);
3126
3127 return nthreads;
3128 }
3129
3130 #else
3131 #if defined (SYS_lwpcreate) || defined (SYS_lwp_create) /* FIXME: multiple */
3132 /*
3133 * Solaris and Unixware version
3134 */
3135 int
3136 proc_get_nthreads (procinfo *pi)
3137 {
3138 if (!pi->status_valid)
3139 if (!proc_get_status (pi))
3140 return 0;
3141
3142 /*
3143 * NEW_PROC_API: only works for the process procinfo,
3144 * because the LWP procinfos do not get prstatus filled in.
3145 */
3146 #ifdef NEW_PROC_API
3147 if (pi->tid != 0) /* find the parent process procinfo */
3148 pi = find_procinfo_or_die (pi->pid, 0);
3149 #endif
3150 return pi->prstatus.pr_nlwp;
3151 }
3152
3153 #else
3154 /*
3155 * Default version
3156 */
3157 int
3158 proc_get_nthreads (procinfo *pi)
3159 {
3160 return 0;
3161 }
3162 #endif
3163 #endif
3164
3165 /*
3166 * Function: proc_get_current_thread (LWP version)
3167 *
3168 * Return the ID of the thread that had an event of interest.
3169 * (ie. the one that hit a breakpoint or other traced event).
3170 * All other things being equal, this should be the ID of a
3171 * thread that is currently executing.
3172 */
3173
3174 #if defined (SYS_lwpcreate) || defined (SYS_lwp_create) /* FIXME: multiple */
3175 /*
3176 * Solaris and Unixware version
3177 */
3178 int
3179 proc_get_current_thread (procinfo *pi)
3180 {
3181 /*
3182 * Note: this should be applied to the root procinfo for the process,
3183 * not to the procinfo for an LWP. If applied to the procinfo for
3184 * an LWP, it will simply return that LWP's ID. In that case,
3185 * find the parent process procinfo.
3186 */
3187
3188 if (pi->tid != 0)
3189 pi = find_procinfo_or_die (pi->pid, 0);
3190
3191 if (!pi->status_valid)
3192 if (!proc_get_status (pi))
3193 return 0;
3194
3195 #ifdef NEW_PROC_API
3196 return pi->prstatus.pr_lwp.pr_lwpid;
3197 #else
3198 return pi->prstatus.pr_who;
3199 #endif
3200 }
3201
3202 #else
3203 #if defined (PIOCNTHR) && defined (PIOCTLIST)
3204 /*
3205 * OSF version
3206 */
3207 int
3208 proc_get_current_thread (procinfo *pi)
3209 {
3210 #if 0 /* FIXME: not ready for prime time? */
3211 return pi->prstatus.pr_tid;
3212 #else
3213 return 0;
3214 #endif
3215 }
3216
3217 #else
3218 /*
3219 * Default version
3220 */
3221 int
3222 proc_get_current_thread (procinfo *pi)
3223 {
3224 return 0;
3225 }
3226
3227 #endif
3228 #endif
3229
3230 /*
3231 * Function: proc_update_threads
3232 *
3233 * Discover the IDs of all the threads within the process, and
3234 * create a procinfo for each of them (chained to the parent).
3235 *
3236 * This unfortunately requires a different method on every OS.
3237 *
3238 * Return: non-zero for success, zero for failure.
3239 */
3240
3241 int
3242 proc_delete_dead_threads (procinfo *parent, procinfo *thread, void *ignore)
3243 {
3244 if (thread && parent) /* sanity */
3245 {
3246 thread->status_valid = 0;
3247 if (!proc_get_status (thread))
3248 destroy_one_procinfo (&parent->thread_list, thread);
3249 }
3250 return 0; /* keep iterating */
3251 }
3252
3253 #if defined (PIOCLSTATUS)
3254 /*
3255 * Solaris 2.5 (ioctl) version
3256 */
3257 int
3258 proc_update_threads (procinfo *pi)
3259 {
3260 gdb_prstatus_t *prstatus;
3261 struct cleanup *old_chain = NULL;
3262 procinfo *thread;
3263 int nlwp, i;
3264
3265 /*
3266 * We should never have to apply this operation to any procinfo
3267 * except the one for the main process. If that ever changes
3268 * for any reason, then take out the following clause and
3269 * replace it with one that makes sure the ctl_fd is open.
3270 */
3271
3272 if (pi->tid != 0)
3273 pi = find_procinfo_or_die (pi->pid, 0);
3274
3275 proc_iterate_over_threads (pi, proc_delete_dead_threads, NULL);
3276
3277 if ((nlwp = proc_get_nthreads (pi)) <= 1)
3278 return 1; /* Process is not multi-threaded; nothing to do. */
3279
3280 prstatus = xmalloc (sizeof (gdb_prstatus_t) * (nlwp + 1));
3281
3282 old_chain = make_cleanup (xfree, prstatus);
3283 if (ioctl (pi->ctl_fd, PIOCLSTATUS, prstatus) < 0)
3284 proc_error (pi, "update_threads (PIOCLSTATUS)", __LINE__);
3285
3286 /* Skip element zero, which represents the process as a whole. */
3287 for (i = 1; i < nlwp + 1; i++)
3288 {
3289 if ((thread = create_procinfo (pi->pid, prstatus[i].pr_who)) == NULL)
3290 proc_error (pi, "update_threads, create_procinfo", __LINE__);
3291
3292 memcpy (&thread->prstatus, &prstatus[i], sizeof (*prstatus));
3293 thread->status_valid = 1;
3294 }
3295 pi->threads_valid = 1;
3296 do_cleanups (old_chain);
3297 return 1;
3298 }
3299 #else
3300 #ifdef NEW_PROC_API
3301 /*
3302 * Unixware and Solaris 6 (and later) version
3303 */
3304 static void
3305 do_closedir_cleanup (void *dir)
3306 {
3307 closedir (dir);
3308 }
3309
3310 int
3311 proc_update_threads (procinfo *pi)
3312 {
3313 char pathname[MAX_PROC_NAME_SIZE + 16];
3314 struct dirent *direntry;
3315 struct cleanup *old_chain = NULL;
3316 procinfo *thread;
3317 DIR *dirp;
3318 int lwpid;
3319
3320 /*
3321 * We should never have to apply this operation to any procinfo
3322 * except the one for the main process. If that ever changes
3323 * for any reason, then take out the following clause and
3324 * replace it with one that makes sure the ctl_fd is open.
3325 */
3326
3327 if (pi->tid != 0)
3328 pi = find_procinfo_or_die (pi->pid, 0);
3329
3330 proc_iterate_over_threads (pi, proc_delete_dead_threads, NULL);
3331
3332 /*
3333 * Unixware
3334 *
3335 * Note: this brute-force method is the only way I know of
3336 * to accomplish this task on Unixware. This method will
3337 * also work on Solaris 2.6 and 2.7. There is a much simpler
3338 * and more elegant way to do this on Solaris, but the margins
3339 * of this manuscript are too small to write it here... ;-)
3340 */
3341
3342 strcpy (pathname, pi->pathname);
3343 strcat (pathname, "/lwp");
3344 if ((dirp = opendir (pathname)) == NULL)
3345 proc_error (pi, "update_threads, opendir", __LINE__);
3346
3347 old_chain = make_cleanup (do_closedir_cleanup, dirp);
3348 while ((direntry = readdir (dirp)) != NULL)
3349 if (direntry->d_name[0] != '.') /* skip '.' and '..' */
3350 {
3351 lwpid = atoi (&direntry->d_name[0]);
3352 if ((thread = create_procinfo (pi->pid, lwpid)) == NULL)
3353 proc_error (pi, "update_threads, create_procinfo", __LINE__);
3354 }
3355 pi->threads_valid = 1;
3356 do_cleanups (old_chain);
3357 return 1;
3358 }
3359 #else
3360 #ifdef PIOCTLIST
3361 /*
3362 * OSF version
3363 */
3364 int
3365 proc_update_threads (procinfo *pi)
3366 {
3367 int nthreads, i;
3368 tid_t *threads;
3369
3370 /*
3371 * We should never have to apply this operation to any procinfo
3372 * except the one for the main process. If that ever changes
3373 * for any reason, then take out the following clause and
3374 * replace it with one that makes sure the ctl_fd is open.
3375 */
3376
3377 if (pi->tid != 0)
3378 pi = find_procinfo_or_die (pi->pid, 0);
3379
3380 proc_iterate_over_threads (pi, proc_delete_dead_threads, NULL);
3381
3382 nthreads = proc_get_nthreads (pi);
3383 if (nthreads < 2)
3384 return 0; /* nothing to do for 1 or fewer threads */
3385
3386 threads = xmalloc (nthreads * sizeof (tid_t));
3387
3388 if (ioctl (pi->ctl_fd, PIOCTLIST, threads) < 0)
3389 proc_error (pi, "procfs: update_threads (PIOCTLIST)", __LINE__);
3390
3391 for (i = 0; i < nthreads; i++)
3392 {
3393 if (!find_procinfo (pi->pid, threads[i]))
3394 if (!create_procinfo (pi->pid, threads[i]))
3395 proc_error (pi, "update_threads, create_procinfo", __LINE__);
3396 }
3397 pi->threads_valid = 1;
3398 return 1;
3399 }
3400 #else
3401 /*
3402 * Default version
3403 */
3404 int
3405 proc_update_threads (procinfo *pi)
3406 {
3407 return 0;
3408 }
3409 #endif /* OSF PIOCTLIST */
3410 #endif /* NEW_PROC_API */
3411 #endif /* SOL 2.5 PIOCLSTATUS */
3412
3413 /*
3414 * Function: proc_iterate_over_threads
3415 *
3416 * Description:
3417 * Given a pointer to a function, call that function once
3418 * for each lwp in the procinfo list, until the function
3419 * returns non-zero, in which event return the value
3420 * returned by the function.
3421 *
3422 * Note: this function does NOT call update_threads.
3423 * If you want to discover new threads first, you must
3424 * call that function explicitly. This function just makes
3425 * a quick pass over the currently-known procinfos.
3426 *
3427 * Arguments:
3428 * pi - parent process procinfo
3429 * func - per-thread function
3430 * ptr - opaque parameter for function.
3431 *
3432 * Return:
3433 * First non-zero return value from the callee, or zero.
3434 */
3435
3436 int
3437 proc_iterate_over_threads (procinfo *pi,
3438 int (*func) (procinfo *, procinfo *, void *),
3439 void *ptr)
3440 {
3441 procinfo *thread, *next;
3442 int retval = 0;
3443
3444 /*
3445 * We should never have to apply this operation to any procinfo
3446 * except the one for the main process. If that ever changes
3447 * for any reason, then take out the following clause and
3448 * replace it with one that makes sure the ctl_fd is open.
3449 */
3450
3451 if (pi->tid != 0)
3452 pi = find_procinfo_or_die (pi->pid, 0);
3453
3454 for (thread = pi->thread_list; thread != NULL; thread = next)
3455 {
3456 next = thread->next; /* in case thread is destroyed */
3457 if ((retval = (*func) (pi, thread, ptr)) != 0)
3458 break;
3459 }
3460
3461 return retval;
3462 }
3463
3464 /* =================== END, Thread "MODULE" =================== */
3465
3466 /* =================== END, /proc "MODULE" =================== */
3467
3468 /* =================== GDB "MODULE" =================== */
3469
3470 /*
3471 * Here are all of the gdb target vector functions and their friends.
3472 */
3473
3474 static ptid_t do_attach (ptid_t ptid);
3475 static void do_detach (int signo);
3476 static int register_gdb_signals (procinfo *, gdb_sigset_t *);
3477 static void proc_trace_syscalls_1 (procinfo *pi, int syscallnum,
3478 int entry_or_exit, int mode, int from_tty);
3479
3480 /* On mips-irix, we need to insert a breakpoint at __dbx_link during
3481 the startup phase. The following two variables are used to record
3482 the address of the breakpoint, and the code that was replaced by
3483 a breakpoint. */
3484 static int dbx_link_bpt_addr = 0;
3485 static void *dbx_link_bpt;
3486
3487 /*
3488 * Function: procfs_debug_inferior
3489 *
3490 * Sets up the inferior to be debugged.
3491 * Registers to trace signals, hardware faults, and syscalls.
3492 * Note: does not set RLC flag: caller may want to customize that.
3493 *
3494 * Returns: zero for success (note! unlike most functions in this module)
3495 * On failure, returns the LINE NUMBER where it failed!
3496 */
3497
3498 static int
3499 procfs_debug_inferior (procinfo *pi)
3500 {
3501 fltset_t traced_faults;
3502 gdb_sigset_t traced_signals;
3503 sysset_t *traced_syscall_entries;
3504 sysset_t *traced_syscall_exits;
3505 int status;
3506
3507 #ifdef PROCFS_DONT_TRACE_FAULTS
3508 /* On some systems (OSF), we don't trace hardware faults.
3509 Apparently it's enough that we catch them as signals.
3510 Wonder why we don't just do that in general? */
3511 premptyset (&traced_faults); /* don't trace faults. */
3512 #else
3513 /* Register to trace hardware faults in the child. */
3514 prfillset (&traced_faults); /* trace all faults... */
3515 gdb_prdelset (&traced_faults, FLTPAGE); /* except page fault. */
3516 #endif
3517 if (!proc_set_traced_faults (pi, &traced_faults))
3518 return __LINE__;
3519
3520 /* Register to trace selected signals in the child. */
3521 premptyset (&traced_signals);
3522 if (!register_gdb_signals (pi, &traced_signals))
3523 return __LINE__;
3524
3525
3526 /* Register to trace the 'exit' system call (on entry). */
3527 traced_syscall_entries = sysset_t_alloc (pi);
3528 gdb_premptysysset (traced_syscall_entries);
3529 #ifdef SYS_exit
3530 gdb_praddsysset (traced_syscall_entries, SYS_exit);
3531 #endif
3532 #ifdef SYS_lwpexit
3533 gdb_praddsysset (traced_syscall_entries, SYS_lwpexit); /* And _lwp_exit... */
3534 #endif
3535 #ifdef SYS_lwp_exit
3536 gdb_praddsysset (traced_syscall_entries, SYS_lwp_exit);
3537 #endif
3538 #ifdef DYNAMIC_SYSCALLS
3539 {
3540 int callnum = find_syscall (pi, "_exit");
3541 if (callnum >= 0)
3542 gdb_praddsysset (traced_syscall_entries, callnum);
3543 }
3544 #endif
3545
3546 status = proc_set_traced_sysentry (pi, traced_syscall_entries);
3547 xfree (traced_syscall_entries);
3548 if (!status)
3549 return __LINE__;
3550
3551 #ifdef PRFS_STOPEXEC /* defined on OSF */
3552 /* OSF method for tracing exec syscalls. Quoting:
3553 Under Alpha OSF/1 we have to use a PIOCSSPCACT ioctl to trace
3554 exits from exec system calls because of the user level loader. */
3555 /* FIXME: make nice and maybe move into an access function. */
3556 {
3557 int prfs_flags;
3558
3559 if (ioctl (pi->ctl_fd, PIOCGSPCACT, &prfs_flags) < 0)
3560 return __LINE__;
3561
3562 prfs_flags |= PRFS_STOPEXEC;
3563
3564 if (ioctl (pi->ctl_fd, PIOCSSPCACT, &prfs_flags) < 0)
3565 return __LINE__;
3566 }
3567 #else /* not PRFS_STOPEXEC */
3568 /* Everyone else's (except OSF) method for tracing exec syscalls */
3569 /* GW: Rationale...
3570 Not all systems with /proc have all the exec* syscalls with the same
3571 names. On the SGI, for example, there is no SYS_exec, but there
3572 *is* a SYS_execv. So, we try to account for that. */
3573
3574 traced_syscall_exits = sysset_t_alloc (pi);
3575 gdb_premptysysset (traced_syscall_exits);
3576 #ifdef SYS_exec
3577 gdb_praddsysset (traced_syscall_exits, SYS_exec);
3578 #endif
3579 #ifdef SYS_execve
3580 gdb_praddsysset (traced_syscall_exits, SYS_execve);
3581 #endif
3582 #ifdef SYS_execv
3583 gdb_praddsysset (traced_syscall_exits, SYS_execv);
3584 #endif
3585
3586 #ifdef SYS_lwpcreate
3587 gdb_praddsysset (traced_syscall_exits, SYS_lwpcreate);
3588 gdb_praddsysset (traced_syscall_exits, SYS_lwpexit);
3589 #endif
3590
3591 #ifdef SYS_lwp_create /* FIXME: once only, please */
3592 gdb_praddsysset (traced_syscall_exits, SYS_lwp_create);
3593 gdb_praddsysset (traced_syscall_exits, SYS_lwp_exit);
3594 #endif
3595
3596 #ifdef DYNAMIC_SYSCALLS
3597 {
3598 int callnum = find_syscall (pi, "execve");
3599 if (callnum >= 0)
3600 gdb_praddsysset (traced_syscall_exits, callnum);
3601 callnum = find_syscall (pi, "ra_execve");
3602 if (callnum >= 0)
3603 gdb_praddsysset (traced_syscall_exits, callnum);
3604 }
3605 #endif
3606
3607 status = proc_set_traced_sysexit (pi, traced_syscall_exits);
3608 xfree (traced_syscall_exits);
3609 if (!status)
3610 return __LINE__;
3611
3612 #endif /* PRFS_STOPEXEC */
3613 return 0;
3614 }
3615
3616 static void
3617 procfs_attach (struct target_ops *ops, char *args, int from_tty)
3618 {
3619 char *exec_file;
3620 int pid;
3621
3622 pid = parse_pid_to_attach (args);
3623
3624 if (pid == getpid ())
3625 error (_("Attaching GDB to itself is not a good idea..."));
3626
3627 if (from_tty)
3628 {
3629 exec_file = get_exec_file (0);
3630
3631 if (exec_file)
3632 printf_filtered (_("Attaching to program `%s', %s\n"),
3633 exec_file, target_pid_to_str (pid_to_ptid (pid)));
3634 else
3635 printf_filtered (_("Attaching to %s\n"),
3636 target_pid_to_str (pid_to_ptid (pid)));
3637
3638 fflush (stdout);
3639 }
3640 inferior_ptid = do_attach (pid_to_ptid (pid));
3641 push_target (ops);
3642 }
3643
3644 static void
3645 procfs_detach (struct target_ops *ops, char *args, int from_tty)
3646 {
3647 int sig = 0;
3648 int pid = PIDGET (inferior_ptid);
3649
3650 if (args)
3651 sig = atoi (args);
3652
3653 if (from_tty)
3654 {
3655 char *exec_file;
3656
3657 exec_file = get_exec_file (0);
3658 if (exec_file == NULL)
3659 exec_file = "";
3660
3661 printf_filtered (_("Detaching from program: %s, %s\n"), exec_file,
3662 target_pid_to_str (pid_to_ptid (pid)));
3663 gdb_flush (gdb_stdout);
3664 }
3665
3666 do_detach (sig);
3667
3668 inferior_ptid = null_ptid;
3669 detach_inferior (pid);
3670 unpush_target (ops);
3671 }
3672
3673 static ptid_t
3674 do_attach (ptid_t ptid)
3675 {
3676 procinfo *pi;
3677 struct inferior *inf;
3678 int fail;
3679 int lwpid;
3680
3681 if ((pi = create_procinfo (PIDGET (ptid), 0)) == NULL)
3682 perror (_("procfs: out of memory in 'attach'"));
3683
3684 if (!open_procinfo_files (pi, FD_CTL))
3685 {
3686 fprintf_filtered (gdb_stderr, "procfs:%d -- ", __LINE__);
3687 sprintf (errmsg, "do_attach: couldn't open /proc file for process %d",
3688 PIDGET (ptid));
3689 dead_procinfo (pi, errmsg, NOKILL);
3690 }
3691
3692 /* Stop the process (if it isn't already stopped). */
3693 if (proc_flags (pi) & (PR_STOPPED | PR_ISTOP))
3694 {
3695 pi->was_stopped = 1;
3696 proc_prettyprint_why (proc_why (pi), proc_what (pi), 1);
3697 }
3698 else
3699 {
3700 pi->was_stopped = 0;
3701 /* Set the process to run again when we close it. */
3702 if (!proc_set_run_on_last_close (pi))
3703 dead_procinfo (pi, "do_attach: couldn't set RLC.", NOKILL);
3704
3705 /* Now stop the process. */
3706 if (!proc_stop_process (pi))
3707 dead_procinfo (pi, "do_attach: couldn't stop the process.", NOKILL);
3708 pi->ignore_next_sigstop = 1;
3709 }
3710 /* Save some of the /proc state to be restored if we detach. */
3711 if (!proc_get_traced_faults (pi, &pi->saved_fltset))
3712 dead_procinfo (pi, "do_attach: couldn't save traced faults.", NOKILL);
3713 if (!proc_get_traced_signals (pi, &pi->saved_sigset))
3714 dead_procinfo (pi, "do_attach: couldn't save traced signals.", NOKILL);
3715 if (!proc_get_traced_sysentry (pi, pi->saved_entryset))
3716 dead_procinfo (pi, "do_attach: couldn't save traced syscall entries.",
3717 NOKILL);
3718 if (!proc_get_traced_sysexit (pi, pi->saved_exitset))
3719 dead_procinfo (pi, "do_attach: couldn't save traced syscall exits.",
3720 NOKILL);
3721 if (!proc_get_held_signals (pi, &pi->saved_sighold))
3722 dead_procinfo (pi, "do_attach: couldn't save held signals.", NOKILL);
3723
3724 if ((fail = procfs_debug_inferior (pi)) != 0)
3725 dead_procinfo (pi, "do_attach: failed in procfs_debug_inferior", NOKILL);
3726
3727 inf = current_inferior ();
3728 inferior_appeared (inf, pi->pid);
3729 /* Let GDB know that the inferior was attached. */
3730 inf->attach_flag = 1;
3731
3732 /* Create a procinfo for the current lwp. */
3733 lwpid = proc_get_current_thread (pi);
3734 create_procinfo (pi->pid, lwpid);
3735
3736 /* Add it to gdb's thread list. */
3737 ptid = MERGEPID (pi->pid, lwpid);
3738 add_thread (ptid);
3739
3740 return ptid;
3741 }
3742
3743 static void
3744 do_detach (int signo)
3745 {
3746 procinfo *pi;
3747
3748 /* Find procinfo for the main process */
3749 pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0); /* FIXME: threads */
3750 if (signo)
3751 if (!proc_set_current_signal (pi, signo))
3752 proc_warn (pi, "do_detach, set_current_signal", __LINE__);
3753
3754 if (!proc_set_traced_signals (pi, &pi->saved_sigset))
3755 proc_warn (pi, "do_detach, set_traced_signal", __LINE__);
3756
3757 if (!proc_set_traced_faults (pi, &pi->saved_fltset))
3758 proc_warn (pi, "do_detach, set_traced_faults", __LINE__);
3759
3760 if (!proc_set_traced_sysentry (pi, pi->saved_entryset))
3761 proc_warn (pi, "do_detach, set_traced_sysentry", __LINE__);
3762
3763 if (!proc_set_traced_sysexit (pi, pi->saved_exitset))
3764 proc_warn (pi, "do_detach, set_traced_sysexit", __LINE__);
3765
3766 if (!proc_set_held_signals (pi, &pi->saved_sighold))
3767 proc_warn (pi, "do_detach, set_held_signals", __LINE__);
3768
3769 if (signo || (proc_flags (pi) & (PR_STOPPED | PR_ISTOP)))
3770 if (signo || !(pi->was_stopped) ||
3771 query (_("Was stopped when attached, make it runnable again? ")))
3772 {
3773 /* Clear any pending signal. */
3774 if (!proc_clear_current_fault (pi))
3775 proc_warn (pi, "do_detach, clear_current_fault", __LINE__);
3776
3777 if (signo == 0 && !proc_clear_current_signal (pi))
3778 proc_warn (pi, "do_detach, clear_current_signal", __LINE__);
3779
3780 if (!proc_set_run_on_last_close (pi))
3781 proc_warn (pi, "do_detach, set_rlc", __LINE__);
3782 }
3783
3784 destroy_procinfo (pi);
3785 }
3786
3787 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
3788 for all registers.
3789
3790 ??? Is the following note still relevant? We can't get individual
3791 registers with the PT_GETREGS ptrace(2) request either, yet we
3792 don't bother with caching at all in that case.
3793
3794 NOTE: Since the /proc interface cannot give us individual
3795 registers, we pay no attention to REGNUM, and just fetch them all.
3796 This results in the possibility that we will do unnecessarily many
3797 fetches, since we may be called repeatedly for individual
3798 registers. So we cache the results, and mark the cache invalid
3799 when the process is resumed. */
3800
3801 static void
3802 procfs_fetch_registers (struct target_ops *ops,
3803 struct regcache *regcache, int regnum)
3804 {
3805 gdb_gregset_t *gregs;
3806 procinfo *pi;
3807 int pid = PIDGET (inferior_ptid);
3808 int tid = TIDGET (inferior_ptid);
3809 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3810
3811 pi = find_procinfo_or_die (pid, tid);
3812
3813 if (pi == NULL)
3814 error (_("procfs: fetch_registers failed to find procinfo for %s"),
3815 target_pid_to_str (inferior_ptid));
3816
3817 gregs = proc_get_gregs (pi);
3818 if (gregs == NULL)
3819 proc_error (pi, "fetch_registers, get_gregs", __LINE__);
3820
3821 supply_gregset (regcache, (const gdb_gregset_t *) gregs);
3822
3823 if (gdbarch_fp0_regnum (gdbarch) >= 0) /* Do we have an FPU? */
3824 {
3825 gdb_fpregset_t *fpregs;
3826
3827 if ((regnum >= 0 && regnum < gdbarch_fp0_regnum (gdbarch))
3828 || regnum == gdbarch_pc_regnum (gdbarch)
3829 || regnum == gdbarch_sp_regnum (gdbarch))
3830 return; /* Not a floating point register. */
3831
3832 fpregs = proc_get_fpregs (pi);
3833 if (fpregs == NULL)
3834 proc_error (pi, "fetch_registers, get_fpregs", __LINE__);
3835
3836 supply_fpregset (regcache, (const gdb_fpregset_t *) fpregs);
3837 }
3838 }
3839
3840 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
3841 this for all registers.
3842
3843 NOTE: Since the /proc interface will not read individual registers,
3844 we will cache these requests until the process is resumed, and only
3845 then write them back to the inferior process.
3846
3847 FIXME: is that a really bad idea? Have to think about cases where
3848 writing one register might affect the value of others, etc. */
3849
3850 static void
3851 procfs_store_registers (struct target_ops *ops,
3852 struct regcache *regcache, int regnum)
3853 {
3854 gdb_gregset_t *gregs;
3855 procinfo *pi;
3856 int pid = PIDGET (inferior_ptid);
3857 int tid = TIDGET (inferior_ptid);
3858 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3859
3860 pi = find_procinfo_or_die (pid, tid);
3861
3862 if (pi == NULL)
3863 error (_("procfs: store_registers: failed to find procinfo for %s"),
3864 target_pid_to_str (inferior_ptid));
3865
3866 gregs = proc_get_gregs (pi);
3867 if (gregs == NULL)
3868 proc_error (pi, "store_registers, get_gregs", __LINE__);
3869
3870 fill_gregset (regcache, gregs, regnum);
3871 if (!proc_set_gregs (pi))
3872 proc_error (pi, "store_registers, set_gregs", __LINE__);
3873
3874 if (gdbarch_fp0_regnum (gdbarch) >= 0) /* Do we have an FPU? */
3875 {
3876 gdb_fpregset_t *fpregs;
3877
3878 if ((regnum >= 0 && regnum < gdbarch_fp0_regnum (gdbarch))
3879 || regnum == gdbarch_pc_regnum (gdbarch)
3880 || regnum == gdbarch_sp_regnum (gdbarch))
3881 return; /* Not a floating point register. */
3882
3883 fpregs = proc_get_fpregs (pi);
3884 if (fpregs == NULL)
3885 proc_error (pi, "store_registers, get_fpregs", __LINE__);
3886
3887 fill_fpregset (regcache, fpregs, regnum);
3888 if (!proc_set_fpregs (pi))
3889 proc_error (pi, "store_registers, set_fpregs", __LINE__);
3890 }
3891 }
3892
3893 static int
3894 syscall_is_lwp_exit (procinfo *pi, int scall)
3895 {
3896
3897 #ifdef SYS_lwp_exit
3898 if (scall == SYS_lwp_exit)
3899 return 1;
3900 #endif
3901 #ifdef SYS_lwpexit
3902 if (scall == SYS_lwpexit)
3903 return 1;
3904 #endif
3905 return 0;
3906 }
3907
3908 static int
3909 syscall_is_exit (procinfo *pi, int scall)
3910 {
3911 #ifdef SYS_exit
3912 if (scall == SYS_exit)
3913 return 1;
3914 #endif
3915 #ifdef DYNAMIC_SYSCALLS
3916 if (find_syscall (pi, "_exit") == scall)
3917 return 1;
3918 #endif
3919 return 0;
3920 }
3921
3922 static int
3923 syscall_is_exec (procinfo *pi, int scall)
3924 {
3925 #ifdef SYS_exec
3926 if (scall == SYS_exec)
3927 return 1;
3928 #endif
3929 #ifdef SYS_execv
3930 if (scall == SYS_execv)
3931 return 1;
3932 #endif
3933 #ifdef SYS_execve
3934 if (scall == SYS_execve)
3935 return 1;
3936 #endif
3937 #ifdef DYNAMIC_SYSCALLS
3938 if (find_syscall (pi, "_execve"))
3939 return 1;
3940 if (find_syscall (pi, "ra_execve"))
3941 return 1;
3942 #endif
3943 return 0;
3944 }
3945
3946 static int
3947 syscall_is_lwp_create (procinfo *pi, int scall)
3948 {
3949 #ifdef SYS_lwp_create
3950 if (scall == SYS_lwp_create)
3951 return 1;
3952 #endif
3953 #ifdef SYS_lwpcreate
3954 if (scall == SYS_lwpcreate)
3955 return 1;
3956 #endif
3957 return 0;
3958 }
3959
3960 /* Remove the breakpoint that we inserted in __dbx_link().
3961 Does nothing if the breakpoint hasn't been inserted or has already
3962 been removed. */
3963
3964 static void
3965 remove_dbx_link_breakpoint (void)
3966 {
3967 if (dbx_link_bpt_addr == 0)
3968 return;
3969
3970 if (deprecated_remove_raw_breakpoint (target_gdbarch, dbx_link_bpt) != 0)
3971 warning (_("Unable to remove __dbx_link breakpoint."));
3972
3973 dbx_link_bpt_addr = 0;
3974 dbx_link_bpt = NULL;
3975 }
3976
3977 #ifdef SYS_syssgi
3978 /* Return the address of the __dbx_link() function in the file
3979 refernced by ABFD by scanning its symbol table. Return 0 if
3980 the symbol was not found. */
3981
3982 static CORE_ADDR
3983 dbx_link_addr (bfd *abfd)
3984 {
3985 long storage_needed;
3986 asymbol **symbol_table;
3987 long number_of_symbols;
3988 long i;
3989
3990 storage_needed = bfd_get_symtab_upper_bound (abfd);
3991 if (storage_needed <= 0)
3992 return 0;
3993
3994 symbol_table = (asymbol **) xmalloc (storage_needed);
3995 make_cleanup (xfree, symbol_table);
3996
3997 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
3998
3999 for (i = 0; i < number_of_symbols; i++)
4000 {
4001 asymbol *sym = symbol_table[i];
4002
4003 if ((sym->flags & BSF_GLOBAL)
4004 && sym->name != NULL && strcmp (sym->name, "__dbx_link") == 0)
4005 return (sym->value + sym->section->vma);
4006 }
4007
4008 /* Symbol not found, return NULL. */
4009 return 0;
4010 }
4011
4012 /* Search the symbol table of the file referenced by FD for a symbol
4013 named __dbx_link(). If found, then insert a breakpoint at this location,
4014 and return nonzero. Return zero otherwise. */
4015
4016 static int
4017 insert_dbx_link_bpt_in_file (int fd, CORE_ADDR ignored)
4018 {
4019 bfd *abfd;
4020 long storage_needed;
4021 CORE_ADDR sym_addr;
4022
4023 abfd = bfd_fdopenr ("unamed", 0, fd);
4024 if (abfd == NULL)
4025 {
4026 warning (_("Failed to create a bfd: %s."), bfd_errmsg (bfd_get_error ()));
4027 return 0;
4028 }
4029
4030 if (!bfd_check_format (abfd, bfd_object))
4031 {
4032 /* Not the correct format, so we can not possibly find the dbx_link
4033 symbol in it. */
4034 bfd_close (abfd);
4035 return 0;
4036 }
4037
4038 sym_addr = dbx_link_addr (abfd);
4039 if (sym_addr != 0)
4040 {
4041 /* Insert the breakpoint. */
4042 dbx_link_bpt_addr = sym_addr;
4043 dbx_link_bpt = deprecated_insert_raw_breakpoint (target_gdbarch, NULL,
4044 sym_addr);
4045 if (dbx_link_bpt == NULL)
4046 {
4047 warning (_("Failed to insert dbx_link breakpoint."));
4048 bfd_close (abfd);
4049 return 0;
4050 }
4051 bfd_close (abfd);
4052 return 1;
4053 }
4054
4055 bfd_close (abfd);
4056 return 0;
4057 }
4058
4059 /* Calls the supplied callback function once for each mapped address
4060 space in the process. The callback function receives an open
4061 file descriptor for the file corresponding to that mapped
4062 address space (if there is one), and the base address of the
4063 mapped space. Quit when the callback function returns a
4064 nonzero value, or at teh end of the mappings.
4065
4066 Returns: the first non-zero return value of the callback function,
4067 or zero. */
4068
4069 static int
4070 solib_mappings_callback (struct prmap *map, int (*func) (int, CORE_ADDR),
4071 void *data)
4072 {
4073 procinfo *pi = data;
4074 int fd;
4075
4076 #ifdef NEW_PROC_API
4077 char name[MAX_PROC_NAME_SIZE + sizeof (map->pr_mapname)];
4078
4079 if (map->pr_vaddr == 0 && map->pr_size == 0)
4080 return -1; /* sanity */
4081
4082 if (map->pr_mapname[0] == 0)
4083 {
4084 fd = -1; /* no map file */
4085 }
4086 else
4087 {
4088 sprintf (name, "/proc/%d/object/%s", pi->pid, map->pr_mapname);
4089 /* Note: caller's responsibility to close this fd! */
4090 fd = open_with_retry (name, O_RDONLY);
4091 /* Note: we don't test the above call for failure;
4092 we just pass the FD on as given. Sometimes there is
4093 no file, so the open may return failure, but that's
4094 not a problem. */
4095 }
4096 #else
4097 fd = ioctl (pi->ctl_fd, PIOCOPENM, &map->pr_vaddr);
4098 /* Note: we don't test the above call for failure;
4099 we just pass the FD on as given. Sometimes there is
4100 no file, so the ioctl may return failure, but that's
4101 not a problem. */
4102 #endif
4103 return (*func) (fd, (CORE_ADDR) map->pr_vaddr);
4104 }
4105
4106 /* If the given memory region MAP contains a symbol named __dbx_link,
4107 insert a breakpoint at this location and return nonzero. Return
4108 zero otherwise. */
4109
4110 static int
4111 insert_dbx_link_bpt_in_region (struct prmap *map,
4112 iterate_over_mappings_cb_ftype *child_func,
4113 void *data)
4114 {
4115 procinfo *pi = (procinfo *) data;
4116
4117 /* We know the symbol we're looking for is in a text region, so
4118 only look for it if the region is a text one. */
4119 if (map->pr_mflags & MA_EXEC)
4120 return solib_mappings_callback (map, insert_dbx_link_bpt_in_file, pi);
4121
4122 return 0;
4123 }
4124
4125 /* Search all memory regions for a symbol named __dbx_link. If found,
4126 insert a breakpoint at its location, and return nonzero. Return zero
4127 otherwise. */
4128
4129 static int
4130 insert_dbx_link_breakpoint (procinfo *pi)
4131 {
4132 return iterate_over_mappings (pi, NULL, pi, insert_dbx_link_bpt_in_region);
4133 }
4134 #endif
4135
4136 /*
4137 * Function: target_wait
4138 *
4139 * Retrieve the next stop event from the child process.
4140 * If child has not stopped yet, wait for it to stop.
4141 * Translate /proc eventcodes (or possibly wait eventcodes)
4142 * into gdb internal event codes.
4143 *
4144 * Return: id of process (and possibly thread) that incurred the event.
4145 * event codes are returned thru a pointer parameter.
4146 */
4147
4148 static ptid_t
4149 procfs_wait (struct target_ops *ops,
4150 ptid_t ptid, struct target_waitstatus *status, int options)
4151 {
4152 /* First cut: loosely based on original version 2.1 */
4153 procinfo *pi;
4154 int wstat;
4155 int temp_tid;
4156 ptid_t retval, temp_ptid;
4157 int why, what, flags;
4158 int retry = 0;
4159
4160 wait_again:
4161
4162 retry++;
4163 wstat = 0;
4164 retval = pid_to_ptid (-1);
4165
4166 /* Find procinfo for main process */
4167 pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
4168 if (pi)
4169 {
4170 /* We must assume that the status is stale now... */
4171 pi->status_valid = 0;
4172 pi->gregs_valid = 0;
4173 pi->fpregs_valid = 0;
4174
4175 #if 0 /* just try this out... */
4176 flags = proc_flags (pi);
4177 why = proc_why (pi);
4178 if ((flags & PR_STOPPED) && (why == PR_REQUESTED))
4179 pi->status_valid = 0; /* re-read again, IMMEDIATELY... */
4180 #endif
4181 /* If child is not stopped, wait for it to stop. */
4182 if (!(proc_flags (pi) & (PR_STOPPED | PR_ISTOP)) &&
4183 !proc_wait_for_stop (pi))
4184 {
4185 /* wait_for_stop failed: has the child terminated? */
4186 if (errno == ENOENT)
4187 {
4188 int wait_retval;
4189
4190 /* /proc file not found; presumably child has terminated. */
4191 wait_retval = wait (&wstat); /* "wait" for the child's exit */
4192
4193 if (wait_retval != PIDGET (inferior_ptid)) /* wrong child? */
4194 error (_("procfs: couldn't stop process %d: wait returned %d."),
4195 PIDGET (inferior_ptid), wait_retval);
4196 /* FIXME: might I not just use waitpid?
4197 Or try find_procinfo to see if I know about this child? */
4198 retval = pid_to_ptid (wait_retval);
4199 }
4200 else if (errno == EINTR)
4201 goto wait_again;
4202 else
4203 {
4204 /* Unknown error from wait_for_stop. */
4205 proc_error (pi, "target_wait (wait_for_stop)", __LINE__);
4206 }
4207 }
4208 else
4209 {
4210 /* This long block is reached if either:
4211 a) the child was already stopped, or
4212 b) we successfully waited for the child with wait_for_stop.
4213 This block will analyze the /proc status, and translate it
4214 into a waitstatus for GDB.
4215
4216 If we actually had to call wait because the /proc file
4217 is gone (child terminated), then we skip this block,
4218 because we already have a waitstatus. */
4219
4220 flags = proc_flags (pi);
4221 why = proc_why (pi);
4222 what = proc_what (pi);
4223
4224 if (flags & (PR_STOPPED | PR_ISTOP))
4225 {
4226 #ifdef PR_ASYNC
4227 /* If it's running async (for single_thread control),
4228 set it back to normal again. */
4229 if (flags & PR_ASYNC)
4230 if (!proc_unset_async (pi))
4231 proc_error (pi, "target_wait, unset_async", __LINE__);
4232 #endif
4233
4234 if (info_verbose)
4235 proc_prettyprint_why (why, what, 1);
4236
4237 /* The 'pid' we will return to GDB is composed of
4238 the process ID plus the lwp ID. */
4239 retval = MERGEPID (pi->pid, proc_get_current_thread (pi));
4240
4241 switch (why) {
4242 case PR_SIGNALLED:
4243 wstat = (what << 8) | 0177;
4244 break;
4245 case PR_SYSENTRY:
4246 if (syscall_is_lwp_exit (pi, what))
4247 {
4248 if (print_thread_events)
4249 printf_unfiltered (_("[%s exited]\n"),
4250 target_pid_to_str (retval));
4251 delete_thread (retval);
4252 status->kind = TARGET_WAITKIND_SPURIOUS;
4253 return retval;
4254 }
4255 else if (syscall_is_exit (pi, what))
4256 {
4257 struct inferior *inf;
4258
4259 /* Handle SYS_exit call only */
4260 /* Stopped at entry to SYS_exit.
4261 Make it runnable, resume it, then use
4262 the wait system call to get its exit code.
4263 Proc_run_process always clears the current
4264 fault and signal.
4265 Then return its exit status. */
4266 pi->status_valid = 0;
4267 wstat = 0;
4268 /* FIXME: what we should do is return
4269 TARGET_WAITKIND_SPURIOUS. */
4270 if (!proc_run_process (pi, 0, 0))
4271 proc_error (pi, "target_wait, run_process", __LINE__);
4272
4273 inf = find_inferior_pid (pi->pid);
4274 if (inf->attach_flag)
4275 {
4276 /* Don't call wait: simulate waiting for exit,
4277 return a "success" exit code. Bogus: what if
4278 it returns something else? */
4279 wstat = 0;
4280 retval = inferior_ptid; /* ? ? ? */
4281 }
4282 else
4283 {
4284 int temp = wait (&wstat);
4285
4286 /* FIXME: shouldn't I make sure I get the right
4287 event from the right process? If (for
4288 instance) I have killed an earlier inferior
4289 process but failed to clean up after it
4290 somehow, I could get its termination event
4291 here. */
4292
4293 /* If wait returns -1, that's what we return to GDB. */
4294 if (temp < 0)
4295 retval = pid_to_ptid (temp);
4296 }
4297 }
4298 else
4299 {
4300 printf_filtered (_("procfs: trapped on entry to "));
4301 proc_prettyprint_syscall (proc_what (pi), 0);
4302 printf_filtered ("\n");
4303 #ifndef PIOCSSPCACT
4304 {
4305 long i, nsysargs, *sysargs;
4306
4307 if ((nsysargs = proc_nsysarg (pi)) > 0 &&
4308 (sysargs = proc_sysargs (pi)) != NULL)
4309 {
4310 printf_filtered (_("%ld syscall arguments:\n"), nsysargs);
4311 for (i = 0; i < nsysargs; i++)
4312 printf_filtered ("#%ld: 0x%08lx\n",
4313 i, sysargs[i]);
4314 }
4315
4316 }
4317 #endif
4318 if (status)
4319 {
4320 /* How to exit gracefully, returning "unknown event" */
4321 status->kind = TARGET_WAITKIND_SPURIOUS;
4322 return inferior_ptid;
4323 }
4324 else
4325 {
4326 /* How to keep going without returning to wfi: */
4327 target_resume (ptid, 0, TARGET_SIGNAL_0);
4328 goto wait_again;
4329 }
4330 }
4331 break;
4332 case PR_SYSEXIT:
4333 if (syscall_is_exec (pi, what))
4334 {
4335 /* Hopefully this is our own "fork-child" execing
4336 the real child. Hoax this event into a trap, and
4337 GDB will see the child about to execute its start
4338 address. */
4339 wstat = (SIGTRAP << 8) | 0177;
4340 }
4341 #ifdef SYS_syssgi
4342 else if (what == SYS_syssgi)
4343 {
4344 /* see if we can break on dbx_link(). If yes, then
4345 we no longer need the SYS_syssgi notifications. */
4346 if (insert_dbx_link_breakpoint (pi))
4347 proc_trace_syscalls_1 (pi, SYS_syssgi, PR_SYSEXIT,
4348 FLAG_RESET, 0);
4349
4350 /* This is an internal event and should be transparent
4351 to wfi, so resume the execution and wait again. See
4352 comment in procfs_init_inferior() for more details. */
4353 target_resume (ptid, 0, TARGET_SIGNAL_0);
4354 goto wait_again;
4355 }
4356 #endif
4357 else if (syscall_is_lwp_create (pi, what))
4358 {
4359 /*
4360 * This syscall is somewhat like fork/exec.
4361 * We will get the event twice: once for the parent LWP,
4362 * and once for the child. We should already know about
4363 * the parent LWP, but the child will be new to us. So,
4364 * whenever we get this event, if it represents a new
4365 * thread, simply add the thread to the list.
4366 */
4367
4368 /* If not in procinfo list, add it. */
4369 temp_tid = proc_get_current_thread (pi);
4370 if (!find_procinfo (pi->pid, temp_tid))
4371 create_procinfo (pi->pid, temp_tid);
4372
4373 temp_ptid = MERGEPID (pi->pid, temp_tid);
4374 /* If not in GDB's thread list, add it. */
4375 if (!in_thread_list (temp_ptid))
4376 add_thread (temp_ptid);
4377
4378 /* Return to WFI, but tell it to immediately resume. */
4379 status->kind = TARGET_WAITKIND_SPURIOUS;
4380 return inferior_ptid;
4381 }
4382 else if (syscall_is_lwp_exit (pi, what))
4383 {
4384 if (print_thread_events)
4385 printf_unfiltered (_("[%s exited]\n"),
4386 target_pid_to_str (retval));
4387 delete_thread (retval);
4388 status->kind = TARGET_WAITKIND_SPURIOUS;
4389 return retval;
4390 }
4391 else if (0)
4392 {
4393 /* FIXME: Do we need to handle SYS_sproc,
4394 SYS_fork, or SYS_vfork here? The old procfs
4395 seemed to use this event to handle threads on
4396 older (non-LWP) systems, where I'm assuming
4397 that threads were actually separate processes.
4398 Irix, maybe? Anyway, low priority for now. */
4399 }
4400 else
4401 {
4402 printf_filtered (_("procfs: trapped on exit from "));
4403 proc_prettyprint_syscall (proc_what (pi), 0);
4404 printf_filtered ("\n");
4405 #ifndef PIOCSSPCACT
4406 {
4407 long i, nsysargs, *sysargs;
4408
4409 if ((nsysargs = proc_nsysarg (pi)) > 0 &&
4410 (sysargs = proc_sysargs (pi)) != NULL)
4411 {
4412 printf_filtered (_("%ld syscall arguments:\n"), nsysargs);
4413 for (i = 0; i < nsysargs; i++)
4414 printf_filtered ("#%ld: 0x%08lx\n",
4415 i, sysargs[i]);
4416 }
4417 }
4418 #endif
4419 status->kind = TARGET_WAITKIND_SPURIOUS;
4420 return inferior_ptid;
4421 }
4422 break;
4423 case PR_REQUESTED:
4424 #if 0 /* FIXME */
4425 wstat = (SIGSTOP << 8) | 0177;
4426 break;
4427 #else
4428 if (retry < 5)
4429 {
4430 printf_filtered (_("Retry #%d:\n"), retry);
4431 pi->status_valid = 0;
4432 goto wait_again;
4433 }
4434 else
4435 {
4436 /* If not in procinfo list, add it. */
4437 temp_tid = proc_get_current_thread (pi);
4438 if (!find_procinfo (pi->pid, temp_tid))
4439 create_procinfo (pi->pid, temp_tid);
4440
4441 /* If not in GDB's thread list, add it. */
4442 temp_ptid = MERGEPID (pi->pid, temp_tid);
4443 if (!in_thread_list (temp_ptid))
4444 add_thread (temp_ptid);
4445
4446 status->kind = TARGET_WAITKIND_STOPPED;
4447 status->value.sig = 0;
4448 return retval;
4449 }
4450 #endif
4451 case PR_JOBCONTROL:
4452 wstat = (what << 8) | 0177;
4453 break;
4454 case PR_FAULTED:
4455 switch (what) {
4456 #ifdef FLTWATCH
4457 case FLTWATCH:
4458 wstat = (SIGTRAP << 8) | 0177;
4459 break;
4460 #endif
4461 #ifdef FLTKWATCH
4462 case FLTKWATCH:
4463 wstat = (SIGTRAP << 8) | 0177;
4464 break;
4465 #endif
4466 /* FIXME: use si_signo where possible. */
4467 case FLTPRIV:
4468 #if (FLTILL != FLTPRIV) /* avoid "duplicate case" error */
4469 case FLTILL:
4470 #endif
4471 wstat = (SIGILL << 8) | 0177;
4472 break;
4473 case FLTBPT:
4474 #if (FLTTRACE != FLTBPT) /* avoid "duplicate case" error */
4475 case FLTTRACE:
4476 #endif
4477 /* If we hit our __dbx_link() internal breakpoint,
4478 then remove it. See comments in procfs_init_inferior()
4479 for more details. */
4480 if (dbx_link_bpt_addr != 0
4481 && dbx_link_bpt_addr
4482 == regcache_read_pc (get_current_regcache ()))
4483 remove_dbx_link_breakpoint ();
4484
4485 wstat = (SIGTRAP << 8) | 0177;
4486 break;
4487 case FLTSTACK:
4488 case FLTACCESS:
4489 #if (FLTBOUNDS != FLTSTACK) /* avoid "duplicate case" error */
4490 case FLTBOUNDS:
4491 #endif
4492 wstat = (SIGSEGV << 8) | 0177;
4493 break;
4494 case FLTIOVF:
4495 case FLTIZDIV:
4496 #if (FLTFPE != FLTIOVF) /* avoid "duplicate case" error */
4497 case FLTFPE:
4498 #endif
4499 wstat = (SIGFPE << 8) | 0177;
4500 break;
4501 case FLTPAGE: /* Recoverable page fault */
4502 default: /* FIXME: use si_signo if possible for fault */
4503 retval = pid_to_ptid (-1);
4504 printf_filtered ("procfs:%d -- ", __LINE__);
4505 printf_filtered (_("child stopped for unknown reason:\n"));
4506 proc_prettyprint_why (why, what, 1);
4507 error (_("... giving up..."));
4508 break;
4509 }
4510 break; /* case PR_FAULTED: */
4511 default: /* switch (why) unmatched */
4512 printf_filtered ("procfs:%d -- ", __LINE__);
4513 printf_filtered (_("child stopped for unknown reason:\n"));
4514 proc_prettyprint_why (why, what, 1);
4515 error (_("... giving up..."));
4516 break;
4517 }
4518 /*
4519 * Got this far without error:
4520 * If retval isn't in the threads database, add it.
4521 */
4522 if (PIDGET (retval) > 0 &&
4523 !ptid_equal (retval, inferior_ptid) &&
4524 !in_thread_list (retval))
4525 {
4526 /*
4527 * We have a new thread.
4528 * We need to add it both to GDB's list and to our own.
4529 * If we don't create a procinfo, resume may be unhappy
4530 * later.
4531 */
4532 add_thread (retval);
4533 if (find_procinfo (PIDGET (retval), TIDGET (retval)) == NULL)
4534 create_procinfo (PIDGET (retval), TIDGET (retval));
4535 }
4536 }
4537 else /* flags do not indicate STOPPED */
4538 {
4539 /* surely this can't happen... */
4540 printf_filtered ("procfs:%d -- process not stopped.\n",
4541 __LINE__);
4542 proc_prettyprint_flags (flags, 1);
4543 error (_("procfs: ...giving up..."));
4544 }
4545 }
4546
4547 if (status)
4548 store_waitstatus (status, wstat);
4549 }
4550
4551 return retval;
4552 }
4553
4554 /* Perform a partial transfer to/from the specified object. For
4555 memory transfers, fall back to the old memory xfer functions. */
4556
4557 static LONGEST
4558 procfs_xfer_partial (struct target_ops *ops, enum target_object object,
4559 const char *annex, gdb_byte *readbuf,
4560 const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
4561 {
4562 switch (object)
4563 {
4564 case TARGET_OBJECT_MEMORY:
4565 if (readbuf)
4566 return (*ops->deprecated_xfer_memory) (offset, readbuf,
4567 len, 0/*read*/, NULL, ops);
4568 if (writebuf)
4569 return (*ops->deprecated_xfer_memory) (offset, (gdb_byte *) writebuf,
4570 len, 1/*write*/, NULL, ops);
4571 return -1;
4572
4573 #ifdef NEW_PROC_API
4574 case TARGET_OBJECT_AUXV:
4575 return memory_xfer_auxv (ops, object, annex, readbuf, writebuf,
4576 offset, len);
4577 #endif
4578
4579 default:
4580 if (ops->beneath != NULL)
4581 return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
4582 readbuf, writebuf, offset, len);
4583 return -1;
4584 }
4585 }
4586
4587
4588 /* Transfer LEN bytes between GDB address MYADDR and target address
4589 MEMADDR. If DOWRITE is non-zero, transfer them to the target,
4590 otherwise transfer them from the target. TARGET is unused.
4591
4592 The return value is 0 if an error occurred or no bytes were
4593 transferred. Otherwise, it will be a positive value which
4594 indicates the number of bytes transferred between gdb and the
4595 target. (Note that the interface also makes provisions for
4596 negative values, but this capability isn't implemented here.) */
4597
4598 static int
4599 procfs_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int dowrite,
4600 struct mem_attrib *attrib, struct target_ops *target)
4601 {
4602 procinfo *pi;
4603 int nbytes = 0;
4604
4605 /* Find procinfo for main process */
4606 pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
4607 if (pi->as_fd == 0 &&
4608 open_procinfo_files (pi, FD_AS) == 0)
4609 {
4610 proc_warn (pi, "xfer_memory, open_proc_files", __LINE__);
4611 return 0;
4612 }
4613
4614 if (lseek (pi->as_fd, (off_t) memaddr, SEEK_SET) == (off_t) memaddr)
4615 {
4616 if (dowrite)
4617 {
4618 #ifdef NEW_PROC_API
4619 PROCFS_NOTE ("write memory: ");
4620 #else
4621 PROCFS_NOTE ("write memory: \n");
4622 #endif
4623 nbytes = write (pi->as_fd, myaddr, len);
4624 }
4625 else
4626 {
4627 PROCFS_NOTE ("read memory: \n");
4628 nbytes = read (pi->as_fd, myaddr, len);
4629 }
4630 if (nbytes < 0)
4631 {
4632 nbytes = 0;
4633 }
4634 }
4635 return nbytes;
4636 }
4637
4638 /*
4639 * Function: invalidate_cache
4640 *
4641 * Called by target_resume before making child runnable.
4642 * Mark cached registers and status's invalid.
4643 * If there are "dirty" caches that need to be written back
4644 * to the child process, do that.
4645 *
4646 * File descriptors are also cached.
4647 * As they are a limited resource, we cannot hold onto them indefinitely.
4648 * However, as they are expensive to open, we don't want to throw them
4649 * away indescriminately either. As a compromise, we will keep the
4650 * file descriptors for the parent process, but discard any file
4651 * descriptors we may have accumulated for the threads.
4652 *
4653 * Return value:
4654 * As this function is called by iterate_over_threads, it always
4655 * returns zero (so that iterate_over_threads will keep iterating).
4656 */
4657
4658
4659 static int
4660 invalidate_cache (procinfo *parent, procinfo *pi, void *ptr)
4661 {
4662 /*
4663 * About to run the child; invalidate caches and do any other cleanup.
4664 */
4665
4666 #if 0
4667 if (pi->gregs_dirty)
4668 if (parent == NULL ||
4669 proc_get_current_thread (parent) != pi->tid)
4670 if (!proc_set_gregs (pi)) /* flush gregs cache */
4671 proc_warn (pi, "target_resume, set_gregs",
4672 __LINE__);
4673 if (gdbarch_fp0_regnum (target_gdbarch) >= 0)
4674 if (pi->fpregs_dirty)
4675 if (parent == NULL ||
4676 proc_get_current_thread (parent) != pi->tid)
4677 if (!proc_set_fpregs (pi)) /* flush fpregs cache */
4678 proc_warn (pi, "target_resume, set_fpregs",
4679 __LINE__);
4680 #endif
4681
4682 if (parent != NULL)
4683 {
4684 /* The presence of a parent indicates that this is an LWP.
4685 Close any file descriptors that it might have open.
4686 We don't do this to the master (parent) procinfo. */
4687
4688 close_procinfo_files (pi);
4689 }
4690 pi->gregs_valid = 0;
4691 pi->fpregs_valid = 0;
4692 #if 0
4693 pi->gregs_dirty = 0;
4694 pi->fpregs_dirty = 0;
4695 #endif
4696 pi->status_valid = 0;
4697 pi->threads_valid = 0;
4698
4699 return 0;
4700 }
4701
4702 #if 0
4703 /*
4704 * Function: make_signal_thread_runnable
4705 *
4706 * A callback function for iterate_over_threads.
4707 * Find the asynchronous signal thread, and make it runnable.
4708 * See if that helps matters any.
4709 */
4710
4711 static int
4712 make_signal_thread_runnable (procinfo *process, procinfo *pi, void *ptr)
4713 {
4714 #ifdef PR_ASLWP
4715 if (proc_flags (pi) & PR_ASLWP)
4716 {
4717 if (!proc_run_process (pi, 0, -1))
4718 proc_error (pi, "make_signal_thread_runnable", __LINE__);
4719 return 1;
4720 }
4721 #endif
4722 return 0;
4723 }
4724 #endif
4725
4726 /*
4727 * Function: target_resume
4728 *
4729 * Make the child process runnable. Normally we will then call
4730 * procfs_wait and wait for it to stop again (unles gdb is async).
4731 *
4732 * Arguments:
4733 * step: if true, then arrange for the child to stop again
4734 * after executing a single instruction.
4735 * signo: if zero, then cancel any pending signal.
4736 * If non-zero, then arrange for the indicated signal
4737 * to be delivered to the child when it runs.
4738 * pid: if -1, then allow any child thread to run.
4739 * if non-zero, then allow only the indicated thread to run.
4740 ******* (not implemented yet)
4741 */
4742
4743 static void
4744 procfs_resume (struct target_ops *ops,
4745 ptid_t ptid, int step, enum target_signal signo)
4746 {
4747 procinfo *pi, *thread;
4748 int native_signo;
4749
4750 /* 2.1:
4751 prrun.prflags |= PRSVADDR;
4752 prrun.pr_vaddr = $PC; set resume address
4753 prrun.prflags |= PRSTRACE; trace signals in pr_trace (all)
4754 prrun.prflags |= PRSFAULT; trace faults in pr_fault (all but PAGE)
4755 prrun.prflags |= PRCFAULT; clear current fault.
4756
4757 PRSTRACE and PRSFAULT can be done by other means
4758 (proc_trace_signals, proc_trace_faults)
4759 PRSVADDR is unnecessary.
4760 PRCFAULT may be replaced by a PIOCCFAULT call (proc_clear_current_fault)
4761 This basically leaves PRSTEP and PRCSIG.
4762 PRCSIG is like PIOCSSIG (proc_clear_current_signal).
4763 So basically PR_STEP is the sole argument that must be passed
4764 to proc_run_process (for use in the prrun struct by ioctl). */
4765
4766 /* Find procinfo for main process */
4767 pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
4768
4769 /* First cut: ignore pid argument */
4770 errno = 0;
4771
4772 /* Convert signal to host numbering. */
4773 if (signo == 0 ||
4774 (signo == TARGET_SIGNAL_STOP && pi->ignore_next_sigstop))
4775 native_signo = 0;
4776 else
4777 native_signo = target_signal_to_host (signo);
4778
4779 pi->ignore_next_sigstop = 0;
4780
4781 /* Running the process voids all cached registers and status. */
4782 /* Void the threads' caches first */
4783 proc_iterate_over_threads (pi, invalidate_cache, NULL);
4784 /* Void the process procinfo's caches. */
4785 invalidate_cache (NULL, pi, NULL);
4786
4787 if (PIDGET (ptid) != -1)
4788 {
4789 /* Resume a specific thread, presumably suppressing the others. */
4790 thread = find_procinfo (PIDGET (ptid), TIDGET (ptid));
4791 if (thread != NULL)
4792 {
4793 if (thread->tid != 0)
4794 {
4795 /* We're to resume a specific thread, and not the others.
4796 * Set the child process's PR_ASYNC flag.
4797 */
4798 #ifdef PR_ASYNC
4799 if (!proc_set_async (pi))
4800 proc_error (pi, "target_resume, set_async", __LINE__);
4801 #endif
4802 #if 0
4803 proc_iterate_over_threads (pi,
4804 make_signal_thread_runnable,
4805 NULL);
4806 #endif
4807 pi = thread; /* substitute the thread's procinfo for run */
4808 }
4809 }
4810 }
4811
4812 if (!proc_run_process (pi, step, native_signo))
4813 {
4814 if (errno == EBUSY)
4815 warning (_("resume: target already running. Pretend to resume, and hope for the best!"));
4816 else
4817 proc_error (pi, "target_resume", __LINE__);
4818 }
4819 }
4820
4821 /*
4822 * Function: register_gdb_signals
4823 *
4824 * Traverse the list of signals that GDB knows about
4825 * (see "handle" command), and arrange for the target
4826 * to be stopped or not, according to these settings.
4827 *
4828 * Returns non-zero for success, zero for failure.
4829 */
4830
4831 static int
4832 register_gdb_signals (procinfo *pi, gdb_sigset_t *signals)
4833 {
4834 int signo;
4835
4836 for (signo = 0; signo < NSIG; signo ++)
4837 if (signal_stop_state (target_signal_from_host (signo)) == 0 &&
4838 signal_print_state (target_signal_from_host (signo)) == 0 &&
4839 signal_pass_state (target_signal_from_host (signo)) == 1)
4840 gdb_prdelset (signals, signo);
4841 else
4842 gdb_praddset (signals, signo);
4843
4844 return proc_set_traced_signals (pi, signals);
4845 }
4846
4847 /*
4848 * Function: target_notice_signals
4849 *
4850 * Set up to trace signals in the child process.
4851 */
4852
4853 static void
4854 procfs_notice_signals (ptid_t ptid)
4855 {
4856 gdb_sigset_t signals;
4857 procinfo *pi = find_procinfo_or_die (PIDGET (ptid), 0);
4858
4859 if (proc_get_traced_signals (pi, &signals) &&
4860 register_gdb_signals (pi, &signals))
4861 return;
4862 else
4863 proc_error (pi, "notice_signals", __LINE__);
4864 }
4865
4866 /*
4867 * Function: target_files_info
4868 *
4869 * Print status information about the child process.
4870 */
4871
4872 static void
4873 procfs_files_info (struct target_ops *ignore)
4874 {
4875 struct inferior *inf = current_inferior ();
4876 printf_filtered (_("\tUsing the running image of %s %s via /proc.\n"),
4877 inf->attach_flag? "attached": "child",
4878 target_pid_to_str (inferior_ptid));
4879 }
4880
4881 /*
4882 * Function: target_stop
4883 *
4884 * Stop the child process asynchronously, as when the
4885 * gdb user types control-c or presses a "stop" button.
4886 *
4887 * Works by sending kill(SIGINT) to the child's process group.
4888 */
4889
4890 static void
4891 procfs_stop (ptid_t ptid)
4892 {
4893 kill (-inferior_process_group (), SIGINT);
4894 }
4895
4896 /*
4897 * Function: unconditionally_kill_inferior
4898 *
4899 * Make it die. Wait for it to die. Clean up after it.
4900 * Note: this should only be applied to the real process,
4901 * not to an LWP, because of the check for parent-process.
4902 * If we need this to work for an LWP, it needs some more logic.
4903 */
4904
4905 static void
4906 unconditionally_kill_inferior (procinfo *pi)
4907 {
4908 int parent_pid;
4909
4910 parent_pid = proc_parent_pid (pi);
4911 #ifdef PROCFS_NEED_CLEAR_CURSIG_FOR_KILL
4912 /* FIXME: use access functions */
4913 /* Alpha OSF/1-3.x procfs needs a clear of the current signal
4914 before the PIOCKILL, otherwise it might generate a corrupted core
4915 file for the inferior. */
4916 if (ioctl (pi->ctl_fd, PIOCSSIG, NULL) < 0)
4917 {
4918 printf_filtered ("unconditionally_kill: SSIG failed!\n");
4919 }
4920 #endif
4921 #ifdef PROCFS_NEED_PIOCSSIG_FOR_KILL
4922 /* Alpha OSF/1-2.x procfs needs a PIOCSSIG call with a SIGKILL signal
4923 to kill the inferior, otherwise it might remain stopped with a
4924 pending SIGKILL.
4925 We do not check the result of the PIOCSSIG, the inferior might have
4926 died already. */
4927 {
4928 gdb_siginfo_t newsiginfo;
4929
4930 memset ((char *) &newsiginfo, 0, sizeof (newsiginfo));
4931 newsiginfo.si_signo = SIGKILL;
4932 newsiginfo.si_code = 0;
4933 newsiginfo.si_errno = 0;
4934 newsiginfo.si_pid = getpid ();
4935 newsiginfo.si_uid = getuid ();
4936 /* FIXME: use proc_set_current_signal */
4937 ioctl (pi->ctl_fd, PIOCSSIG, &newsiginfo);
4938 }
4939 #else /* PROCFS_NEED_PIOCSSIG_FOR_KILL */
4940 if (!proc_kill (pi, SIGKILL))
4941 proc_error (pi, "unconditionally_kill, proc_kill", __LINE__);
4942 #endif /* PROCFS_NEED_PIOCSSIG_FOR_KILL */
4943 destroy_procinfo (pi);
4944
4945 /* If pi is GDB's child, wait for it to die. */
4946 if (parent_pid == getpid ())
4947 /* FIXME: should we use waitpid to make sure we get the right event?
4948 Should we check the returned event? */
4949 {
4950 #if 0
4951 int status, ret;
4952
4953 ret = waitpid (pi->pid, &status, 0);
4954 #else
4955 wait (NULL);
4956 #endif
4957 }
4958 }
4959
4960 /*
4961 * Function: target_kill_inferior
4962 *
4963 * We're done debugging it, and we want it to go away.
4964 * Then we want GDB to forget all about it.
4965 */
4966
4967 static void
4968 procfs_kill_inferior (struct target_ops *ops)
4969 {
4970 if (!ptid_equal (inferior_ptid, null_ptid)) /* ? */
4971 {
4972 /* Find procinfo for main process */
4973 procinfo *pi = find_procinfo (PIDGET (inferior_ptid), 0);
4974
4975 if (pi)
4976 unconditionally_kill_inferior (pi);
4977 target_mourn_inferior ();
4978 }
4979 }
4980
4981 /*
4982 * Function: target_mourn_inferior
4983 *
4984 * Forget we ever debugged this thing!
4985 */
4986
4987 static void
4988 procfs_mourn_inferior (struct target_ops *ops)
4989 {
4990 procinfo *pi;
4991
4992 if (!ptid_equal (inferior_ptid, null_ptid))
4993 {
4994 /* Find procinfo for main process */
4995 pi = find_procinfo (PIDGET (inferior_ptid), 0);
4996 if (pi)
4997 destroy_procinfo (pi);
4998 }
4999 unpush_target (ops);
5000
5001 if (dbx_link_bpt != NULL)
5002 {
5003 deprecated_remove_raw_breakpoint (target_gdbarch, dbx_link_bpt);
5004 dbx_link_bpt_addr = 0;
5005 dbx_link_bpt = NULL;
5006 }
5007
5008 generic_mourn_inferior ();
5009 }
5010
5011 /*
5012 * Function: init_inferior
5013 *
5014 * When GDB forks to create a runnable inferior process,
5015 * this function is called on the parent side of the fork.
5016 * It's job is to do whatever is necessary to make the child
5017 * ready to be debugged, and then wait for the child to synchronize.
5018 */
5019
5020 static void
5021 procfs_init_inferior (struct target_ops *ops, int pid)
5022 {
5023 procinfo *pi;
5024 gdb_sigset_t signals;
5025 int fail;
5026 int lwpid;
5027
5028 /* This routine called on the parent side (GDB side)
5029 after GDB forks the inferior. */
5030 push_target (ops);
5031
5032 if ((pi = create_procinfo (pid, 0)) == NULL)
5033 perror ("procfs: out of memory in 'init_inferior'");
5034
5035 if (!open_procinfo_files (pi, FD_CTL))
5036 proc_error (pi, "init_inferior, open_proc_files", __LINE__);
5037
5038 /*
5039 xmalloc // done
5040 open_procinfo_files // done
5041 link list // done
5042 prfillset (trace)
5043 procfs_notice_signals
5044 prfillset (fault)
5045 prdelset (FLTPAGE)
5046 PIOCWSTOP
5047 PIOCSFAULT
5048 */
5049
5050 /* If not stopped yet, wait for it to stop. */
5051 if (!(proc_flags (pi) & PR_STOPPED) &&
5052 !(proc_wait_for_stop (pi)))
5053 dead_procinfo (pi, "init_inferior: wait_for_stop failed", KILL);
5054
5055 /* Save some of the /proc state to be restored if we detach. */
5056 /* FIXME: Why? In case another debugger was debugging it?
5057 We're it's parent, for Ghu's sake! */
5058 if (!proc_get_traced_signals (pi, &pi->saved_sigset))
5059 proc_error (pi, "init_inferior, get_traced_signals", __LINE__);
5060 if (!proc_get_held_signals (pi, &pi->saved_sighold))
5061 proc_error (pi, "init_inferior, get_held_signals", __LINE__);
5062 if (!proc_get_traced_faults (pi, &pi->saved_fltset))
5063 proc_error (pi, "init_inferior, get_traced_faults", __LINE__);
5064 if (!proc_get_traced_sysentry (pi, pi->saved_entryset))
5065 proc_error (pi, "init_inferior, get_traced_sysentry", __LINE__);
5066 if (!proc_get_traced_sysexit (pi, pi->saved_exitset))
5067 proc_error (pi, "init_inferior, get_traced_sysexit", __LINE__);
5068
5069 /* Register to trace selected signals in the child. */
5070 prfillset (&signals);
5071 if (!register_gdb_signals (pi, &signals))
5072 proc_error (pi, "init_inferior, register_signals", __LINE__);
5073
5074 if ((fail = procfs_debug_inferior (pi)) != 0)
5075 proc_error (pi, "init_inferior (procfs_debug_inferior)", fail);
5076
5077 /* FIXME: logically, we should really be turning OFF run-on-last-close,
5078 and possibly even turning ON kill-on-last-close at this point. But
5079 I can't make that change without careful testing which I don't have
5080 time to do right now... */
5081 /* Turn on run-on-last-close flag so that the child
5082 will die if GDB goes away for some reason. */
5083 if (!proc_set_run_on_last_close (pi))
5084 proc_error (pi, "init_inferior, set_RLC", __LINE__);
5085
5086 /* We now have have access to the lwpid of the main thread/lwp. */
5087 lwpid = proc_get_current_thread (pi);
5088
5089 /* Create a procinfo for the main lwp. */
5090 create_procinfo (pid, lwpid);
5091
5092 /* We already have a main thread registered in the thread table at
5093 this point, but it didn't have any lwp info yet. Notify the core
5094 about it. This changes inferior_ptid as well. */
5095 thread_change_ptid (pid_to_ptid (pid),
5096 MERGEPID (pid, lwpid));
5097
5098 /* Typically two, one trap to exec the shell, one to exec the
5099 program being debugged. Defined by "inferior.h". */
5100 startup_inferior (START_INFERIOR_TRAPS_EXPECTED);
5101
5102 #ifdef SYS_syssgi
5103 /* On mips-irix, we need to stop the inferior early enough during
5104 the startup phase in order to be able to load the shared library
5105 symbols and insert the breakpoints that are located in these shared
5106 libraries. Stopping at the program entry point is not good enough
5107 because the -init code is executed before the execution reaches
5108 that point.
5109
5110 So what we need to do is to insert a breakpoint in the runtime
5111 loader (rld), more precisely in __dbx_link(). This procedure is
5112 called by rld once all shared libraries have been mapped, but before
5113 the -init code is executed. Unfortuantely, this is not straightforward,
5114 as rld is not part of the executable we are running, and thus we need
5115 the inferior to run until rld itself has been mapped in memory.
5116
5117 For this, we trace all syssgi() syscall exit events. Each time
5118 we detect such an event, we iterate over each text memory maps,
5119 get its associated fd, and scan the symbol table for __dbx_link().
5120 When found, we know that rld has been mapped, and that we can insert
5121 the breakpoint at the symbol address. Once the dbx_link() breakpoint
5122 has been inserted, the syssgi() notifications are no longer necessary,
5123 so they should be canceled. */
5124 proc_trace_syscalls_1 (pi, SYS_syssgi, PR_SYSEXIT, FLAG_SET, 0);
5125 #endif
5126 }
5127
5128 /*
5129 * Function: set_exec_trap
5130 *
5131 * When GDB forks to create a new process, this function is called
5132 * on the child side of the fork before GDB exec's the user program.
5133 * Its job is to make the child minimally debuggable, so that the
5134 * parent GDB process can connect to the child and take over.
5135 * This function should do only the minimum to make that possible,
5136 * and to synchronize with the parent process. The parent process
5137 * should take care of the details.
5138 */
5139
5140 static void
5141 procfs_set_exec_trap (void)
5142 {
5143 /* This routine called on the child side (inferior side)
5144 after GDB forks the inferior. It must use only local variables,
5145 because it may be sharing data space with its parent. */
5146
5147 procinfo *pi;
5148 sysset_t *exitset;
5149
5150 if ((pi = create_procinfo (getpid (), 0)) == NULL)
5151 perror_with_name (_("procfs: create_procinfo failed in child."));
5152
5153 if (open_procinfo_files (pi, FD_CTL) == 0)
5154 {
5155 proc_warn (pi, "set_exec_trap, open_proc_files", __LINE__);
5156 gdb_flush (gdb_stderr);
5157 /* no need to call "dead_procinfo", because we're going to exit. */
5158 _exit (127);
5159 }
5160
5161 #ifdef PRFS_STOPEXEC /* defined on OSF */
5162 /* OSF method for tracing exec syscalls. Quoting:
5163 Under Alpha OSF/1 we have to use a PIOCSSPCACT ioctl to trace
5164 exits from exec system calls because of the user level loader. */
5165 /* FIXME: make nice and maybe move into an access function. */
5166 {
5167 int prfs_flags;
5168
5169 if (ioctl (pi->ctl_fd, PIOCGSPCACT, &prfs_flags) < 0)
5170 {
5171 proc_warn (pi, "set_exec_trap (PIOCGSPCACT)", __LINE__);
5172 gdb_flush (gdb_stderr);
5173 _exit (127);
5174 }
5175 prfs_flags |= PRFS_STOPEXEC;
5176
5177 if (ioctl (pi->ctl_fd, PIOCSSPCACT, &prfs_flags) < 0)
5178 {
5179 proc_warn (pi, "set_exec_trap (PIOCSSPCACT)", __LINE__);
5180 gdb_flush (gdb_stderr);
5181 _exit (127);
5182 }
5183 }
5184 #else /* not PRFS_STOPEXEC */
5185 /* Everyone else's (except OSF) method for tracing exec syscalls */
5186 /* GW: Rationale...
5187 Not all systems with /proc have all the exec* syscalls with the same
5188 names. On the SGI, for example, there is no SYS_exec, but there
5189 *is* a SYS_execv. So, we try to account for that. */
5190
5191 exitset = sysset_t_alloc (pi);
5192 gdb_premptysysset (exitset);
5193 #ifdef SYS_exec
5194 gdb_praddsysset (exitset, SYS_exec);
5195 #endif
5196 #ifdef SYS_execve
5197 gdb_praddsysset (exitset, SYS_execve);
5198 #endif
5199 #ifdef SYS_execv
5200 gdb_praddsysset (exitset, SYS_execv);
5201 #endif
5202 #ifdef DYNAMIC_SYSCALLS
5203 {
5204 int callnum = find_syscall (pi, "execve");
5205
5206 if (callnum >= 0)
5207 gdb_praddsysset (exitset, callnum);
5208
5209 callnum = find_syscall (pi, "ra_execve");
5210 if (callnum >= 0)
5211 gdb_praddsysset (exitset, callnum);
5212 }
5213 #endif /* DYNAMIC_SYSCALLS */
5214
5215 if (!proc_set_traced_sysexit (pi, exitset))
5216 {
5217 proc_warn (pi, "set_exec_trap, set_traced_sysexit", __LINE__);
5218 gdb_flush (gdb_stderr);
5219 _exit (127);
5220 }
5221 #endif /* PRFS_STOPEXEC */
5222
5223 /* FIXME: should this be done in the parent instead? */
5224 /* Turn off inherit on fork flag so that all grand-children
5225 of gdb start with tracing flags cleared. */
5226 if (!proc_unset_inherit_on_fork (pi))
5227 proc_warn (pi, "set_exec_trap, unset_inherit", __LINE__);
5228
5229 /* Turn off run on last close flag, so that the child process
5230 cannot run away just because we close our handle on it.
5231 We want it to wait for the parent to attach. */
5232 if (!proc_unset_run_on_last_close (pi))
5233 proc_warn (pi, "set_exec_trap, unset_RLC", __LINE__);
5234
5235 /* FIXME: No need to destroy the procinfo --
5236 we have our own address space, and we're about to do an exec! */
5237 /*destroy_procinfo (pi);*/
5238 }
5239
5240 /*
5241 * Function: create_inferior
5242 *
5243 * This function is called BEFORE gdb forks the inferior process.
5244 * Its only real responsibility is to set things up for the fork,
5245 * and tell GDB which two functions to call after the fork (one
5246 * for the parent, and one for the child).
5247 *
5248 * This function does a complicated search for a unix shell program,
5249 * which it then uses to parse arguments and environment variables
5250 * to be sent to the child. I wonder whether this code could not
5251 * be abstracted out and shared with other unix targets such as
5252 * infptrace?
5253 */
5254
5255 static void
5256 procfs_create_inferior (struct target_ops *ops, char *exec_file,
5257 char *allargs, char **env, int from_tty)
5258 {
5259 char *shell_file = getenv ("SHELL");
5260 char *tryname;
5261 int pid;
5262
5263 if (shell_file != NULL && strchr (shell_file, '/') == NULL)
5264 {
5265
5266 /* We will be looking down the PATH to find shell_file. If we
5267 just do this the normal way (via execlp, which operates by
5268 attempting an exec for each element of the PATH until it
5269 finds one which succeeds), then there will be an exec for
5270 each failed attempt, each of which will cause a PR_SYSEXIT
5271 stop, and we won't know how to distinguish the PR_SYSEXIT's
5272 for these failed execs with the ones for successful execs
5273 (whether the exec has succeeded is stored at that time in the
5274 carry bit or some such architecture-specific and
5275 non-ABI-specified place).
5276
5277 So I can't think of anything better than to search the PATH
5278 now. This has several disadvantages: (1) There is a race
5279 condition; if we find a file now and it is deleted before we
5280 exec it, we lose, even if the deletion leaves a valid file
5281 further down in the PATH, (2) there is no way to know exactly
5282 what an executable (in the sense of "capable of being
5283 exec'd") file is. Using access() loses because it may lose
5284 if the caller is the superuser; failing to use it loses if
5285 there are ACLs or some such. */
5286
5287 char *p;
5288 char *p1;
5289 /* FIXME-maybe: might want "set path" command so user can change what
5290 path is used from within GDB. */
5291 char *path = getenv ("PATH");
5292 int len;
5293 struct stat statbuf;
5294
5295 if (path == NULL)
5296 path = "/bin:/usr/bin";
5297
5298 tryname = alloca (strlen (path) + strlen (shell_file) + 2);
5299 for (p = path; p != NULL; p = p1 ? p1 + 1: NULL)
5300 {
5301 p1 = strchr (p, ':');
5302 if (p1 != NULL)
5303 len = p1 - p;
5304 else
5305 len = strlen (p);
5306 strncpy (tryname, p, len);
5307 tryname[len] = '\0';
5308 strcat (tryname, "/");
5309 strcat (tryname, shell_file);
5310 if (access (tryname, X_OK) < 0)
5311 continue;
5312 if (stat (tryname, &statbuf) < 0)
5313 continue;
5314 if (!S_ISREG (statbuf.st_mode))
5315 /* We certainly need to reject directories. I'm not quite
5316 as sure about FIFOs, sockets, etc., but I kind of doubt
5317 that people want to exec() these things. */
5318 continue;
5319 break;
5320 }
5321 if (p == NULL)
5322 /* Not found. This must be an error rather than merely passing
5323 the file to execlp(), because execlp() would try all the
5324 exec()s, causing GDB to get confused. */
5325 error (_("procfs:%d -- Can't find shell %s in PATH"),
5326 __LINE__, shell_file);
5327
5328 shell_file = tryname;
5329 }
5330
5331 pid = fork_inferior (exec_file, allargs, env, procfs_set_exec_trap,
5332 NULL, NULL, shell_file);
5333
5334 procfs_init_inferior (ops, pid);
5335 }
5336
5337 /* An observer for the "inferior_created" event. */
5338
5339 static void
5340 procfs_inferior_created (struct target_ops *ops, int from_tty)
5341 {
5342 #ifdef SYS_syssgi
5343 /* Make sure to cancel the syssgi() syscall-exit notifications.
5344 They should normally have been removed by now, but they may still
5345 be activated if the inferior doesn't use shared libraries, or if
5346 we didn't locate __dbx_link, or if we never stopped in __dbx_link.
5347 See procfs_init_inferior() for more details.
5348
5349 Since these notifications are only ever enabled when we spawned
5350 the inferior ourselves, there is nothing to do when the inferior
5351 was created by attaching to an already running process, or when
5352 debugging a core file. */
5353 if (current_inferior ()->attach_flag || !target_can_run (&current_target))
5354 return;
5355
5356 proc_trace_syscalls_1 (find_procinfo_or_die (PIDGET (inferior_ptid), 0),
5357 SYS_syssgi, PR_SYSEXIT, FLAG_RESET, 0);
5358 #endif
5359 }
5360
5361 /*
5362 * Function: notice_thread
5363 *
5364 * Callback for find_new_threads.
5365 * Calls "add_thread".
5366 */
5367
5368 static int
5369 procfs_notice_thread (procinfo *pi, procinfo *thread, void *ptr)
5370 {
5371 ptid_t gdb_threadid = MERGEPID (pi->pid, thread->tid);
5372
5373 if (!in_thread_list (gdb_threadid) || is_exited (gdb_threadid))
5374 add_thread (gdb_threadid);
5375
5376 return 0;
5377 }
5378
5379 /*
5380 * Function: target_find_new_threads
5381 *
5382 * Query all the threads that the target knows about,
5383 * and give them back to GDB to add to its list.
5384 */
5385
5386 void
5387 procfs_find_new_threads (struct target_ops *ops)
5388 {
5389 procinfo *pi;
5390
5391 /* Find procinfo for main process */
5392 pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
5393 proc_update_threads (pi);
5394 proc_iterate_over_threads (pi, procfs_notice_thread, NULL);
5395 }
5396
5397 /*
5398 * Function: target_thread_alive
5399 *
5400 * Return true if the thread is still 'alive'.
5401 *
5402 * This guy doesn't really seem to be doing his job.
5403 * Got to investigate how to tell when a thread is really gone.
5404 */
5405
5406 static int
5407 procfs_thread_alive (struct target_ops *ops, ptid_t ptid)
5408 {
5409 int proc, thread;
5410 procinfo *pi;
5411
5412 proc = PIDGET (ptid);
5413 thread = TIDGET (ptid);
5414 /* If I don't know it, it ain't alive! */
5415 if ((pi = find_procinfo (proc, thread)) == NULL)
5416 return 0;
5417
5418 /* If I can't get its status, it ain't alive!
5419 What's more, I need to forget about it! */
5420 if (!proc_get_status (pi))
5421 {
5422 destroy_procinfo (pi);
5423 return 0;
5424 }
5425 /* I couldn't have got its status if it weren't alive, so it's alive. */
5426 return 1;
5427 }
5428
5429 /* Convert PTID to a string. Returns the string in a static buffer. */
5430
5431 char *
5432 procfs_pid_to_str (struct target_ops *ops, ptid_t ptid)
5433 {
5434 static char buf[80];
5435
5436 if (TIDGET (ptid) == 0)
5437 sprintf (buf, "process %d", PIDGET (ptid));
5438 else
5439 sprintf (buf, "LWP %ld", TIDGET (ptid));
5440
5441 return buf;
5442 }
5443
5444 /*
5445 * Function: procfs_set_watchpoint
5446 * Insert a watchpoint
5447 */
5448
5449 int
5450 procfs_set_watchpoint (ptid_t ptid, CORE_ADDR addr, int len, int rwflag,
5451 int after)
5452 {
5453 #ifndef UNIXWARE
5454 #ifndef AIX5
5455 int pflags = 0;
5456 procinfo *pi;
5457
5458 pi = find_procinfo_or_die (PIDGET (ptid) == -1 ?
5459 PIDGET (inferior_ptid) : PIDGET (ptid), 0);
5460
5461 /* Translate from GDB's flags to /proc's */
5462 if (len > 0) /* len == 0 means delete watchpoint */
5463 {
5464 switch (rwflag) { /* FIXME: need an enum! */
5465 case hw_write: /* default watchpoint (write) */
5466 pflags = WRITE_WATCHFLAG;
5467 break;
5468 case hw_read: /* read watchpoint */
5469 pflags = READ_WATCHFLAG;
5470 break;
5471 case hw_access: /* access watchpoint */
5472 pflags = READ_WATCHFLAG | WRITE_WATCHFLAG;
5473 break;
5474 case hw_execute: /* execution HW breakpoint */
5475 pflags = EXEC_WATCHFLAG;
5476 break;
5477 default: /* Something weird. Return error. */
5478 return -1;
5479 }
5480 if (after) /* Stop after r/w access is completed. */
5481 pflags |= AFTER_WATCHFLAG;
5482 }
5483
5484 if (!proc_set_watchpoint (pi, addr, len, pflags))
5485 {
5486 if (errno == E2BIG) /* Typical error for no resources */
5487 return -1; /* fail */
5488 /* GDB may try to remove the same watchpoint twice.
5489 If a remove request returns no match, don't error. */
5490 if (errno == ESRCH && len == 0)
5491 return 0; /* ignore */
5492 proc_error (pi, "set_watchpoint", __LINE__);
5493 }
5494 #endif /* AIX5 */
5495 #endif /* UNIXWARE */
5496 return 0;
5497 }
5498
5499 /* Return non-zero if we can set a hardware watchpoint of type TYPE. TYPE
5500 is one of bp_hardware_watchpoint, bp_read_watchpoint, bp_write_watchpoint,
5501 or bp_hardware_watchpoint. CNT is the number of watchpoints used so
5502 far.
5503
5504 Note: procfs_can_use_hw_breakpoint() is not yet used by all
5505 procfs.c targets due to the fact that some of them still define
5506 target_can_use_hardware_watchpoint. */
5507
5508 static int
5509 procfs_can_use_hw_breakpoint (int type, int cnt, int othertype)
5510 {
5511 /* Due to the way that proc_set_watchpoint() is implemented, host
5512 and target pointers must be of the same size. If they are not,
5513 we can't use hardware watchpoints. This limitation is due to the
5514 fact that proc_set_watchpoint() calls
5515 procfs_address_to_host_pointer(); a close inspection of
5516 procfs_address_to_host_pointer will reveal that an internal error
5517 will be generated when the host and target pointer sizes are
5518 different. */
5519 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
5520 if (sizeof (void *) != TYPE_LENGTH (ptr_type))
5521 return 0;
5522
5523 /* Other tests here??? */
5524
5525 return 1;
5526 }
5527
5528 /*
5529 * Function: stopped_by_watchpoint
5530 *
5531 * Returns non-zero if process is stopped on a hardware watchpoint fault,
5532 * else returns zero.
5533 */
5534
5535 static int
5536 procfs_stopped_by_watchpoint (void)
5537 {
5538 procinfo *pi;
5539
5540 pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
5541
5542 if (!pi) /* If no process, then not stopped by watchpoint! */
5543 return 0;
5544
5545 if (proc_flags (pi) & (PR_STOPPED | PR_ISTOP))
5546 {
5547 if (proc_why (pi) == PR_FAULTED)
5548 {
5549 #ifdef FLTWATCH
5550 if (proc_what (pi) == FLTWATCH)
5551 return 1;
5552 #endif
5553 #ifdef FLTKWATCH
5554 if (proc_what (pi) == FLTKWATCH)
5555 return 1;
5556 #endif
5557 }
5558 }
5559 return 0;
5560 }
5561
5562 static int
5563 procfs_insert_watchpoint (CORE_ADDR addr, int len, int type)
5564 {
5565 if (!target_have_steppable_watchpoint
5566 && !gdbarch_have_nonsteppable_watchpoint (target_gdbarch))
5567 {
5568 /* When a hardware watchpoint fires off the PC will be left at
5569 the instruction following the one which caused the
5570 watchpoint. It will *NOT* be necessary for GDB to step over
5571 the watchpoint. */
5572 return procfs_set_watchpoint (inferior_ptid, addr, len, type, 1);
5573 }
5574 else
5575 {
5576 /* When a hardware watchpoint fires off the PC will be left at
5577 the instruction which caused the watchpoint. It will be
5578 necessary for GDB to step over the watchpoint. */
5579 return procfs_set_watchpoint (inferior_ptid, addr, len, type, 0);
5580 }
5581 }
5582
5583 static int
5584 procfs_remove_watchpoint (CORE_ADDR addr, int len, int type)
5585 {
5586 return procfs_set_watchpoint (inferior_ptid, addr, 0, 0, 0);
5587 }
5588
5589 static int
5590 procfs_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
5591 {
5592 /* The man page for proc(4) on Solaris 2.6 and up says that the
5593 system can support "thousands" of hardware watchpoints, but gives
5594 no method for finding out how many; It doesn't say anything about
5595 the allowed size for the watched area either. So we just tell
5596 GDB 'yes'. */
5597 return 1;
5598 }
5599
5600 void
5601 procfs_use_watchpoints (struct target_ops *t)
5602 {
5603 t->to_stopped_by_watchpoint = procfs_stopped_by_watchpoint;
5604 t->to_insert_watchpoint = procfs_insert_watchpoint;
5605 t->to_remove_watchpoint = procfs_remove_watchpoint;
5606 t->to_region_ok_for_hw_watchpoint = procfs_region_ok_for_hw_watchpoint;
5607 t->to_can_use_hw_breakpoint = procfs_can_use_hw_breakpoint;
5608 }
5609
5610 /*
5611 * Memory Mappings Functions:
5612 */
5613
5614 /*
5615 * Function: iterate_over_mappings
5616 *
5617 * Call a callback function once for each mapping, passing it the mapping,
5618 * an optional secondary callback function, and some optional opaque data.
5619 * Quit and return the first non-zero value returned from the callback.
5620 *
5621 * Arguments:
5622 * pi -- procinfo struct for the process to be mapped.
5623 * func -- callback function to be called by this iterator.
5624 * data -- optional opaque data to be passed to the callback function.
5625 * child_func -- optional secondary function pointer to be passed
5626 * to the child function.
5627 *
5628 * Return: First non-zero return value from the callback function,
5629 * or zero.
5630 */
5631
5632 static int
5633 iterate_over_mappings (procinfo *pi,
5634 iterate_over_mappings_cb_ftype *child_func,
5635 void *data,
5636 int (*func) (struct prmap *map,
5637 iterate_over_mappings_cb_ftype *child_func,
5638 void *data))
5639 {
5640 char pathname[MAX_PROC_NAME_SIZE];
5641 struct prmap *prmaps;
5642 struct prmap *prmap;
5643 int funcstat;
5644 int map_fd;
5645 int nmap;
5646 #ifdef NEW_PROC_API
5647 struct stat sbuf;
5648 #endif
5649
5650 /* Get the number of mappings, allocate space,
5651 and read the mappings into prmaps. */
5652 #ifdef NEW_PROC_API
5653 /* Open map fd. */
5654 sprintf (pathname, "/proc/%d/map", pi->pid);
5655 if ((map_fd = open (pathname, O_RDONLY)) < 0)
5656 proc_error (pi, "iterate_over_mappings (open)", __LINE__);
5657
5658 /* Make sure it gets closed again. */
5659 make_cleanup_close (map_fd);
5660
5661 /* Use stat to determine the file size, and compute
5662 the number of prmap_t objects it contains. */
5663 if (fstat (map_fd, &sbuf) != 0)
5664 proc_error (pi, "iterate_over_mappings (fstat)", __LINE__);
5665
5666 nmap = sbuf.st_size / sizeof (prmap_t);
5667 prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps));
5668 if (read (map_fd, (char *) prmaps, nmap * sizeof (*prmaps))
5669 != (nmap * sizeof (*prmaps)))
5670 proc_error (pi, "iterate_over_mappings (read)", __LINE__);
5671 #else
5672 /* Use ioctl command PIOCNMAP to get number of mappings. */
5673 if (ioctl (pi->ctl_fd, PIOCNMAP, &nmap) != 0)
5674 proc_error (pi, "iterate_over_mappings (PIOCNMAP)", __LINE__);
5675
5676 prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps));
5677 if (ioctl (pi->ctl_fd, PIOCMAP, prmaps) != 0)
5678 proc_error (pi, "iterate_over_mappings (PIOCMAP)", __LINE__);
5679 #endif
5680
5681 for (prmap = prmaps; nmap > 0; prmap++, nmap--)
5682 if ((funcstat = (*func) (prmap, child_func, data)) != 0)
5683 return funcstat;
5684
5685 return 0;
5686 }
5687
5688 /*
5689 * Function: find_memory_regions_callback
5690 *
5691 * Implements the to_find_memory_regions method.
5692 * Calls an external function for each memory region.
5693 * External function will have the signiture:
5694 *
5695 * int callback (CORE_ADDR vaddr,
5696 * unsigned long size,
5697 * int read, int write, int execute,
5698 * void *data);
5699 *
5700 * Returns the integer value returned by the callback.
5701 */
5702
5703 static int
5704 find_memory_regions_callback (struct prmap *map,
5705 int (*func) (CORE_ADDR,
5706 unsigned long,
5707 int, int, int,
5708 void *),
5709 void *data)
5710 {
5711 return (*func) ((CORE_ADDR) map->pr_vaddr,
5712 map->pr_size,
5713 (map->pr_mflags & MA_READ) != 0,
5714 (map->pr_mflags & MA_WRITE) != 0,
5715 (map->pr_mflags & MA_EXEC) != 0,
5716 data);
5717 }
5718
5719 /*
5720 * Function: proc_find_memory_regions
5721 *
5722 * External interface. Calls a callback function once for each
5723 * mapped memory region in the child process, passing as arguments
5724 * CORE_ADDR virtual_address,
5725 * unsigned long size,
5726 * int read, TRUE if region is readable by the child
5727 * int write, TRUE if region is writable by the child
5728 * int execute TRUE if region is executable by the child.
5729 *
5730 * Stops iterating and returns the first non-zero value
5731 * returned by the callback.
5732 */
5733
5734 static int
5735 proc_find_memory_regions (int (*func) (CORE_ADDR,
5736 unsigned long,
5737 int, int, int,
5738 void *),
5739 void *data)
5740 {
5741 procinfo *pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
5742
5743 return iterate_over_mappings (pi, func, data,
5744 find_memory_regions_callback);
5745 }
5746
5747 /*
5748 * Function: mappingflags
5749 *
5750 * Returns an ascii representation of a memory mapping's flags.
5751 */
5752
5753 static char *
5754 mappingflags (long flags)
5755 {
5756 static char asciiflags[8];
5757
5758 strcpy (asciiflags, "-------");
5759 #if defined (MA_PHYS)
5760 if (flags & MA_PHYS)
5761 asciiflags[0] = 'd';
5762 #endif
5763 if (flags & MA_STACK)
5764 asciiflags[1] = 's';
5765 if (flags & MA_BREAK)
5766 asciiflags[2] = 'b';
5767 if (flags & MA_SHARED)
5768 asciiflags[3] = 's';
5769 if (flags & MA_READ)
5770 asciiflags[4] = 'r';
5771 if (flags & MA_WRITE)
5772 asciiflags[5] = 'w';
5773 if (flags & MA_EXEC)
5774 asciiflags[6] = 'x';
5775 return (asciiflags);
5776 }
5777
5778 /*
5779 * Function: info_mappings_callback
5780 *
5781 * Callback function, does the actual work for 'info proc mappings'.
5782 */
5783
5784 static int
5785 info_mappings_callback (struct prmap *map,
5786 iterate_over_mappings_cb_ftype *ignore,
5787 void *unused)
5788 {
5789 unsigned int pr_off;
5790
5791 #ifdef PCAGENT /* Horrible hack: only defined on Solaris 2.6+ */
5792 pr_off = (unsigned int) map->pr_offset;
5793 #else
5794 pr_off = map->pr_off;
5795 #endif
5796
5797 if (gdbarch_addr_bit (target_gdbarch) == 32)
5798 printf_filtered ("\t%#10lx %#10lx %#10lx %#10x %7s\n",
5799 (unsigned long) map->pr_vaddr,
5800 (unsigned long) map->pr_vaddr + map->pr_size - 1,
5801 (unsigned long) map->pr_size,
5802 pr_off,
5803 mappingflags (map->pr_mflags));
5804 else
5805 printf_filtered (" %#18lx %#18lx %#10lx %#10x %7s\n",
5806 (unsigned long) map->pr_vaddr,
5807 (unsigned long) map->pr_vaddr + map->pr_size - 1,
5808 (unsigned long) map->pr_size,
5809 pr_off,
5810 mappingflags (map->pr_mflags));
5811
5812 return 0;
5813 }
5814
5815 /*
5816 * Function: info_proc_mappings
5817 *
5818 * Implement the "info proc mappings" subcommand.
5819 */
5820
5821 static void
5822 info_proc_mappings (procinfo *pi, int summary)
5823 {
5824 if (summary)
5825 return; /* No output for summary mode. */
5826
5827 printf_filtered (_("Mapped address spaces:\n\n"));
5828 if (gdbarch_ptr_bit (target_gdbarch) == 32)
5829 printf_filtered ("\t%10s %10s %10s %10s %7s\n",
5830 "Start Addr",
5831 " End Addr",
5832 " Size",
5833 " Offset",
5834 "Flags");
5835 else
5836 printf_filtered (" %18s %18s %10s %10s %7s\n",
5837 "Start Addr",
5838 " End Addr",
5839 " Size",
5840 " Offset",
5841 "Flags");
5842
5843 iterate_over_mappings (pi, NULL, NULL, info_mappings_callback);
5844 printf_filtered ("\n");
5845 }
5846
5847 /*
5848 * Function: info_proc_cmd
5849 *
5850 * Implement the "info proc" command.
5851 */
5852
5853 static void
5854 info_proc_cmd (char *args, int from_tty)
5855 {
5856 struct cleanup *old_chain;
5857 procinfo *process = NULL;
5858 procinfo *thread = NULL;
5859 char **argv = NULL;
5860 char *tmp = NULL;
5861 int pid = 0;
5862 int tid = 0;
5863 int mappings = 0;
5864
5865 old_chain = make_cleanup (null_cleanup, 0);
5866 if (args)
5867 {
5868 argv = gdb_buildargv (args);
5869 make_cleanup_freeargv (argv);
5870 }
5871 while (argv != NULL && *argv != NULL)
5872 {
5873 if (isdigit (argv[0][0]))
5874 {
5875 pid = strtoul (argv[0], &tmp, 10);
5876 if (*tmp == '/')
5877 tid = strtoul (++tmp, NULL, 10);
5878 }
5879 else if (argv[0][0] == '/')
5880 {
5881 tid = strtoul (argv[0] + 1, NULL, 10);
5882 }
5883 else if (strncmp (argv[0], "mappings", strlen (argv[0])) == 0)
5884 {
5885 mappings = 1;
5886 }
5887 else
5888 {
5889 /* [...] */
5890 }
5891 argv++;
5892 }
5893 if (pid == 0)
5894 pid = PIDGET (inferior_ptid);
5895 if (pid == 0)
5896 error (_("No current process: you must name one."));
5897 else
5898 {
5899 /* Have pid, will travel.
5900 First see if it's a process we're already debugging. */
5901 process = find_procinfo (pid, 0);
5902 if (process == NULL)
5903 {
5904 /* No. So open a procinfo for it, but
5905 remember to close it again when finished. */
5906 process = create_procinfo (pid, 0);
5907 make_cleanup (do_destroy_procinfo_cleanup, process);
5908 if (!open_procinfo_files (process, FD_CTL))
5909 proc_error (process, "info proc, open_procinfo_files", __LINE__);
5910 }
5911 }
5912 if (tid != 0)
5913 thread = create_procinfo (pid, tid);
5914
5915 if (process)
5916 {
5917 printf_filtered (_("process %d flags:\n"), process->pid);
5918 proc_prettyprint_flags (proc_flags (process), 1);
5919 if (proc_flags (process) & (PR_STOPPED | PR_ISTOP))
5920 proc_prettyprint_why (proc_why (process), proc_what (process), 1);
5921 if (proc_get_nthreads (process) > 1)
5922 printf_filtered ("Process has %d threads.\n",
5923 proc_get_nthreads (process));
5924 }
5925 if (thread)
5926 {
5927 printf_filtered (_("thread %d flags:\n"), thread->tid);
5928 proc_prettyprint_flags (proc_flags (thread), 1);
5929 if (proc_flags (thread) & (PR_STOPPED | PR_ISTOP))
5930 proc_prettyprint_why (proc_why (thread), proc_what (thread), 1);
5931 }
5932
5933 if (mappings)
5934 {
5935 info_proc_mappings (process, 0);
5936 }
5937
5938 do_cleanups (old_chain);
5939 }
5940
5941 /* Modify the status of the system call identified by SYSCALLNUM in
5942 the set of syscalls that are currently traced/debugged.
5943
5944 If ENTRY_OR_EXIT is set to PR_SYSENTRY, then the entry syscalls set
5945 will be updated. Otherwise, the exit syscalls set will be updated.
5946
5947 If MODE is FLAG_SET, then traces will be enabled. Otherwise, they
5948 will be disabled. */
5949
5950 static void
5951 proc_trace_syscalls_1 (procinfo *pi, int syscallnum, int entry_or_exit,
5952 int mode, int from_tty)
5953 {
5954 sysset_t *sysset;
5955
5956 if (entry_or_exit == PR_SYSENTRY)
5957 sysset = proc_get_traced_sysentry (pi, NULL);
5958 else
5959 sysset = proc_get_traced_sysexit (pi, NULL);
5960
5961 if (sysset == NULL)
5962 proc_error (pi, "proc-trace, get_traced_sysset", __LINE__);
5963
5964 if (mode == FLAG_SET)
5965 gdb_praddsysset (sysset, syscallnum);
5966 else
5967 gdb_prdelsysset (sysset, syscallnum);
5968
5969 if (entry_or_exit == PR_SYSENTRY)
5970 {
5971 if (!proc_set_traced_sysentry (pi, sysset))
5972 proc_error (pi, "proc-trace, set_traced_sysentry", __LINE__);
5973 }
5974 else
5975 {
5976 if (!proc_set_traced_sysexit (pi, sysset))
5977 proc_error (pi, "proc-trace, set_traced_sysexit", __LINE__);
5978 }
5979 }
5980
5981 static void
5982 proc_trace_syscalls (char *args, int from_tty, int entry_or_exit, int mode)
5983 {
5984 procinfo *pi;
5985
5986 if (PIDGET (inferior_ptid) <= 0)
5987 error (_("you must be debugging a process to use this command."));
5988
5989 if (args == NULL || args[0] == 0)
5990 error_no_arg (_("system call to trace"));
5991
5992 pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
5993 if (isdigit (args[0]))
5994 {
5995 const int syscallnum = atoi (args);
5996
5997 proc_trace_syscalls_1 (pi, syscallnum, entry_or_exit, mode, from_tty);
5998 }
5999 }
6000
6001 static void
6002 proc_trace_sysentry_cmd (char *args, int from_tty)
6003 {
6004 proc_trace_syscalls (args, from_tty, PR_SYSENTRY, FLAG_SET);
6005 }
6006
6007 static void
6008 proc_trace_sysexit_cmd (char *args, int from_tty)
6009 {
6010 proc_trace_syscalls (args, from_tty, PR_SYSEXIT, FLAG_SET);
6011 }
6012
6013 static void
6014 proc_untrace_sysentry_cmd (char *args, int from_tty)
6015 {
6016 proc_trace_syscalls (args, from_tty, PR_SYSENTRY, FLAG_RESET);
6017 }
6018
6019 static void
6020 proc_untrace_sysexit_cmd (char *args, int from_tty)
6021 {
6022 proc_trace_syscalls (args, from_tty, PR_SYSEXIT, FLAG_RESET);
6023 }
6024
6025
6026 void
6027 _initialize_procfs (void)
6028 {
6029 observer_attach_inferior_created (procfs_inferior_created);
6030
6031 add_info ("proc", info_proc_cmd, _("\
6032 Show /proc process information about any running process.\n\
6033 Specify process id, or use the program being debugged by default.\n\
6034 Specify keyword 'mappings' for detailed info on memory mappings."));
6035 add_com ("proc-trace-entry", no_class, proc_trace_sysentry_cmd,
6036 _("Give a trace of entries into the syscall."));
6037 add_com ("proc-trace-exit", no_class, proc_trace_sysexit_cmd,
6038 _("Give a trace of exits from the syscall."));
6039 add_com ("proc-untrace-entry", no_class, proc_untrace_sysentry_cmd,
6040 _("Cancel a trace of entries into the syscall."));
6041 add_com ("proc-untrace-exit", no_class, proc_untrace_sysexit_cmd,
6042 _("Cancel a trace of exits from the syscall."));
6043 }
6044
6045 /* =================== END, GDB "MODULE" =================== */
6046
6047
6048
6049 /* miscellaneous stubs: */
6050 /* The following satisfy a few random symbols mostly created by */
6051 /* the solaris threads implementation, which I will chase down */
6052 /* later. */
6053
6054 /*
6055 * Return a pid for which we guarantee
6056 * we will be able to find a 'live' procinfo.
6057 */
6058
6059 ptid_t
6060 procfs_first_available (void)
6061 {
6062 return pid_to_ptid (procinfo_list ? procinfo_list->pid : -1);
6063 }
6064
6065 /* =================== GCORE .NOTE "MODULE" =================== */
6066 #if defined (UNIXWARE) || defined (PIOCOPENLWP) || defined (PCAGENT)
6067 /* gcore only implemented on solaris and unixware (so far) */
6068
6069 static char *
6070 procfs_do_thread_registers (bfd *obfd, ptid_t ptid,
6071 char *note_data, int *note_size,
6072 enum target_signal stop_signal)
6073 {
6074 struct regcache *regcache = get_thread_regcache (ptid);
6075 gdb_gregset_t gregs;
6076 gdb_fpregset_t fpregs;
6077 unsigned long merged_pid;
6078 struct cleanup *old_chain;
6079
6080 merged_pid = TIDGET (ptid) << 16 | PIDGET (ptid);
6081
6082 /* This part is the old method for fetching registers.
6083 It should be replaced by the newer one using regsets
6084 once it is implemented in this platform:
6085 gdbarch_regset_from_core_section() and regset->collect_regset(). */
6086
6087 old_chain = save_inferior_ptid ();
6088 inferior_ptid = ptid;
6089 target_fetch_registers (regcache, -1);
6090
6091 fill_gregset (regcache, &gregs, -1);
6092 #if defined (NEW_PROC_API)
6093 note_data = (char *) elfcore_write_lwpstatus (obfd,
6094 note_data,
6095 note_size,
6096 merged_pid,
6097 stop_signal,
6098 &gregs);
6099 #else
6100 note_data = (char *) elfcore_write_prstatus (obfd,
6101 note_data,
6102 note_size,
6103 merged_pid,
6104 stop_signal,
6105 &gregs);
6106 #endif
6107 fill_fpregset (regcache, &fpregs, -1);
6108 note_data = (char *) elfcore_write_prfpreg (obfd,
6109 note_data,
6110 note_size,
6111 &fpregs,
6112 sizeof (fpregs));
6113
6114 do_cleanups (old_chain);
6115
6116 return note_data;
6117 }
6118
6119 struct procfs_corefile_thread_data {
6120 bfd *obfd;
6121 char *note_data;
6122 int *note_size;
6123 enum target_signal stop_signal;
6124 };
6125
6126 static int
6127 procfs_corefile_thread_callback (procinfo *pi, procinfo *thread, void *data)
6128 {
6129 struct procfs_corefile_thread_data *args = data;
6130
6131 if (pi != NULL)
6132 {
6133 ptid_t ptid = MERGEPID (pi->pid, thread->tid);
6134 args->note_data = procfs_do_thread_registers (args->obfd, ptid,
6135 args->note_data,
6136 args->note_size,
6137 args->stop_signal);
6138 }
6139 return 0;
6140 }
6141
6142 static int
6143 find_signalled_thread (struct thread_info *info, void *data)
6144 {
6145 if (info->stop_signal != TARGET_SIGNAL_0
6146 && ptid_get_pid (info->ptid) == ptid_get_pid (inferior_ptid))
6147 return 1;
6148
6149 return 0;
6150 }
6151
6152 static enum target_signal
6153 find_stop_signal (void)
6154 {
6155 struct thread_info *info =
6156 iterate_over_threads (find_signalled_thread, NULL);
6157
6158 if (info)
6159 return info->stop_signal;
6160 else
6161 return TARGET_SIGNAL_0;
6162 }
6163
6164 static char *
6165 procfs_make_note_section (bfd *obfd, int *note_size)
6166 {
6167 struct cleanup *old_chain;
6168 gdb_gregset_t gregs;
6169 gdb_fpregset_t fpregs;
6170 char fname[16] = {'\0'};
6171 char psargs[80] = {'\0'};
6172 procinfo *pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
6173 char *note_data = NULL;
6174 char *inf_args;
6175 struct procfs_corefile_thread_data thread_args;
6176 gdb_byte *auxv;
6177 int auxv_len;
6178 enum target_signal stop_signal;
6179
6180 if (get_exec_file (0))
6181 {
6182 strncpy (fname, strrchr (get_exec_file (0), '/') + 1, sizeof (fname));
6183 strncpy (psargs, get_exec_file (0),
6184 sizeof (psargs));
6185
6186 inf_args = get_inferior_args ();
6187 if (inf_args && *inf_args &&
6188 strlen (inf_args) < ((int) sizeof (psargs) - (int) strlen (psargs)))
6189 {
6190 strncat (psargs, " ",
6191 sizeof (psargs) - strlen (psargs));
6192 strncat (psargs, inf_args,
6193 sizeof (psargs) - strlen (psargs));
6194 }
6195 }
6196
6197 note_data = (char *) elfcore_write_prpsinfo (obfd,
6198 note_data,
6199 note_size,
6200 fname,
6201 psargs);
6202
6203 stop_signal = find_stop_signal ();
6204
6205 #ifdef UNIXWARE
6206 fill_gregset (get_current_regcache (), &gregs, -1);
6207 note_data = elfcore_write_pstatus (obfd, note_data, note_size,
6208 PIDGET (inferior_ptid),
6209 stop_signal, &gregs);
6210 #endif
6211
6212 thread_args.obfd = obfd;
6213 thread_args.note_data = note_data;
6214 thread_args.note_size = note_size;
6215 thread_args.stop_signal = stop_signal;
6216 proc_iterate_over_threads (pi, procfs_corefile_thread_callback, &thread_args);
6217
6218 /* There should be always at least one thread. */
6219 gdb_assert (thread_args.note_data != note_data);
6220 note_data = thread_args.note_data;
6221
6222 auxv_len = target_read_alloc (&current_target, TARGET_OBJECT_AUXV,
6223 NULL, &auxv);
6224 if (auxv_len > 0)
6225 {
6226 note_data = elfcore_write_note (obfd, note_data, note_size,
6227 "CORE", NT_AUXV, auxv, auxv_len);
6228 xfree (auxv);
6229 }
6230
6231 make_cleanup (xfree, note_data);
6232 return note_data;
6233 }
6234 #else /* !(Solaris or Unixware) */
6235 static char *
6236 procfs_make_note_section (bfd *obfd, int *note_size)
6237 {
6238 error (_("gcore not implemented for this host."));
6239 return NULL; /* lint */
6240 }
6241 #endif /* Solaris or Unixware */
6242 /* =================== END GCORE .NOTE "MODULE" =================== */
This page took 0.185709 seconds and 5 git commands to generate.