* configure.in: removed target_dependent line.
[deliverable/binutils-gdb.git] / gdb / procfs.c
CommitLineData
35f5886e 1/* Machine independent support for SVR4 /proc (process file system) for GDB.
ec8ceca3 2 Copyright 1991, 1992 Free Software Foundation, Inc.
35f5886e
FF
3 Written by Fred Fish at Cygnus Support.
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21
22/* N O T E S
23
24For information on the details of using /proc consult section proc(4)
25in the UNIX System V Release 4 System Administrator's Reference Manual.
26
27The general register and floating point register sets are manipulated by
28separate ioctl's. This file makes the assumption that if FP0_REGNUM is
29defined, then support for the floating point register set is desired,
30regardless of whether or not the actual target has floating point hardware.
31
32 */
33
34
5129100c 35#include "defs.h"
35f5886e
FF
36
37#ifdef USE_PROC_FS /* Entire file goes away if not using /proc */
38
407a8389 39#include <time.h>
35f5886e
FF
40#include <sys/procfs.h>
41#include <fcntl.h>
42#include <errno.h>
51b57ded 43#include <string.h>
35f5886e 44
35f5886e
FF
45#include "inferior.h"
46#include "target.h"
51b57ded 47#include "command.h"
cc221e76
FF
48
49#define MAX_SYSCALLS 256 /* Maximum number of syscalls for table */
35f5886e
FF
50
51#ifndef PROC_NAME_FMT
6c316cfd 52#define PROC_NAME_FMT "/proc/%05d"
35f5886e
FF
53#endif
54
35f5886e
FF
55#if 1 /* FIXME: Gross and ugly hack to resolve coredep.c global */
56CORE_ADDR kernel_u_addr;
57#endif
58
cc221e76
FF
59#ifdef BROKEN_SIGINFO_H /* Workaround broken SGS <sys/siginfo.h> */
60#undef si_pid
61#define si_pid _data._proc.pid
62#undef si_uid
63#define si_uid _data._proc._pdata._kill.uid
64#endif /* BROKEN_SIGINFO_H */
65
35f5886e
FF
66/* All access to the inferior, either one started by gdb or one that has
67 been attached to, is controlled by an instance of a procinfo structure,
68 defined below. Since gdb currently only handles one inferior at a time,
a39ad5ce
FF
69 the procinfo structure for the inferior is statically allocated and
70 only one exists at any given time. There is a separate procinfo
71 structure for use by the "info proc" command, so that we can print
72 useful information about any random process without interfering with
73 the inferior's procinfo information. */
35f5886e
FF
74
75struct procinfo {
76 int valid; /* Nonzero if pid, fd, & pathname are valid */
77 int pid; /* Process ID of inferior */
78 int fd; /* File descriptor for /proc entry */
79 char *pathname; /* Pathname to /proc entry */
80 int was_stopped; /* Nonzero if was stopped prior to attach */
d65eee73 81 int nopass_next_sigstop; /* Don't pass a sigstop on next resume */
35f5886e
FF
82 prrun_t prrun; /* Control state when it is run */
83 prstatus_t prstatus; /* Current process status info */
84 gregset_t gregset; /* General register set */
85 fpregset_t fpregset; /* Floating point register set */
86 fltset_t fltset; /* Current traced hardware fault set */
87 sigset_t trace; /* Current traced signal set */
88 sysset_t exitset; /* Current traced system call exit set */
89 sysset_t entryset; /* Current traced system call entry set */
cc221e76
FF
90 fltset_t saved_fltset; /* Saved traced hardware fault set */
91 sigset_t saved_trace; /* Saved traced signal set */
92 sigset_t saved_sighold; /* Saved held signal set */
93 sysset_t saved_exitset; /* Saved traced system call exit set */
94 sysset_t saved_entryset; /* Saved traced system call entry set */
a39ad5ce
FF
95};
96
97static struct procinfo pi; /* Inferior's process information */
35f5886e 98
cc221e76
FF
99/* Much of the information used in the /proc interface, particularly for
100 printing status information, is kept as tables of structures of the
101 following form. These tables can be used to map numeric values to
102 their symbolic names and to a string that describes their specific use. */
103
104struct trans {
105 int value; /* The numeric value */
106 char *name; /* The equivalent symbolic value */
107 char *desc; /* Short description of value */
108};
109
110/* Translate bits in the pr_flags member of the prstatus structure, into the
111 names and desc information. */
112
113static struct trans pr_flag_table[] =
114{
115#if defined (PR_STOPPED)
116 PR_STOPPED, "PR_STOPPED", "Process is stopped",
117#endif
118#if defined (PR_ISTOP)
119 PR_ISTOP, "PR_ISTOP", "Stopped on an event of interest",
120#endif
121#if defined (PR_DSTOP)
122 PR_DSTOP, "PR_DSTOP", "A stop directive is in effect",
123#endif
124#if defined (PR_ASLEEP)
125 PR_ASLEEP, "PR_ASLEEP", "Sleeping in an interruptible system call",
126#endif
127#if defined (PR_FORK)
128 PR_FORK, "PR_FORK", "Inherit-on-fork is in effect",
129#endif
130#if defined (PR_RLC)
131 PR_RLC, "PR_RLC", "Run-on-last-close is in effect",
132#endif
133#if defined (PR_PTRACE)
134 PR_PTRACE, "PR_PTRACE", "Process is being controlled by ptrace",
135#endif
136#if defined (PR_PCINVAL)
137 PR_PCINVAL, "PR_PCINVAL", "PC refers to an invalid virtual address",
138#endif
139#if defined (PR_ISSYS)
140 PR_ISSYS, "PR_ISSYS", "Is a system process",
5c1c5e67
FF
141#endif
142#if defined (PR_STEP)
143 PR_STEP, "PR_STEP", "Process has single step pending",
144#endif
145#if defined (PR_KLC)
146 PR_KLC, "PR_KLC", "Kill-on-last-close is in effect",
147#endif
148#if defined (PR_ASYNC)
149 PR_ASYNC, "PR_ASYNC", "Asynchronous stop is in effect",
150#endif
151#if defined (PR_PCOMPAT)
152 PR_PCOMPAT, "PR_PCOMPAT", "Ptrace compatibility mode in effect",
cc221e76
FF
153#endif
154 0, NULL, NULL
155};
156
157/* Translate values in the pr_why field of the prstatus struct. */
158
159static struct trans pr_why_table[] =
160{
161#if defined (PR_REQUESTED)
162 PR_REQUESTED, "PR_REQUESTED", "Directed to stop via PIOCSTOP/PIOCWSTOP",
163#endif
164#if defined (PR_SIGNALLED)
165 PR_SIGNALLED, "PR_SIGNALLED", "Receipt of a traced signal",
166#endif
167#if defined (PR_FAULTED)
168 PR_FAULTED, "PR_FAULTED", "Incurred a traced hardware fault",
169#endif
170#if defined (PR_SYSENTRY)
171 PR_SYSENTRY, "PR_SYSENTRY", "Entry to a traced system call",
172#endif
173#if defined (PR_SYSEXIT)
174 PR_SYSEXIT, "PR_SYSEXIT", "Exit from a traced system call",
175#endif
176#if defined (PR_JOBCONTROL)
177 PR_JOBCONTROL, "PR_JOBCONTROL", "Default job control stop signal action",
5c1c5e67
FF
178#endif
179#if defined (PR_SUSPENDED)
180 PR_SUSPENDED, "PR_SUSPENDED", "Process suspended",
cc221e76
FF
181#endif
182 0, NULL, NULL
183};
184
185/* Hardware fault translation table. */
186
187static struct trans faults_table[] =
188{
189#if defined (FLTILL)
190 FLTILL, "FLTILL", "Illegal instruction",
191#endif
192#if defined (FLTPRIV)
193 FLTPRIV, "FLTPRIV", "Privileged instruction",
194#endif
195#if defined (FLTBPT)
196 FLTBPT, "FLTBPT", "Breakpoint trap",
197#endif
198#if defined (FLTTRACE)
199 FLTTRACE, "FLTTRACE", "Trace trap",
200#endif
201#if defined (FLTACCESS)
202 FLTACCESS, "FLTACCESS", "Memory access fault",
203#endif
204#if defined (FLTBOUNDS)
205 FLTBOUNDS, "FLTBOUNDS", "Memory bounds violation",
206#endif
207#if defined (FLTIOVF)
208 FLTIOVF, "FLTIOVF", "Integer overflow",
209#endif
210#if defined (FLTIZDIV)
211 FLTIZDIV, "FLTIZDIV", "Integer zero divide",
212#endif
213#if defined (FLTFPE)
214 FLTFPE, "FLTFPE", "Floating-point exception",
215#endif
216#if defined (FLTSTACK)
217 FLTSTACK, "FLTSTACK", "Unrecoverable stack fault",
218#endif
219#if defined (FLTPAGE)
220 FLTPAGE, "FLTPAGE", "Recoverable page fault",
221#endif
222 0, NULL, NULL
223};
224
225/* Translation table for signal generation information. See UNIX System
226 V Release 4 Programmer's Reference Manual, siginfo(5). */
227
228static struct sigcode {
229 int signo;
230 int code;
231 char *codename;
232 char *desc;
233} siginfo_table[] = {
234#if defined (SIGILL) && defined (ILL_ILLOPC)
235 SIGILL, ILL_ILLOPC, "ILL_ILLOPC", "Illegal opcode",
236#endif
237#if defined (SIGILL) && defined (ILL_ILLOPN)
238 SIGILL, ILL_ILLOPN, "ILL_ILLOPN", "Illegal operand",
239#endif
240#if defined (SIGILL) && defined (ILL_ILLADR)
241 SIGILL, ILL_ILLADR, "ILL_ILLADR", "Illegal addressing mode",
242#endif
243#if defined (SIGILL) && defined (ILL_ILLTRP)
244 SIGILL, ILL_ILLTRP, "ILL_ILLTRP", "Illegal trap",
245#endif
246#if defined (SIGILL) && defined (ILL_PRVOPC)
247 SIGILL, ILL_PRVOPC, "ILL_PRVOPC", "Privileged opcode",
248#endif
249#if defined (SIGILL) && defined (ILL_PRVREG)
250 SIGILL, ILL_PRVREG, "ILL_PRVREG", "Privileged register",
251#endif
252#if defined (SIGILL) && defined (ILL_COPROC)
253 SIGILL, ILL_COPROC, "ILL_COPROC", "Coprocessor error",
254#endif
255#if defined (SIGILL) && defined (ILL_BADSTK)
256 SIGILL, ILL_BADSTK, "ILL_BADSTK", "Internal stack error",
257#endif
258#if defined (SIGFPE) && defined (FPE_INTDIV)
259 SIGFPE, FPE_INTDIV, "FPE_INTDIV", "Integer divide by zero",
260#endif
261#if defined (SIGFPE) && defined (FPE_INTOVF)
262 SIGFPE, FPE_INTOVF, "FPE_INTOVF", "Integer overflow",
263#endif
264#if defined (SIGFPE) && defined (FPE_FLTDIV)
265 SIGFPE, FPE_FLTDIV, "FPE_FLTDIV", "Floating point divide by zero",
266#endif
267#if defined (SIGFPE) && defined (FPE_FLTOVF)
268 SIGFPE, FPE_FLTOVF, "FPE_FLTOVF", "Floating point overflow",
269#endif
270#if defined (SIGFPE) && defined (FPE_FLTUND)
271 SIGFPE, FPE_FLTUND, "FPE_FLTUND", "Floating point underflow",
272#endif
273#if defined (SIGFPE) && defined (FPE_FLTRES)
274 SIGFPE, FPE_FLTRES, "FPE_FLTRES", "Floating point inexact result",
275#endif
276#if defined (SIGFPE) && defined (FPE_FLTINV)
277 SIGFPE, FPE_FLTINV, "FPE_FLTINV", "Invalid floating point operation",
278#endif
279#if defined (SIGFPE) && defined (FPE_FLTSUB)
280 SIGFPE, FPE_FLTSUB, "FPE_FLTSUB", "Subscript out of range",
281#endif
282#if defined (SIGSEGV) && defined (SEGV_MAPERR)
283 SIGSEGV, SEGV_MAPERR, "SEGV_MAPERR", "Address not mapped to object",
284#endif
285#if defined (SIGSEGV) && defined (SEGV_ACCERR)
286 SIGSEGV, SEGV_ACCERR, "SEGV_ACCERR", "Invalid permissions for object",
287#endif
288#if defined (SIGBUS) && defined (BUS_ADRALN)
289 SIGBUS, BUS_ADRALN, "BUS_ADRALN", "Invalid address alignment",
290#endif
291#if defined (SIGBUS) && defined (BUS_ADRERR)
292 SIGBUS, BUS_ADRERR, "BUS_ADRERR", "Non-existent physical address",
293#endif
294#if defined (SIGBUS) && defined (BUS_OBJERR)
295 SIGBUS, BUS_OBJERR, "BUS_OBJERR", "Object specific hardware error",
296#endif
297#if defined (SIGTRAP) && defined (TRAP_BRKPT)
298 SIGTRAP, TRAP_BRKPT, "TRAP_BRKPT", "Process breakpoint",
299#endif
300#if defined (SIGTRAP) && defined (TRAP_TRACE)
301 SIGTRAP, TRAP_TRACE, "TRAP_TRACE", "Process trace trap",
302#endif
303#if defined (SIGCLD) && defined (CLD_EXITED)
304 SIGCLD, CLD_EXITED, "CLD_EXITED", "Child has exited",
305#endif
306#if defined (SIGCLD) && defined (CLD_KILLED)
307 SIGCLD, CLD_KILLED, "CLD_KILLED", "Child was killed",
308#endif
309#if defined (SIGCLD) && defined (CLD_DUMPED)
310 SIGCLD, CLD_DUMPED, "CLD_DUMPED", "Child has terminated abnormally",
311#endif
312#if defined (SIGCLD) && defined (CLD_TRAPPED)
313 SIGCLD, CLD_TRAPPED, "CLD_TRAPPED", "Traced child has trapped",
314#endif
315#if defined (SIGCLD) && defined (CLD_STOPPED)
316 SIGCLD, CLD_STOPPED, "CLD_STOPPED", "Child has stopped",
317#endif
318#if defined (SIGCLD) && defined (CLD_CONTINUED)
319 SIGCLD, CLD_CONTINUED, "CLD_CONTINUED", "Stopped child had continued",
320#endif
321#if defined (SIGPOLL) && defined (POLL_IN)
322 SIGPOLL, POLL_IN, "POLL_IN", "Input input available",
323#endif
324#if defined (SIGPOLL) && defined (POLL_OUT)
325 SIGPOLL, POLL_OUT, "POLL_OUT", "Output buffers available",
326#endif
327#if defined (SIGPOLL) && defined (POLL_MSG)
328 SIGPOLL, POLL_MSG, "POLL_MSG", "Input message available",
329#endif
330#if defined (SIGPOLL) && defined (POLL_ERR)
331 SIGPOLL, POLL_ERR, "POLL_ERR", "I/O error",
332#endif
333#if defined (SIGPOLL) && defined (POLL_PRI)
334 SIGPOLL, POLL_PRI, "POLL_PRI", "High priority input available",
335#endif
336#if defined (SIGPOLL) && defined (POLL_HUP)
337 SIGPOLL, POLL_HUP, "POLL_HUP", "Device disconnected",
338#endif
339 0, 0, NULL, NULL
340};
341
cc221e76
FF
342static char *syscall_table[MAX_SYSCALLS];
343
1ab3bf1b
JG
344/* Prototypes for local functions */
345
6b801388
FF
346static void
347set_proc_siginfo PARAMS ((struct procinfo *, int));
348
cc221e76
FF
349static void
350init_syscall_table PARAMS ((void));
351
352static char *
353syscallname PARAMS ((int));
354
355static char *
356signalname PARAMS ((int));
357
4ace50a5
FF
358static char *
359errnoname PARAMS ((int));
360
1ab3bf1b
JG
361static int
362proc_address_to_fd PARAMS ((CORE_ADDR, int));
363
364static int
ec8ceca3 365open_proc_file PARAMS ((int, struct procinfo *, int));
1ab3bf1b
JG
366
367static void
368close_proc_file PARAMS ((struct procinfo *));
369
370static void
371unconditionally_kill_inferior PARAMS ((void));
372
373static void
374proc_init_failed PARAMS ((char *));
375
376static void
cc221e76
FF
377info_proc PARAMS ((char *, int));
378
379static void
380info_proc_flags PARAMS ((struct procinfo *, int));
381
382static void
383info_proc_stop PARAMS ((struct procinfo *, int));
1ab3bf1b
JG
384
385static void
cc221e76
FF
386info_proc_siginfo PARAMS ((struct procinfo *, int));
387
388static void
389info_proc_syscalls PARAMS ((struct procinfo *, int));
390
391static void
392info_proc_mappings PARAMS ((struct procinfo *, int));
393
394static void
395info_proc_signals PARAMS ((struct procinfo *, int));
396
397static void
398info_proc_faults PARAMS ((struct procinfo *, int));
1ab3bf1b
JG
399
400static char *
401mappingflags PARAMS ((long));
402
cc221e76
FF
403static char *
404lookupname PARAMS ((struct trans *, unsigned int, char *));
405
406static char *
407lookupdesc PARAMS ((struct trans *, unsigned int));
408
1ab3bf1b
JG
409/* External function prototypes that can't be easily included in any
410 header file because the args are typedefs in system include files. */
411
412extern void
413supply_gregset PARAMS ((gregset_t *));
414
415extern void
416fill_gregset PARAMS ((gregset_t *, int));
417
418extern void
419supply_fpregset PARAMS ((fpregset_t *));
420
421extern void
422fill_fpregset PARAMS ((fpregset_t *, int));
35f5886e 423
cc221e76
FF
424/*
425
426LOCAL FUNCTION
427
428 lookupdesc -- translate a value to a summary desc string
429
430SYNOPSIS
431
432 static char *lookupdesc (struct trans *transp, unsigned int val);
433
434DESCRIPTION
435
436 Given a pointer to a translation table and a value to be translated,
437 lookup the desc string and return it.
438 */
439
440static char *
441lookupdesc (transp, val)
442 struct trans *transp;
443 unsigned int val;
444{
445 char *desc;
446
447 for (desc = NULL; transp -> name != NULL; transp++)
448 {
449 if (transp -> value == val)
450 {
451 desc = transp -> desc;
452 break;
453 }
454 }
455
456 /* Didn't find a translation for the specified value, set a default one. */
457
458 if (desc == NULL)
459 {
460 desc = "Unknown";
461 }
462 return (desc);
463}
464
465/*
466
467LOCAL FUNCTION
468
469 lookupname -- translate a value to symbolic name
470
471SYNOPSIS
472
473 static char *lookupname (struct trans *transp, unsigned int val,
474 char *prefix);
475
476DESCRIPTION
477
478 Given a pointer to a translation table, a value to be translated,
479 and a default prefix to return if the value can't be translated,
480 match the value with one of the translation table entries and
481 return a pointer to the symbolic name.
482
483 If no match is found it just returns the value as a printable string,
484 with the given prefix. The previous such value, if any, is freed
485 at this time.
486 */
487
488static char *
489lookupname (transp, val, prefix)
490 struct trans *transp;
491 unsigned int val;
492 char *prefix;
493{
494 static char *locbuf;
495 char *name;
496
497 for (name = NULL; transp -> name != NULL; transp++)
498 {
499 if (transp -> value == val)
500 {
501 name = transp -> name;
502 break;
503 }
504 }
505
506 /* Didn't find a translation for the specified value, build a default
507 one using the specified prefix and return it. The lifetime of
508 the value is only until the next one is needed. */
509
510 if (name == NULL)
511 {
512 if (locbuf != NULL)
513 {
514 free (locbuf);
515 }
516 locbuf = xmalloc (strlen (prefix) + 16);
4ed3a9ea 517 sprintf (locbuf, "%s %u", prefix, val);
cc221e76
FF
518 name = locbuf;
519 }
520 return (name);
521}
522
523static char *
524sigcodename (sip)
525 siginfo_t *sip;
526{
527 struct sigcode *scp;
528 char *name = NULL;
529 static char locbuf[32];
530
531 for (scp = siginfo_table; scp -> codename != NULL; scp++)
532 {
533 if ((scp -> signo == sip -> si_signo) &&
534 (scp -> code == sip -> si_code))
535 {
536 name = scp -> codename;
537 break;
538 }
539 }
540 if (name == NULL)
541 {
4ed3a9ea 542 sprintf (locbuf, "sigcode %u", sip -> si_signo);
cc221e76
FF
543 name = locbuf;
544 }
545 return (name);
546}
547
548static char *sigcodedesc (sip)
549 siginfo_t *sip;
550{
551 struct sigcode *scp;
552 char *desc = NULL;
553
554 for (scp = siginfo_table; scp -> codename != NULL; scp++)
555 {
556 if ((scp -> signo == sip -> si_signo) &&
557 (scp -> code == sip -> si_code))
558 {
559 desc = scp -> desc;
560 break;
561 }
562 }
563 if (desc == NULL)
564 {
565 desc = "Unrecognized signal or trap use";
566 }
567 return (desc);
568}
569
570/*
571
572LOCAL FUNCTION
573
574 syscallname - translate a system call number into a system call name
575
576SYNOPSIS
577
578 char *syscallname (int syscallnum)
579
580DESCRIPTION
581
582 Given a system call number, translate it into the printable name
583 of a system call, or into "syscall <num>" if it is an unknown
584 number.
585 */
586
587static char *
588syscallname (syscallnum)
589 int syscallnum;
590{
591 static char locbuf[32];
592 char *rtnval;
593
594 if (syscallnum >= 0 && syscallnum < MAX_SYSCALLS)
595 {
596 rtnval = syscall_table[syscallnum];
597 }
598 else
599 {
4ed3a9ea 600 sprintf (locbuf, "syscall %u", syscallnum);
cc221e76
FF
601 rtnval = locbuf;
602 }
603 return (rtnval);
604}
605
606/*
607
608LOCAL FUNCTION
609
610 init_syscall_table - initialize syscall translation table
611
612SYNOPSIS
613
614 void init_syscall_table (void)
615
616DESCRIPTION
617
618 Dynamically initialize the translation table to convert system
619 call numbers into printable system call names. Done once per
620 gdb run, on initialization.
621
622NOTES
623
624 This is awfully ugly, but preprocessor tricks to make it prettier
625 tend to be nonportable.
626 */
627
628static void
629init_syscall_table ()
630{
cc221e76
FF
631#if defined (SYS_exit)
632 syscall_table[SYS_exit] = "exit";
633#endif
634#if defined (SYS_fork)
635 syscall_table[SYS_fork] = "fork";
636#endif
637#if defined (SYS_read)
638 syscall_table[SYS_read] = "read";
639#endif
640#if defined (SYS_write)
641 syscall_table[SYS_write] = "write";
642#endif
643#if defined (SYS_open)
644 syscall_table[SYS_open] = "open";
645#endif
646#if defined (SYS_close)
647 syscall_table[SYS_close] = "close";
648#endif
649#if defined (SYS_wait)
650 syscall_table[SYS_wait] = "wait";
651#endif
652#if defined (SYS_creat)
653 syscall_table[SYS_creat] = "creat";
654#endif
655#if defined (SYS_link)
656 syscall_table[SYS_link] = "link";
657#endif
658#if defined (SYS_unlink)
659 syscall_table[SYS_unlink] = "unlink";
660#endif
661#if defined (SYS_exec)
662 syscall_table[SYS_exec] = "exec";
663#endif
664#if defined (SYS_execv)
665 syscall_table[SYS_execv] = "execv";
666#endif
667#if defined (SYS_execve)
668 syscall_table[SYS_execve] = "execve";
669#endif
670#if defined (SYS_chdir)
671 syscall_table[SYS_chdir] = "chdir";
672#endif
673#if defined (SYS_time)
674 syscall_table[SYS_time] = "time";
675#endif
676#if defined (SYS_mknod)
677 syscall_table[SYS_mknod] = "mknod";
678#endif
679#if defined (SYS_chmod)
680 syscall_table[SYS_chmod] = "chmod";
681#endif
682#if defined (SYS_chown)
683 syscall_table[SYS_chown] = "chown";
684#endif
685#if defined (SYS_brk)
686 syscall_table[SYS_brk] = "brk";
687#endif
688#if defined (SYS_stat)
689 syscall_table[SYS_stat] = "stat";
690#endif
691#if defined (SYS_lseek)
692 syscall_table[SYS_lseek] = "lseek";
693#endif
694#if defined (SYS_getpid)
695 syscall_table[SYS_getpid] = "getpid";
696#endif
697#if defined (SYS_mount)
698 syscall_table[SYS_mount] = "mount";
699#endif
700#if defined (SYS_umount)
701 syscall_table[SYS_umount] = "umount";
702#endif
703#if defined (SYS_setuid)
704 syscall_table[SYS_setuid] = "setuid";
705#endif
706#if defined (SYS_getuid)
707 syscall_table[SYS_getuid] = "getuid";
708#endif
709#if defined (SYS_stime)
710 syscall_table[SYS_stime] = "stime";
711#endif
712#if defined (SYS_ptrace)
713 syscall_table[SYS_ptrace] = "ptrace";
714#endif
715#if defined (SYS_alarm)
716 syscall_table[SYS_alarm] = "alarm";
717#endif
718#if defined (SYS_fstat)
719 syscall_table[SYS_fstat] = "fstat";
720#endif
721#if defined (SYS_pause)
722 syscall_table[SYS_pause] = "pause";
723#endif
724#if defined (SYS_utime)
725 syscall_table[SYS_utime] = "utime";
726#endif
727#if defined (SYS_stty)
728 syscall_table[SYS_stty] = "stty";
729#endif
730#if defined (SYS_gtty)
731 syscall_table[SYS_gtty] = "gtty";
732#endif
733#if defined (SYS_access)
734 syscall_table[SYS_access] = "access";
735#endif
736#if defined (SYS_nice)
737 syscall_table[SYS_nice] = "nice";
738#endif
739#if defined (SYS_statfs)
740 syscall_table[SYS_statfs] = "statfs";
741#endif
742#if defined (SYS_sync)
743 syscall_table[SYS_sync] = "sync";
744#endif
745#if defined (SYS_kill)
746 syscall_table[SYS_kill] = "kill";
747#endif
748#if defined (SYS_fstatfs)
749 syscall_table[SYS_fstatfs] = "fstatfs";
750#endif
751#if defined (SYS_pgrpsys)
752 syscall_table[SYS_pgrpsys] = "pgrpsys";
753#endif
754#if defined (SYS_xenix)
755 syscall_table[SYS_xenix] = "xenix";
756#endif
757#if defined (SYS_dup)
758 syscall_table[SYS_dup] = "dup";
759#endif
760#if defined (SYS_pipe)
761 syscall_table[SYS_pipe] = "pipe";
762#endif
763#if defined (SYS_times)
764 syscall_table[SYS_times] = "times";
765#endif
766#if defined (SYS_profil)
767 syscall_table[SYS_profil] = "profil";
768#endif
769#if defined (SYS_plock)
770 syscall_table[SYS_plock] = "plock";
771#endif
772#if defined (SYS_setgid)
773 syscall_table[SYS_setgid] = "setgid";
774#endif
775#if defined (SYS_getgid)
776 syscall_table[SYS_getgid] = "getgid";
777#endif
778#if defined (SYS_signal)
779 syscall_table[SYS_signal] = "signal";
780#endif
781#if defined (SYS_msgsys)
782 syscall_table[SYS_msgsys] = "msgsys";
783#endif
784#if defined (SYS_sys3b)
785 syscall_table[SYS_sys3b] = "sys3b";
786#endif
787#if defined (SYS_acct)
788 syscall_table[SYS_acct] = "acct";
789#endif
790#if defined (SYS_shmsys)
791 syscall_table[SYS_shmsys] = "shmsys";
792#endif
793#if defined (SYS_semsys)
794 syscall_table[SYS_semsys] = "semsys";
795#endif
796#if defined (SYS_ioctl)
797 syscall_table[SYS_ioctl] = "ioctl";
798#endif
799#if defined (SYS_uadmin)
800 syscall_table[SYS_uadmin] = "uadmin";
801#endif
802#if defined (SYS_utssys)
803 syscall_table[SYS_utssys] = "utssys";
804#endif
805#if defined (SYS_fsync)
806 syscall_table[SYS_fsync] = "fsync";
807#endif
808#if defined (SYS_umask)
809 syscall_table[SYS_umask] = "umask";
810#endif
811#if defined (SYS_chroot)
812 syscall_table[SYS_chroot] = "chroot";
813#endif
814#if defined (SYS_fcntl)
815 syscall_table[SYS_fcntl] = "fcntl";
816#endif
817#if defined (SYS_ulimit)
818 syscall_table[SYS_ulimit] = "ulimit";
819#endif
820#if defined (SYS_rfsys)
821 syscall_table[SYS_rfsys] = "rfsys";
822#endif
823#if defined (SYS_rmdir)
824 syscall_table[SYS_rmdir] = "rmdir";
825#endif
826#if defined (SYS_mkdir)
827 syscall_table[SYS_mkdir] = "mkdir";
828#endif
829#if defined (SYS_getdents)
830 syscall_table[SYS_getdents] = "getdents";
831#endif
832#if defined (SYS_sysfs)
833 syscall_table[SYS_sysfs] = "sysfs";
834#endif
835#if defined (SYS_getmsg)
836 syscall_table[SYS_getmsg] = "getmsg";
837#endif
838#if defined (SYS_putmsg)
839 syscall_table[SYS_putmsg] = "putmsg";
840#endif
841#if defined (SYS_poll)
842 syscall_table[SYS_poll] = "poll";
843#endif
844#if defined (SYS_lstat)
845 syscall_table[SYS_lstat] = "lstat";
846#endif
847#if defined (SYS_symlink)
848 syscall_table[SYS_symlink] = "symlink";
849#endif
850#if defined (SYS_readlink)
851 syscall_table[SYS_readlink] = "readlink";
852#endif
853#if defined (SYS_setgroups)
854 syscall_table[SYS_setgroups] = "setgroups";
855#endif
856#if defined (SYS_getgroups)
857 syscall_table[SYS_getgroups] = "getgroups";
858#endif
859#if defined (SYS_fchmod)
860 syscall_table[SYS_fchmod] = "fchmod";
861#endif
862#if defined (SYS_fchown)
863 syscall_table[SYS_fchown] = "fchown";
864#endif
865#if defined (SYS_sigprocmask)
866 syscall_table[SYS_sigprocmask] = "sigprocmask";
867#endif
868#if defined (SYS_sigsuspend)
869 syscall_table[SYS_sigsuspend] = "sigsuspend";
870#endif
871#if defined (SYS_sigaltstack)
872 syscall_table[SYS_sigaltstack] = "sigaltstack";
873#endif
874#if defined (SYS_sigaction)
875 syscall_table[SYS_sigaction] = "sigaction";
876#endif
877#if defined (SYS_sigpending)
878 syscall_table[SYS_sigpending] = "sigpending";
879#endif
880#if defined (SYS_context)
881 syscall_table[SYS_context] = "context";
882#endif
883#if defined (SYS_evsys)
884 syscall_table[SYS_evsys] = "evsys";
885#endif
886#if defined (SYS_evtrapret)
887 syscall_table[SYS_evtrapret] = "evtrapret";
888#endif
889#if defined (SYS_statvfs)
890 syscall_table[SYS_statvfs] = "statvfs";
891#endif
892#if defined (SYS_fstatvfs)
893 syscall_table[SYS_fstatvfs] = "fstatvfs";
894#endif
895#if defined (SYS_nfssys)
896 syscall_table[SYS_nfssys] = "nfssys";
897#endif
898#if defined (SYS_waitsys)
899 syscall_table[SYS_waitsys] = "waitsys";
900#endif
901#if defined (SYS_sigsendsys)
902 syscall_table[SYS_sigsendsys] = "sigsendsys";
903#endif
904#if defined (SYS_hrtsys)
905 syscall_table[SYS_hrtsys] = "hrtsys";
906#endif
907#if defined (SYS_acancel)
908 syscall_table[SYS_acancel] = "acancel";
909#endif
910#if defined (SYS_async)
911 syscall_table[SYS_async] = "async";
912#endif
913#if defined (SYS_priocntlsys)
914 syscall_table[SYS_priocntlsys] = "priocntlsys";
915#endif
916#if defined (SYS_pathconf)
917 syscall_table[SYS_pathconf] = "pathconf";
918#endif
919#if defined (SYS_mincore)
920 syscall_table[SYS_mincore] = "mincore";
921#endif
922#if defined (SYS_mmap)
923 syscall_table[SYS_mmap] = "mmap";
924#endif
925#if defined (SYS_mprotect)
926 syscall_table[SYS_mprotect] = "mprotect";
927#endif
928#if defined (SYS_munmap)
929 syscall_table[SYS_munmap] = "munmap";
930#endif
931#if defined (SYS_fpathconf)
932 syscall_table[SYS_fpathconf] = "fpathconf";
933#endif
934#if defined (SYS_vfork)
935 syscall_table[SYS_vfork] = "vfork";
936#endif
937#if defined (SYS_fchdir)
938 syscall_table[SYS_fchdir] = "fchdir";
939#endif
940#if defined (SYS_readv)
941 syscall_table[SYS_readv] = "readv";
942#endif
943#if defined (SYS_writev)
944 syscall_table[SYS_writev] = "writev";
945#endif
946#if defined (SYS_xstat)
947 syscall_table[SYS_xstat] = "xstat";
948#endif
949#if defined (SYS_lxstat)
950 syscall_table[SYS_lxstat] = "lxstat";
951#endif
952#if defined (SYS_fxstat)
953 syscall_table[SYS_fxstat] = "fxstat";
954#endif
955#if defined (SYS_xmknod)
956 syscall_table[SYS_xmknod] = "xmknod";
957#endif
958#if defined (SYS_clocal)
959 syscall_table[SYS_clocal] = "clocal";
960#endif
961#if defined (SYS_setrlimit)
962 syscall_table[SYS_setrlimit] = "setrlimit";
963#endif
964#if defined (SYS_getrlimit)
965 syscall_table[SYS_getrlimit] = "getrlimit";
966#endif
967#if defined (SYS_lchown)
968 syscall_table[SYS_lchown] = "lchown";
969#endif
970#if defined (SYS_memcntl)
971 syscall_table[SYS_memcntl] = "memcntl";
972#endif
973#if defined (SYS_getpmsg)
974 syscall_table[SYS_getpmsg] = "getpmsg";
975#endif
976#if defined (SYS_putpmsg)
977 syscall_table[SYS_putpmsg] = "putpmsg";
978#endif
979#if defined (SYS_rename)
980 syscall_table[SYS_rename] = "rename";
981#endif
982#if defined (SYS_uname)
983 syscall_table[SYS_uname] = "uname";
984#endif
985#if defined (SYS_setegid)
986 syscall_table[SYS_setegid] = "setegid";
987#endif
988#if defined (SYS_sysconfig)
989 syscall_table[SYS_sysconfig] = "sysconfig";
990#endif
991#if defined (SYS_adjtime)
992 syscall_table[SYS_adjtime] = "adjtime";
993#endif
994#if defined (SYS_systeminfo)
995 syscall_table[SYS_systeminfo] = "systeminfo";
996#endif
997#if defined (SYS_seteuid)
998 syscall_table[SYS_seteuid] = "seteuid";
999#endif
1000}
35f5886e
FF
1001
1002/*
1003
1004GLOBAL FUNCTION
1005
1006 ptrace -- override library version to force errors for /proc version
1007
1008SYNOPSIS
1009
e676a15f 1010 int ptrace (int request, int pid, PTRACE_ARG3_TYPE arg3, int arg4)
35f5886e
FF
1011
1012DESCRIPTION
1013
1014 When gdb is configured to use /proc, it should not be calling
1015 or otherwise attempting to use ptrace. In order to catch errors
1016 where use of /proc is configured, but some routine is still calling
1017 ptrace, we provide a local version of a function with that name
1018 that does nothing but issue an error message.
1019*/
1020
1021int
1ab3bf1b
JG
1022ptrace (request, pid, arg3, arg4)
1023 int request;
1024 int pid;
e676a15f 1025 PTRACE_ARG3_TYPE arg3;
1ab3bf1b 1026 int arg4;
35f5886e
FF
1027{
1028 error ("internal error - there is a call to ptrace() somewhere");
1029 /*NOTREACHED*/
1030}
1031
1032/*
1033
1034GLOBAL FUNCTION
1035
1036 kill_inferior_fast -- kill inferior while gdb is exiting
1037
1038SYNOPSIS
1039
1040 void kill_inferior_fast (void)
1041
1042DESCRIPTION
1043
1044 This is used when GDB is exiting. It gives less chance of error.
1045
1046NOTES
1047
1048 Don't attempt to kill attached inferiors since we may be called
1049 when gdb is in the process of aborting, and killing the attached
1050 inferior may be very anti-social. This is particularly true if we
1051 were attached just so we could use the /proc facilities to get
1052 detailed information about it's status.
1053
1054*/
1055
1056void
1ab3bf1b 1057kill_inferior_fast ()
35f5886e
FF
1058{
1059 if (inferior_pid != 0 && !attach_flag)
1060 {
1061 unconditionally_kill_inferior ();
1062 }
1063}
1064
1065/*
1066
1067GLOBAL FUNCTION
1068
1069 kill_inferior - kill any currently inferior
1070
1071SYNOPSIS
1072
1073 void kill_inferior (void)
1074
1075DESCRIPTION
1076
1077 Kill any current inferior.
1078
1079NOTES
1080
1081 Kills even attached inferiors. Presumably the user has already
1082 been prompted that the inferior is an attached one rather than
1083 one started by gdb. (FIXME?)
1084
1085*/
1086
1087void
1ab3bf1b 1088kill_inferior ()
35f5886e
FF
1089{
1090 if (inferior_pid != 0)
1091 {
1092 unconditionally_kill_inferior ();
1093 target_mourn_inferior ();
1094 }
1095}
1096
1097/*
1098
1099LOCAL FUNCTION
1100
1101 unconditionally_kill_inferior - terminate the inferior
1102
1103SYNOPSIS
1104
1105 static void unconditionally_kill_inferior (void)
1106
1107DESCRIPTION
1108
1109 Kill the current inferior. Should not be called until it
1110 is at least tested that there is an inferior.
1111
1112NOTE
1113
1114 A possibly useful enhancement would be to first try sending
1115 the inferior a terminate signal, politely asking it to commit
1116 suicide, before we murder it.
1117
1118*/
1119
1120static void
1ab3bf1b 1121unconditionally_kill_inferior ()
35f5886e
FF
1122{
1123 int signo;
1124
1125 signo = SIGKILL;
4ed3a9ea 1126 ioctl (pi.fd, PIOCKILL, &signo);
a39ad5ce 1127 close_proc_file (&pi);
35f5886e
FF
1128 wait ((int *) 0);
1129}
1130
1131/*
1132
1133GLOBAL FUNCTION
1134
1135 child_xfer_memory -- copy data to or from inferior memory space
1136
1137SYNOPSIS
1138
1139 int child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
1140 int dowrite, struct target_ops target)
1141
1142DESCRIPTION
1143
1144 Copy LEN bytes to/from inferior's memory starting at MEMADDR
1145 from/to debugger memory starting at MYADDR. Copy from inferior
1146 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
1147
1148 Returns the length copied, which is either the LEN argument or
1149 zero. This xfer function does not do partial moves, since child_ops
1150 doesn't allow memory operations to cross below us in the target stack
1151 anyway.
1152
1153NOTES
1154
1155 The /proc interface makes this an almost trivial task.
1156 */
1157
1158
1159int
1ab3bf1b
JG
1160child_xfer_memory (memaddr, myaddr, len, dowrite, target)
1161 CORE_ADDR memaddr;
1162 char *myaddr;
1163 int len;
1164 int dowrite;
1165 struct target_ops *target; /* ignored */
35f5886e
FF
1166{
1167 int nbytes = 0;
1168
1169 if (lseek (pi.fd, (off_t) memaddr, 0) == (off_t) memaddr)
1170 {
1171 if (dowrite)
1172 {
1173 nbytes = write (pi.fd, myaddr, len);
1174 }
1175 else
1176 {
1177 nbytes = read (pi.fd, myaddr, len);
1178 }
1179 if (nbytes < 0)
1180 {
1181 nbytes = 0;
1182 }
1183 }
1184 return (nbytes);
1185}
1186
1187/*
1188
1189GLOBAL FUNCTION
1190
1191 store_inferior_registers -- copy register values back to inferior
1192
1193SYNOPSIS
1194
1195 void store_inferior_registers (int regno)
1196
1197DESCRIPTION
1198
1199 Store our current register values back into the inferior. If
1200 REGNO is -1 then store all the register, otherwise store just
1201 the value specified by REGNO.
1202
1203NOTES
1204
1205 If we are storing only a single register, we first have to get all
1206 the current values from the process, overwrite the desired register
1207 in the gregset with the one we want from gdb's registers, and then
1208 send the whole set back to the process. For writing all the
1209 registers, all we have to do is generate the gregset and send it to
1210 the process.
1211
1212 Also note that the process has to be stopped on an event of interest
1213 for this to work, which basically means that it has to have been
1214 run under the control of one of the other /proc ioctl calls and not
1215 ptrace. Since we don't use ptrace anyway, we don't worry about this
1216 fine point, but it is worth noting for future reference.
1217
1218 Gdb is confused about what this function is supposed to return.
1219 Some versions return a value, others return nothing. Some are
1220 declared to return a value and actually return nothing. Gdb ignores
1221 anything returned. (FIXME)
1222
1223 */
1224
1225void
1ab3bf1b
JG
1226store_inferior_registers (regno)
1227 int regno;
35f5886e
FF
1228{
1229 if (regno != -1)
1230 {
4ed3a9ea 1231 ioctl (pi.fd, PIOCGREG, &pi.gregset);
35f5886e
FF
1232 }
1233 fill_gregset (&pi.gregset, regno);
4ed3a9ea 1234 ioctl (pi.fd, PIOCSREG, &pi.gregset);
35f5886e
FF
1235
1236#if defined (FP0_REGNUM)
1237
1238 /* Now repeat everything using the floating point register set, if the
1239 target has floating point hardware. Since we ignore the returned value,
1240 we'll never know whether it worked or not anyway. */
1241
1242 if (regno != -1)
1243 {
4ed3a9ea 1244 ioctl (pi.fd, PIOCGFPREG, &pi.fpregset);
35f5886e
FF
1245 }
1246 fill_fpregset (&pi.fpregset, regno);
4ed3a9ea 1247 ioctl (pi.fd, PIOCSFPREG, &pi.fpregset);
35f5886e
FF
1248
1249#endif /* FP0_REGNUM */
1250
1251}
1252
1253/*
1254
1255GLOBAL FUNCTION
1256
1257 inferior_proc_init - initialize access to a /proc entry
1258
1259SYNOPSIS
1260
1261 void inferior_proc_init (int pid)
1262
1263DESCRIPTION
1264
1265 When gdb starts an inferior, this function is called in the parent
1266 process immediately after the fork. It waits for the child to stop
1267 on the return from the exec system call (the child itself takes care
1268 of ensuring that this is set up), then sets up the set of signals
1269 and faults that are to be traced.
1270
1271NOTES
1272
1273 If proc_init_failed ever gets called, control returns to the command
1274 processing loop via the standard error handling code.
cc221e76 1275
35f5886e
FF
1276 */
1277
1278void
1ab3bf1b
JG
1279inferior_proc_init (pid)
1280 int pid;
35f5886e 1281{
ec8ceca3 1282 if (!open_proc_file (pid, &pi, O_RDWR))
35f5886e
FF
1283 {
1284 proc_init_failed ("can't open process file");
1285 }
1286 else
1287 {
4ed3a9ea 1288 memset ((char *) &pi.prrun, 0, sizeof (pi.prrun));
35f5886e 1289 prfillset (&pi.prrun.pr_trace);
cc221e76 1290 proc_signal_handling_change ();
35f5886e
FF
1291 prfillset (&pi.prrun.pr_fault);
1292 prdelset (&pi.prrun.pr_fault, FLTPAGE);
1293 if (ioctl (pi.fd, PIOCWSTOP, &pi.prstatus) < 0)
1294 {
1295 proc_init_failed ("PIOCWSTOP failed");
1296 }
35f5886e
FF
1297 else if (ioctl (pi.fd, PIOCSFAULT, &pi.prrun.pr_fault) < 0)
1298 {
1299 proc_init_failed ("PIOCSFAULT failed");
1300 }
1301 }
1302}
1303
1304/*
1305
cc221e76
FF
1306GLOBAL FUNCTION
1307
1308 proc_signal_handling_change
1309
1310SYNOPSIS
1311
1312 void proc_signal_handling_change (void);
1313
1314DESCRIPTION
1315
1316 When the user changes the state of gdb's signal handling via the
1317 "handle" command, this function gets called to see if any change
1318 in the /proc interface is required. It is also called internally
1319 by other /proc interface functions to initialize the state of
1320 the traced signal set.
1321
1322 One thing it does is that signals for which the state is "nostop",
1323 "noprint", and "pass", have their trace bits reset in the pr_trace
1324 field, so that they are no longer traced. This allows them to be
1325 delivered directly to the inferior without the debugger ever being
1326 involved.
1327 */
1328
1329void
1330proc_signal_handling_change ()
1331{
1332 int signo;
1333
1334 if (pi.valid)
1335 {
1336 for (signo = 0; signo < NSIG; signo++)
1337 {
1338 if (signal_stop_state (signo) == 0 &&
1339 signal_print_state (signo) == 0 &&
1340 signal_pass_state (signo) == 1)
1341 {
1342 prdelset (&pi.prrun.pr_trace, signo);
1343 }
1344 else
1345 {
1346 praddset (&pi.prrun.pr_trace, signo);
1347 }
1348 }
1349 if (ioctl (pi.fd, PIOCSTRACE, &pi.prrun.pr_trace))
1350 {
1351 print_sys_errmsg ("PIOCSTRACE failed", errno);
1352 }
1353 }
1354}
1355
1356/*
1357
35f5886e
FF
1358GLOBAL FUNCTION
1359
1360 proc_set_exec_trap -- arrange for exec'd child to halt at startup
1361
1362SYNOPSIS
1363
1364 void proc_set_exec_trap (void)
1365
1366DESCRIPTION
1367
1368 This function is called in the child process when starting up
1369 an inferior, prior to doing the exec of the actual inferior.
1370 It sets the child process's exitset to make exit from the exec
1371 system call an event of interest to stop on, and then simply
1372 returns. The child does the exec, the system call returns, and
1373 the child stops at the first instruction, ready for the gdb
1374 parent process to take control of it.
1375
1376NOTE
1377
1378 We need to use all local variables since the child may be sharing
1379 it's data space with the parent, if vfork was used rather than
1380 fork.
cc221e76
FF
1381
1382 Also note that we want to turn off the inherit-on-fork flag in
1383 the child process so that any grand-children start with all
1384 tracing flags cleared.
35f5886e
FF
1385 */
1386
1387void
1ab3bf1b 1388proc_set_exec_trap ()
35f5886e
FF
1389{
1390 sysset_t exitset;
1391 auto char procname[32];
1392 int fd;
1393
4ed3a9ea 1394 sprintf (procname, PROC_NAME_FMT, getpid ());
35f5886e
FF
1395 if ((fd = open (procname, O_RDWR)) < 0)
1396 {
1397 perror (procname);
1398 fflush (stderr);
1399 _exit (127);
1400 }
1401 premptyset (&exitset);
407a8389 1402
cc221e76
FF
1403 /* GW: Rationale...
1404 Not all systems with /proc have all the exec* syscalls with the same
1405 names. On the SGI, for example, there is no SYS_exec, but there
1406 *is* a SYS_execv. So, we try to account for that. */
1407
407a8389 1408#ifdef SYS_exec
35f5886e 1409 praddset (&exitset, SYS_exec);
407a8389
SG
1410#endif
1411#ifdef SYS_execve
35f5886e 1412 praddset (&exitset, SYS_execve);
407a8389
SG
1413#endif
1414#ifdef SYS_execv
1415 praddset(&exitset, SYS_execv);
1416#endif
1417
35f5886e
FF
1418 if (ioctl (fd, PIOCSEXIT, &exitset) < 0)
1419 {
1420 perror (procname);
1421 fflush (stderr);
1422 _exit (127);
1423 }
cc221e76
FF
1424
1425 /* Turn off inherit-on-fork flag so that all grand-children of gdb
1426 start with tracing flags cleared. */
1427
5c1c5e67 1428#if defined (PIOCRESET) /* New method */
cc221e76
FF
1429 {
1430 long pr_flags;
1431 pr_flags = PR_FORK;
4ed3a9ea 1432 ioctl (fd, PIOCRESET, &pr_flags);
cc221e76 1433 }
5c1c5e67
FF
1434#else
1435#if defined (PIOCRFORK) /* Original method */
4ed3a9ea 1436 ioctl (fd, PIOCRFORK, NULL);
cc221e76 1437#endif
ec8ceca3
JG
1438#endif
1439
1440 /* Turn on run-on-last-close flag so that this process will not hang
1441 if GDB goes away for some reason. */
1442
1443#if defined (PIOCSET) /* New method */
1444 {
1445 long pr_flags;
1446 pr_flags = PR_RLC;
1447 (void) ioctl (fd, PIOCSET, &pr_flags);
1448 }
1449#else
1450#if defined (PIOCSRLC) /* Original method */
1451 (void) ioctl (fd, PIOCSRLC, 0);
1452#endif
cc221e76 1453#endif
35f5886e
FF
1454}
1455
f8b76e70
FF
1456/*
1457
a39ad5ce
FF
1458GLOBAL FUNCTION
1459
1460 proc_iterate_over_mappings -- call function for every mapped space
1461
1462SYNOPSIS
1463
1464 int proc_iterate_over_mappings (int (*func)())
1465
1466DESCRIPTION
1467
1468 Given a pointer to a function, call that function for every
1469 mapped address space, passing it an open file descriptor for
1470 the file corresponding to that mapped address space (if any)
1471 and the base address of the mapped space. Quit when we hit
1472 the end of the mappings or the function returns nonzero.
1473 */
1474
1475int
1ab3bf1b
JG
1476proc_iterate_over_mappings (func)
1477 int (*func) PARAMS ((int, CORE_ADDR));
a39ad5ce
FF
1478{
1479 int nmap;
1480 int fd;
1481 int funcstat = 0;
1482 struct prmap *prmaps;
1483 struct prmap *prmap;
a39ad5ce
FF
1484
1485 if (pi.valid && (ioctl (pi.fd, PIOCNMAP, &nmap) == 0))
1486 {
1ab3bf1b 1487 prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps));
a39ad5ce
FF
1488 if (ioctl (pi.fd, PIOCMAP, prmaps) == 0)
1489 {
1490 for (prmap = prmaps; prmap -> pr_size && funcstat == 0; ++prmap)
1491 {
1ab3bf1b
JG
1492 fd = proc_address_to_fd ((CORE_ADDR) prmap -> pr_vaddr, 0);
1493 funcstat = (*func) (fd, (CORE_ADDR) prmap -> pr_vaddr);
a39ad5ce
FF
1494 close (fd);
1495 }
1496 }
1497 }
1498 return (funcstat);
1499}
1500
1501/*
1502
f8b76e70
FF
1503GLOBAL FUNCTION
1504
1505 proc_base_address -- find base address for segment containing address
1506
1507SYNOPSIS
1508
1509 CORE_ADDR proc_base_address (CORE_ADDR addr)
1510
1511DESCRIPTION
1512
1513 Given an address of a location in the inferior, find and return
1514 the base address of the mapped segment containing that address.
1515
1516 This is used for example, by the shared library support code,
1517 where we have the pc value for some location in the shared library
1518 where we are stopped, and need to know the base address of the
1519 segment containing that address.
1520*/
1521
1522
1ab3bf1b
JG
1523#if 0 /* Currently unused */
1524
f8b76e70 1525CORE_ADDR
1ab3bf1b 1526proc_base_address (addr)
cc221e76 1527 CORE_ADDR addr;
f8b76e70
FF
1528{
1529 int nmap;
1530 struct prmap *prmaps;
1531 struct prmap *prmap;
1532 CORE_ADDR baseaddr = 0;
1533
a39ad5ce 1534 if (pi.valid && (ioctl (pi.fd, PIOCNMAP, &nmap) == 0))
f8b76e70 1535 {
1ab3bf1b 1536 prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps));
f8b76e70
FF
1537 if (ioctl (pi.fd, PIOCMAP, prmaps) == 0)
1538 {
1539 for (prmap = prmaps; prmap -> pr_size; ++prmap)
1540 {
1541 if ((prmap -> pr_vaddr <= (caddr_t) addr) &&
1542 (prmap -> pr_vaddr + prmap -> pr_size > (caddr_t) addr))
1543 {
1544 baseaddr = (CORE_ADDR) prmap -> pr_vaddr;
1545 break;
1546 }
1547 }
1548 }
1549 }
1550 return (baseaddr);
1551}
1552
1ab3bf1b
JG
1553#endif /* 0 */
1554
f8b76e70
FF
1555/*
1556
cc221e76 1557LOCAL FUNCTION
f8b76e70
FF
1558
1559 proc_address_to_fd -- return open fd for file mapped to address
1560
1561SYNOPSIS
1562
a39ad5ce 1563 int proc_address_to_fd (CORE_ADDR addr, complain)
f8b76e70
FF
1564
1565DESCRIPTION
1566
1567 Given an address in the current inferior's address space, use the
1568 /proc interface to find an open file descriptor for the file that
1569 this address was mapped in from. Return -1 if there is no current
1570 inferior. Print a warning message if there is an inferior but
1571 the address corresponds to no file (IE a bogus address).
1572
1573*/
1574
1ab3bf1b
JG
1575static int
1576proc_address_to_fd (addr, complain)
1577 CORE_ADDR addr;
1578 int complain;
f8b76e70
FF
1579{
1580 int fd = -1;
1581
1582 if (pi.valid)
1583 {
1584 if ((fd = ioctl (pi.fd, PIOCOPENM, (caddr_t *) &addr)) < 0)
1585 {
a39ad5ce
FF
1586 if (complain)
1587 {
1588 print_sys_errmsg (pi.pathname, errno);
1589 warning ("can't find mapped file for address 0x%x", addr);
1590 }
f8b76e70
FF
1591 }
1592 }
1593 return (fd);
1594}
1595
35f5886e
FF
1596
1597#ifdef ATTACH_DETACH
1598
1599/*
1600
1601GLOBAL FUNCTION
1602
1603 attach -- attach to an already existing process
1604
1605SYNOPSIS
1606
1607 int attach (int pid)
1608
1609DESCRIPTION
1610
1611 Attach to an already existing process with the specified process
1612 id. If the process is not already stopped, query whether to
1613 stop it or not.
1614
1615NOTES
1616
1617 The option of stopping at attach time is specific to the /proc
1618 versions of gdb. Versions using ptrace force the attachee
ec8ceca3
JG
1619 to stop. (I have changed this version to do so, too. All you
1620 have to do is "continue" to make it go on. -- gnu@cygnus.com)
35f5886e
FF
1621
1622*/
1623
1624int
1ab3bf1b
JG
1625attach (pid)
1626 int pid;
35f5886e 1627{
ec8ceca3
JG
1628 int result;
1629
1630 if (!open_proc_file (pid, &pi, O_RDWR))
35f5886e
FF
1631 {
1632 perror_with_name (pi.pathname);
1633 /* NOTREACHED */
1634 }
1635
1636 /* Get current status of process and if it is not already stopped,
1637 then stop it. Remember whether or not it was stopped when we first
1638 examined it. */
1639
1640 if (ioctl (pi.fd, PIOCSTATUS, &pi.prstatus) < 0)
1641 {
1642 print_sys_errmsg (pi.pathname, errno);
a39ad5ce 1643 close_proc_file (&pi);
35f5886e
FF
1644 error ("PIOCSTATUS failed");
1645 }
1646 if (pi.prstatus.pr_flags & (PR_STOPPED | PR_ISTOP))
1647 {
1648 pi.was_stopped = 1;
1649 }
1650 else
1651 {
1652 pi.was_stopped = 0;
ec8ceca3 1653 if (1 || query ("Process is currently running, stop it? "))
35f5886e 1654 {
ec8ceca3
JG
1655 /* Make it run again when we close it. */
1656#if defined (PIOCSET) /* New method */
1657 {
1658 long pr_flags;
1659 pr_flags = PR_RLC;
1660 result = ioctl (pi.fd, PIOCSET, &pr_flags);
1661 }
1662#else
1663#if defined (PIOCSRLC) /* Original method */
1664 result = ioctl (pi.fd, PIOCSRLC, 0);
1665#endif
1666#endif
1667 if (result < 0)
1668 {
1669 print_sys_errmsg (pi.pathname, errno);
1670 close_proc_file (&pi);
1671 error ("PIOCSRLC or PIOCSET failed");
1672 }
35f5886e
FF
1673 if (ioctl (pi.fd, PIOCSTOP, &pi.prstatus) < 0)
1674 {
1675 print_sys_errmsg (pi.pathname, errno);
a39ad5ce 1676 close_proc_file (&pi);
35f5886e
FF
1677 error ("PIOCSTOP failed");
1678 }
d65eee73
FF
1679 pi.nopass_next_sigstop = 1;
1680 }
1681 else
1682 {
1683 printf ("Ok, gdb will wait for process %u to stop.\n", pid);
35f5886e
FF
1684 }
1685 }
ec8ceca3 1686
35f5886e
FF
1687 /* Remember some things about the inferior that we will, or might, change
1688 so that we can restore them when we detach. */
1689
4ed3a9ea
FF
1690 ioctl (pi.fd, PIOCGTRACE, &pi.saved_trace);
1691 ioctl (pi.fd, PIOCGHOLD, &pi.saved_sighold);
1692 ioctl (pi.fd, PIOCGFAULT, &pi.saved_fltset);
1693 ioctl (pi.fd, PIOCGENTRY, &pi.saved_entryset);
1694 ioctl (pi.fd, PIOCGEXIT, &pi.saved_exitset);
35f5886e
FF
1695
1696 /* Set up trace and fault sets, as gdb expects them. */
1697
4ed3a9ea 1698 memset (&pi.prrun, 0, sizeof (pi.prrun));
35f5886e 1699 prfillset (&pi.prrun.pr_trace);
cc221e76 1700 proc_signal_handling_change ();
35f5886e
FF
1701 prfillset (&pi.prrun.pr_fault);
1702 prdelset (&pi.prrun.pr_fault, FLTPAGE);
1703 if (ioctl (pi.fd, PIOCSFAULT, &pi.prrun.pr_fault))
1704 {
f66f459f 1705 print_sys_errmsg ("PIOCSFAULT failed", errno);
35f5886e
FF
1706 }
1707 if (ioctl (pi.fd, PIOCSTRACE, &pi.prrun.pr_trace))
1708 {
f66f459f 1709 print_sys_errmsg ("PIOCSTRACE failed", errno);
35f5886e
FF
1710 }
1711 attach_flag = 1;
1712 return (pid);
1713}
1714
1715/*
1716
1717GLOBAL FUNCTION
1718
1719 detach -- detach from an attached-to process
1720
1721SYNOPSIS
1722
1723 void detach (int signal)
1724
1725DESCRIPTION
1726
1727 Detach from the current attachee.
1728
1729 If signal is non-zero, the attachee is started running again and sent
1730 the specified signal.
1731
1732 If signal is zero and the attachee was not already stopped when we
1733 attached to it, then we make it runnable again when we detach.
1734
1735 Otherwise, we query whether or not to make the attachee runnable
1736 again, since we may simply want to leave it in the state it was in
1737 when we attached.
1738
1739 We report any problems, but do not consider them errors, since we
1740 MUST detach even if some things don't seem to go right. This may not
1741 be the ideal situation. (FIXME).
1742 */
1743
1744void
1ab3bf1b
JG
1745detach (signal)
1746 int signal;
35f5886e 1747{
ec8ceca3
JG
1748 int result;
1749
35f5886e
FF
1750 if (signal)
1751 {
6b801388 1752 set_proc_siginfo (&pi, signal);
35f5886e 1753 }
cc221e76 1754 if (ioctl (pi.fd, PIOCSEXIT, &pi.saved_exitset) < 0)
35f5886e
FF
1755 {
1756 print_sys_errmsg (pi.pathname, errno);
1757 printf ("PIOCSEXIT failed.\n");
1758 }
cc221e76 1759 if (ioctl (pi.fd, PIOCSENTRY, &pi.saved_entryset) < 0)
35f5886e
FF
1760 {
1761 print_sys_errmsg (pi.pathname, errno);
1762 printf ("PIOCSENTRY failed.\n");
1763 }
cc221e76 1764 if (ioctl (pi.fd, PIOCSTRACE, &pi.saved_trace) < 0)
35f5886e
FF
1765 {
1766 print_sys_errmsg (pi.pathname, errno);
1767 printf ("PIOCSTRACE failed.\n");
1768 }
cc221e76
FF
1769 if (ioctl (pi.fd, PIOCSHOLD, &pi.saved_sighold) < 0)
1770 {
1771 print_sys_errmsg (pi.pathname, errno);
1772 printf ("PIOSCHOLD failed.\n");
1773 }
1774 if (ioctl (pi.fd, PIOCSFAULT, &pi.saved_fltset) < 0)
35f5886e
FF
1775 {
1776 print_sys_errmsg (pi.pathname, errno);
1777 printf ("PIOCSFAULT failed.\n");
1778 }
1779 if (ioctl (pi.fd, PIOCSTATUS, &pi.prstatus) < 0)
1780 {
1781 print_sys_errmsg (pi.pathname, errno);
1782 printf ("PIOCSTATUS failed.\n");
1783 }
1784 else
1785 {
1786 if (signal || (pi.prstatus.pr_flags & (PR_STOPPED | PR_ISTOP)))
1787 {
1788 if (signal || !pi.was_stopped ||
1789 query ("Was stopped when attached, make it runnable again? "))
1790 {
ec8ceca3
JG
1791 /* Clear any fault that might have stopped it. */
1792 if (ioctl (pi.fd, PIOCCFAULT, 0))
1793 {
1794 print_sys_errmsg (pi.pathname, errno);
1795 printf ("PIOCCFAULT failed.\n");
1796 }
1797
1798 /* Make it run again when we close it. */
1799#if defined (PIOCSET) /* New method */
1800 {
1801 long pr_flags;
1802 pr_flags = PR_RLC;
1803 result = ioctl (pi.fd, PIOCSET, &pr_flags);
1804 }
1805#else
1806#if defined (PIOCSRLC) /* Original method */
1807 result = ioctl (pi.fd, PIOCSRLC, 0);
1808#endif
1809#endif
1810 if (result)
35f5886e
FF
1811 {
1812 print_sys_errmsg (pi.pathname, errno);
ec8ceca3 1813 printf ("PIOCSRLC or PIOCSET failed.\n");
35f5886e
FF
1814 }
1815 }
1816 }
1817 }
a39ad5ce 1818 close_proc_file (&pi);
35f5886e
FF
1819 attach_flag = 0;
1820}
1821
fb182850
FF
1822#endif /* ATTACH_DETACH */
1823
35f5886e
FF
1824/*
1825
1826GLOBAL FUNCTION
1827
1828 proc_wait -- emulate wait() as much as possible
1829
1830SYNOPSIS
1831
1832 int proc_wait (int *statloc)
1833
1834DESCRIPTION
1835
1836 Try to emulate wait() as much as possible. Not sure why we can't
1837 just use wait(), but it seems to have problems when applied to a
1838 process being controlled with the /proc interface.
1839
1840NOTES
1841
1842 We have a race problem here with no obvious solution. We need to let
1843 the inferior run until it stops on an event of interest, which means
1844 that we need to use the PIOCWSTOP ioctl. However, we cannot use this
1845 ioctl if the process is already stopped on something that is not an
1846 event of interest, or the call will hang indefinitely. Thus we first
1847 use PIOCSTATUS to see if the process is not stopped. If not, then we
1848 use PIOCWSTOP. But during the window between the two, if the process
1849 stops for any reason that is not an event of interest (such as a job
1850 control signal) then gdb will hang. One possible workaround is to set
1851 an alarm to wake up every minute of so and check to see if the process
1852 is still running, and if so, then reissue the PIOCWSTOP. But this is
1853 a real kludge, so has not been implemented. FIXME: investigate
1854 alternatives.
1855
1856 FIXME: Investigate why wait() seems to have problems with programs
1857 being control by /proc routines.
1858
1859 */
1860
1861int
1ab3bf1b
JG
1862proc_wait (statloc)
1863 int *statloc;
35f5886e
FF
1864{
1865 short what;
1866 short why;
1867 int statval = 0;
1868 int checkerr = 0;
1869 int rtnval = -1;
1870
1871 if (ioctl (pi.fd, PIOCSTATUS, &pi.prstatus) < 0)
1872 {
1873 checkerr++;
1874 }
1875 else if (!(pi.prstatus.pr_flags & (PR_STOPPED | PR_ISTOP)))
1876 {
1877 if (ioctl (pi.fd, PIOCWSTOP, &pi.prstatus) < 0)
1878 {
1879 checkerr++;
1880 }
1881 }
1882 if (checkerr)
1883 {
1884 if (errno == ENOENT)
1885 {
1886 rtnval = wait (&statval);
1887 if (rtnval != inferior_pid)
1888 {
34da3608 1889 print_sys_errmsg (pi.pathname, errno);
35f5886e
FF
1890 error ("PIOCWSTOP, wait failed, returned %d", rtnval);
1891 /* NOTREACHED */
1892 }
1893 }
1894 else
1895 {
1896 print_sys_errmsg (pi.pathname, errno);
1897 error ("PIOCSTATUS or PIOCWSTOP failed.");
1898 /* NOTREACHED */
1899 }
1900 }
1901 else if (pi.prstatus.pr_flags & (PR_STOPPED | PR_ISTOP))
1902 {
1903 rtnval = pi.prstatus.pr_pid;
1904 why = pi.prstatus.pr_why;
1905 what = pi.prstatus.pr_what;
1906 if (why == PR_SIGNALLED)
1907 {
1908 statval = (what << 8) | 0177;
1909 }
407a8389
SG
1910 else if ((why == PR_SYSEXIT)
1911 &&
1912 (
1913#ifdef SYS_exec
1914 what == SYS_exec
1915#else
1916 0 == 0
1917#endif
1918#ifdef SYS_execve
1919 || what == SYS_execve
1920#endif
1921#ifdef SYS_execv
1922 || what == SYS_execv
1923#endif
1924 ))
35f5886e
FF
1925 {
1926 statval = (SIGTRAP << 8) | 0177;
1927 }
1928 else if (why == PR_REQUESTED)
1929 {
1930 statval = (SIGSTOP << 8) | 0177;
1931 }
1932 else if (why == PR_JOBCONTROL)
1933 {
1934 statval = (what << 8) | 0177;
1935 }
1936 else if (why == PR_FAULTED)
1937 {
1938 switch (what)
1939 {
1940 case FLTPRIV:
1941 case FLTILL:
1942 statval = (SIGILL << 8) | 0177;
1943 break;
1944 case FLTBPT:
1945 case FLTTRACE:
1946 statval = (SIGTRAP << 8) | 0177;
1947 break;
1948 case FLTSTACK:
1949 case FLTACCESS:
1950 case FLTBOUNDS:
1951 statval = (SIGSEGV << 8) | 0177;
1952 break;
1953 case FLTIOVF:
1954 case FLTIZDIV:
1955 case FLTFPE:
1956 statval = (SIGFPE << 8) | 0177;
1957 break;
1958 case FLTPAGE: /* Recoverable page fault */
1959 default:
1960 rtnval = -1;
1961 error ("PIOCWSTOP, unknown why %d, what %d", why, what);
1962 /* NOTREACHED */
1963 }
1964 }
1965 else
1966 {
1967 rtnval = -1;
1968 error ("PIOCWSTOP, unknown why %d, what %d", why, what);
1969 /* NOTREACHED */
1970 }
1971 }
1972 else
1973 {
1974 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
1975 pi.prstatus.pr_flags);
1976 /* NOTREACHED */
1977 }
1978 if (statloc)
1979 {
1980 *statloc = statval;
1981 }
1982 return (rtnval);
1983}
1984
1985/*
1986
6b801388
FF
1987LOCAL FUNCTION
1988
1989 set_proc_siginfo - set a process's current signal info
1990
1991SYNOPSIS
1992
1993 void set_proc_siginfo (struct procinfo *pip, int signo);
1994
1995DESCRIPTION
1996
1997 Given a pointer to a process info struct in PIP and a signal number
1998 in SIGNO, set the process's current signal and its associated signal
1999 information. The signal will be delivered to the process immediately
2000 after execution is resumed, even if it is being held. In addition,
2001 this particular delivery will not cause another PR_SIGNALLED stop
2002 even if the signal is being traced.
2003
2004 If we are not delivering the same signal that the prstatus siginfo
2005 struct contains information about, then synthesize a siginfo struct
2006 to match the signal we are doing to deliver, make it of the type
2007 "generated by a user process", and send this synthesized copy. When
2008 used to set the inferior's signal state, this will be required if we
2009 are not currently stopped because of a traced signal, or if we decide
2010 to continue with a different signal.
2011
2012 Note that when continuing the inferior from a stop due to receipt
2013 of a traced signal, we either have set PRCSIG to clear the existing
2014 signal, or we have to call this function to do a PIOCSSIG with either
2015 the existing siginfo struct from pr_info, or one we have synthesized
2016 appropriately for the signal we want to deliver. Otherwise if the
2017 signal is still being traced, the inferior will immediately stop
2018 again.
2019
2020 See siginfo(5) for more details.
2021*/
2022
2023static void
2024set_proc_siginfo (pip, signo)
cc221e76
FF
2025 struct procinfo *pip;
2026 int signo;
6b801388
FF
2027{
2028 struct siginfo newsiginfo;
2029 struct siginfo *sip;
2030
2031 if (pip -> valid)
2032 {
2033 if (signo == pip -> prstatus.pr_info.si_signo)
2034 {
2035 sip = &pip -> prstatus.pr_info;
2036 }
2037 else
2038 {
4ed3a9ea 2039 memset ((char *) &newsiginfo, 0, sizeof (newsiginfo));
6b801388
FF
2040 sip = &newsiginfo;
2041 sip -> si_signo = signo;
2042 sip -> si_code = 0;
2043 sip -> si_errno = 0;
2044 sip -> si_pid = getpid ();
2045 sip -> si_uid = getuid ();
2046 }
2047 if (ioctl (pip -> fd, PIOCSSIG, sip) < 0)
2048 {
2049 print_sys_errmsg (pip -> pathname, errno);
2050 warning ("PIOCSSIG failed");
2051 }
2052 }
2053}
2054
2055/*
2056
35f5886e
FF
2057GLOBAL FUNCTION
2058
2059 child_resume -- resume execution of the inferior process
2060
2061SYNOPSIS
2062
cc221e76 2063 void child_resume (int step, int signo)
35f5886e
FF
2064
2065DESCRIPTION
2066
2067 Resume execution of the inferior process. If STEP is nozero, then
2068 just single step it. If SIGNAL is nonzero, restart it with that
2069 signal activated.
2070
2071NOTE
2072
2073 It may not be absolutely necessary to specify the PC value for
2074 restarting, but to be safe we use the value that gdb considers
2075 to be current. One case where this might be necessary is if the
2076 user explicitly changes the PC value that gdb considers to be
2077 current. FIXME: Investigate if this is necessary or not.
d65eee73
FF
2078
2079 When attaching to a child process, if we forced it to stop with
2080 a PIOCSTOP, then we will have set the nopass_next_sigstop flag.
2081 Upon resuming the first time after such a stop, we explicitly
2082 inhibit sending it another SIGSTOP, which would be the normal
2083 result of default signal handling. One potential drawback to
2084 this is that we will also ignore any attempt to by the user
2085 to explicitly continue after the attach with a SIGSTOP. Ultimately
2086 this problem should be dealt with by making the routines that
2087 deal with the inferior a little smarter, and possibly even allow
2088 an inferior to continue running at the same time as gdb. (FIXME?)
35f5886e
FF
2089 */
2090
2091void
cc221e76 2092child_resume (step, signo)
1ab3bf1b 2093 int step;
cc221e76 2094 int signo;
35f5886e
FF
2095{
2096 errno = 0;
99fd9e3e
SG
2097 pi.prrun.pr_flags = PRSTRACE | PRSFAULT | PRCFAULT;
2098
c3192172 2099#ifdef PRSVADDR_BROKEN
99fd9e3e
SG
2100/* Can't do this under Solaris running on a Sparc, as there seems to be no
2101 place to put nPC. In fact, if you use this, nPC seems to be set to some
2102 random garbage. We have to rely on the fact that PC and nPC have been
2103 written previously via PIOCSREG during a register flush. */
2104
35f5886e 2105 pi.prrun.pr_vaddr = (caddr_t) *(int *) &registers[REGISTER_BYTE (PC_REGNUM)];
99fd9e3e
SG
2106 pi.prrun.pr_flags != PRSVADDR;
2107#endif
2108
d65eee73 2109 if (signo && !(signo == SIGSTOP && pi.nopass_next_sigstop))
35f5886e 2110 {
cc221e76 2111 set_proc_siginfo (&pi, signo);
35f5886e
FF
2112 }
2113 else
2114 {
2115 pi.prrun.pr_flags |= PRCSIG;
2116 }
d65eee73 2117 pi.nopass_next_sigstop = 0;
35f5886e
FF
2118 if (step)
2119 {
2120 pi.prrun.pr_flags |= PRSTEP;
2121 }
2122 if (ioctl (pi.fd, PIOCRUN, &pi.prrun) != 0)
2123 {
2124 perror_with_name (pi.pathname);
2125 /* NOTREACHED */
2126 }
2127}
2128
2129/*
2130
2131GLOBAL FUNCTION
2132
2133 fetch_inferior_registers -- fetch current registers from inferior
2134
2135SYNOPSIS
2136
1ab3bf1b 2137 void fetch_inferior_registers (int regno)
35f5886e
FF
2138
2139DESCRIPTION
2140
2141 Read the current values of the inferior's registers, both the
2142 general register set and floating point registers (if supported)
2143 and update gdb's idea of their current values.
2144
2145*/
2146
2147void
1ab3bf1b
JG
2148fetch_inferior_registers (regno)
2149 int regno;
35f5886e
FF
2150{
2151 if (ioctl (pi.fd, PIOCGREG, &pi.gregset) != -1)
2152 {
2153 supply_gregset (&pi.gregset);
2154 }
2155#if defined (FP0_REGNUM)
2156 if (ioctl (pi.fd, PIOCGFPREG, &pi.fpregset) != -1)
2157 {
2158 supply_fpregset (&pi.fpregset);
2159 }
2160#endif
2161}
2162
fb182850
FF
2163/*
2164
2165GLOBAL FUNCTION
2166
2167 fetch_core_registers -- fetch current registers from core file data
2168
2169SYNOPSIS
2170
2171 void fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
1ab3bf1b 2172 int which, unsigned in reg_addr)
fb182850
FF
2173
2174DESCRIPTION
2175
2176 Read the values of either the general register set (WHICH equals 0)
2177 or the floating point register set (WHICH equals 2) from the core
2178 file data (pointed to by CORE_REG_SECT), and update gdb's idea of
2179 their current values. The CORE_REG_SIZE parameter is ignored.
2180
2181NOTES
2182
2183 Use the indicated sizes to validate the gregset and fpregset
2184 structures.
2185*/
2186
2187void
1ab3bf1b 2188fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
cc221e76
FF
2189 char *core_reg_sect;
2190 unsigned core_reg_size;
2191 int which;
2192 unsigned int reg_addr; /* Unused in this version */
fb182850
FF
2193{
2194
2195 if (which == 0)
2196 {
2197 if (core_reg_size != sizeof (pi.gregset))
2198 {
2199 warning ("wrong size gregset struct in core file");
2200 }
2201 else
2202 {
4ed3a9ea 2203 memcpy ((char *) &pi.gregset, core_reg_sect, sizeof (pi.gregset));
fb182850
FF
2204 supply_gregset (&pi.gregset);
2205 }
2206 }
2207 else if (which == 2)
2208 {
2209 if (core_reg_size != sizeof (pi.fpregset))
2210 {
2211 warning ("wrong size fpregset struct in core file");
2212 }
2213 else
2214 {
4ed3a9ea 2215 memcpy ((char *) &pi.fpregset, core_reg_sect, sizeof (pi.fpregset));
fb182850
FF
2216#if defined (FP0_REGNUM)
2217 supply_fpregset (&pi.fpregset);
2218#endif
2219 }
2220 }
2221}
35f5886e
FF
2222
2223/*
2224
2225LOCAL FUNCTION
2226
2227 proc_init_failed - called whenever /proc access initialization fails
2228
2229SYNOPSIS
2230
2231 static void proc_init_failed (char *why)
2232
2233DESCRIPTION
2234
2235 This function is called whenever initialization of access to a /proc
2236 entry fails. It prints a suitable error message, does some cleanup,
2237 and then invokes the standard error processing routine which dumps
2238 us back into the command loop.
2239 */
2240
2241static void
1ab3bf1b
JG
2242proc_init_failed (why)
2243 char *why;
35f5886e
FF
2244{
2245 print_sys_errmsg (pi.pathname, errno);
4ed3a9ea 2246 kill (pi.pid, SIGKILL);
a39ad5ce 2247 close_proc_file (&pi);
35f5886e
FF
2248 error (why);
2249 /* NOTREACHED */
2250}
2251
2252/*
2253
2254LOCAL FUNCTION
2255
2256 close_proc_file - close any currently open /proc entry
2257
2258SYNOPSIS
2259
a39ad5ce 2260 static void close_proc_file (struct procinfo *pip)
35f5886e
FF
2261
2262DESCRIPTION
2263
2264 Close any currently open /proc entry and mark the process information
2265 entry as invalid. In order to ensure that we don't try to reuse any
2266 stale information, the pid, fd, and pathnames are explicitly
2267 invalidated, which may be overkill.
2268
2269 */
2270
2271static void
1ab3bf1b
JG
2272close_proc_file (pip)
2273 struct procinfo *pip;
35f5886e 2274{
a39ad5ce
FF
2275 pip -> pid = 0;
2276 if (pip -> valid)
35f5886e 2277 {
4ed3a9ea 2278 close (pip -> fd);
35f5886e 2279 }
a39ad5ce
FF
2280 pip -> fd = -1;
2281 if (pip -> pathname)
35f5886e 2282 {
a39ad5ce
FF
2283 free (pip -> pathname);
2284 pip -> pathname = NULL;
35f5886e 2285 }
a39ad5ce 2286 pip -> valid = 0;
35f5886e
FF
2287}
2288
2289/*
2290
2291LOCAL FUNCTION
2292
2293 open_proc_file - open a /proc entry for a given process id
2294
2295SYNOPSIS
2296
ec8ceca3 2297 static int open_proc_file (int pid, struct procinfo *pip, int mode)
35f5886e
FF
2298
2299DESCRIPTION
2300
ec8ceca3
JG
2301 Given a process id and a mode, close the existing open /proc
2302 entry (if any) and open one for the new process id, in the
2303 specified mode. Once it is open, then mark the local process
2304 information structure as valid, which guarantees that the pid,
2305 fd, and pathname fields match an open /proc entry. Returns
2306 zero if the open fails, nonzero otherwise.
35f5886e
FF
2307
2308 Note that the pathname is left intact, even when the open fails,
2309 so that callers can use it to construct meaningful error messages
2310 rather than just "file open failed".
2311 */
2312
2313static int
ec8ceca3 2314open_proc_file (pid, pip, mode)
1ab3bf1b
JG
2315 int pid;
2316 struct procinfo *pip;
ec8ceca3 2317 int mode;
35f5886e 2318{
ec8ceca3 2319 pip -> valid = 0; /* FIXME, what is this? ?! */
a39ad5ce
FF
2320 if (pip -> valid)
2321 {
4ed3a9ea 2322 close (pip -> fd);
a39ad5ce
FF
2323 }
2324 if (pip -> pathname == NULL)
2325 {
2326 pip -> pathname = xmalloc (32);
2327 }
2328 sprintf (pip -> pathname, PROC_NAME_FMT, pid);
ec8ceca3 2329 if ((pip -> fd = open (pip -> pathname, mode)) >= 0)
a39ad5ce
FF
2330 {
2331 pip -> valid = 1;
2332 pip -> pid = pid;
2333 }
2334 return (pip -> valid);
2335}
2336
f66f459f 2337static char *
1ab3bf1b
JG
2338mappingflags (flags)
2339 long flags;
a39ad5ce 2340{
5c1c5e67 2341 static char asciiflags[8];
a39ad5ce 2342
5c1c5e67
FF
2343 strcpy (asciiflags, "-------");
2344#if defined (MA_PHYS)
2345 if (flags & MA_PHYS) asciiflags[0] = 'd';
2346#endif
2347 if (flags & MA_STACK) asciiflags[1] = 's';
2348 if (flags & MA_BREAK) asciiflags[2] = 'b';
2349 if (flags & MA_SHARED) asciiflags[3] = 's';
2350 if (flags & MA_READ) asciiflags[4] = 'r';
2351 if (flags & MA_WRITE) asciiflags[5] = 'w';
2352 if (flags & MA_EXEC) asciiflags[6] = 'x';
a39ad5ce
FF
2353 return (asciiflags);
2354}
2355
2356static void
cc221e76
FF
2357info_proc_flags (pip, summary)
2358 struct procinfo *pip;
2359 int summary;
2360{
2361 struct trans *transp;
2362
2363 printf_filtered ("%-32s", "Process status flags:");
2364 if (!summary)
2365 {
2366 printf_filtered ("\n\n");
2367 }
2368 for (transp = pr_flag_table; transp -> name != NULL; transp++)
2369 {
2370 if (pip -> prstatus.pr_flags & transp -> value)
2371 {
2372 if (summary)
2373 {
2374 printf_filtered ("%s ", transp -> name);
2375 }
2376 else
2377 {
2378 printf_filtered ("\t%-16s %s.\n", transp -> name, transp -> desc);
2379 }
2380 }
2381 }
2382 printf_filtered ("\n");
2383}
2384
2385static void
2386info_proc_stop (pip, summary)
2387 struct procinfo *pip;
2388 int summary;
2389{
2390 struct trans *transp;
2391 int why;
2392 int what;
2393
2394 why = pip -> prstatus.pr_why;
2395 what = pip -> prstatus.pr_what;
2396
2397 if (pip -> prstatus.pr_flags & PR_STOPPED)
2398 {
2399 printf_filtered ("%-32s", "Reason for stopping:");
2400 if (!summary)
2401 {
2402 printf_filtered ("\n\n");
2403 }
2404 for (transp = pr_why_table; transp -> name != NULL; transp++)
2405 {
2406 if (why == transp -> value)
2407 {
2408 if (summary)
2409 {
2410 printf_filtered ("%s ", transp -> name);
2411 }
2412 else
2413 {
2414 printf_filtered ("\t%-16s %s.\n",
2415 transp -> name, transp -> desc);
2416 }
2417 break;
2418 }
2419 }
2420
2421 /* Use the pr_why field to determine what the pr_what field means, and
2422 print more information. */
2423
2424 switch (why)
2425 {
2426 case PR_REQUESTED:
2427 /* pr_what is unused for this case */
2428 break;
2429 case PR_JOBCONTROL:
2430 case PR_SIGNALLED:
2431 if (summary)
2432 {
2433 printf_filtered ("%s ", signalname (what));
2434 }
2435 else
2436 {
2437 printf_filtered ("\t%-16s %s.\n", signalname (what),
4ace50a5 2438 safe_strsignal (what));
cc221e76
FF
2439 }
2440 break;
2441 case PR_SYSENTRY:
2442 if (summary)
2443 {
2444 printf_filtered ("%s ", syscallname (what));
2445 }
2446 else
2447 {
2448 printf_filtered ("\t%-16s %s.\n", syscallname (what),
2449 "Entered this system call");
2450 }
2451 break;
2452 case PR_SYSEXIT:
2453 if (summary)
2454 {
2455 printf_filtered ("%s ", syscallname (what));
2456 }
2457 else
2458 {
2459 printf_filtered ("\t%-16s %s.\n", syscallname (what),
2460 "Returned from this system call");
2461 }
2462 break;
2463 case PR_FAULTED:
2464 if (summary)
2465 {
2466 printf_filtered ("%s ",
2467 lookupname (faults_table, what, "fault"));
2468 }
2469 else
2470 {
2471 printf_filtered ("\t%-16s %s.\n",
2472 lookupname (faults_table, what, "fault"),
2473 lookupdesc (faults_table, what));
2474 }
2475 break;
2476 }
2477 printf_filtered ("\n");
2478 }
2479}
2480
2481static void
2482info_proc_siginfo (pip, summary)
2483 struct procinfo *pip;
2484 int summary;
2485{
2486 struct siginfo *sip;
2487
2488 if ((pip -> prstatus.pr_flags & PR_STOPPED) &&
2489 (pip -> prstatus.pr_why == PR_SIGNALLED ||
2490 pip -> prstatus.pr_why == PR_FAULTED))
2491 {
2492 printf_filtered ("%-32s", "Additional signal/fault info:");
2493 sip = &pip -> prstatus.pr_info;
2494 if (summary)
2495 {
2496 printf_filtered ("%s ", signalname (sip -> si_signo));
2497 if (sip -> si_errno > 0)
2498 {
4ace50a5 2499 printf_filtered ("%s ", errnoname (sip -> si_errno));
cc221e76
FF
2500 }
2501 if (sip -> si_code <= 0)
2502 {
2503 printf_filtered ("sent by pid %d, uid %d ", sip -> si_pid,
2504 sip -> si_uid);
2505 }
2506 else
2507 {
2508 printf_filtered ("%s ", sigcodename (sip));
2509 if ((sip -> si_signo == SIGILL) ||
2510 (sip -> si_signo == SIGFPE) ||
2511 (sip -> si_signo == SIGSEGV) ||
2512 (sip -> si_signo == SIGBUS))
2513 {
2514 printf_filtered ("addr=%#x ", sip -> si_addr);
2515 }
2516 else if ((sip -> si_signo == SIGCHLD))
2517 {
2518 printf_filtered ("child pid %u, status %u ",
2519 sip -> si_pid,
2520 sip -> si_status);
2521 }
2522 else if ((sip -> si_signo == SIGPOLL))
2523 {
2524 printf_filtered ("band %u ", sip -> si_band);
2525 }
2526 }
2527 }
2528 else
2529 {
2530 printf_filtered ("\n\n");
2531 printf_filtered ("\t%-16s %s.\n", signalname (sip -> si_signo),
4ace50a5 2532 safe_strsignal (sip -> si_signo));
cc221e76
FF
2533 if (sip -> si_errno > 0)
2534 {
2535 printf_filtered ("\t%-16s %s.\n",
4ace50a5
FF
2536 errnoname (sip -> si_errno),
2537 safe_strerror (sip -> si_errno));
cc221e76
FF
2538 }
2539 if (sip -> si_code <= 0)
2540 {
2541 printf_filtered ("\t%-16u %s\n", sip -> si_pid,
2542 "PID of process sending signal");
2543 printf_filtered ("\t%-16u %s\n", sip -> si_uid,
2544 "UID of process sending signal");
2545 }
2546 else
2547 {
2548 printf_filtered ("\t%-16s %s.\n", sigcodename (sip),
2549 sigcodedesc (sip));
2550 if ((sip -> si_signo == SIGILL) ||
2551 (sip -> si_signo == SIGFPE))
2552 {
2553 printf_filtered ("\t%-16#x %s.\n", sip -> si_addr,
2554 "Address of faulting instruction");
2555 }
2556 else if ((sip -> si_signo == SIGSEGV) ||
2557 (sip -> si_signo == SIGBUS))
2558 {
2559 printf_filtered ("\t%-16#x %s.\n", sip -> si_addr,
2560 "Address of faulting memory reference");
2561 }
2562 else if ((sip -> si_signo == SIGCHLD))
2563 {
2564 printf_filtered ("\t%-16u %s.\n", sip -> si_pid,
2565 "Child process ID");
2566 printf_filtered ("\t%-16u %s.\n", sip -> si_status,
2567 "Child process exit value or signal");
2568 }
2569 else if ((sip -> si_signo == SIGPOLL))
2570 {
2571 printf_filtered ("\t%-16u %s.\n", sip -> si_band,
2572 "Band event for POLL_{IN,OUT,MSG}");
2573 }
2574 }
2575 }
2576 printf_filtered ("\n");
2577 }
2578}
2579
2580static void
2581info_proc_syscalls (pip, summary)
2582 struct procinfo *pip;
2583 int summary;
2584{
2585 int syscallnum;
2586
2587 if (!summary)
2588 {
2589
2590#if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */
2591 if (pip -> prstatus.pr_flags & PR_ASLEEP)
2592 {
2593 int syscallnum = pip -> prstatus.pr_reg[R_D0];
2594 if (summary)
2595 {
2596 printf_filtered ("%-32s", "Sleeping in system call:");
2597 printf_filtered ("%s", syscallname (syscallnum));
2598 }
2599 else
2600 {
2601 printf_filtered ("Sleeping in system call '%s'.\n",
2602 syscallname (syscallnum));
2603 }
2604 }
2605#endif
2606
2607 if (ioctl (pip -> fd, PIOCGENTRY, &pip -> entryset) < 0)
2608 {
2609 print_sys_errmsg (pip -> pathname, errno);
2610 error ("PIOCGENTRY failed");
2611 }
2612
2613 if (ioctl (pip -> fd, PIOCGEXIT, &pip -> exitset) < 0)
2614 {
2615 print_sys_errmsg (pip -> pathname, errno);
2616 error ("PIOCGEXIT failed");
2617 }
2618
2619 printf_filtered ("System call tracing information:\n\n");
2620
2621 printf_filtered ("\t%-12s %-8s %-8s\n",
2622 "System call",
2623 "Entry",
2624 "Exit");
2625 for (syscallnum = 0; syscallnum < MAX_SYSCALLS; syscallnum++)
2626 {
2627 QUIT;
2628 if (syscall_table[syscallnum] != NULL)
2629 {
2630 printf_filtered ("\t%-12s ", syscall_table[syscallnum]);
2631 printf_filtered ("%-8s ",
2632 prismember (&pip -> entryset, syscallnum)
2633 ? "on" : "off");
2634 printf_filtered ("%-8s ",
2635 prismember (&pip -> exitset, syscallnum)
2636 ? "on" : "off");
2637 printf_filtered ("\n");
2638 }
2639 }
2640 printf_filtered ("\n");
2641 }
2642}
2643
2644static char *
2645signalname (signo)
2646 int signo;
2647{
4ace50a5
FF
2648 char *name;
2649 static char locbuf[32];
2650
2651 name = strsigno (signo);
2652 if (name == NULL)
2653 {
2654 sprintf (locbuf, "Signal %d", signo);
2655 }
2656 else
2657 {
2658 sprintf (locbuf, "%s (%d)", name, signo);
2659 }
2660 return (locbuf);
2661}
2662
2663static char *
2664errnoname (errnum)
2665 int errnum;
2666{
2667 char *name;
cc221e76
FF
2668 static char locbuf[32];
2669
4ace50a5
FF
2670 name = strerrno (errnum);
2671 if (name == NULL)
cc221e76 2672 {
4ace50a5 2673 sprintf (locbuf, "Errno %d", errnum);
cc221e76
FF
2674 }
2675 else
2676 {
4ace50a5 2677 sprintf (locbuf, "%s (%d)", name, errnum);
cc221e76
FF
2678 }
2679 return (locbuf);
2680}
2681
2682static void
2683info_proc_signals (pip, summary)
2684 struct procinfo *pip;
2685 int summary;
2686{
2687 int signo;
2688
2689 if (!summary)
2690 {
2691 if (ioctl (pip -> fd, PIOCGTRACE, &pip -> trace) < 0)
2692 {
2693 print_sys_errmsg (pip -> pathname, errno);
2694 error ("PIOCGTRACE failed");
2695 }
2696
2697 printf_filtered ("Disposition of signals:\n\n");
2698 printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n",
2699 "Signal", "Trace", "Hold", "Pending", "Description");
2700 for (signo = 0; signo < NSIG; signo++)
2701 {
2702 QUIT;
2703 printf_filtered ("\t%-15s ", signalname (signo));
2704 printf_filtered ("%-8s ",
2705 prismember (&pip -> trace, signo)
2706 ? "on" : "off");
2707 printf_filtered ("%-8s ",
2708 prismember (&pip -> prstatus.pr_sighold, signo)
2709 ? "on" : "off");
2710 printf_filtered ("%-8s ",
2711 prismember (&pip -> prstatus.pr_sigpend, signo)
2712 ? "yes" : "no");
4ace50a5 2713 printf_filtered (" %s\n", safe_strsignal (signo));
cc221e76
FF
2714 }
2715 printf_filtered ("\n");
2716 }
2717}
2718
2719static void
2720info_proc_faults (pip, summary)
2721 struct procinfo *pip;
2722 int summary;
2723{
2724 struct trans *transp;
2725
2726 if (!summary)
2727 {
2728 if (ioctl (pip -> fd, PIOCGFAULT, &pip -> fltset) < 0)
2729 {
2730 print_sys_errmsg (pip -> pathname, errno);
2731 error ("PIOCGFAULT failed");
2732 }
2733
2734 printf_filtered ("Current traced hardware fault set:\n\n");
2735 printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace");
2736
2737 for (transp = faults_table; transp -> name != NULL; transp++)
2738 {
2739 QUIT;
2740 printf_filtered ("\t%-12s ", transp -> name);
2741 printf_filtered ("%-8s", prismember (&pip -> fltset, transp -> value)
2742 ? "on" : "off");
2743 printf_filtered ("\n");
2744 }
2745 printf_filtered ("\n");
2746 }
2747}
2748
2749static void
2750info_proc_mappings (pip, summary)
1ab3bf1b 2751 struct procinfo *pip;
cc221e76 2752 int summary;
a39ad5ce
FF
2753{
2754 int nmap;
2755 struct prmap *prmaps;
2756 struct prmap *prmap;
2757
cc221e76 2758 if (!summary)
a39ad5ce 2759 {
cc221e76 2760 printf_filtered ("Mapped address spaces:\n\n");
5c1c5e67 2761 printf_filtered ("\t%10s %10s %10s %10s %7s\n",
cc221e76
FF
2762 "Start Addr",
2763 " End Addr",
2764 " Size",
2765 " Offset",
2766 "Flags");
2767 if (ioctl (pip -> fd, PIOCNMAP, &nmap) == 0)
a39ad5ce 2768 {
cc221e76
FF
2769 prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps));
2770 if (ioctl (pip -> fd, PIOCMAP, prmaps) == 0)
a39ad5ce 2771 {
cc221e76
FF
2772 for (prmap = prmaps; prmap -> pr_size; ++prmap)
2773 {
5c1c5e67 2774 printf_filtered ("\t%#10x %#10x %#10x %#10x %7s\n",
cc221e76
FF
2775 prmap -> pr_vaddr,
2776 prmap -> pr_vaddr + prmap -> pr_size - 1,
2777 prmap -> pr_size,
2778 prmap -> pr_off,
2779 mappingflags (prmap -> pr_mflags));
2780 }
a39ad5ce
FF
2781 }
2782 }
cc221e76 2783 printf_filtered ("\n");
a39ad5ce 2784 }
a39ad5ce
FF
2785}
2786
2787/*
2788
2789LOCAL FUNCTION
2790
cc221e76 2791 info_proc -- implement the "info proc" command
a39ad5ce
FF
2792
2793SYNOPSIS
2794
cc221e76 2795 void info_proc (char *args, int from_tty)
a39ad5ce
FF
2796
2797DESCRIPTION
2798
2799 Implement gdb's "info proc" command by using the /proc interface
2800 to print status information about any currently running process.
2801
2802 Examples of the use of "info proc" are:
2803
cc221e76
FF
2804 info proc (prints summary info for current inferior)
2805 info proc 123 (prints summary info for process with pid 123)
2806 info proc mappings (prints address mappings)
2807 info proc times (prints process/children times)
2808 info proc id (prints pid, ppid, gid, sid, etc)
2809 info proc status (prints general process state info)
2810 info proc signals (prints info about signal handling)
2811 info proc all (prints all info)
a39ad5ce
FF
2812
2813 */
2814
2815static void
cc221e76 2816info_proc (args, from_tty)
1ab3bf1b
JG
2817 char *args;
2818 int from_tty;
a39ad5ce 2819{
a39ad5ce
FF
2820 int pid;
2821 struct procinfo pii;
2822 struct procinfo *pip;
2823 struct cleanup *old_chain;
cc221e76
FF
2824 char **argv;
2825 int argsize;
2826 int summary = 1;
2827 int flags = 0;
2828 int syscalls = 0;
2829 int signals = 0;
2830 int faults = 0;
2831 int mappings = 0;
2832 int times = 0;
2833 int id = 0;
2834 int status = 0;
2835 int all = 0;
a39ad5ce
FF
2836
2837 old_chain = make_cleanup (null_cleanup, 0);
2838
2839 /* Default to using the current inferior if no pid specified */
2840
2841 pip = &pi;
2842
a39ad5ce 2843 if (args != NULL)
35f5886e 2844 {
cc221e76 2845 if ((argv = buildargv (args)) == NULL)
a39ad5ce 2846 {
cc221e76
FF
2847 nomem (0);
2848 }
2849 make_cleanup (freeargv, (char *) argv);
2850
2851 while (*argv != NULL)
2852 {
2853 argsize = strlen (*argv);
2854 if (argsize >= 1 && strncmp (*argv, "all", argsize) == 0)
2855 {
2856 summary = 0;
2857 all = 1;
2858 }
2859 else if (argsize >= 2 && strncmp (*argv, "faults", argsize) == 0)
2860 {
2861 summary = 0;
2862 faults = 1;
2863 }
2864 else if (argsize >= 2 && strncmp (*argv, "flags", argsize) == 0)
2865 {
2866 summary = 0;
2867 flags = 1;
2868 }
2869 else if (argsize >= 1 && strncmp (*argv, "id", argsize) == 0)
2870 {
2871 summary = 0;
2872 id = 1;
2873 }
2874 else if (argsize >= 1 && strncmp (*argv, "mappings", argsize) == 0)
2875 {
2876 summary = 0;
2877 mappings = 1;
2878 }
2879 else if (argsize >= 2 && strncmp (*argv, "signals", argsize) == 0)
2880 {
2881 summary = 0;
2882 signals = 1;
2883 }
2884 else if (argsize >= 2 && strncmp (*argv, "status", argsize) == 0)
2885 {
2886 summary = 0;
2887 status = 1;
2888 }
2889 else if (argsize >= 2 && strncmp (*argv, "syscalls", argsize) == 0)
2890 {
2891 summary = 0;
2892 syscalls = 1;
2893 }
2894 else if (argsize >= 1 && strncmp (*argv, "times", argsize) == 0)
a39ad5ce 2895 {
cc221e76
FF
2896 summary = 0;
2897 times = 1;
a39ad5ce 2898 }
cc221e76 2899 else if ((pii.pid = atoi (*argv)) > 0)
a39ad5ce
FF
2900 {
2901 pid = pii.pid;
2902 pip = &pii;
4ed3a9ea 2903 memset (&pii, 0, sizeof (pii));
ec8ceca3 2904 if (!open_proc_file (pid, pip, O_RDONLY))
a39ad5ce
FF
2905 {
2906 perror_with_name (pip -> pathname);
2907 /* NOTREACHED */
2908 }
2909 make_cleanup (close_proc_file, pip);
2910 }
cc221e76
FF
2911 else if (**argv != '\000')
2912 {
2913 error ("Unrecognized or ambiguous keyword `%s'.", *argv);
2914 }
2915 argv++;
a39ad5ce 2916 }
35f5886e 2917 }
a39ad5ce
FF
2918
2919 /* If we don't have a valid open process at this point, then we have no
2920 inferior or didn't specify a specific pid. */
2921
2922 if (!pip -> valid)
35f5886e 2923 {
a39ad5ce 2924 error ("No process. Run an inferior or specify an explicit pid.");
35f5886e 2925 }
a39ad5ce 2926 if (ioctl (pip -> fd, PIOCSTATUS, &(pip -> prstatus)) < 0)
35f5886e 2927 {
a39ad5ce
FF
2928 print_sys_errmsg (pip -> pathname, errno);
2929 error ("PIOCSTATUS failed");
35f5886e 2930 }
a39ad5ce 2931
cc221e76
FF
2932 /* Print verbose information of the requested type(s), or just a summary
2933 of the information for all types. */
2934
2935 printf_filtered ("\nInformation for %s:\n\n", pip -> pathname);
2936 if (summary || all || flags)
2937 {
2938 info_proc_flags (pip, summary);
2939 }
2940 if (summary || all)
2941 {
2942 info_proc_stop (pip, summary);
2943 }
2944 if (summary || all || signals || faults)
2945 {
2946 info_proc_siginfo (pip, summary);
2947 }
2948 if (summary || all || syscalls)
2949 {
2950 info_proc_syscalls (pip, summary);
2951 }
2952 if (summary || all || mappings)
2953 {
2954 info_proc_mappings (pip, summary);
2955 }
2956 if (summary || all || signals)
2957 {
2958 info_proc_signals (pip, summary);
2959 }
2960 if (summary || all || faults)
2961 {
2962 info_proc_faults (pip, summary);
2963 }
2964 printf_filtered ("\n");
a39ad5ce
FF
2965
2966 /* All done, deal with closing any temporary process info structure,
2967 freeing temporary memory , etc. */
2968
2969 do_cleanups (old_chain);
2970}
2971
2972/*
2973
2974GLOBAL FUNCTION
2975
2976 _initialize_proc_fs -- initialize the process file system stuff
2977
2978SYNOPSIS
2979
2980 void _initialize_proc_fs (void)
2981
2982DESCRIPTION
2983
2984 Do required initializations during gdb startup for using the
2985 /proc file system interface.
2986
2987*/
2988
2989static char *proc_desc =
cc221e76
FF
2990"Show process status information using /proc entry.\n\
2991Specify process id or use current inferior by default.\n\
2992Specify keywords for detailed information; default is summary.\n\
2993Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\
2994`status', `syscalls', and `times'.\n\
2995Unambiguous abbreviations may be used.";
a39ad5ce
FF
2996
2997void
2998_initialize_proc_fs ()
2999{
cc221e76
FF
3000 add_info ("proc", info_proc, proc_desc);
3001 init_syscall_table ();
35f5886e
FF
3002}
3003
3004#endif /* USE_PROC_FS */
This page took 0.32616 seconds and 4 git commands to generate.