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