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