* defs.h (QUIT): Call interactive_hook to allow GUI to interrupt.
[deliverable/binutils-gdb.git] / gdb / procfs.c
1 /* Machine independent support for SVR4 /proc (process file system) for GDB.
2 Copyright 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
3 Written by Fred Fish at Cygnus Support.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21
22 /* N O T E S
23
24 For information on the details of using /proc consult section proc(4)
25 in the UNIX System V Release 4 System Administrator's Reference Manual.
26
27 The general register and floating point register sets are manipulated by
28 separate ioctl's. This file makes the assumption that if FP0_REGNUM is
29 defined, then support for the floating point register set is desired,
30 regardless of whether or not the actual target has floating point hardware.
31
32 */
33
34
35 #include "defs.h"
36
37 #include <sys/types.h>
38 #include <time.h>
39 #include <sys/procfs.h>
40 #include <fcntl.h>
41 #include <errno.h>
42 #include <string.h>
43 #include <stropts.h>
44 #include <poll.h>
45 #include <unistd.h>
46 #include <sys/stat.h>
47
48 #include "inferior.h"
49 #include "target.h"
50 #include "command.h"
51 #include "gdbcore.h"
52
53 #define MAX_SYSCALLS 256 /* Maximum number of syscalls for table */
54
55 #ifndef PROC_NAME_FMT
56 #define PROC_NAME_FMT "/proc/%05d"
57 #endif
58
59 extern struct target_ops procfs_ops; /* Forward declaration */
60
61 #if 1 /* FIXME: Gross and ugly hack to resolve coredep.c global */
62 CORE_ADDR kernel_u_addr;
63 #endif
64
65 #ifdef BROKEN_SIGINFO_H /* Workaround broken SGS <sys/siginfo.h> */
66 #undef si_pid
67 #define si_pid _data._proc.pid
68 #undef si_uid
69 #define si_uid _data._proc._pdata._kill.uid
70 #endif /* BROKEN_SIGINFO_H */
71
72 /* All access to the inferior, either one started by gdb or one that has
73 been attached to, is controlled by an instance of a procinfo structure,
74 defined below. Since gdb currently only handles one inferior at a time,
75 the procinfo structure for the inferior is statically allocated and
76 only one exists at any given time. There is a separate procinfo
77 structure for use by the "info proc" command, so that we can print
78 useful information about any random process without interfering with
79 the inferior's procinfo information. */
80
81 struct procinfo {
82 struct procinfo *next;
83 int pid; /* Process ID of inferior */
84 int fd; /* File descriptor for /proc entry */
85 char *pathname; /* Pathname to /proc entry */
86 int had_event; /* poll/select says something happened */
87 int was_stopped; /* Nonzero if was stopped prior to attach */
88 int nopass_next_sigstop; /* Don't pass a sigstop on next resume */
89 prrun_t prrun; /* Control state when it is run */
90 prstatus_t prstatus; /* Current process status info */
91 gregset_t gregset; /* General register set */
92 fpregset_t fpregset; /* Floating point register set */
93 fltset_t fltset; /* Current traced hardware fault set */
94 sigset_t trace; /* Current traced signal set */
95 sysset_t exitset; /* Current traced system call exit set */
96 sysset_t entryset; /* Current traced system call entry set */
97 fltset_t saved_fltset; /* Saved traced hardware fault set */
98 sigset_t saved_trace; /* Saved traced signal set */
99 sigset_t saved_sighold; /* Saved held signal set */
100 sysset_t saved_exitset; /* Saved traced system call exit set */
101 sysset_t saved_entryset; /* Saved traced system call entry set */
102 };
103
104 /* List of inferior process information */
105 static struct procinfo *procinfo_list = NULL;
106
107 static struct pollfd *poll_list; /* pollfds used for waiting on /proc */
108
109 static int num_poll_list = 0; /* Number of entries in poll_list */
110
111 static int last_resume_pid = -1; /* Last pid used with procfs_resume */
112
113 /* Much of the information used in the /proc interface, particularly for
114 printing status information, is kept as tables of structures of the
115 following form. These tables can be used to map numeric values to
116 their symbolic names and to a string that describes their specific use. */
117
118 struct trans {
119 int value; /* The numeric value */
120 char *name; /* The equivalent symbolic value */
121 char *desc; /* Short description of value */
122 };
123
124 /* Translate bits in the pr_flags member of the prstatus structure, into the
125 names and desc information. */
126
127 static struct trans pr_flag_table[] =
128 {
129 #if defined (PR_STOPPED)
130 PR_STOPPED, "PR_STOPPED", "Process is stopped",
131 #endif
132 #if defined (PR_ISTOP)
133 PR_ISTOP, "PR_ISTOP", "Stopped on an event of interest",
134 #endif
135 #if defined (PR_DSTOP)
136 PR_DSTOP, "PR_DSTOP", "A stop directive is in effect",
137 #endif
138 #if defined (PR_ASLEEP)
139 PR_ASLEEP, "PR_ASLEEP", "Sleeping in an interruptible system call",
140 #endif
141 #if defined (PR_FORK)
142 PR_FORK, "PR_FORK", "Inherit-on-fork is in effect",
143 #endif
144 #if defined (PR_RLC)
145 PR_RLC, "PR_RLC", "Run-on-last-close is in effect",
146 #endif
147 #if defined (PR_PTRACE)
148 PR_PTRACE, "PR_PTRACE", "Process is being controlled by ptrace",
149 #endif
150 #if defined (PR_PCINVAL)
151 PR_PCINVAL, "PR_PCINVAL", "PC refers to an invalid virtual address",
152 #endif
153 #if defined (PR_ISSYS)
154 PR_ISSYS, "PR_ISSYS", "Is a system process",
155 #endif
156 #if defined (PR_STEP)
157 PR_STEP, "PR_STEP", "Process has single step pending",
158 #endif
159 #if defined (PR_KLC)
160 PR_KLC, "PR_KLC", "Kill-on-last-close is in effect",
161 #endif
162 #if defined (PR_ASYNC)
163 PR_ASYNC, "PR_ASYNC", "Asynchronous stop is in effect",
164 #endif
165 #if defined (PR_PCOMPAT)
166 PR_PCOMPAT, "PR_PCOMPAT", "Ptrace compatibility mode in effect",
167 #endif
168 0, NULL, NULL
169 };
170
171 /* Translate values in the pr_why field of the prstatus struct. */
172
173 static struct trans pr_why_table[] =
174 {
175 #if defined (PR_REQUESTED)
176 PR_REQUESTED, "PR_REQUESTED", "Directed to stop via PIOCSTOP/PIOCWSTOP",
177 #endif
178 #if defined (PR_SIGNALLED)
179 PR_SIGNALLED, "PR_SIGNALLED", "Receipt of a traced signal",
180 #endif
181 #if defined (PR_FAULTED)
182 PR_FAULTED, "PR_FAULTED", "Incurred a traced hardware fault",
183 #endif
184 #if defined (PR_SYSENTRY)
185 PR_SYSENTRY, "PR_SYSENTRY", "Entry to a traced system call",
186 #endif
187 #if defined (PR_SYSEXIT)
188 PR_SYSEXIT, "PR_SYSEXIT", "Exit from a traced system call",
189 #endif
190 #if defined (PR_JOBCONTROL)
191 PR_JOBCONTROL, "PR_JOBCONTROL", "Default job control stop signal action",
192 #endif
193 #if defined (PR_SUSPENDED)
194 PR_SUSPENDED, "PR_SUSPENDED", "Process suspended",
195 #endif
196 0, NULL, NULL
197 };
198
199 /* Hardware fault translation table. */
200
201 static struct trans faults_table[] =
202 {
203 #if defined (FLTILL)
204 FLTILL, "FLTILL", "Illegal instruction",
205 #endif
206 #if defined (FLTPRIV)
207 FLTPRIV, "FLTPRIV", "Privileged instruction",
208 #endif
209 #if defined (FLTBPT)
210 FLTBPT, "FLTBPT", "Breakpoint trap",
211 #endif
212 #if defined (FLTTRACE)
213 FLTTRACE, "FLTTRACE", "Trace trap",
214 #endif
215 #if defined (FLTACCESS)
216 FLTACCESS, "FLTACCESS", "Memory access fault",
217 #endif
218 #if defined (FLTBOUNDS)
219 FLTBOUNDS, "FLTBOUNDS", "Memory bounds violation",
220 #endif
221 #if defined (FLTIOVF)
222 FLTIOVF, "FLTIOVF", "Integer overflow",
223 #endif
224 #if defined (FLTIZDIV)
225 FLTIZDIV, "FLTIZDIV", "Integer zero divide",
226 #endif
227 #if defined (FLTFPE)
228 FLTFPE, "FLTFPE", "Floating-point exception",
229 #endif
230 #if defined (FLTSTACK)
231 FLTSTACK, "FLTSTACK", "Unrecoverable stack fault",
232 #endif
233 #if defined (FLTPAGE)
234 FLTPAGE, "FLTPAGE", "Recoverable page fault",
235 #endif
236 0, NULL, NULL
237 };
238
239 /* Translation table for signal generation information. See UNIX System
240 V Release 4 Programmer's Reference Manual, siginfo(5). */
241
242 static struct sigcode {
243 int signo;
244 int code;
245 char *codename;
246 char *desc;
247 } siginfo_table[] = {
248 #if defined (SIGILL) && defined (ILL_ILLOPC)
249 SIGILL, ILL_ILLOPC, "ILL_ILLOPC", "Illegal opcode",
250 #endif
251 #if defined (SIGILL) && defined (ILL_ILLOPN)
252 SIGILL, ILL_ILLOPN, "ILL_ILLOPN", "Illegal operand",
253 #endif
254 #if defined (SIGILL) && defined (ILL_ILLADR)
255 SIGILL, ILL_ILLADR, "ILL_ILLADR", "Illegal addressing mode",
256 #endif
257 #if defined (SIGILL) && defined (ILL_ILLTRP)
258 SIGILL, ILL_ILLTRP, "ILL_ILLTRP", "Illegal trap",
259 #endif
260 #if defined (SIGILL) && defined (ILL_PRVOPC)
261 SIGILL, ILL_PRVOPC, "ILL_PRVOPC", "Privileged opcode",
262 #endif
263 #if defined (SIGILL) && defined (ILL_PRVREG)
264 SIGILL, ILL_PRVREG, "ILL_PRVREG", "Privileged register",
265 #endif
266 #if defined (SIGILL) && defined (ILL_COPROC)
267 SIGILL, ILL_COPROC, "ILL_COPROC", "Coprocessor error",
268 #endif
269 #if defined (SIGILL) && defined (ILL_BADSTK)
270 SIGILL, ILL_BADSTK, "ILL_BADSTK", "Internal stack error",
271 #endif
272 #if defined (SIGFPE) && defined (FPE_INTDIV)
273 SIGFPE, FPE_INTDIV, "FPE_INTDIV", "Integer divide by zero",
274 #endif
275 #if defined (SIGFPE) && defined (FPE_INTOVF)
276 SIGFPE, FPE_INTOVF, "FPE_INTOVF", "Integer overflow",
277 #endif
278 #if defined (SIGFPE) && defined (FPE_FLTDIV)
279 SIGFPE, FPE_FLTDIV, "FPE_FLTDIV", "Floating point divide by zero",
280 #endif
281 #if defined (SIGFPE) && defined (FPE_FLTOVF)
282 SIGFPE, FPE_FLTOVF, "FPE_FLTOVF", "Floating point overflow",
283 #endif
284 #if defined (SIGFPE) && defined (FPE_FLTUND)
285 SIGFPE, FPE_FLTUND, "FPE_FLTUND", "Floating point underflow",
286 #endif
287 #if defined (SIGFPE) && defined (FPE_FLTRES)
288 SIGFPE, FPE_FLTRES, "FPE_FLTRES", "Floating point inexact result",
289 #endif
290 #if defined (SIGFPE) && defined (FPE_FLTINV)
291 SIGFPE, FPE_FLTINV, "FPE_FLTINV", "Invalid floating point operation",
292 #endif
293 #if defined (SIGFPE) && defined (FPE_FLTSUB)
294 SIGFPE, FPE_FLTSUB, "FPE_FLTSUB", "Subscript out of range",
295 #endif
296 #if defined (SIGSEGV) && defined (SEGV_MAPERR)
297 SIGSEGV, SEGV_MAPERR, "SEGV_MAPERR", "Address not mapped to object",
298 #endif
299 #if defined (SIGSEGV) && defined (SEGV_ACCERR)
300 SIGSEGV, SEGV_ACCERR, "SEGV_ACCERR", "Invalid permissions for object",
301 #endif
302 #if defined (SIGBUS) && defined (BUS_ADRALN)
303 SIGBUS, BUS_ADRALN, "BUS_ADRALN", "Invalid address alignment",
304 #endif
305 #if defined (SIGBUS) && defined (BUS_ADRERR)
306 SIGBUS, BUS_ADRERR, "BUS_ADRERR", "Non-existent physical address",
307 #endif
308 #if defined (SIGBUS) && defined (BUS_OBJERR)
309 SIGBUS, BUS_OBJERR, "BUS_OBJERR", "Object specific hardware error",
310 #endif
311 #if defined (SIGTRAP) && defined (TRAP_BRKPT)
312 SIGTRAP, TRAP_BRKPT, "TRAP_BRKPT", "Process breakpoint",
313 #endif
314 #if defined (SIGTRAP) && defined (TRAP_TRACE)
315 SIGTRAP, TRAP_TRACE, "TRAP_TRACE", "Process trace trap",
316 #endif
317 #if defined (SIGCLD) && defined (CLD_EXITED)
318 SIGCLD, CLD_EXITED, "CLD_EXITED", "Child has exited",
319 #endif
320 #if defined (SIGCLD) && defined (CLD_KILLED)
321 SIGCLD, CLD_KILLED, "CLD_KILLED", "Child was killed",
322 #endif
323 #if defined (SIGCLD) && defined (CLD_DUMPED)
324 SIGCLD, CLD_DUMPED, "CLD_DUMPED", "Child has terminated abnormally",
325 #endif
326 #if defined (SIGCLD) && defined (CLD_TRAPPED)
327 SIGCLD, CLD_TRAPPED, "CLD_TRAPPED", "Traced child has trapped",
328 #endif
329 #if defined (SIGCLD) && defined (CLD_STOPPED)
330 SIGCLD, CLD_STOPPED, "CLD_STOPPED", "Child has stopped",
331 #endif
332 #if defined (SIGCLD) && defined (CLD_CONTINUED)
333 SIGCLD, CLD_CONTINUED, "CLD_CONTINUED", "Stopped child had continued",
334 #endif
335 #if defined (SIGPOLL) && defined (POLL_IN)
336 SIGPOLL, POLL_IN, "POLL_IN", "Input input available",
337 #endif
338 #if defined (SIGPOLL) && defined (POLL_OUT)
339 SIGPOLL, POLL_OUT, "POLL_OUT", "Output buffers available",
340 #endif
341 #if defined (SIGPOLL) && defined (POLL_MSG)
342 SIGPOLL, POLL_MSG, "POLL_MSG", "Input message available",
343 #endif
344 #if defined (SIGPOLL) && defined (POLL_ERR)
345 SIGPOLL, POLL_ERR, "POLL_ERR", "I/O error",
346 #endif
347 #if defined (SIGPOLL) && defined (POLL_PRI)
348 SIGPOLL, POLL_PRI, "POLL_PRI", "High priority input available",
349 #endif
350 #if defined (SIGPOLL) && defined (POLL_HUP)
351 SIGPOLL, POLL_HUP, "POLL_HUP", "Device disconnected",
352 #endif
353 0, 0, NULL, NULL
354 };
355
356 static char *syscall_table[MAX_SYSCALLS];
357
358 /* Prototypes for local functions */
359
360 static void
361 set_proc_siginfo PARAMS ((struct procinfo *, int));
362
363 static void
364 init_syscall_table PARAMS ((void));
365
366 static char *
367 syscallname PARAMS ((int));
368
369 static char *
370 signalname PARAMS ((int));
371
372 static char *
373 errnoname PARAMS ((int));
374
375 static int
376 proc_address_to_fd PARAMS ((struct procinfo *, CORE_ADDR, int));
377
378 static int
379 open_proc_file PARAMS ((int, struct procinfo *, int));
380
381 static void
382 close_proc_file PARAMS ((struct procinfo *));
383
384 static void
385 unconditionally_kill_inferior PARAMS ((struct procinfo *));
386
387 static NORETURN void
388 proc_init_failed PARAMS ((struct procinfo *, char *)) ATTR_NORETURN;
389
390 static void
391 info_proc PARAMS ((char *, int));
392
393 static void
394 info_proc_flags PARAMS ((struct procinfo *, int));
395
396 static void
397 info_proc_stop PARAMS ((struct procinfo *, int));
398
399 static void
400 info_proc_siginfo PARAMS ((struct procinfo *, int));
401
402 static void
403 info_proc_syscalls PARAMS ((struct procinfo *, int));
404
405 static void
406 info_proc_mappings PARAMS ((struct procinfo *, int));
407
408 static void
409 info_proc_signals PARAMS ((struct procinfo *, int));
410
411 static void
412 info_proc_faults PARAMS ((struct procinfo *, int));
413
414 static char *
415 mappingflags PARAMS ((long));
416
417 static char *
418 lookupname PARAMS ((struct trans *, unsigned int, char *));
419
420 static char *
421 lookupdesc PARAMS ((struct trans *, unsigned int));
422
423 static int
424 do_attach PARAMS ((int pid));
425
426 static void
427 do_detach PARAMS ((int siggnal));
428
429 static void
430 procfs_create_inferior PARAMS ((char *, char *, char **));
431
432 static void
433 procfs_notice_signals PARAMS ((int pid));
434
435 static struct procinfo *
436 find_procinfo PARAMS ((pid_t pid, int okfail));
437
438 /* External function prototypes that can't be easily included in any
439 header file because the args are typedefs in system include files. */
440
441 extern void
442 supply_gregset PARAMS ((gregset_t *));
443
444 extern void
445 fill_gregset PARAMS ((gregset_t *, int));
446
447 extern void
448 supply_fpregset PARAMS ((fpregset_t *));
449
450 extern void
451 fill_fpregset PARAMS ((fpregset_t *, int));
452
453 /*
454
455 LOCAL FUNCTION
456
457 find_procinfo -- convert a process id to a struct procinfo
458
459 SYNOPSIS
460
461 static struct procinfo * find_procinfo (pid_t pid, int okfail);
462
463 DESCRIPTION
464
465 Given a process id, look it up in the procinfo chain. Returns
466 a struct procinfo *. If can't find pid, then call error(),
467 unless okfail is set, in which case, return NULL;
468 */
469
470 static struct procinfo *
471 find_procinfo (pid, okfail)
472 pid_t pid;
473 int okfail;
474 {
475 struct procinfo *procinfo;
476
477 for (procinfo = procinfo_list; procinfo; procinfo = procinfo->next)
478 if (procinfo->pid == pid)
479 return procinfo;
480
481 if (okfail)
482 return NULL;
483
484 error ("procfs (find_procinfo): Couldn't locate pid %d", pid);
485 }
486
487 /*
488
489 LOCAL MACRO
490
491 current_procinfo -- convert inferior_pid to a struct procinfo
492
493 SYNOPSIS
494
495 static struct procinfo * current_procinfo;
496
497 DESCRIPTION
498
499 Looks up inferior_pid in the procinfo chain. Always returns a
500 struct procinfo *. If process can't be found, we error() out.
501 */
502
503 #define current_procinfo find_procinfo (inferior_pid, 0)
504
505 /*
506
507 LOCAL FUNCTION
508
509 add_fd -- Add the fd to the poll/select list
510
511 SYNOPSIS
512
513 static void add_fd (struct procinfo *);
514
515 DESCRIPTION
516
517 Add the fd of the supplied procinfo to the list of fds used for
518 poll/select operations.
519 */
520
521 static void
522 add_fd (pi)
523 struct procinfo *pi;
524 {
525 if (num_poll_list <= 0)
526 poll_list = (struct pollfd *) xmalloc (sizeof (struct pollfd));
527 else
528 poll_list = (struct pollfd *) xrealloc (poll_list,
529 (num_poll_list + 1)
530 * sizeof (struct pollfd));
531 poll_list[num_poll_list].fd = pi->fd;
532 poll_list[num_poll_list].events = POLLPRI;
533
534 num_poll_list++;
535 }
536
537 static void
538 remove_fd (pi)
539 struct procinfo *pi;
540 {
541 int i;
542
543 for (i = 0; i < num_poll_list; i++)
544 {
545 if (poll_list[i].fd == pi->fd)
546 {
547 if (i != num_poll_list - 1)
548 memcpy (poll_list, poll_list + i + 1,
549 (num_poll_list - i - 1) * sizeof (struct pollfd));
550
551 num_poll_list--;
552
553 if (num_poll_list == 0)
554 free (poll_list);
555 else
556 poll_list = (struct pollfd *) xrealloc (poll_list,
557 num_poll_list
558 * sizeof (struct pollfd));
559 return;
560 }
561 }
562 }
563
564 #define LOSING_POLL unixware_sux
565
566 static struct procinfo *
567 wait_fd ()
568 {
569 struct procinfo *pi;
570 int num_fds;
571 int i;
572
573 set_sigint_trap (); /* Causes SIGINT to be passed on to the
574 attached process. */
575 set_sigio_trap ();
576
577 #ifndef LOSING_POLL
578 num_fds = poll (poll_list, num_poll_list, -1);
579 #else
580 pi = current_procinfo;
581
582 while (ioctl (pi->fd, PIOCWSTOP, &pi->prstatus) < 0)
583 {
584 if (errno == ENOENT)
585 {
586 /* Process exited. */
587 pi->prstatus.pr_flags = 0;
588 break;
589 }
590 else if (errno != EINTR)
591 {
592 print_sys_errmsg (pi->pathname, errno);
593 error ("PIOCWSTOP failed");
594 }
595 }
596 pi->had_event = 1;
597 #endif
598
599 clear_sigint_trap ();
600 clear_sigio_trap ();
601
602 #ifndef LOSING_POLL
603
604 if (num_fds <= 0)
605 {
606 print_sys_errmsg ("poll failed\n", errno);
607 error ("Poll failed, returned %d", num_fds);
608 }
609
610 for (i = 0; i < num_poll_list && num_fds > 0; i++)
611 {
612 if ((poll_list[i].revents & (POLLPRI|POLLERR|POLLHUP|POLLNVAL)) == 0)
613 continue;
614 for (pi = procinfo_list; pi; pi = pi->next)
615 {
616 if (poll_list[i].fd == pi->fd)
617 {
618 if (ioctl (pi->fd, PIOCSTATUS, &pi->prstatus) < 0)
619 {
620 print_sys_errmsg (pi->pathname, errno);
621 error ("PIOCSTATUS failed");
622 }
623 num_fds--;
624 pi->had_event = 1;
625 break;
626 }
627 }
628 if (!pi)
629 error ("procfs_wait: Couldn't find procinfo for fd %d\n",
630 poll_list[i].fd);
631 }
632 #endif /* LOSING_POLL */
633
634 return pi;
635 }
636
637 /*
638
639 LOCAL FUNCTION
640
641 lookupdesc -- translate a value to a summary desc string
642
643 SYNOPSIS
644
645 static char *lookupdesc (struct trans *transp, unsigned int val);
646
647 DESCRIPTION
648
649 Given a pointer to a translation table and a value to be translated,
650 lookup the desc string and return it.
651 */
652
653 static char *
654 lookupdesc (transp, val)
655 struct trans *transp;
656 unsigned int val;
657 {
658 char *desc;
659
660 for (desc = NULL; transp -> name != NULL; transp++)
661 {
662 if (transp -> value == val)
663 {
664 desc = transp -> desc;
665 break;
666 }
667 }
668
669 /* Didn't find a translation for the specified value, set a default one. */
670
671 if (desc == NULL)
672 {
673 desc = "Unknown";
674 }
675 return (desc);
676 }
677
678 /*
679
680 LOCAL FUNCTION
681
682 lookupname -- translate a value to symbolic name
683
684 SYNOPSIS
685
686 static char *lookupname (struct trans *transp, unsigned int val,
687 char *prefix);
688
689 DESCRIPTION
690
691 Given a pointer to a translation table, a value to be translated,
692 and a default prefix to return if the value can't be translated,
693 match the value with one of the translation table entries and
694 return a pointer to the symbolic name.
695
696 If no match is found it just returns the value as a printable string,
697 with the given prefix. The previous such value, if any, is freed
698 at this time.
699 */
700
701 static char *
702 lookupname (transp, val, prefix)
703 struct trans *transp;
704 unsigned int val;
705 char *prefix;
706 {
707 static char *locbuf;
708 char *name;
709
710 for (name = NULL; transp -> name != NULL; transp++)
711 {
712 if (transp -> value == val)
713 {
714 name = transp -> name;
715 break;
716 }
717 }
718
719 /* Didn't find a translation for the specified value, build a default
720 one using the specified prefix and return it. The lifetime of
721 the value is only until the next one is needed. */
722
723 if (name == NULL)
724 {
725 if (locbuf != NULL)
726 {
727 free (locbuf);
728 }
729 locbuf = xmalloc (strlen (prefix) + 16);
730 sprintf (locbuf, "%s %u", prefix, val);
731 name = locbuf;
732 }
733 return (name);
734 }
735
736 static char *
737 sigcodename (sip)
738 siginfo_t *sip;
739 {
740 struct sigcode *scp;
741 char *name = NULL;
742 static char locbuf[32];
743
744 for (scp = siginfo_table; scp -> codename != NULL; scp++)
745 {
746 if ((scp -> signo == sip -> si_signo) &&
747 (scp -> code == sip -> si_code))
748 {
749 name = scp -> codename;
750 break;
751 }
752 }
753 if (name == NULL)
754 {
755 sprintf (locbuf, "sigcode %u", sip -> si_signo);
756 name = locbuf;
757 }
758 return (name);
759 }
760
761 static char *
762 sigcodedesc (sip)
763 siginfo_t *sip;
764 {
765 struct sigcode *scp;
766 char *desc = NULL;
767
768 for (scp = siginfo_table; scp -> codename != NULL; scp++)
769 {
770 if ((scp -> signo == sip -> si_signo) &&
771 (scp -> code == sip -> si_code))
772 {
773 desc = scp -> desc;
774 break;
775 }
776 }
777 if (desc == NULL)
778 {
779 desc = "Unrecognized signal or trap use";
780 }
781 return (desc);
782 }
783
784 /*
785
786 LOCAL FUNCTION
787
788 syscallname - translate a system call number into a system call name
789
790 SYNOPSIS
791
792 char *syscallname (int syscallnum)
793
794 DESCRIPTION
795
796 Given a system call number, translate it into the printable name
797 of a system call, or into "syscall <num>" if it is an unknown
798 number.
799 */
800
801 static char *
802 syscallname (syscallnum)
803 int syscallnum;
804 {
805 static char locbuf[32];
806 char *rtnval;
807
808 if (syscallnum >= 0 && syscallnum < MAX_SYSCALLS)
809 {
810 rtnval = syscall_table[syscallnum];
811 }
812 else
813 {
814 sprintf (locbuf, "syscall %u", syscallnum);
815 rtnval = locbuf;
816 }
817 return (rtnval);
818 }
819
820 /*
821
822 LOCAL FUNCTION
823
824 init_syscall_table - initialize syscall translation table
825
826 SYNOPSIS
827
828 void init_syscall_table (void)
829
830 DESCRIPTION
831
832 Dynamically initialize the translation table to convert system
833 call numbers into printable system call names. Done once per
834 gdb run, on initialization.
835
836 NOTES
837
838 This is awfully ugly, but preprocessor tricks to make it prettier
839 tend to be nonportable.
840 */
841
842 static void
843 init_syscall_table ()
844 {
845 #if defined (SYS_exit)
846 syscall_table[SYS_exit] = "exit";
847 #endif
848 #if defined (SYS_fork)
849 syscall_table[SYS_fork] = "fork";
850 #endif
851 #if defined (SYS_read)
852 syscall_table[SYS_read] = "read";
853 #endif
854 #if defined (SYS_write)
855 syscall_table[SYS_write] = "write";
856 #endif
857 #if defined (SYS_open)
858 syscall_table[SYS_open] = "open";
859 #endif
860 #if defined (SYS_close)
861 syscall_table[SYS_close] = "close";
862 #endif
863 #if defined (SYS_wait)
864 syscall_table[SYS_wait] = "wait";
865 #endif
866 #if defined (SYS_creat)
867 syscall_table[SYS_creat] = "creat";
868 #endif
869 #if defined (SYS_link)
870 syscall_table[SYS_link] = "link";
871 #endif
872 #if defined (SYS_unlink)
873 syscall_table[SYS_unlink] = "unlink";
874 #endif
875 #if defined (SYS_exec)
876 syscall_table[SYS_exec] = "exec";
877 #endif
878 #if defined (SYS_execv)
879 syscall_table[SYS_execv] = "execv";
880 #endif
881 #if defined (SYS_execve)
882 syscall_table[SYS_execve] = "execve";
883 #endif
884 #if defined (SYS_chdir)
885 syscall_table[SYS_chdir] = "chdir";
886 #endif
887 #if defined (SYS_time)
888 syscall_table[SYS_time] = "time";
889 #endif
890 #if defined (SYS_mknod)
891 syscall_table[SYS_mknod] = "mknod";
892 #endif
893 #if defined (SYS_chmod)
894 syscall_table[SYS_chmod] = "chmod";
895 #endif
896 #if defined (SYS_chown)
897 syscall_table[SYS_chown] = "chown";
898 #endif
899 #if defined (SYS_brk)
900 syscall_table[SYS_brk] = "brk";
901 #endif
902 #if defined (SYS_stat)
903 syscall_table[SYS_stat] = "stat";
904 #endif
905 #if defined (SYS_lseek)
906 syscall_table[SYS_lseek] = "lseek";
907 #endif
908 #if defined (SYS_getpid)
909 syscall_table[SYS_getpid] = "getpid";
910 #endif
911 #if defined (SYS_mount)
912 syscall_table[SYS_mount] = "mount";
913 #endif
914 #if defined (SYS_umount)
915 syscall_table[SYS_umount] = "umount";
916 #endif
917 #if defined (SYS_setuid)
918 syscall_table[SYS_setuid] = "setuid";
919 #endif
920 #if defined (SYS_getuid)
921 syscall_table[SYS_getuid] = "getuid";
922 #endif
923 #if defined (SYS_stime)
924 syscall_table[SYS_stime] = "stime";
925 #endif
926 #if defined (SYS_ptrace)
927 syscall_table[SYS_ptrace] = "ptrace";
928 #endif
929 #if defined (SYS_alarm)
930 syscall_table[SYS_alarm] = "alarm";
931 #endif
932 #if defined (SYS_fstat)
933 syscall_table[SYS_fstat] = "fstat";
934 #endif
935 #if defined (SYS_pause)
936 syscall_table[SYS_pause] = "pause";
937 #endif
938 #if defined (SYS_utime)
939 syscall_table[SYS_utime] = "utime";
940 #endif
941 #if defined (SYS_stty)
942 syscall_table[SYS_stty] = "stty";
943 #endif
944 #if defined (SYS_gtty)
945 syscall_table[SYS_gtty] = "gtty";
946 #endif
947 #if defined (SYS_access)
948 syscall_table[SYS_access] = "access";
949 #endif
950 #if defined (SYS_nice)
951 syscall_table[SYS_nice] = "nice";
952 #endif
953 #if defined (SYS_statfs)
954 syscall_table[SYS_statfs] = "statfs";
955 #endif
956 #if defined (SYS_sync)
957 syscall_table[SYS_sync] = "sync";
958 #endif
959 #if defined (SYS_kill)
960 syscall_table[SYS_kill] = "kill";
961 #endif
962 #if defined (SYS_fstatfs)
963 syscall_table[SYS_fstatfs] = "fstatfs";
964 #endif
965 #if defined (SYS_pgrpsys)
966 syscall_table[SYS_pgrpsys] = "pgrpsys";
967 #endif
968 #if defined (SYS_xenix)
969 syscall_table[SYS_xenix] = "xenix";
970 #endif
971 #if defined (SYS_dup)
972 syscall_table[SYS_dup] = "dup";
973 #endif
974 #if defined (SYS_pipe)
975 syscall_table[SYS_pipe] = "pipe";
976 #endif
977 #if defined (SYS_times)
978 syscall_table[SYS_times] = "times";
979 #endif
980 #if defined (SYS_profil)
981 syscall_table[SYS_profil] = "profil";
982 #endif
983 #if defined (SYS_plock)
984 syscall_table[SYS_plock] = "plock";
985 #endif
986 #if defined (SYS_setgid)
987 syscall_table[SYS_setgid] = "setgid";
988 #endif
989 #if defined (SYS_getgid)
990 syscall_table[SYS_getgid] = "getgid";
991 #endif
992 #if defined (SYS_signal)
993 syscall_table[SYS_signal] = "signal";
994 #endif
995 #if defined (SYS_msgsys)
996 syscall_table[SYS_msgsys] = "msgsys";
997 #endif
998 #if defined (SYS_sys3b)
999 syscall_table[SYS_sys3b] = "sys3b";
1000 #endif
1001 #if defined (SYS_acct)
1002 syscall_table[SYS_acct] = "acct";
1003 #endif
1004 #if defined (SYS_shmsys)
1005 syscall_table[SYS_shmsys] = "shmsys";
1006 #endif
1007 #if defined (SYS_semsys)
1008 syscall_table[SYS_semsys] = "semsys";
1009 #endif
1010 #if defined (SYS_ioctl)
1011 syscall_table[SYS_ioctl] = "ioctl";
1012 #endif
1013 #if defined (SYS_uadmin)
1014 syscall_table[SYS_uadmin] = "uadmin";
1015 #endif
1016 #if defined (SYS_utssys)
1017 syscall_table[SYS_utssys] = "utssys";
1018 #endif
1019 #if defined (SYS_fsync)
1020 syscall_table[SYS_fsync] = "fsync";
1021 #endif
1022 #if defined (SYS_umask)
1023 syscall_table[SYS_umask] = "umask";
1024 #endif
1025 #if defined (SYS_chroot)
1026 syscall_table[SYS_chroot] = "chroot";
1027 #endif
1028 #if defined (SYS_fcntl)
1029 syscall_table[SYS_fcntl] = "fcntl";
1030 #endif
1031 #if defined (SYS_ulimit)
1032 syscall_table[SYS_ulimit] = "ulimit";
1033 #endif
1034 #if defined (SYS_rfsys)
1035 syscall_table[SYS_rfsys] = "rfsys";
1036 #endif
1037 #if defined (SYS_rmdir)
1038 syscall_table[SYS_rmdir] = "rmdir";
1039 #endif
1040 #if defined (SYS_mkdir)
1041 syscall_table[SYS_mkdir] = "mkdir";
1042 #endif
1043 #if defined (SYS_getdents)
1044 syscall_table[SYS_getdents] = "getdents";
1045 #endif
1046 #if defined (SYS_sysfs)
1047 syscall_table[SYS_sysfs] = "sysfs";
1048 #endif
1049 #if defined (SYS_getmsg)
1050 syscall_table[SYS_getmsg] = "getmsg";
1051 #endif
1052 #if defined (SYS_putmsg)
1053 syscall_table[SYS_putmsg] = "putmsg";
1054 #endif
1055 #if defined (SYS_poll)
1056 syscall_table[SYS_poll] = "poll";
1057 #endif
1058 #if defined (SYS_lstat)
1059 syscall_table[SYS_lstat] = "lstat";
1060 #endif
1061 #if defined (SYS_symlink)
1062 syscall_table[SYS_symlink] = "symlink";
1063 #endif
1064 #if defined (SYS_readlink)
1065 syscall_table[SYS_readlink] = "readlink";
1066 #endif
1067 #if defined (SYS_setgroups)
1068 syscall_table[SYS_setgroups] = "setgroups";
1069 #endif
1070 #if defined (SYS_getgroups)
1071 syscall_table[SYS_getgroups] = "getgroups";
1072 #endif
1073 #if defined (SYS_fchmod)
1074 syscall_table[SYS_fchmod] = "fchmod";
1075 #endif
1076 #if defined (SYS_fchown)
1077 syscall_table[SYS_fchown] = "fchown";
1078 #endif
1079 #if defined (SYS_sigprocmask)
1080 syscall_table[SYS_sigprocmask] = "sigprocmask";
1081 #endif
1082 #if defined (SYS_sigsuspend)
1083 syscall_table[SYS_sigsuspend] = "sigsuspend";
1084 #endif
1085 #if defined (SYS_sigaltstack)
1086 syscall_table[SYS_sigaltstack] = "sigaltstack";
1087 #endif
1088 #if defined (SYS_sigaction)
1089 syscall_table[SYS_sigaction] = "sigaction";
1090 #endif
1091 #if defined (SYS_sigpending)
1092 syscall_table[SYS_sigpending] = "sigpending";
1093 #endif
1094 #if defined (SYS_context)
1095 syscall_table[SYS_context] = "context";
1096 #endif
1097 #if defined (SYS_evsys)
1098 syscall_table[SYS_evsys] = "evsys";
1099 #endif
1100 #if defined (SYS_evtrapret)
1101 syscall_table[SYS_evtrapret] = "evtrapret";
1102 #endif
1103 #if defined (SYS_statvfs)
1104 syscall_table[SYS_statvfs] = "statvfs";
1105 #endif
1106 #if defined (SYS_fstatvfs)
1107 syscall_table[SYS_fstatvfs] = "fstatvfs";
1108 #endif
1109 #if defined (SYS_nfssys)
1110 syscall_table[SYS_nfssys] = "nfssys";
1111 #endif
1112 #if defined (SYS_waitsys)
1113 syscall_table[SYS_waitsys] = "waitsys";
1114 #endif
1115 #if defined (SYS_sigsendsys)
1116 syscall_table[SYS_sigsendsys] = "sigsendsys";
1117 #endif
1118 #if defined (SYS_hrtsys)
1119 syscall_table[SYS_hrtsys] = "hrtsys";
1120 #endif
1121 #if defined (SYS_acancel)
1122 syscall_table[SYS_acancel] = "acancel";
1123 #endif
1124 #if defined (SYS_async)
1125 syscall_table[SYS_async] = "async";
1126 #endif
1127 #if defined (SYS_priocntlsys)
1128 syscall_table[SYS_priocntlsys] = "priocntlsys";
1129 #endif
1130 #if defined (SYS_pathconf)
1131 syscall_table[SYS_pathconf] = "pathconf";
1132 #endif
1133 #if defined (SYS_mincore)
1134 syscall_table[SYS_mincore] = "mincore";
1135 #endif
1136 #if defined (SYS_mmap)
1137 syscall_table[SYS_mmap] = "mmap";
1138 #endif
1139 #if defined (SYS_mprotect)
1140 syscall_table[SYS_mprotect] = "mprotect";
1141 #endif
1142 #if defined (SYS_munmap)
1143 syscall_table[SYS_munmap] = "munmap";
1144 #endif
1145 #if defined (SYS_fpathconf)
1146 syscall_table[SYS_fpathconf] = "fpathconf";
1147 #endif
1148 #if defined (SYS_vfork)
1149 syscall_table[SYS_vfork] = "vfork";
1150 #endif
1151 #if defined (SYS_fchdir)
1152 syscall_table[SYS_fchdir] = "fchdir";
1153 #endif
1154 #if defined (SYS_readv)
1155 syscall_table[SYS_readv] = "readv";
1156 #endif
1157 #if defined (SYS_writev)
1158 syscall_table[SYS_writev] = "writev";
1159 #endif
1160 #if defined (SYS_xstat)
1161 syscall_table[SYS_xstat] = "xstat";
1162 #endif
1163 #if defined (SYS_lxstat)
1164 syscall_table[SYS_lxstat] = "lxstat";
1165 #endif
1166 #if defined (SYS_fxstat)
1167 syscall_table[SYS_fxstat] = "fxstat";
1168 #endif
1169 #if defined (SYS_xmknod)
1170 syscall_table[SYS_xmknod] = "xmknod";
1171 #endif
1172 #if defined (SYS_clocal)
1173 syscall_table[SYS_clocal] = "clocal";
1174 #endif
1175 #if defined (SYS_setrlimit)
1176 syscall_table[SYS_setrlimit] = "setrlimit";
1177 #endif
1178 #if defined (SYS_getrlimit)
1179 syscall_table[SYS_getrlimit] = "getrlimit";
1180 #endif
1181 #if defined (SYS_lchown)
1182 syscall_table[SYS_lchown] = "lchown";
1183 #endif
1184 #if defined (SYS_memcntl)
1185 syscall_table[SYS_memcntl] = "memcntl";
1186 #endif
1187 #if defined (SYS_getpmsg)
1188 syscall_table[SYS_getpmsg] = "getpmsg";
1189 #endif
1190 #if defined (SYS_putpmsg)
1191 syscall_table[SYS_putpmsg] = "putpmsg";
1192 #endif
1193 #if defined (SYS_rename)
1194 syscall_table[SYS_rename] = "rename";
1195 #endif
1196 #if defined (SYS_uname)
1197 syscall_table[SYS_uname] = "uname";
1198 #endif
1199 #if defined (SYS_setegid)
1200 syscall_table[SYS_setegid] = "setegid";
1201 #endif
1202 #if defined (SYS_sysconfig)
1203 syscall_table[SYS_sysconfig] = "sysconfig";
1204 #endif
1205 #if defined (SYS_adjtime)
1206 syscall_table[SYS_adjtime] = "adjtime";
1207 #endif
1208 #if defined (SYS_systeminfo)
1209 syscall_table[SYS_systeminfo] = "systeminfo";
1210 #endif
1211 #if defined (SYS_seteuid)
1212 syscall_table[SYS_seteuid] = "seteuid";
1213 #endif
1214 #if defined (SYS_sproc)
1215 syscall_table[SYS_sproc] = "sproc";
1216 #endif
1217 }
1218
1219 /*
1220
1221 LOCAL FUNCTION
1222
1223 procfs_kill_inferior - kill any currently inferior
1224
1225 SYNOPSIS
1226
1227 void procfs_kill_inferior (void)
1228
1229 DESCRIPTION
1230
1231 Kill any current inferior.
1232
1233 NOTES
1234
1235 Kills even attached inferiors. Presumably the user has already
1236 been prompted that the inferior is an attached one rather than
1237 one started by gdb. (FIXME?)
1238
1239 */
1240
1241 static void
1242 procfs_kill_inferior ()
1243 {
1244 target_mourn_inferior ();
1245 }
1246
1247 /*
1248
1249 LOCAL FUNCTION
1250
1251 unconditionally_kill_inferior - terminate the inferior
1252
1253 SYNOPSIS
1254
1255 static void unconditionally_kill_inferior (struct procinfo *)
1256
1257 DESCRIPTION
1258
1259 Kill the specified inferior.
1260
1261 NOTE
1262
1263 A possibly useful enhancement would be to first try sending
1264 the inferior a terminate signal, politely asking it to commit
1265 suicide, before we murder it (we could call that
1266 politely_kill_inferior()).
1267
1268 */
1269
1270 static void
1271 unconditionally_kill_inferior (pi)
1272 struct procinfo *pi;
1273 {
1274 int signo;
1275 int ppid;
1276
1277 ppid = pi->prstatus.pr_ppid;
1278
1279 signo = SIGKILL;
1280 ioctl (pi->fd, PIOCKILL, &signo);
1281 close_proc_file (pi);
1282
1283 /* Only wait() for our direct children. Our grandchildren zombies are killed
1284 by the death of their parents. */
1285
1286 if (ppid == getpid())
1287 wait ((int *) 0);
1288 }
1289
1290 /*
1291
1292 LOCAL FUNCTION
1293
1294 procfs_xfer_memory -- copy data to or from inferior memory space
1295
1296 SYNOPSIS
1297
1298 int procfs_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
1299 int dowrite, struct target_ops target)
1300
1301 DESCRIPTION
1302
1303 Copy LEN bytes to/from inferior's memory starting at MEMADDR
1304 from/to debugger memory starting at MYADDR. Copy from inferior
1305 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
1306
1307 Returns the length copied, which is either the LEN argument or
1308 zero. This xfer function does not do partial moves, since procfs_ops
1309 doesn't allow memory operations to cross below us in the target stack
1310 anyway.
1311
1312 NOTES
1313
1314 The /proc interface makes this an almost trivial task.
1315 */
1316
1317 static int
1318 procfs_xfer_memory (memaddr, myaddr, len, dowrite, target)
1319 CORE_ADDR memaddr;
1320 char *myaddr;
1321 int len;
1322 int dowrite;
1323 struct target_ops *target; /* ignored */
1324 {
1325 int nbytes = 0;
1326 struct procinfo *pi;
1327
1328 pi = current_procinfo;
1329
1330 if (lseek(pi->fd, (off_t) memaddr, 0) == (off_t) memaddr)
1331 {
1332 if (dowrite)
1333 {
1334 nbytes = write (pi->fd, myaddr, len);
1335 }
1336 else
1337 {
1338 nbytes = read (pi->fd, myaddr, len);
1339 }
1340 if (nbytes < 0)
1341 {
1342 nbytes = 0;
1343 }
1344 }
1345 return (nbytes);
1346 }
1347
1348 /*
1349
1350 LOCAL FUNCTION
1351
1352 procfs_store_registers -- copy register values back to inferior
1353
1354 SYNOPSIS
1355
1356 void procfs_store_registers (int regno)
1357
1358 DESCRIPTION
1359
1360 Store our current register values back into the inferior. If
1361 REGNO is -1 then store all the register, otherwise store just
1362 the value specified by REGNO.
1363
1364 NOTES
1365
1366 If we are storing only a single register, we first have to get all
1367 the current values from the process, overwrite the desired register
1368 in the gregset with the one we want from gdb's registers, and then
1369 send the whole set back to the process. For writing all the
1370 registers, all we have to do is generate the gregset and send it to
1371 the process.
1372
1373 Also note that the process has to be stopped on an event of interest
1374 for this to work, which basically means that it has to have been
1375 run under the control of one of the other /proc ioctl calls and not
1376 ptrace. Since we don't use ptrace anyway, we don't worry about this
1377 fine point, but it is worth noting for future reference.
1378
1379 Gdb is confused about what this function is supposed to return.
1380 Some versions return a value, others return nothing. Some are
1381 declared to return a value and actually return nothing. Gdb ignores
1382 anything returned. (FIXME)
1383
1384 */
1385
1386 static void
1387 procfs_store_registers (regno)
1388 int regno;
1389 {
1390 struct procinfo *pi;
1391
1392 pi = current_procinfo;
1393
1394 if (regno != -1)
1395 {
1396 ioctl (pi->fd, PIOCGREG, &pi->gregset);
1397 }
1398 fill_gregset (&pi->gregset, regno);
1399 ioctl (pi->fd, PIOCSREG, &pi->gregset);
1400
1401 #if defined (FP0_REGNUM)
1402
1403 /* Now repeat everything using the floating point register set, if the
1404 target has floating point hardware. Since we ignore the returned value,
1405 we'll never know whether it worked or not anyway. */
1406
1407 if (regno != -1)
1408 {
1409 ioctl (pi->fd, PIOCGFPREG, &pi->fpregset);
1410 }
1411 fill_fpregset (&pi->fpregset, regno);
1412 ioctl (pi->fd, PIOCSFPREG, &pi->fpregset);
1413
1414 #endif /* FP0_REGNUM */
1415
1416 }
1417
1418 /*
1419
1420 LOCAL FUNCTION
1421
1422 create_procinfo - initialize access to a /proc entry
1423
1424 SYNOPSIS
1425
1426 struct procinfo * create_procinfo (int pid)
1427
1428 DESCRIPTION
1429
1430 Allocate a procinfo structure, open the /proc file and then set up the
1431 set of signals and faults that are to be traced. Returns a pointer to
1432 the new procinfo structure.
1433
1434 NOTES
1435
1436 If proc_init_failed ever gets called, control returns to the command
1437 processing loop via the standard error handling code.
1438
1439 */
1440
1441 static struct procinfo *
1442 create_procinfo (pid)
1443 int pid;
1444 {
1445 struct procinfo *pi;
1446
1447 if (find_procinfo (pid, 1))
1448 return; /* All done! It already exists */
1449
1450 pi = (struct procinfo *) xmalloc (sizeof (struct procinfo));
1451
1452 if (!open_proc_file (pid, pi, O_RDWR))
1453 proc_init_failed (pi, "can't open process file");
1454
1455 /* Add new process to process info list */
1456
1457 pi->next = procinfo_list;
1458 procinfo_list = pi;
1459
1460 add_fd (pi); /* Add to list for poll/select */
1461
1462 memset ((char *) &pi->prrun, 0, sizeof (pi->prrun));
1463 prfillset (&pi->prrun.pr_trace);
1464 procfs_notice_signals (pid);
1465 prfillset (&pi->prrun.pr_fault);
1466 prdelset (&pi->prrun.pr_fault, FLTPAGE);
1467
1468 if (ioctl (pi->fd, PIOCWSTOP, &pi->prstatus) < 0)
1469 proc_init_failed (pi, "PIOCWSTOP failed");
1470
1471 if (ioctl (pi->fd, PIOCSFAULT, &pi->prrun.pr_fault) < 0)
1472 proc_init_failed (pi, "PIOCSFAULT failed");
1473
1474 return pi;
1475 }
1476
1477 /*
1478
1479 LOCAL FUNCTION
1480
1481 procfs_init_inferior - initialize target vector and access to a
1482 /proc entry
1483
1484 SYNOPSIS
1485
1486 void procfs_init_inferior (int pid)
1487
1488 DESCRIPTION
1489
1490 When gdb starts an inferior, this function is called in the parent
1491 process immediately after the fork. It waits for the child to stop
1492 on the return from the exec system call (the child itself takes care
1493 of ensuring that this is set up), then sets up the set of signals
1494 and faults that are to be traced.
1495
1496 NOTES
1497
1498 If proc_init_failed ever gets called, control returns to the command
1499 processing loop via the standard error handling code.
1500
1501 */
1502
1503 static void
1504 procfs_init_inferior (pid)
1505 int pid;
1506 {
1507 push_target (&procfs_ops);
1508
1509 create_procinfo (pid);
1510 add_thread (pid); /* Setup initial thread */
1511
1512 /* One trap to exec the shell, one to exec the program being debugged. */
1513 startup_inferior (2);
1514 }
1515
1516 /*
1517
1518 GLOBAL FUNCTION
1519
1520 procfs_notice_signals
1521
1522 SYNOPSIS
1523
1524 static void procfs_notice_signals (int pid);
1525
1526 DESCRIPTION
1527
1528 When the user changes the state of gdb's signal handling via the
1529 "handle" command, this function gets called to see if any change
1530 in the /proc interface is required. It is also called internally
1531 by other /proc interface functions to initialize the state of
1532 the traced signal set.
1533
1534 One thing it does is that signals for which the state is "nostop",
1535 "noprint", and "pass", have their trace bits reset in the pr_trace
1536 field, so that they are no longer traced. This allows them to be
1537 delivered directly to the inferior without the debugger ever being
1538 involved.
1539 */
1540
1541 static void
1542 procfs_notice_signals (pid)
1543 int pid;
1544 {
1545 int signo;
1546 struct procinfo *pi;
1547
1548 pi = find_procinfo (pid, 0);
1549
1550 for (signo = 0; signo < NSIG; signo++)
1551 {
1552 if (signal_stop_state (target_signal_from_host (signo)) == 0 &&
1553 signal_print_state (target_signal_from_host (signo)) == 0 &&
1554 signal_pass_state (target_signal_from_host (signo)) == 1)
1555 {
1556 prdelset (&pi->prrun.pr_trace, signo);
1557 }
1558 else
1559 {
1560 praddset (&pi->prrun.pr_trace, signo);
1561 }
1562 }
1563 if (ioctl (pi->fd, PIOCSTRACE, &pi->prrun.pr_trace))
1564 {
1565 print_sys_errmsg ("PIOCSTRACE failed", errno);
1566 }
1567 }
1568
1569 /*
1570
1571 LOCAL FUNCTION
1572
1573 proc_set_exec_trap -- arrange for exec'd child to halt at startup
1574
1575 SYNOPSIS
1576
1577 void proc_set_exec_trap (void)
1578
1579 DESCRIPTION
1580
1581 This function is called in the child process when starting up
1582 an inferior, prior to doing the exec of the actual inferior.
1583 It sets the child process's exitset to make exit from the exec
1584 system call an event of interest to stop on, and then simply
1585 returns. The child does the exec, the system call returns, and
1586 the child stops at the first instruction, ready for the gdb
1587 parent process to take control of it.
1588
1589 NOTE
1590
1591 We need to use all local variables since the child may be sharing
1592 it's data space with the parent, if vfork was used rather than
1593 fork.
1594
1595 Also note that we want to turn off the inherit-on-fork flag in
1596 the child process so that any grand-children start with all
1597 tracing flags cleared.
1598 */
1599
1600 static void
1601 proc_set_exec_trap ()
1602 {
1603 sysset_t exitset;
1604 sysset_t entryset;
1605 auto char procname[32];
1606 int fd;
1607
1608 sprintf (procname, PROC_NAME_FMT, getpid ());
1609 if ((fd = open (procname, O_RDWR)) < 0)
1610 {
1611 perror (procname);
1612 gdb_flush (gdb_stderr);
1613 _exit (127);
1614 }
1615 premptyset (&exitset);
1616 premptyset (&entryset);
1617
1618 /* GW: Rationale...
1619 Not all systems with /proc have all the exec* syscalls with the same
1620 names. On the SGI, for example, there is no SYS_exec, but there
1621 *is* a SYS_execv. So, we try to account for that. */
1622
1623 #ifdef SYS_exec
1624 praddset (&exitset, SYS_exec);
1625 #endif
1626 #ifdef SYS_execve
1627 praddset (&exitset, SYS_execve);
1628 #endif
1629 #ifdef SYS_execv
1630 praddset (&exitset, SYS_execv);
1631 #endif
1632
1633 if (ioctl (fd, PIOCSEXIT, &exitset) < 0)
1634 {
1635 perror (procname);
1636 gdb_flush (gdb_stderr);
1637 _exit (127);
1638 }
1639
1640 praddset (&entryset, SYS_exit);
1641
1642 if (ioctl (fd, PIOCSENTRY, &entryset) < 0)
1643 {
1644 perror (procname);
1645 gdb_flush (gdb_stderr);
1646 _exit (126);
1647 }
1648
1649 /* Turn off inherit-on-fork flag so that all grand-children of gdb
1650 start with tracing flags cleared. */
1651
1652 #if defined (PIOCRESET) /* New method */
1653 {
1654 long pr_flags;
1655 pr_flags = PR_FORK;
1656 ioctl (fd, PIOCRESET, &pr_flags);
1657 }
1658 #else
1659 #if defined (PIOCRFORK) /* Original method */
1660 ioctl (fd, PIOCRFORK, NULL);
1661 #endif
1662 #endif
1663
1664 /* Turn on run-on-last-close flag so that this process will not hang
1665 if GDB goes away for some reason. */
1666
1667 #if defined (PIOCSET) /* New method */
1668 {
1669 long pr_flags;
1670 pr_flags = PR_RLC;
1671 (void) ioctl (fd, PIOCSET, &pr_flags);
1672 }
1673 #else
1674 #if defined (PIOCSRLC) /* Original method */
1675 (void) ioctl (fd, PIOCSRLC, 0);
1676 #endif
1677 #endif
1678 }
1679
1680 /*
1681
1682 GLOBAL FUNCTION
1683
1684 proc_iterate_over_mappings -- call function for every mapped space
1685
1686 SYNOPSIS
1687
1688 int proc_iterate_over_mappings (int (*func)())
1689
1690 DESCRIPTION
1691
1692 Given a pointer to a function, call that function for every
1693 mapped address space, passing it an open file descriptor for
1694 the file corresponding to that mapped address space (if any)
1695 and the base address of the mapped space. Quit when we hit
1696 the end of the mappings or the function returns nonzero.
1697 */
1698
1699 int
1700 proc_iterate_over_mappings (func)
1701 int (*func) PARAMS ((int, CORE_ADDR));
1702 {
1703 int nmap;
1704 int fd;
1705 int funcstat = 0;
1706 struct prmap *prmaps;
1707 struct prmap *prmap;
1708 struct procinfo *pi;
1709
1710 pi = current_procinfo;
1711
1712 if (ioctl (pi->fd, PIOCNMAP, &nmap) == 0)
1713 {
1714 prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps));
1715 if (ioctl (pi->fd, PIOCMAP, prmaps) == 0)
1716 {
1717 for (prmap = prmaps; prmap -> pr_size && funcstat == 0; ++prmap)
1718 {
1719 fd = proc_address_to_fd (pi, (CORE_ADDR) prmap -> pr_vaddr, 0);
1720 funcstat = (*func) (fd, (CORE_ADDR) prmap -> pr_vaddr);
1721 close (fd);
1722 }
1723 }
1724 }
1725 return (funcstat);
1726 }
1727
1728 #if 0 /* Currently unused */
1729 /*
1730
1731 GLOBAL FUNCTION
1732
1733 proc_base_address -- find base address for segment containing address
1734
1735 SYNOPSIS
1736
1737 CORE_ADDR proc_base_address (CORE_ADDR addr)
1738
1739 DESCRIPTION
1740
1741 Given an address of a location in the inferior, find and return
1742 the base address of the mapped segment containing that address.
1743
1744 This is used for example, by the shared library support code,
1745 where we have the pc value for some location in the shared library
1746 where we are stopped, and need to know the base address of the
1747 segment containing that address.
1748 */
1749
1750 CORE_ADDR
1751 proc_base_address (addr)
1752 CORE_ADDR addr;
1753 {
1754 int nmap;
1755 struct prmap *prmaps;
1756 struct prmap *prmap;
1757 CORE_ADDR baseaddr = 0;
1758 struct procinfo *pi;
1759
1760 pi = current_procinfo;
1761
1762 if (ioctl (pi->fd, PIOCNMAP, &nmap) == 0)
1763 {
1764 prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps));
1765 if (ioctl (pi->fd, PIOCMAP, prmaps) == 0)
1766 {
1767 for (prmap = prmaps; prmap -> pr_size; ++prmap)
1768 {
1769 if ((prmap -> pr_vaddr <= (caddr_t) addr) &&
1770 (prmap -> pr_vaddr + prmap -> pr_size > (caddr_t) addr))
1771 {
1772 baseaddr = (CORE_ADDR) prmap -> pr_vaddr;
1773 break;
1774 }
1775 }
1776 }
1777 }
1778 return (baseaddr);
1779 }
1780
1781 #endif /* 0 */
1782
1783 /*
1784
1785 LOCAL FUNCTION
1786
1787 proc_address_to_fd -- return open fd for file mapped to address
1788
1789 SYNOPSIS
1790
1791 int proc_address_to_fd (struct procinfo *pi, CORE_ADDR addr, complain)
1792
1793 DESCRIPTION
1794
1795 Given an address in the current inferior's address space, use the
1796 /proc interface to find an open file descriptor for the file that
1797 this address was mapped in from. Return -1 if there is no current
1798 inferior. Print a warning message if there is an inferior but
1799 the address corresponds to no file (IE a bogus address).
1800
1801 */
1802
1803 static int
1804 proc_address_to_fd (pi, addr, complain)
1805 struct procinfo *pi;
1806 CORE_ADDR addr;
1807 int complain;
1808 {
1809 int fd = -1;
1810
1811 if ((fd = ioctl (pi->fd, PIOCOPENM, (caddr_t *) &addr)) < 0)
1812 {
1813 if (complain)
1814 {
1815 print_sys_errmsg (pi->pathname, errno);
1816 warning ("can't find mapped file for address 0x%x", addr);
1817 }
1818 }
1819 return (fd);
1820 }
1821
1822
1823 /* Attach to process PID, then initialize for debugging it
1824 and wait for the trace-trap that results from attaching. */
1825
1826 static void
1827 procfs_attach (args, from_tty)
1828 char *args;
1829 int from_tty;
1830 {
1831 char *exec_file;
1832 int pid;
1833
1834 if (!args)
1835 error_no_arg ("process-id to attach");
1836
1837 pid = atoi (args);
1838
1839 if (pid == getpid()) /* Trying to masturbate? */
1840 error ("I refuse to debug myself!");
1841
1842 if (from_tty)
1843 {
1844 exec_file = (char *) get_exec_file (0);
1845
1846 if (exec_file)
1847 printf_unfiltered ("Attaching to program `%s', %s\n", exec_file, target_pid_to_str (pid));
1848 else
1849 printf_unfiltered ("Attaching to %s\n", target_pid_to_str (pid));
1850
1851 gdb_flush (gdb_stdout);
1852 }
1853
1854 do_attach (pid);
1855 inferior_pid = pid;
1856 push_target (&procfs_ops);
1857 }
1858
1859
1860 /* Take a program previously attached to and detaches it.
1861 The program resumes execution and will no longer stop
1862 on signals, etc. We'd better not have left any breakpoints
1863 in the program or it'll die when it hits one. For this
1864 to work, it may be necessary for the process to have been
1865 previously attached. It *might* work if the program was
1866 started via the normal ptrace (PTRACE_TRACEME). */
1867
1868 static void
1869 procfs_detach (args, from_tty)
1870 char *args;
1871 int from_tty;
1872 {
1873 int siggnal = 0;
1874
1875 if (from_tty)
1876 {
1877 char *exec_file = get_exec_file (0);
1878 if (exec_file == 0)
1879 exec_file = "";
1880 printf_unfiltered ("Detaching from program: %s %s\n",
1881 exec_file, target_pid_to_str (inferior_pid));
1882 gdb_flush (gdb_stdout);
1883 }
1884 if (args)
1885 siggnal = atoi (args);
1886
1887 do_detach (siggnal);
1888 inferior_pid = 0;
1889 unpush_target (&procfs_ops); /* Pop out of handling an inferior */
1890 }
1891
1892 /* Get ready to modify the registers array. On machines which store
1893 individual registers, this doesn't need to do anything. On machines
1894 which store all the registers in one fell swoop, this makes sure
1895 that registers contains all the registers from the program being
1896 debugged. */
1897
1898 static void
1899 procfs_prepare_to_store ()
1900 {
1901 #ifdef CHILD_PREPARE_TO_STORE
1902 CHILD_PREPARE_TO_STORE ();
1903 #endif
1904 }
1905
1906 /* Print status information about what we're accessing. */
1907
1908 static void
1909 procfs_files_info (ignore)
1910 struct target_ops *ignore;
1911 {
1912 printf_unfiltered ("\tUsing the running image of %s %s via /proc.\n",
1913 attach_flag? "attached": "child", target_pid_to_str (inferior_pid));
1914 }
1915
1916 /* ARGSUSED */
1917 static void
1918 procfs_open (arg, from_tty)
1919 char *arg;
1920 int from_tty;
1921 {
1922 error ("Use the \"run\" command to start a Unix child process.");
1923 }
1924
1925 /*
1926
1927 LOCAL FUNCTION
1928
1929 do_attach -- attach to an already existing process
1930
1931 SYNOPSIS
1932
1933 int do_attach (int pid)
1934
1935 DESCRIPTION
1936
1937 Attach to an already existing process with the specified process
1938 id. If the process is not already stopped, query whether to
1939 stop it or not.
1940
1941 NOTES
1942
1943 The option of stopping at attach time is specific to the /proc
1944 versions of gdb. Versions using ptrace force the attachee
1945 to stop. (I have changed this version to do so, too. All you
1946 have to do is "continue" to make it go on. -- gnu@cygnus.com)
1947
1948 */
1949
1950 static int
1951 do_attach (pid)
1952 int pid;
1953 {
1954 int result;
1955 struct procinfo *pi;
1956
1957 pi = (struct procinfo *) xmalloc (sizeof (struct procinfo));
1958
1959 if (!open_proc_file (pid, pi, O_RDWR))
1960 {
1961 free (pi);
1962 perror_with_name (pi->pathname);
1963 /* NOTREACHED */
1964 }
1965
1966 /* Add new process to process info list */
1967
1968 pi->next = procinfo_list;
1969 procinfo_list = pi;
1970
1971 add_fd (pi); /* Add to list for poll/select */
1972
1973 /* Get current status of process and if it is not already stopped,
1974 then stop it. Remember whether or not it was stopped when we first
1975 examined it. */
1976
1977 if (ioctl (pi->fd, PIOCSTATUS, &pi->prstatus) < 0)
1978 {
1979 print_sys_errmsg (pi->pathname, errno);
1980 close_proc_file (pi);
1981 error ("PIOCSTATUS failed");
1982 }
1983 if (pi->prstatus.pr_flags & (PR_STOPPED | PR_ISTOP))
1984 {
1985 pi->was_stopped = 1;
1986 }
1987 else
1988 {
1989 pi->was_stopped = 0;
1990 if (1 || query ("Process is currently running, stop it? "))
1991 {
1992 /* Make it run again when we close it. */
1993 #if defined (PIOCSET) /* New method */
1994 {
1995 long pr_flags;
1996 pr_flags = PR_RLC;
1997 result = ioctl (pi->fd, PIOCSET, &pr_flags);
1998 }
1999 #else
2000 #if defined (PIOCSRLC) /* Original method */
2001 result = ioctl (pi->fd, PIOCSRLC, 0);
2002 #endif
2003 #endif
2004 if (result < 0)
2005 {
2006 print_sys_errmsg (pi->pathname, errno);
2007 close_proc_file (pi);
2008 error ("PIOCSRLC or PIOCSET failed");
2009 }
2010 if (ioctl (pi->fd, PIOCSTOP, &pi->prstatus) < 0)
2011 {
2012 print_sys_errmsg (pi->pathname, errno);
2013 close_proc_file (pi);
2014 error ("PIOCSTOP failed");
2015 }
2016 pi->nopass_next_sigstop = 1;
2017 }
2018 else
2019 {
2020 printf_unfiltered ("Ok, gdb will wait for %s to stop.\n", target_pid_to_str (pid));
2021 }
2022 }
2023
2024 /* Remember some things about the inferior that we will, or might, change
2025 so that we can restore them when we detach. */
2026
2027 ioctl (pi->fd, PIOCGTRACE, &pi->saved_trace);
2028 ioctl (pi->fd, PIOCGHOLD, &pi->saved_sighold);
2029 ioctl (pi->fd, PIOCGFAULT, &pi->saved_fltset);
2030 ioctl (pi->fd, PIOCGENTRY, &pi->saved_entryset);
2031 ioctl (pi->fd, PIOCGEXIT, &pi->saved_exitset);
2032
2033 /* Set up trace and fault sets, as gdb expects them. */
2034
2035 memset (&pi->prrun, 0, sizeof (pi->prrun));
2036 prfillset (&pi->prrun.pr_trace);
2037 procfs_notice_signals (pid);
2038 prfillset (&pi->prrun.pr_fault);
2039 prdelset (&pi->prrun.pr_fault, FLTPAGE);
2040 if (ioctl (pi->fd, PIOCSFAULT, &pi->prrun.pr_fault))
2041 {
2042 print_sys_errmsg ("PIOCSFAULT failed", errno);
2043 }
2044 if (ioctl (pi->fd, PIOCSTRACE, &pi->prrun.pr_trace))
2045 {
2046 print_sys_errmsg ("PIOCSTRACE failed", errno);
2047 }
2048 attach_flag = 1;
2049 return (pid);
2050 }
2051
2052 /*
2053
2054 LOCAL FUNCTION
2055
2056 do_detach -- detach from an attached-to process
2057
2058 SYNOPSIS
2059
2060 void do_detach (int signal)
2061
2062 DESCRIPTION
2063
2064 Detach from the current attachee.
2065
2066 If signal is non-zero, the attachee is started running again and sent
2067 the specified signal.
2068
2069 If signal is zero and the attachee was not already stopped when we
2070 attached to it, then we make it runnable again when we detach.
2071
2072 Otherwise, we query whether or not to make the attachee runnable
2073 again, since we may simply want to leave it in the state it was in
2074 when we attached.
2075
2076 We report any problems, but do not consider them errors, since we
2077 MUST detach even if some things don't seem to go right. This may not
2078 be the ideal situation. (FIXME).
2079 */
2080
2081 static void
2082 do_detach (signal)
2083 int signal;
2084 {
2085 int result;
2086 struct procinfo *pi;
2087
2088 pi = current_procinfo;
2089
2090 if (signal)
2091 {
2092 set_proc_siginfo (pi, signal);
2093 }
2094 if (ioctl (pi->fd, PIOCSEXIT, &pi->saved_exitset) < 0)
2095 {
2096 print_sys_errmsg (pi->pathname, errno);
2097 printf_unfiltered ("PIOCSEXIT failed.\n");
2098 }
2099 if (ioctl (pi->fd, PIOCSENTRY, &pi->saved_entryset) < 0)
2100 {
2101 print_sys_errmsg (pi->pathname, errno);
2102 printf_unfiltered ("PIOCSENTRY failed.\n");
2103 }
2104 if (ioctl (pi->fd, PIOCSTRACE, &pi->saved_trace) < 0)
2105 {
2106 print_sys_errmsg (pi->pathname, errno);
2107 printf_unfiltered ("PIOCSTRACE failed.\n");
2108 }
2109 if (ioctl (pi->fd, PIOCSHOLD, &pi->saved_sighold) < 0)
2110 {
2111 print_sys_errmsg (pi->pathname, errno);
2112 printf_unfiltered ("PIOSCHOLD failed.\n");
2113 }
2114 if (ioctl (pi->fd, PIOCSFAULT, &pi->saved_fltset) < 0)
2115 {
2116 print_sys_errmsg (pi->pathname, errno);
2117 printf_unfiltered ("PIOCSFAULT failed.\n");
2118 }
2119 if (ioctl (pi->fd, PIOCSTATUS, &pi->prstatus) < 0)
2120 {
2121 print_sys_errmsg (pi->pathname, errno);
2122 printf_unfiltered ("PIOCSTATUS failed.\n");
2123 }
2124 else
2125 {
2126 if (signal || (pi->prstatus.pr_flags & (PR_STOPPED | PR_ISTOP)))
2127 {
2128 if (signal || !pi->was_stopped ||
2129 query ("Was stopped when attached, make it runnable again? "))
2130 {
2131 /* Clear any fault that might have stopped it. */
2132 if (ioctl (pi->fd, PIOCCFAULT, 0))
2133 {
2134 print_sys_errmsg (pi->pathname, errno);
2135 printf_unfiltered ("PIOCCFAULT failed.\n");
2136 }
2137
2138 /* Make it run again when we close it. */
2139 #if defined (PIOCSET) /* New method */
2140 {
2141 long pr_flags;
2142 pr_flags = PR_RLC;
2143 result = ioctl (pi->fd, PIOCSET, &pr_flags);
2144 }
2145 #else
2146 #if defined (PIOCSRLC) /* Original method */
2147 result = ioctl (pi->fd, PIOCSRLC, 0);
2148 #endif
2149 #endif
2150 if (result)
2151 {
2152 print_sys_errmsg (pi->pathname, errno);
2153 printf_unfiltered ("PIOCSRLC or PIOCSET failed.\n");
2154 }
2155 }
2156 }
2157 }
2158 close_proc_file (pi);
2159 attach_flag = 0;
2160 }
2161
2162 /* emulate wait() as much as possible.
2163 Wait for child to do something. Return pid of child, or -1 in case
2164 of error; store status in *OURSTATUS.
2165
2166 Not sure why we can't
2167 just use wait(), but it seems to have problems when applied to a
2168 process being controlled with the /proc interface.
2169
2170 We have a race problem here with no obvious solution. We need to let
2171 the inferior run until it stops on an event of interest, which means
2172 that we need to use the PIOCWSTOP ioctl. However, we cannot use this
2173 ioctl if the process is already stopped on something that is not an
2174 event of interest, or the call will hang indefinitely. Thus we first
2175 use PIOCSTATUS to see if the process is not stopped. If not, then we
2176 use PIOCWSTOP. But during the window between the two, if the process
2177 stops for any reason that is not an event of interest (such as a job
2178 control signal) then gdb will hang. One possible workaround is to set
2179 an alarm to wake up every minute of so and check to see if the process
2180 is still running, and if so, then reissue the PIOCWSTOP. But this is
2181 a real kludge, so has not been implemented. FIXME: investigate
2182 alternatives.
2183
2184 FIXME: Investigate why wait() seems to have problems with programs
2185 being control by /proc routines. */
2186
2187 static int
2188 procfs_wait (pid, ourstatus)
2189 int pid;
2190 struct target_waitstatus *ourstatus;
2191 {
2192 short what;
2193 short why;
2194 int statval = 0;
2195 int checkerr = 0;
2196 int rtnval = -1;
2197 struct procinfo *pi;
2198
2199 if (pid != -1) /* Non-specific process? */
2200 pi = NULL;
2201 else
2202 for (pi = procinfo_list; pi; pi = pi->next)
2203 if (pi->had_event)
2204 break;
2205
2206 if (!pi)
2207 {
2208 wait_again:
2209
2210 pi = wait_fd ();
2211 }
2212
2213 if (pid != -1)
2214 for (pi = procinfo_list; pi; pi = pi->next)
2215 if (pi->pid == pid && pi->had_event)
2216 break;
2217
2218 if (!pi && !checkerr)
2219 goto wait_again;
2220
2221 if (!checkerr && !(pi->prstatus.pr_flags & (PR_STOPPED | PR_ISTOP)))
2222 {
2223 if (ioctl (pi->fd, PIOCWSTOP, &pi->prstatus) < 0)
2224 {
2225 checkerr++;
2226 }
2227 }
2228 if (checkerr)
2229 {
2230 if (errno == ENOENT)
2231 {
2232 rtnval = wait (&statval);
2233 if (rtnval != inferior_pid)
2234 {
2235 print_sys_errmsg (pi->pathname, errno);
2236 error ("PIOCWSTOP, wait failed, returned %d", rtnval);
2237 /* NOTREACHED */
2238 }
2239 }
2240 else
2241 {
2242 print_sys_errmsg (pi->pathname, errno);
2243 error ("PIOCSTATUS or PIOCWSTOP failed.");
2244 /* NOTREACHED */
2245 }
2246 }
2247 else if (pi->prstatus.pr_flags & (PR_STOPPED | PR_ISTOP))
2248 {
2249 rtnval = pi->prstatus.pr_pid;
2250 why = pi->prstatus.pr_why;
2251 what = pi->prstatus.pr_what;
2252
2253 switch (why)
2254 {
2255 case PR_SIGNALLED:
2256 statval = (what << 8) | 0177;
2257 break;
2258 case PR_SYSENTRY:
2259 if (what != SYS_exit)
2260 error ("PR_SYSENTRY, unknown system call %d", what);
2261
2262 pi->prrun.pr_flags = PRCFAULT;
2263
2264 if (ioctl (pi->fd, PIOCRUN, &pi->prrun) != 0)
2265 perror_with_name (pi->pathname);
2266
2267 rtnval = wait (&statval);
2268
2269 break;
2270 case PR_SYSEXIT:
2271 switch (what)
2272 {
2273 #ifdef SYS_exec
2274 case SYS_exec:
2275 #endif
2276 #ifdef SYS_execve
2277 case SYS_execve:
2278 #endif
2279 #ifdef SYS_execv
2280 case SYS_execv:
2281 #endif
2282 statval = (SIGTRAP << 8) | 0177;
2283 break;
2284 #ifdef SYS_sproc
2285 case SYS_sproc:
2286 /* We've just detected the completion of an sproc system call. Now we need to
2287 setup a procinfo struct for this thread, and notify the thread system of the
2288 new arrival. */
2289
2290 /* If sproc failed, then nothing interesting happened. Continue the process and
2291 go back to sleep. */
2292
2293 if (pi->prstatus.pr_errno != 0)
2294 {
2295 pi->prrun.pr_flags &= PRSTEP;
2296 pi->prrun.pr_flags |= PRCFAULT;
2297
2298 if (ioctl (pi->fd, PIOCRUN, &pi->prrun) != 0)
2299 perror_with_name (pi->pathname);
2300
2301 goto wait_again;
2302 }
2303
2304 /* At this point, the new thread is stopped at it's first instruction, and
2305 the parent is stopped at the exit from sproc. */
2306
2307 /* Notify the caller of the arrival of a new thread. */
2308 create_procinfo (pi->prstatus.pr_rval1);
2309
2310 rtnval = pi->prstatus.pr_rval1;
2311 statval = (SIGTRAP << 8) | 0177;
2312
2313 break;
2314 case SYS_fork:
2315 #ifdef SYS_vfork
2316 case SYS_vfork:
2317 #endif
2318 /* At this point, we've detected the completion of a fork (or vfork) call in
2319 our child. The grandchild is also stopped because we set inherit-on-fork
2320 earlier. (Note that nobody has the grandchilds' /proc file open at this
2321 point.) We will release the grandchild from the debugger by opening it's
2322 /proc file and then closing it. Since run-on-last-close is set, the
2323 grandchild continues on its' merry way. */
2324
2325 {
2326 struct procinfo *pitemp;
2327
2328 pitemp = create_procinfo (pi->prstatus.pr_rval1);
2329 if (pitemp)
2330 close_proc_file (pitemp);
2331
2332 if (ioctl (pi->fd, PIOCRUN, &pi->prrun) != 0)
2333 perror_with_name (pi->pathname);
2334 }
2335 goto wait_again;
2336 #endif /* SYS_sproc */
2337
2338 default:
2339 error ("PIOCSTATUS (PR_SYSEXIT): Unknown system call %d", what);
2340 }
2341 break;
2342 case PR_REQUESTED:
2343 statval = (SIGSTOP << 8) | 0177;
2344 break;
2345 case PR_JOBCONTROL:
2346 statval = (what << 8) | 0177;
2347 break;
2348 case PR_FAULTED:
2349 switch (what)
2350 {
2351 #ifdef FLTWATCH
2352 case FLTWATCH:
2353 statval = (SIGTRAP << 8) | 0177;
2354 break;
2355 #endif
2356 #ifdef FLTKWATCH
2357 case FLTKWATCH:
2358 statval = (SIGTRAP << 8) | 0177;
2359 break;
2360 #endif
2361 #ifndef FAULTED_USE_SIGINFO
2362 /* Irix, contrary to the documentation, fills in 0 for si_signo.
2363 Solaris fills in si_signo. I'm not sure about others. */
2364 case FLTPRIV:
2365 case FLTILL:
2366 statval = (SIGILL << 8) | 0177;
2367 break;
2368 case FLTBPT:
2369 case FLTTRACE:
2370 statval = (SIGTRAP << 8) | 0177;
2371 break;
2372 case FLTSTACK:
2373 case FLTACCESS:
2374 case FLTBOUNDS:
2375 statval = (SIGSEGV << 8) | 0177;
2376 break;
2377 case FLTIOVF:
2378 case FLTIZDIV:
2379 case FLTFPE:
2380 statval = (SIGFPE << 8) | 0177;
2381 break;
2382 case FLTPAGE: /* Recoverable page fault */
2383 #endif /* not FAULTED_USE_SIGINFO */
2384 default:
2385 /* Use the signal which the kernel assigns. This is better than
2386 trying to second-guess it from the fault. In fact, I suspect
2387 that FLTACCESS can be either SIGSEGV or SIGBUS. */
2388 statval = ((pi->prstatus.pr_info.si_signo) << 8) | 0177;
2389 break;
2390 }
2391 break;
2392 default:
2393 error ("PIOCWSTOP, unknown why %d, what %d", why, what);
2394 }
2395 /* Stop all the other threads when any of them stops. */
2396
2397 {
2398 struct procinfo *procinfo;
2399
2400 for (procinfo = procinfo_list; procinfo; procinfo = procinfo->next)
2401 {
2402 if (!procinfo->had_event)
2403 if (ioctl (procinfo->fd, PIOCSTOP, &procinfo->prstatus) < 0)
2404 {
2405 print_sys_errmsg (procinfo->pathname, errno);
2406 error ("PIOCSTOP failed");
2407 }
2408 }
2409 }
2410 }
2411 else
2412 {
2413 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
2414 pi->prstatus.pr_flags);
2415 }
2416
2417 store_waitstatus (ourstatus, statval);
2418
2419 if (rtnval == -1) /* No more children to wait for */
2420 {
2421 fprintf_unfiltered (gdb_stderr, "Child process unexpectedly missing.\n");
2422 /* Claim it exited with unknown signal. */
2423 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
2424 ourstatus->value.sig = TARGET_SIGNAL_UNKNOWN;
2425 return rtnval;
2426 }
2427
2428 pi->had_event = 0; /* Indicate that we've seen this one */
2429 return (rtnval);
2430 }
2431
2432 /*
2433
2434 LOCAL FUNCTION
2435
2436 set_proc_siginfo - set a process's current signal info
2437
2438 SYNOPSIS
2439
2440 void set_proc_siginfo (struct procinfo *pip, int signo);
2441
2442 DESCRIPTION
2443
2444 Given a pointer to a process info struct in PIP and a signal number
2445 in SIGNO, set the process's current signal and its associated signal
2446 information. The signal will be delivered to the process immediately
2447 after execution is resumed, even if it is being held. In addition,
2448 this particular delivery will not cause another PR_SIGNALLED stop
2449 even if the signal is being traced.
2450
2451 If we are not delivering the same signal that the prstatus siginfo
2452 struct contains information about, then synthesize a siginfo struct
2453 to match the signal we are doing to deliver, make it of the type
2454 "generated by a user process", and send this synthesized copy. When
2455 used to set the inferior's signal state, this will be required if we
2456 are not currently stopped because of a traced signal, or if we decide
2457 to continue with a different signal.
2458
2459 Note that when continuing the inferior from a stop due to receipt
2460 of a traced signal, we either have set PRCSIG to clear the existing
2461 signal, or we have to call this function to do a PIOCSSIG with either
2462 the existing siginfo struct from pr_info, or one we have synthesized
2463 appropriately for the signal we want to deliver. Otherwise if the
2464 signal is still being traced, the inferior will immediately stop
2465 again.
2466
2467 See siginfo(5) for more details.
2468 */
2469
2470 static void
2471 set_proc_siginfo (pip, signo)
2472 struct procinfo *pip;
2473 int signo;
2474 {
2475 struct siginfo newsiginfo;
2476 struct siginfo *sip;
2477
2478 if (signo == pip -> prstatus.pr_info.si_signo)
2479 {
2480 sip = &pip -> prstatus.pr_info;
2481 }
2482 else
2483 {
2484 memset ((char *) &newsiginfo, 0, sizeof (newsiginfo));
2485 sip = &newsiginfo;
2486 sip -> si_signo = signo;
2487 sip -> si_code = 0;
2488 sip -> si_errno = 0;
2489 sip -> si_pid = getpid ();
2490 sip -> si_uid = getuid ();
2491 }
2492 if (ioctl (pip -> fd, PIOCSSIG, sip) < 0)
2493 {
2494 print_sys_errmsg (pip -> pathname, errno);
2495 warning ("PIOCSSIG failed");
2496 }
2497 }
2498
2499 /* Resume execution of process PID. If STEP is nozero, then
2500 just single step it. If SIGNAL is nonzero, restart it with that
2501 signal activated. */
2502
2503 static void
2504 procfs_resume (pid, step, signo)
2505 int pid;
2506 int step;
2507 enum target_signal signo;
2508 {
2509 int signal_to_pass;
2510 struct procinfo *pi, *procinfo;
2511
2512 pi = find_procinfo (pid == -1 ? inferior_pid : pid, 0);
2513
2514 errno = 0;
2515 pi->prrun.pr_flags = PRSTRACE | PRSFAULT | PRCFAULT;
2516
2517 #if 0
2518 /* It should not be necessary. If the user explicitly changes the value,
2519 value_assign calls write_register_bytes, which writes it. */
2520 /* It may not be absolutely necessary to specify the PC value for
2521 restarting, but to be safe we use the value that gdb considers
2522 to be current. One case where this might be necessary is if the
2523 user explicitly changes the PC value that gdb considers to be
2524 current. FIXME: Investigate if this is necessary or not. */
2525
2526 #ifdef PRSVADDR_BROKEN
2527 /* Can't do this under Solaris running on a Sparc, as there seems to be no
2528 place to put nPC. In fact, if you use this, nPC seems to be set to some
2529 random garbage. We have to rely on the fact that PC and nPC have been
2530 written previously via PIOCSREG during a register flush. */
2531
2532 pi->prrun.pr_vaddr = (caddr_t) *(int *) &registers[REGISTER_BYTE (PC_REGNUM)];
2533 pi->prrun.pr_flags != PRSVADDR;
2534 #endif
2535 #endif
2536
2537 if (signo == TARGET_SIGNAL_STOP && pi->nopass_next_sigstop)
2538 /* When attaching to a child process, if we forced it to stop with
2539 a PIOCSTOP, then we will have set the nopass_next_sigstop flag.
2540 Upon resuming the first time after such a stop, we explicitly
2541 inhibit sending it another SIGSTOP, which would be the normal
2542 result of default signal handling. One potential drawback to
2543 this is that we will also ignore any attempt to by the user
2544 to explicitly continue after the attach with a SIGSTOP. Ultimately
2545 this problem should be dealt with by making the routines that
2546 deal with the inferior a little smarter, and possibly even allow
2547 an inferior to continue running at the same time as gdb. (FIXME?) */
2548 signal_to_pass = 0;
2549 else if (signo == TARGET_SIGNAL_TSTP
2550 && pi->prstatus.pr_cursig == SIGTSTP
2551 && pi->prstatus.pr_action.sa_handler == SIG_DFL)
2552
2553 /* We are about to pass the inferior a SIGTSTP whose action is
2554 SIG_DFL. The SIG_DFL action for a SIGTSTP is to stop
2555 (notifying the parent via wait()), and then keep going from the
2556 same place when the parent is ready for you to keep going. So
2557 under the debugger, it should do nothing (as if the program had
2558 been stopped and then later resumed. Under ptrace, this
2559 happens for us, but under /proc, the system obligingly stops
2560 the process, and wait_for_inferior would have no way of
2561 distinguishing that type of stop (which indicates that we
2562 should just start it again), with a stop due to the pr_trace
2563 field of the prrun_t struct.
2564
2565 Note that if the SIGTSTP is being caught, we *do* need to pass it,
2566 because the handler needs to get executed. */
2567 signal_to_pass = 0;
2568 else
2569 signal_to_pass = target_signal_to_host (signo);
2570
2571 if (signal_to_pass)
2572 {
2573 set_proc_siginfo (pi, signal_to_pass);
2574 }
2575 else
2576 {
2577 pi->prrun.pr_flags |= PRCSIG;
2578 }
2579 pi->nopass_next_sigstop = 0;
2580 if (step)
2581 {
2582 pi->prrun.pr_flags |= PRSTEP;
2583 }
2584 if (ioctl (pi->fd, PIOCRUN, &pi->prrun) != 0)
2585 {
2586 perror_with_name (pi->pathname);
2587 /* NOTREACHED */
2588 }
2589
2590 pi->had_event = 0;
2591
2592 /* Continue all the other threads that haven't had an event of
2593 interest. */
2594
2595 if (pid == -1)
2596 for (procinfo = procinfo_list; procinfo; procinfo = procinfo->next)
2597 {
2598 if (pi != procinfo && !procinfo->had_event)
2599 {
2600 procinfo->prrun.pr_flags &= PRSTEP;
2601 procinfo->prrun.pr_flags |= PRCFAULT | PRCSIG;
2602 ioctl (procinfo->fd, PIOCSTATUS, &procinfo->prstatus);
2603 if (ioctl (procinfo->fd, PIOCRUN, &procinfo->prrun) < 0)
2604 {
2605 if (ioctl (procinfo->fd, PIOCSTATUS, &procinfo->prstatus) < 0)
2606 {
2607 fprintf_unfiltered(gdb_stderr, "PIOCSTATUS failed, errno=%d\n", errno);
2608 }
2609 print_sys_errmsg (procinfo->pathname, errno);
2610 error ("PIOCRUN failed");
2611 }
2612 ioctl (procinfo->fd, PIOCSTATUS, &procinfo->prstatus);
2613 }
2614 }
2615 }
2616
2617 /*
2618
2619 LOCAL FUNCTION
2620
2621 procfs_fetch_registers -- fetch current registers from inferior
2622
2623 SYNOPSIS
2624
2625 void procfs_fetch_registers (int regno)
2626
2627 DESCRIPTION
2628
2629 Read the current values of the inferior's registers, both the
2630 general register set and floating point registers (if supported)
2631 and update gdb's idea of their current values.
2632
2633 */
2634
2635 static void
2636 procfs_fetch_registers (regno)
2637 int regno;
2638 {
2639 struct procinfo *pi;
2640
2641 pi = current_procinfo;
2642
2643 if (ioctl (pi->fd, PIOCGREG, &pi->gregset) != -1)
2644 {
2645 supply_gregset (&pi->gregset);
2646 }
2647 #if defined (FP0_REGNUM)
2648 if (ioctl (pi->fd, PIOCGFPREG, &pi->fpregset) != -1)
2649 {
2650 supply_fpregset (&pi->fpregset);
2651 }
2652 #endif
2653 }
2654
2655 /*
2656
2657 LOCAL FUNCTION
2658
2659 proc_init_failed - called whenever /proc access initialization
2660 fails
2661
2662 SYNOPSIS
2663
2664 static void proc_init_failed (struct procinfo *pi, char *why)
2665
2666 DESCRIPTION
2667
2668 This function is called whenever initialization of access to a /proc
2669 entry fails. It prints a suitable error message, does some cleanup,
2670 and then invokes the standard error processing routine which dumps
2671 us back into the command loop.
2672 */
2673
2674 static void
2675 proc_init_failed (pi, why)
2676 struct procinfo *pi;
2677 char *why;
2678 {
2679 print_sys_errmsg (pi->pathname, errno);
2680 kill (pi->pid, SIGKILL);
2681 close_proc_file (pi);
2682 error (why);
2683 /* NOTREACHED */
2684 }
2685
2686 /*
2687
2688 LOCAL FUNCTION
2689
2690 close_proc_file - close any currently open /proc entry
2691
2692 SYNOPSIS
2693
2694 static void close_proc_file (struct procinfo *pip)
2695
2696 DESCRIPTION
2697
2698 Close any currently open /proc entry and mark the process information
2699 entry as invalid. In order to ensure that we don't try to reuse any
2700 stale information, the pid, fd, and pathnames are explicitly
2701 invalidated, which may be overkill.
2702
2703 */
2704
2705 static void
2706 close_proc_file (pip)
2707 struct procinfo *pip;
2708 {
2709 struct procinfo *procinfo;
2710
2711 remove_fd (pip); /* Remove fd from poll/select list */
2712
2713 close (pip -> fd);
2714
2715 free (pip -> pathname);
2716
2717 /* Unlink pip from the procinfo chain. Note pip might not be on the list. */
2718
2719 if (procinfo_list == pip)
2720 procinfo_list = pip->next;
2721 else
2722 for (procinfo = procinfo_list; procinfo; procinfo = procinfo->next)
2723 if (procinfo->next == pip)
2724 procinfo->next = pip->next;
2725
2726 free (pip);
2727 }
2728
2729 /*
2730
2731 LOCAL FUNCTION
2732
2733 open_proc_file - open a /proc entry for a given process id
2734
2735 SYNOPSIS
2736
2737 static int open_proc_file (int pid, struct procinfo *pip, int mode)
2738
2739 DESCRIPTION
2740
2741 Given a process id and a mode, close the existing open /proc
2742 entry (if any) and open one for the new process id, in the
2743 specified mode. Once it is open, then mark the local process
2744 information structure as valid, which guarantees that the pid,
2745 fd, and pathname fields match an open /proc entry. Returns
2746 zero if the open fails, nonzero otherwise.
2747
2748 Note that the pathname is left intact, even when the open fails,
2749 so that callers can use it to construct meaningful error messages
2750 rather than just "file open failed".
2751 */
2752
2753 static int
2754 open_proc_file (pid, pip, mode)
2755 int pid;
2756 struct procinfo *pip;
2757 int mode;
2758 {
2759 pip -> next = NULL;
2760 pip -> had_event = 0;
2761 pip -> pathname = xmalloc (32);
2762 pip -> pid = pid;
2763
2764 sprintf (pip -> pathname, PROC_NAME_FMT, pid);
2765 if ((pip -> fd = open (pip -> pathname, mode)) < 0)
2766 return 0;
2767
2768 return 1;
2769 }
2770
2771 static char *
2772 mappingflags (flags)
2773 long flags;
2774 {
2775 static char asciiflags[8];
2776
2777 strcpy (asciiflags, "-------");
2778 #if defined (MA_PHYS)
2779 if (flags & MA_PHYS) asciiflags[0] = 'd';
2780 #endif
2781 if (flags & MA_STACK) asciiflags[1] = 's';
2782 if (flags & MA_BREAK) asciiflags[2] = 'b';
2783 if (flags & MA_SHARED) asciiflags[3] = 's';
2784 if (flags & MA_READ) asciiflags[4] = 'r';
2785 if (flags & MA_WRITE) asciiflags[5] = 'w';
2786 if (flags & MA_EXEC) asciiflags[6] = 'x';
2787 return (asciiflags);
2788 }
2789
2790 static void
2791 info_proc_flags (pip, summary)
2792 struct procinfo *pip;
2793 int summary;
2794 {
2795 struct trans *transp;
2796
2797 printf_filtered ("%-32s", "Process status flags:");
2798 if (!summary)
2799 {
2800 printf_filtered ("\n\n");
2801 }
2802 for (transp = pr_flag_table; transp -> name != NULL; transp++)
2803 {
2804 if (pip -> prstatus.pr_flags & transp -> value)
2805 {
2806 if (summary)
2807 {
2808 printf_filtered ("%s ", transp -> name);
2809 }
2810 else
2811 {
2812 printf_filtered ("\t%-16s %s.\n", transp -> name, transp -> desc);
2813 }
2814 }
2815 }
2816 printf_filtered ("\n");
2817 }
2818
2819 static void
2820 info_proc_stop (pip, summary)
2821 struct procinfo *pip;
2822 int summary;
2823 {
2824 struct trans *transp;
2825 int why;
2826 int what;
2827
2828 why = pip -> prstatus.pr_why;
2829 what = pip -> prstatus.pr_what;
2830
2831 if (pip -> prstatus.pr_flags & PR_STOPPED)
2832 {
2833 printf_filtered ("%-32s", "Reason for stopping:");
2834 if (!summary)
2835 {
2836 printf_filtered ("\n\n");
2837 }
2838 for (transp = pr_why_table; transp -> name != NULL; transp++)
2839 {
2840 if (why == transp -> value)
2841 {
2842 if (summary)
2843 {
2844 printf_filtered ("%s ", transp -> name);
2845 }
2846 else
2847 {
2848 printf_filtered ("\t%-16s %s.\n",
2849 transp -> name, transp -> desc);
2850 }
2851 break;
2852 }
2853 }
2854
2855 /* Use the pr_why field to determine what the pr_what field means, and
2856 print more information. */
2857
2858 switch (why)
2859 {
2860 case PR_REQUESTED:
2861 /* pr_what is unused for this case */
2862 break;
2863 case PR_JOBCONTROL:
2864 case PR_SIGNALLED:
2865 if (summary)
2866 {
2867 printf_filtered ("%s ", signalname (what));
2868 }
2869 else
2870 {
2871 printf_filtered ("\t%-16s %s.\n", signalname (what),
2872 safe_strsignal (what));
2873 }
2874 break;
2875 case PR_SYSENTRY:
2876 if (summary)
2877 {
2878 printf_filtered ("%s ", syscallname (what));
2879 }
2880 else
2881 {
2882 printf_filtered ("\t%-16s %s.\n", syscallname (what),
2883 "Entered this system call");
2884 }
2885 break;
2886 case PR_SYSEXIT:
2887 if (summary)
2888 {
2889 printf_filtered ("%s ", syscallname (what));
2890 }
2891 else
2892 {
2893 printf_filtered ("\t%-16s %s.\n", syscallname (what),
2894 "Returned from this system call");
2895 }
2896 break;
2897 case PR_FAULTED:
2898 if (summary)
2899 {
2900 printf_filtered ("%s ",
2901 lookupname (faults_table, what, "fault"));
2902 }
2903 else
2904 {
2905 printf_filtered ("\t%-16s %s.\n",
2906 lookupname (faults_table, what, "fault"),
2907 lookupdesc (faults_table, what));
2908 }
2909 break;
2910 }
2911 printf_filtered ("\n");
2912 }
2913 }
2914
2915 static void
2916 info_proc_siginfo (pip, summary)
2917 struct procinfo *pip;
2918 int summary;
2919 {
2920 struct siginfo *sip;
2921
2922 if ((pip -> prstatus.pr_flags & PR_STOPPED) &&
2923 (pip -> prstatus.pr_why == PR_SIGNALLED ||
2924 pip -> prstatus.pr_why == PR_FAULTED))
2925 {
2926 printf_filtered ("%-32s", "Additional signal/fault info:");
2927 sip = &pip -> prstatus.pr_info;
2928 if (summary)
2929 {
2930 printf_filtered ("%s ", signalname (sip -> si_signo));
2931 if (sip -> si_errno > 0)
2932 {
2933 printf_filtered ("%s ", errnoname (sip -> si_errno));
2934 }
2935 if (sip -> si_code <= 0)
2936 {
2937 printf_filtered ("sent by %s, uid %d ",
2938 target_pid_to_str (sip -> si_pid),
2939 sip -> si_uid);
2940 }
2941 else
2942 {
2943 printf_filtered ("%s ", sigcodename (sip));
2944 if ((sip -> si_signo == SIGILL) ||
2945 (sip -> si_signo == SIGFPE) ||
2946 (sip -> si_signo == SIGSEGV) ||
2947 (sip -> si_signo == SIGBUS))
2948 {
2949 printf_filtered ("addr=%#x ", sip -> si_addr);
2950 }
2951 else if ((sip -> si_signo == SIGCHLD))
2952 {
2953 printf_filtered ("child %s, status %u ",
2954 target_pid_to_str (sip -> si_pid),
2955 sip -> si_status);
2956 }
2957 else if ((sip -> si_signo == SIGPOLL))
2958 {
2959 printf_filtered ("band %u ", sip -> si_band);
2960 }
2961 }
2962 }
2963 else
2964 {
2965 printf_filtered ("\n\n");
2966 printf_filtered ("\t%-16s %s.\n", signalname (sip -> si_signo),
2967 safe_strsignal (sip -> si_signo));
2968 if (sip -> si_errno > 0)
2969 {
2970 printf_filtered ("\t%-16s %s.\n",
2971 errnoname (sip -> si_errno),
2972 safe_strerror (sip -> si_errno));
2973 }
2974 if (sip -> si_code <= 0)
2975 {
2976 printf_filtered ("\t%-16u %s\n", sip -> si_pid, /* XXX need target_pid_to_str() */
2977 "PID of process sending signal");
2978 printf_filtered ("\t%-16u %s\n", sip -> si_uid,
2979 "UID of process sending signal");
2980 }
2981 else
2982 {
2983 printf_filtered ("\t%-16s %s.\n", sigcodename (sip),
2984 sigcodedesc (sip));
2985 if ((sip -> si_signo == SIGILL) ||
2986 (sip -> si_signo == SIGFPE))
2987 {
2988 printf_filtered ("\t%-16#x %s.\n", sip -> si_addr,
2989 "Address of faulting instruction");
2990 }
2991 else if ((sip -> si_signo == SIGSEGV) ||
2992 (sip -> si_signo == SIGBUS))
2993 {
2994 printf_filtered ("\t%-16#x %s.\n", sip -> si_addr,
2995 "Address of faulting memory reference");
2996 }
2997 else if ((sip -> si_signo == SIGCHLD))
2998 {
2999 printf_filtered ("\t%-16u %s.\n", sip -> si_pid, /* XXX need target_pid_to_str() */
3000 "Child process ID");
3001 printf_filtered ("\t%-16u %s.\n", sip -> si_status,
3002 "Child process exit value or signal");
3003 }
3004 else if ((sip -> si_signo == SIGPOLL))
3005 {
3006 printf_filtered ("\t%-16u %s.\n", sip -> si_band,
3007 "Band event for POLL_{IN,OUT,MSG}");
3008 }
3009 }
3010 }
3011 printf_filtered ("\n");
3012 }
3013 }
3014
3015 static void
3016 info_proc_syscalls (pip, summary)
3017 struct procinfo *pip;
3018 int summary;
3019 {
3020 int syscallnum;
3021
3022 if (!summary)
3023 {
3024
3025 #if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */
3026 if (pip -> prstatus.pr_flags & PR_ASLEEP)
3027 {
3028 int syscallnum = pip -> prstatus.pr_reg[R_D0];
3029 if (summary)
3030 {
3031 printf_filtered ("%-32s", "Sleeping in system call:");
3032 printf_filtered ("%s", syscallname (syscallnum));
3033 }
3034 else
3035 {
3036 printf_filtered ("Sleeping in system call '%s'.\n",
3037 syscallname (syscallnum));
3038 }
3039 }
3040 #endif
3041
3042 if (ioctl (pip -> fd, PIOCGENTRY, &pip -> entryset) < 0)
3043 {
3044 print_sys_errmsg (pip -> pathname, errno);
3045 error ("PIOCGENTRY failed");
3046 }
3047
3048 if (ioctl (pip -> fd, PIOCGEXIT, &pip -> exitset) < 0)
3049 {
3050 print_sys_errmsg (pip -> pathname, errno);
3051 error ("PIOCGEXIT failed");
3052 }
3053
3054 printf_filtered ("System call tracing information:\n\n");
3055
3056 printf_filtered ("\t%-12s %-8s %-8s\n",
3057 "System call",
3058 "Entry",
3059 "Exit");
3060 for (syscallnum = 0; syscallnum < MAX_SYSCALLS; syscallnum++)
3061 {
3062 QUIT;
3063 if (syscall_table[syscallnum] != NULL)
3064 {
3065 printf_filtered ("\t%-12s ", syscall_table[syscallnum]);
3066 printf_filtered ("%-8s ",
3067 prismember (&pip -> entryset, syscallnum)
3068 ? "on" : "off");
3069 printf_filtered ("%-8s ",
3070 prismember (&pip -> exitset, syscallnum)
3071 ? "on" : "off");
3072 printf_filtered ("\n");
3073 }
3074 }
3075 printf_filtered ("\n");
3076 }
3077 }
3078
3079 static char *
3080 signalname (signo)
3081 int signo;
3082 {
3083 const char *name;
3084 static char locbuf[32];
3085
3086 name = strsigno (signo);
3087 if (name == NULL)
3088 {
3089 sprintf (locbuf, "Signal %d", signo);
3090 }
3091 else
3092 {
3093 sprintf (locbuf, "%s (%d)", name, signo);
3094 }
3095 return (locbuf);
3096 }
3097
3098 static char *
3099 errnoname (errnum)
3100 int errnum;
3101 {
3102 const char *name;
3103 static char locbuf[32];
3104
3105 name = strerrno (errnum);
3106 if (name == NULL)
3107 {
3108 sprintf (locbuf, "Errno %d", errnum);
3109 }
3110 else
3111 {
3112 sprintf (locbuf, "%s (%d)", name, errnum);
3113 }
3114 return (locbuf);
3115 }
3116
3117 static void
3118 info_proc_signals (pip, summary)
3119 struct procinfo *pip;
3120 int summary;
3121 {
3122 int signo;
3123
3124 if (!summary)
3125 {
3126 if (ioctl (pip -> fd, PIOCGTRACE, &pip -> trace) < 0)
3127 {
3128 print_sys_errmsg (pip -> pathname, errno);
3129 error ("PIOCGTRACE failed");
3130 }
3131
3132 printf_filtered ("Disposition of signals:\n\n");
3133 printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n",
3134 "Signal", "Trace", "Hold", "Pending", "Description");
3135 for (signo = 0; signo < NSIG; signo++)
3136 {
3137 QUIT;
3138 printf_filtered ("\t%-15s ", signalname (signo));
3139 printf_filtered ("%-8s ",
3140 prismember (&pip -> trace, signo)
3141 ? "on" : "off");
3142 printf_filtered ("%-8s ",
3143 prismember (&pip -> prstatus.pr_sighold, signo)
3144 ? "on" : "off");
3145 printf_filtered ("%-8s ",
3146 prismember (&pip -> prstatus.pr_sigpend, signo)
3147 ? "yes" : "no");
3148 printf_filtered (" %s\n", safe_strsignal (signo));
3149 }
3150 printf_filtered ("\n");
3151 }
3152 }
3153
3154 static void
3155 info_proc_faults (pip, summary)
3156 struct procinfo *pip;
3157 int summary;
3158 {
3159 struct trans *transp;
3160
3161 if (!summary)
3162 {
3163 if (ioctl (pip -> fd, PIOCGFAULT, &pip -> fltset) < 0)
3164 {
3165 print_sys_errmsg (pip -> pathname, errno);
3166 error ("PIOCGFAULT failed");
3167 }
3168
3169 printf_filtered ("Current traced hardware fault set:\n\n");
3170 printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace");
3171
3172 for (transp = faults_table; transp -> name != NULL; transp++)
3173 {
3174 QUIT;
3175 printf_filtered ("\t%-12s ", transp -> name);
3176 printf_filtered ("%-8s", prismember (&pip -> fltset, transp -> value)
3177 ? "on" : "off");
3178 printf_filtered ("\n");
3179 }
3180 printf_filtered ("\n");
3181 }
3182 }
3183
3184 static void
3185 info_proc_mappings (pip, summary)
3186 struct procinfo *pip;
3187 int summary;
3188 {
3189 int nmap;
3190 struct prmap *prmaps;
3191 struct prmap *prmap;
3192
3193 if (!summary)
3194 {
3195 printf_filtered ("Mapped address spaces:\n\n");
3196 printf_filtered ("\t%10s %10s %10s %10s %7s\n",
3197 "Start Addr",
3198 " End Addr",
3199 " Size",
3200 " Offset",
3201 "Flags");
3202 if (ioctl (pip -> fd, PIOCNMAP, &nmap) == 0)
3203 {
3204 prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps));
3205 if (ioctl (pip -> fd, PIOCMAP, prmaps) == 0)
3206 {
3207 for (prmap = prmaps; prmap -> pr_size; ++prmap)
3208 {
3209 printf_filtered ("\t%#10x %#10x %#10x %#10x %7s\n",
3210 prmap -> pr_vaddr,
3211 prmap -> pr_vaddr + prmap -> pr_size - 1,
3212 prmap -> pr_size,
3213 prmap -> pr_off,
3214 mappingflags (prmap -> pr_mflags));
3215 }
3216 }
3217 }
3218 printf_filtered ("\n");
3219 }
3220 }
3221
3222 /*
3223
3224 LOCAL FUNCTION
3225
3226 info_proc -- implement the "info proc" command
3227
3228 SYNOPSIS
3229
3230 void info_proc (char *args, int from_tty)
3231
3232 DESCRIPTION
3233
3234 Implement gdb's "info proc" command by using the /proc interface
3235 to print status information about any currently running process.
3236
3237 Examples of the use of "info proc" are:
3238
3239 info proc (prints summary info for current inferior)
3240 info proc 123 (prints summary info for process with pid 123)
3241 info proc mappings (prints address mappings)
3242 info proc times (prints process/children times)
3243 info proc id (prints pid, ppid, gid, sid, etc)
3244 FIXME: i proc id not implemented.
3245 info proc status (prints general process state info)
3246 FIXME: i proc status not implemented.
3247 info proc signals (prints info about signal handling)
3248 info proc all (prints all info)
3249
3250 */
3251
3252 static void
3253 info_proc (args, from_tty)
3254 char *args;
3255 int from_tty;
3256 {
3257 int pid;
3258 struct procinfo *pip;
3259 struct cleanup *old_chain;
3260 char **argv;
3261 int argsize;
3262 int summary = 1;
3263 int flags = 0;
3264 int syscalls = 0;
3265 int signals = 0;
3266 int faults = 0;
3267 int mappings = 0;
3268 int times = 0;
3269 int id = 0;
3270 int status = 0;
3271 int all = 0;
3272
3273 old_chain = make_cleanup (null_cleanup, 0);
3274
3275 /* Default to using the current inferior if no pid specified. Note
3276 that inferior_pid may be 0, hence we set okerr. */
3277
3278 pip = find_procinfo (inferior_pid, 1);
3279
3280 if (args != NULL)
3281 {
3282 if ((argv = buildargv (args)) == NULL)
3283 {
3284 nomem (0);
3285 }
3286 make_cleanup (freeargv, (char *) argv);
3287
3288 while (*argv != NULL)
3289 {
3290 argsize = strlen (*argv);
3291 if (argsize >= 1 && strncmp (*argv, "all", argsize) == 0)
3292 {
3293 summary = 0;
3294 all = 1;
3295 }
3296 else if (argsize >= 2 && strncmp (*argv, "faults", argsize) == 0)
3297 {
3298 summary = 0;
3299 faults = 1;
3300 }
3301 else if (argsize >= 2 && strncmp (*argv, "flags", argsize) == 0)
3302 {
3303 summary = 0;
3304 flags = 1;
3305 }
3306 else if (argsize >= 1 && strncmp (*argv, "id", argsize) == 0)
3307 {
3308 summary = 0;
3309 id = 1;
3310 }
3311 else if (argsize >= 1 && strncmp (*argv, "mappings", argsize) == 0)
3312 {
3313 summary = 0;
3314 mappings = 1;
3315 }
3316 else if (argsize >= 2 && strncmp (*argv, "signals", argsize) == 0)
3317 {
3318 summary = 0;
3319 signals = 1;
3320 }
3321 else if (argsize >= 2 && strncmp (*argv, "status", argsize) == 0)
3322 {
3323 summary = 0;
3324 status = 1;
3325 }
3326 else if (argsize >= 2 && strncmp (*argv, "syscalls", argsize) == 0)
3327 {
3328 summary = 0;
3329 syscalls = 1;
3330 }
3331 else if (argsize >= 1 && strncmp (*argv, "times", argsize) == 0)
3332 {
3333 summary = 0;
3334 times = 1;
3335 }
3336 else if ((pid = atoi (*argv)) > 0)
3337 {
3338 pip = (struct procinfo *) xmalloc (sizeof (struct procinfo));
3339 memset (pip, 0, sizeof (*pip));
3340
3341 pip->pid = pid;
3342 if (!open_proc_file (pid, pip, O_RDONLY))
3343 {
3344 perror_with_name (pip -> pathname);
3345 /* NOTREACHED */
3346 }
3347 make_cleanup (close_proc_file, pip);
3348 }
3349 else if (**argv != '\000')
3350 {
3351 error ("Unrecognized or ambiguous keyword `%s'.", *argv);
3352 }
3353 argv++;
3354 }
3355 }
3356
3357 /* If we don't have a valid open process at this point, then we have no
3358 inferior or didn't specify a specific pid. */
3359
3360 if (!pip)
3361 {
3362 error ("\
3363 No process. Start debugging a program or specify an explicit process ID.");
3364 }
3365 if (ioctl (pip -> fd, PIOCSTATUS, &(pip -> prstatus)) < 0)
3366 {
3367 print_sys_errmsg (pip -> pathname, errno);
3368 error ("PIOCSTATUS failed");
3369 }
3370
3371 /* Print verbose information of the requested type(s), or just a summary
3372 of the information for all types. */
3373
3374 printf_filtered ("\nInformation for %s:\n\n", pip -> pathname);
3375 if (summary || all || flags)
3376 {
3377 info_proc_flags (pip, summary);
3378 }
3379 if (summary || all)
3380 {
3381 info_proc_stop (pip, summary);
3382 }
3383 if (summary || all || signals || faults)
3384 {
3385 info_proc_siginfo (pip, summary);
3386 }
3387 if (summary || all || syscalls)
3388 {
3389 info_proc_syscalls (pip, summary);
3390 }
3391 if (summary || all || mappings)
3392 {
3393 info_proc_mappings (pip, summary);
3394 }
3395 if (summary || all || signals)
3396 {
3397 info_proc_signals (pip, summary);
3398 }
3399 if (summary || all || faults)
3400 {
3401 info_proc_faults (pip, summary);
3402 }
3403 printf_filtered ("\n");
3404
3405 /* All done, deal with closing any temporary process info structure,
3406 freeing temporary memory , etc. */
3407
3408 do_cleanups (old_chain);
3409 }
3410
3411 /*
3412
3413 LOCAL FUNCTION
3414
3415 procfs_set_sproc_trap -- arrange for child to stop on sproc().
3416
3417 SYNOPSIS
3418
3419 void procfs_set_sproc_trap (struct procinfo *)
3420
3421 DESCRIPTION
3422
3423 This function sets up a trap on sproc system call exits so that we can
3424 detect the arrival of a new thread. We are called with the new thread
3425 stopped prior to it's first instruction.
3426
3427 Also note that we turn on the inherit-on-fork flag in the child process
3428 so that any grand-children start with all tracing flags set.
3429 */
3430
3431 #ifdef SYS_sproc
3432
3433 static void
3434 procfs_set_sproc_trap (pi)
3435 struct procinfo *pi;
3436 {
3437 sysset_t exitset;
3438
3439 if (ioctl (pi->fd, PIOCGEXIT, &exitset) < 0)
3440 {
3441 print_sys_errmsg (pi->pathname, errno);
3442 error ("PIOCGEXIT failed");
3443 }
3444
3445 praddset (&exitset, SYS_sproc);
3446
3447 /* We trap on fork() and vfork() in order to disable debugging in our grand-
3448 children and descendant processes. At this time, GDB can only handle
3449 threads (multiple processes, one address space). forks (and execs) result
3450 in the creation of multiple address spaces, which GDB can't handle yet. */
3451
3452 praddset (&exitset, SYS_fork);
3453 #ifdef SYS_vfork
3454 praddset (&exitset, SYS_vfork);
3455 #endif
3456
3457 if (ioctl (pi->fd, PIOCSEXIT, &exitset) < 0)
3458 {
3459 print_sys_errmsg (pi->pathname, errno);
3460 error ("PIOCSEXIT failed");
3461 }
3462
3463 /* Turn on inherit-on-fork flag so that all grand-children of gdb start with
3464 tracing flags set. */
3465
3466 #ifdef PIOCSET /* New method */
3467 {
3468 long pr_flags;
3469 pr_flags = PR_FORK;
3470 ioctl (pi->fd, PIOCSET, &pr_flags);
3471 }
3472 #else
3473 #ifdef PIOCSFORK /* Original method */
3474 ioctl (pi->fd, PIOCSFORK, NULL);
3475 #endif
3476 #endif
3477 }
3478 #endif /* SYS_sproc */
3479
3480 /* Fork an inferior process, and start debugging it with /proc. */
3481
3482 static void
3483 procfs_create_inferior (exec_file, allargs, env)
3484 char *exec_file;
3485 char *allargs;
3486 char **env;
3487 {
3488 char *shell_file = getenv ("SHELL");
3489 char *tryname;
3490 if (shell_file != NULL && strchr (shell_file, '/') == NULL)
3491 {
3492
3493 /* We will be looking down the PATH to find shell_file. If we
3494 just do this the normal way (via execlp, which operates by
3495 attempting an exec for each element of the PATH until it
3496 finds one which succeeds), then there will be an exec for
3497 each failed attempt, each of which will cause a PR_SYSEXIT
3498 stop, and we won't know how to distinguish the PR_SYSEXIT's
3499 for these failed execs with the ones for successful execs
3500 (whether the exec has succeeded is stored at that time in the
3501 carry bit or some such architecture-specific and
3502 non-ABI-specified place).
3503
3504 So I can't think of anything better than to search the PATH
3505 now. This has several disadvantages: (1) There is a race
3506 condition; if we find a file now and it is deleted before we
3507 exec it, we lose, even if the deletion leaves a valid file
3508 further down in the PATH, (2) there is no way to know exactly
3509 what an executable (in the sense of "capable of being
3510 exec'd") file is. Using access() loses because it may lose
3511 if the caller is the superuser; failing to use it loses if
3512 there are ACLs or some such. */
3513
3514 char *p;
3515 char *p1;
3516 /* FIXME-maybe: might want "set path" command so user can change what
3517 path is used from within GDB. */
3518 char *path = getenv ("PATH");
3519 int len;
3520 struct stat statbuf;
3521
3522 if (path == NULL)
3523 path = "/bin:/usr/bin";
3524
3525 tryname = alloca (strlen (path) + strlen (shell_file) + 2);
3526 for (p = path; p != NULL; p = p1 ? p1 + 1: NULL)
3527 {
3528 p1 = strchr (p, ':');
3529 if (p1 != NULL)
3530 len = p1 - p;
3531 else
3532 len = strlen (p);
3533 strncpy (tryname, p, len);
3534 tryname[len] = '\0';
3535 strcat (tryname, "/");
3536 strcat (tryname, shell_file);
3537 if (access (tryname, X_OK) < 0)
3538 continue;
3539 if (stat (tryname, &statbuf) < 0)
3540 continue;
3541 if (!S_ISREG (statbuf.st_mode))
3542 /* We certainly need to reject directories. I'm not quite
3543 as sure about FIFOs, sockets, etc., but I kind of doubt
3544 that people want to exec() these things. */
3545 continue;
3546 break;
3547 }
3548 if (p == NULL)
3549 /* Not found. This must be an error rather than merely passing
3550 the file to execlp(), because execlp() would try all the
3551 exec()s, causing GDB to get confused. */
3552 error ("Can't find shell %s in PATH", shell_file);
3553
3554 shell_file = tryname;
3555 }
3556
3557 fork_inferior (exec_file, allargs, env,
3558 proc_set_exec_trap, procfs_init_inferior, shell_file);
3559
3560 /* We are at the first instruction we care about. */
3561 /* Pedal to the metal... */
3562
3563 /* Setup traps on exit from sproc() */
3564
3565 #ifdef SYS_sproc
3566 procfs_set_sproc_trap (current_procinfo);
3567 #endif
3568
3569 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
3570 }
3571
3572 /* Clean up after the inferior dies. */
3573
3574 static void
3575 procfs_mourn_inferior ()
3576 {
3577 struct procinfo *pi;
3578 struct procinfo *next_pi;
3579
3580 for (pi = procinfo_list; pi; pi = next_pi)
3581 {
3582 next_pi = pi->next;
3583 unconditionally_kill_inferior (pi);
3584 }
3585
3586 unpush_target (&procfs_ops);
3587 generic_mourn_inferior ();
3588 }
3589
3590
3591 /* Mark our target-struct as eligible for stray "run" and "attach" commands. */
3592 static int
3593 procfs_can_run ()
3594 {
3595 return(1);
3596 }
3597 #ifdef TARGET_CAN_USE_HARDWARE_WATCHPOINT
3598 \f
3599 /* Insert a watchpoint */
3600 int
3601 procfs_set_watchpoint(pid, addr, len, rw)
3602 int pid;
3603 CORE_ADDR addr;
3604 int len;
3605 int rw;
3606 {
3607 struct procinfo *pi;
3608 prwatch_t wpt;
3609
3610 pi = find_procinfo (pid == -1 ? inferior_pid : pid, 0);
3611 wpt.pr_vaddr = (caddr_t)addr;
3612 wpt.pr_size = len;
3613 wpt.pr_wflags = ((rw & 1) ? MA_READ : 0) | ((rw & 2) ? MA_WRITE : 0);
3614 if (ioctl (pi->fd, PIOCSWATCH, &wpt) < 0)
3615 {
3616 if (errno == E2BIG)
3617 return -1;
3618 /* Currently it sometimes happens that the same watchpoint gets
3619 deleted twice - don't die in this case (FIXME please) */
3620 if (errno == ESRCH && len == 0)
3621 return 0;
3622 print_sys_errmsg (pi->pathname, errno);
3623 error ("PIOCSWATCH failed");
3624 }
3625 return 0;
3626 }
3627
3628 int
3629 procfs_stopped_by_watchpoint(pid)
3630 int pid;
3631 {
3632 struct procinfo *pi;
3633 short what;
3634 short why;
3635
3636 pi = find_procinfo (pid == -1 ? inferior_pid : pid, 0);
3637 if (pi->prstatus.pr_flags & (PR_STOPPED | PR_ISTOP))
3638 {
3639 why = pi->prstatus.pr_why;
3640 what = pi->prstatus.pr_what;
3641 if (why == PR_FAULTED
3642 #if defined (FLTWATCH) && defined (FLTKWATCH)
3643 && (what == FLTWATCH) || (what == FLTKWATCH)
3644 #else
3645 #ifdef FLTWATCH
3646 && (what == FLTWATCH)
3647 #endif
3648 #ifdef FLTKWATCH
3649 && (what == FLTKWATCH)
3650 #endif
3651 #endif
3652 )
3653 return what;
3654 }
3655 return 0;
3656 }
3657 #endif
3658
3659 \f
3660 struct target_ops procfs_ops = {
3661 "procfs", /* to_shortname */
3662 "Unix /proc child process", /* to_longname */
3663 "Unix /proc child process (started by the \"run\" command).", /* to_doc */
3664 procfs_open, /* to_open */
3665 0, /* to_close */
3666 procfs_attach, /* to_attach */
3667 procfs_detach, /* to_detach */
3668 procfs_resume, /* to_resume */
3669 procfs_wait, /* to_wait */
3670 procfs_fetch_registers, /* to_fetch_registers */
3671 procfs_store_registers, /* to_store_registers */
3672 procfs_prepare_to_store, /* to_prepare_to_store */
3673 procfs_xfer_memory, /* to_xfer_memory */
3674 procfs_files_info, /* to_files_info */
3675 memory_insert_breakpoint, /* to_insert_breakpoint */
3676 memory_remove_breakpoint, /* to_remove_breakpoint */
3677 terminal_init_inferior, /* to_terminal_init */
3678 terminal_inferior, /* to_terminal_inferior */
3679 terminal_ours_for_output, /* to_terminal_ours_for_output */
3680 terminal_ours, /* to_terminal_ours */
3681 child_terminal_info, /* to_terminal_info */
3682 procfs_kill_inferior, /* to_kill */
3683 0, /* to_load */
3684 0, /* to_lookup_symbol */
3685 procfs_create_inferior, /* to_create_inferior */
3686 procfs_mourn_inferior, /* to_mourn_inferior */
3687 procfs_can_run, /* to_can_run */
3688 procfs_notice_signals, /* to_notice_signals */
3689 process_stratum, /* to_stratum */
3690 0, /* to_next */
3691 1, /* to_has_all_memory */
3692 1, /* to_has_memory */
3693 1, /* to_has_stack */
3694 1, /* to_has_registers */
3695 1, /* to_has_execution */
3696 0, /* sections */
3697 0, /* sections_end */
3698 OPS_MAGIC /* to_magic */
3699 };
3700
3701 void
3702 _initialize_procfs ()
3703 {
3704 add_target (&procfs_ops);
3705
3706 add_info ("proc", info_proc,
3707 "Show process status information using /proc entry.\n\
3708 Specify process id or use current inferior by default.\n\
3709 Specify keywords for detailed information; default is summary.\n\
3710 Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\
3711 `status', `syscalls', and `times'.\n\
3712 Unambiguous abbreviations may be used.");
3713
3714 init_syscall_table ();
3715 }
This page took 0.126546 seconds and 4 git commands to generate.