1 /* Machine independent support for SVR4 /proc (process file system) for GDB.
2 Copyright (C) 1991 Free Software Foundation, Inc.
3 Written by Fred Fish at Cygnus Support.
5 This file is part of GDB.
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.
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.
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. */
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.
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.
37 #ifdef USE_PROC_FS /* Entire file goes away if not using /proc */
40 #include <sys/procfs.h>
48 #define PROC_NAME_FMT "/proc/%d"
51 #if 1 /* FIXME: Gross and ugly hack to resolve coredep.c global */
52 CORE_ADDR kernel_u_addr
;
55 /* All access to the inferior, either one started by gdb or one that has
56 been attached to, is controlled by an instance of a procinfo structure,
57 defined below. Since gdb currently only handles one inferior at a time,
58 the procinfo structure for the inferior is statically allocated and
59 only one exists at any given time. There is a separate procinfo
60 structure for use by the "info proc" command, so that we can print
61 useful information about any random process without interfering with
62 the inferior's procinfo information. */
65 int valid
; /* Nonzero if pid, fd, & pathname are valid */
66 int pid
; /* Process ID of inferior */
67 int fd
; /* File descriptor for /proc entry */
68 char *pathname
; /* Pathname to /proc entry */
69 int was_stopped
; /* Nonzero if was stopped prior to attach */
70 prrun_t prrun
; /* Control state when it is run */
71 prstatus_t prstatus
; /* Current process status info */
72 gregset_t gregset
; /* General register set */
73 fpregset_t fpregset
; /* Floating point register set */
74 fltset_t fltset
; /* Current traced hardware fault set */
75 sigset_t trace
; /* Current traced signal set */
76 sysset_t exitset
; /* Current traced system call exit set */
77 sysset_t entryset
; /* Current traced system call entry set */
80 static struct procinfo pi
; /* Inferior's process information */
82 /* Prototypes for local functions */
85 set_proc_siginfo
PARAMS ((struct procinfo
*, int));
88 proc_address_to_fd
PARAMS ((CORE_ADDR
, int));
91 open_proc_file
PARAMS ((int, struct procinfo
*));
94 close_proc_file
PARAMS ((struct procinfo
*));
97 unconditionally_kill_inferior
PARAMS ((void));
100 proc_init_failed
PARAMS ((char *));
103 proc_info
PARAMS ((char *, int));
106 proc_info_address_map
PARAMS ((struct procinfo
*, int));
109 mappingflags
PARAMS ((long));
111 /* External function prototypes that can't be easily included in any
112 header file because the args are typedefs in system include files. */
115 supply_gregset
PARAMS ((gregset_t
*));
118 fill_gregset
PARAMS ((gregset_t
*, int));
121 supply_fpregset
PARAMS ((fpregset_t
*));
124 fill_fpregset
PARAMS ((fpregset_t
*, int));
131 ptrace -- override library version to force errors for /proc version
135 int ptrace (int request, int pid, int arg3, int arg4)
139 When gdb is configured to use /proc, it should not be calling
140 or otherwise attempting to use ptrace. In order to catch errors
141 where use of /proc is configured, but some routine is still calling
142 ptrace, we provide a local version of a function with that name
143 that does nothing but issue an error message.
147 ptrace (request
, pid
, arg3
, arg4
)
153 error ("internal error - there is a call to ptrace() somewhere");
161 kill_inferior_fast -- kill inferior while gdb is exiting
165 void kill_inferior_fast (void)
169 This is used when GDB is exiting. It gives less chance of error.
173 Don't attempt to kill attached inferiors since we may be called
174 when gdb is in the process of aborting, and killing the attached
175 inferior may be very anti-social. This is particularly true if we
176 were attached just so we could use the /proc facilities to get
177 detailed information about it's status.
182 kill_inferior_fast ()
184 if (inferior_pid
!= 0 && !attach_flag
)
186 unconditionally_kill_inferior ();
194 kill_inferior - kill any currently inferior
198 void kill_inferior (void)
202 Kill any current inferior.
206 Kills even attached inferiors. Presumably the user has already
207 been prompted that the inferior is an attached one rather than
208 one started by gdb. (FIXME?)
215 if (inferior_pid
!= 0)
217 unconditionally_kill_inferior ();
218 target_mourn_inferior ();
226 unconditionally_kill_inferior - terminate the inferior
230 static void unconditionally_kill_inferior (void)
234 Kill the current inferior. Should not be called until it
235 is at least tested that there is an inferior.
239 A possibly useful enhancement would be to first try sending
240 the inferior a terminate signal, politely asking it to commit
241 suicide, before we murder it.
246 unconditionally_kill_inferior ()
251 (void) ioctl (pi
.fd
, PIOCKILL
, &signo
);
252 close_proc_file (&pi
);
260 child_xfer_memory -- copy data to or from inferior memory space
264 int child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
265 int dowrite, struct target_ops target)
269 Copy LEN bytes to/from inferior's memory starting at MEMADDR
270 from/to debugger memory starting at MYADDR. Copy from inferior
271 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
273 Returns the length copied, which is either the LEN argument or
274 zero. This xfer function does not do partial moves, since child_ops
275 doesn't allow memory operations to cross below us in the target stack
280 The /proc interface makes this an almost trivial task.
285 child_xfer_memory (memaddr
, myaddr
, len
, dowrite
, target
)
290 struct target_ops
*target
; /* ignored */
294 if (lseek (pi
.fd
, (off_t
) memaddr
, 0) == (off_t
) memaddr
)
298 nbytes
= write (pi
.fd
, myaddr
, len
);
302 nbytes
= read (pi
.fd
, myaddr
, len
);
316 store_inferior_registers -- copy register values back to inferior
320 void store_inferior_registers (int regno)
324 Store our current register values back into the inferior. If
325 REGNO is -1 then store all the register, otherwise store just
326 the value specified by REGNO.
330 If we are storing only a single register, we first have to get all
331 the current values from the process, overwrite the desired register
332 in the gregset with the one we want from gdb's registers, and then
333 send the whole set back to the process. For writing all the
334 registers, all we have to do is generate the gregset and send it to
337 Also note that the process has to be stopped on an event of interest
338 for this to work, which basically means that it has to have been
339 run under the control of one of the other /proc ioctl calls and not
340 ptrace. Since we don't use ptrace anyway, we don't worry about this
341 fine point, but it is worth noting for future reference.
343 Gdb is confused about what this function is supposed to return.
344 Some versions return a value, others return nothing. Some are
345 declared to return a value and actually return nothing. Gdb ignores
346 anything returned. (FIXME)
351 store_inferior_registers (regno
)
356 (void) ioctl (pi
.fd
, PIOCGREG
, &pi
.gregset
);
358 fill_gregset (&pi
.gregset
, regno
);
359 (void) ioctl (pi
.fd
, PIOCSREG
, &pi
.gregset
);
361 #if defined (FP0_REGNUM)
363 /* Now repeat everything using the floating point register set, if the
364 target has floating point hardware. Since we ignore the returned value,
365 we'll never know whether it worked or not anyway. */
369 (void) ioctl (pi
.fd
, PIOCGFPREG
, &pi
.fpregset
);
371 fill_fpregset (&pi
.fpregset
, regno
);
372 (void) ioctl (pi
.fd
, PIOCSFPREG
, &pi
.fpregset
);
374 #endif /* FP0_REGNUM */
382 inferior_proc_init - initialize access to a /proc entry
386 void inferior_proc_init (int pid)
390 When gdb starts an inferior, this function is called in the parent
391 process immediately after the fork. It waits for the child to stop
392 on the return from the exec system call (the child itself takes care
393 of ensuring that this is set up), then sets up the set of signals
394 and faults that are to be traced.
398 If proc_init_failed ever gets called, control returns to the command
399 processing loop via the standard error handling code.
403 inferior_proc_init (pid
)
406 if (!open_proc_file (pid
, &pi
))
408 proc_init_failed ("can't open process file");
412 (void) memset (&pi
.prrun
, 0, sizeof (pi
.prrun
));
413 prfillset (&pi
.prrun
.pr_trace
);
414 prfillset (&pi
.prrun
.pr_fault
);
415 prdelset (&pi
.prrun
.pr_fault
, FLTPAGE
);
416 if (ioctl (pi
.fd
, PIOCWSTOP
, &pi
.prstatus
) < 0)
418 proc_init_failed ("PIOCWSTOP failed");
420 else if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.prrun
.pr_trace
) < 0)
422 proc_init_failed ("PIOCSTRACE failed");
424 else if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.prrun
.pr_fault
) < 0)
426 proc_init_failed ("PIOCSFAULT failed");
435 proc_set_exec_trap -- arrange for exec'd child to halt at startup
439 void proc_set_exec_trap (void)
443 This function is called in the child process when starting up
444 an inferior, prior to doing the exec of the actual inferior.
445 It sets the child process's exitset to make exit from the exec
446 system call an event of interest to stop on, and then simply
447 returns. The child does the exec, the system call returns, and
448 the child stops at the first instruction, ready for the gdb
449 parent process to take control of it.
453 We need to use all local variables since the child may be sharing
454 it's data space with the parent, if vfork was used rather than
459 proc_set_exec_trap ()
462 auto char procname
[32];
465 (void) sprintf (procname
, PROC_NAME_FMT
, getpid ());
466 if ((fd
= open (procname
, O_RDWR
)) < 0)
472 premptyset (&exitset
);
476 * Not all systems with /proc have all the exec* syscalls with the same
477 * names. On the SGI, for example, there is no SYS_exec, but there
478 * *is* a SYS_execv. So, we try to account for that.
481 praddset (&exitset
, SYS_exec
);
484 praddset (&exitset
, SYS_execve
);
487 praddset(&exitset
, SYS_execv
);
490 if (ioctl (fd
, PIOCSEXIT
, &exitset
) < 0)
502 proc_iterate_over_mappings -- call function for every mapped space
506 int proc_iterate_over_mappings (int (*func)())
510 Given a pointer to a function, call that function for every
511 mapped address space, passing it an open file descriptor for
512 the file corresponding to that mapped address space (if any)
513 and the base address of the mapped space. Quit when we hit
514 the end of the mappings or the function returns nonzero.
518 proc_iterate_over_mappings (func
)
519 int (*func
) PARAMS ((int, CORE_ADDR
));
524 struct prmap
*prmaps
;
526 CORE_ADDR baseaddr
= 0;
528 if (pi
.valid
&& (ioctl (pi
.fd
, PIOCNMAP
, &nmap
) == 0))
530 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
531 if (ioctl (pi
.fd
, PIOCMAP
, prmaps
) == 0)
533 for (prmap
= prmaps
; prmap
-> pr_size
&& funcstat
== 0; ++prmap
)
535 fd
= proc_address_to_fd ((CORE_ADDR
) prmap
-> pr_vaddr
, 0);
536 funcstat
= (*func
) (fd
, (CORE_ADDR
) prmap
-> pr_vaddr
);
548 proc_base_address -- find base address for segment containing address
552 CORE_ADDR proc_base_address (CORE_ADDR addr)
556 Given an address of a location in the inferior, find and return
557 the base address of the mapped segment containing that address.
559 This is used for example, by the shared library support code,
560 where we have the pc value for some location in the shared library
561 where we are stopped, and need to know the base address of the
562 segment containing that address.
566 #if 0 /* Currently unused */
569 proc_base_address (addr
)
573 struct prmap
*prmaps
;
575 CORE_ADDR baseaddr
= 0;
577 if (pi
.valid
&& (ioctl (pi
.fd
, PIOCNMAP
, &nmap
) == 0))
579 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
580 if (ioctl (pi
.fd
, PIOCMAP
, prmaps
) == 0)
582 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
584 if ((prmap
-> pr_vaddr
<= (caddr_t
) addr
) &&
585 (prmap
-> pr_vaddr
+ prmap
-> pr_size
> (caddr_t
) addr
))
587 baseaddr
= (CORE_ADDR
) prmap
-> pr_vaddr
;
602 proc_address_to_fd -- return open fd for file mapped to address
606 int proc_address_to_fd (CORE_ADDR addr, complain)
610 Given an address in the current inferior's address space, use the
611 /proc interface to find an open file descriptor for the file that
612 this address was mapped in from. Return -1 if there is no current
613 inferior. Print a warning message if there is an inferior but
614 the address corresponds to no file (IE a bogus address).
619 proc_address_to_fd (addr
, complain
)
627 if ((fd
= ioctl (pi
.fd
, PIOCOPENM
, (caddr_t
*) &addr
)) < 0)
631 print_sys_errmsg (pi
.pathname
, errno
);
632 warning ("can't find mapped file for address 0x%x", addr
);
646 attach -- attach to an already existing process
654 Attach to an already existing process with the specified process
655 id. If the process is not already stopped, query whether to
660 The option of stopping at attach time is specific to the /proc
661 versions of gdb. Versions using ptrace force the attachee
670 if (!open_proc_file (pid
, &pi
))
672 perror_with_name (pi
.pathname
);
676 /* Get current status of process and if it is not already stopped,
677 then stop it. Remember whether or not it was stopped when we first
680 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
682 print_sys_errmsg (pi
.pathname
, errno
);
683 close_proc_file (&pi
);
684 error ("PIOCSTATUS failed");
686 if (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
693 if (query ("Process is currently running, stop it? "))
695 if (ioctl (pi
.fd
, PIOCSTOP
, &pi
.prstatus
) < 0)
697 print_sys_errmsg (pi
.pathname
, errno
);
698 close_proc_file (&pi
);
699 error ("PIOCSTOP failed");
704 /* Remember some things about the inferior that we will, or might, change
705 so that we can restore them when we detach. */
707 (void) ioctl (pi
.fd
, PIOCGTRACE
, &pi
.trace
);
708 (void) ioctl (pi
.fd
, PIOCGFAULT
, &pi
.fltset
);
709 (void) ioctl (pi
.fd
, PIOCGENTRY
, &pi
.entryset
);
710 (void) ioctl (pi
.fd
, PIOCGEXIT
, &pi
.exitset
);
712 /* Set up trace and fault sets, as gdb expects them. */
714 (void) memset (&pi
.prrun
, 0, sizeof (pi
.prrun
));
715 prfillset (&pi
.prrun
.pr_trace
);
716 prfillset (&pi
.prrun
.pr_fault
);
717 prdelset (&pi
.prrun
.pr_fault
, FLTPAGE
);
718 if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.prrun
.pr_fault
))
720 print_sys_errmsg ("PIOCSFAULT failed", errno
);
722 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.prrun
.pr_trace
))
724 print_sys_errmsg ("PIOCSTRACE failed", errno
);
734 detach -- detach from an attached-to process
738 void detach (int signal)
742 Detach from the current attachee.
744 If signal is non-zero, the attachee is started running again and sent
745 the specified signal.
747 If signal is zero and the attachee was not already stopped when we
748 attached to it, then we make it runnable again when we detach.
750 Otherwise, we query whether or not to make the attachee runnable
751 again, since we may simply want to leave it in the state it was in
754 We report any problems, but do not consider them errors, since we
755 MUST detach even if some things don't seem to go right. This may not
756 be the ideal situation. (FIXME).
765 set_proc_siginfo (&pi
, signal
);
767 if (ioctl (pi
.fd
, PIOCSEXIT
, &pi
.exitset
) < 0)
769 print_sys_errmsg (pi
.pathname
, errno
);
770 printf ("PIOCSEXIT failed.\n");
772 if (ioctl (pi
.fd
, PIOCSENTRY
, &pi
.entryset
) < 0)
774 print_sys_errmsg (pi
.pathname
, errno
);
775 printf ("PIOCSENTRY failed.\n");
777 if (ioctl (pi
.fd
, PIOCSTRACE
, &pi
.trace
) < 0)
779 print_sys_errmsg (pi
.pathname
, errno
);
780 printf ("PIOCSTRACE failed.\n");
782 if (ioctl (pi
.fd
, PIOCSFAULT
, &pi
.fltset
) < 0)
784 print_sys_errmsg (pi
.pathname
, errno
);
785 printf ("PIOCSFAULT failed.\n");
787 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
789 print_sys_errmsg (pi
.pathname
, errno
);
790 printf ("PIOCSTATUS failed.\n");
794 if (signal
|| (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
796 if (signal
|| !pi
.was_stopped
||
797 query ("Was stopped when attached, make it runnable again? "))
799 (void) memset (&pi
.prrun
, 0, sizeof (pi
.prrun
));
800 pi
.prrun
.pr_flags
= PRCFAULT
;
801 if (ioctl (pi
.fd
, PIOCRUN
, &pi
.prrun
))
803 print_sys_errmsg (pi
.pathname
, errno
);
804 printf ("PIOCRUN failed.\n");
809 close_proc_file (&pi
);
813 #endif /* ATTACH_DETACH */
819 proc_wait -- emulate wait() as much as possible
823 int proc_wait (int *statloc)
827 Try to emulate wait() as much as possible. Not sure why we can't
828 just use wait(), but it seems to have problems when applied to a
829 process being controlled with the /proc interface.
833 We have a race problem here with no obvious solution. We need to let
834 the inferior run until it stops on an event of interest, which means
835 that we need to use the PIOCWSTOP ioctl. However, we cannot use this
836 ioctl if the process is already stopped on something that is not an
837 event of interest, or the call will hang indefinitely. Thus we first
838 use PIOCSTATUS to see if the process is not stopped. If not, then we
839 use PIOCWSTOP. But during the window between the two, if the process
840 stops for any reason that is not an event of interest (such as a job
841 control signal) then gdb will hang. One possible workaround is to set
842 an alarm to wake up every minute of so and check to see if the process
843 is still running, and if so, then reissue the PIOCWSTOP. But this is
844 a real kludge, so has not been implemented. FIXME: investigate
847 FIXME: Investigate why wait() seems to have problems with programs
848 being control by /proc routines.
862 if (ioctl (pi
.fd
, PIOCSTATUS
, &pi
.prstatus
) < 0)
866 else if (!(pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
)))
868 if (ioctl (pi
.fd
, PIOCWSTOP
, &pi
.prstatus
) < 0)
877 rtnval
= wait (&statval
);
878 if (rtnval
!= inferior_pid
)
880 error ("PIOCWSTOP, wait failed, returned %d", rtnval
);
886 print_sys_errmsg (pi
.pathname
, errno
);
887 error ("PIOCSTATUS or PIOCWSTOP failed.");
891 else if (pi
.prstatus
.pr_flags
& (PR_STOPPED
| PR_ISTOP
))
893 rtnval
= pi
.prstatus
.pr_pid
;
894 why
= pi
.prstatus
.pr_why
;
895 what
= pi
.prstatus
.pr_what
;
896 if (why
== PR_SIGNALLED
)
898 statval
= (what
<< 8) | 0177;
900 else if ((why
== PR_SYSEXIT
)
909 || what
== SYS_execve
916 statval
= (SIGTRAP
<< 8) | 0177;
918 else if (why
== PR_REQUESTED
)
920 statval
= (SIGSTOP
<< 8) | 0177;
922 else if (why
== PR_JOBCONTROL
)
924 statval
= (what
<< 8) | 0177;
926 else if (why
== PR_FAULTED
)
932 statval
= (SIGILL
<< 8) | 0177;
936 statval
= (SIGTRAP
<< 8) | 0177;
941 statval
= (SIGSEGV
<< 8) | 0177;
946 statval
= (SIGFPE
<< 8) | 0177;
948 case FLTPAGE
: /* Recoverable page fault */
951 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
958 error ("PIOCWSTOP, unknown why %d, what %d", why
, what
);
964 error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x",
965 pi
.prstatus
.pr_flags
);
979 set_proc_siginfo - set a process's current signal info
983 void set_proc_siginfo (struct procinfo *pip, int signo);
987 Given a pointer to a process info struct in PIP and a signal number
988 in SIGNO, set the process's current signal and its associated signal
989 information. The signal will be delivered to the process immediately
990 after execution is resumed, even if it is being held. In addition,
991 this particular delivery will not cause another PR_SIGNALLED stop
992 even if the signal is being traced.
994 If we are not delivering the same signal that the prstatus siginfo
995 struct contains information about, then synthesize a siginfo struct
996 to match the signal we are doing to deliver, make it of the type
997 "generated by a user process", and send this synthesized copy. When
998 used to set the inferior's signal state, this will be required if we
999 are not currently stopped because of a traced signal, or if we decide
1000 to continue with a different signal.
1002 Note that when continuing the inferior from a stop due to receipt
1003 of a traced signal, we either have set PRCSIG to clear the existing
1004 signal, or we have to call this function to do a PIOCSSIG with either
1005 the existing siginfo struct from pr_info, or one we have synthesized
1006 appropriately for the signal we want to deliver. Otherwise if the
1007 signal is still being traced, the inferior will immediately stop
1010 See siginfo(5) for more details.
1014 set_proc_siginfo (pip
, signo
)
1015 struct procinfo
*pip
;
1018 struct siginfo newsiginfo
;
1019 struct siginfo
*sip
;
1023 if (signo
== pip
-> prstatus
.pr_info
.si_signo
)
1025 sip
= &pip
-> prstatus
.pr_info
;
1029 (void) memset ((char *) &newsiginfo
, 0, sizeof (newsiginfo
));
1031 sip
-> si_signo
= signo
;
1033 sip
-> si_errno
= 0;
1034 sip
-> si_pid
= getpid ();
1035 sip
-> si_uid
= getuid ();
1037 if (ioctl (pip
-> fd
, PIOCSSIG
, sip
) < 0)
1039 print_sys_errmsg (pip
-> pathname
, errno
);
1040 warning ("PIOCSSIG failed");
1049 child_resume -- resume execution of the inferior process
1053 void child_resume (int step, int signal)
1057 Resume execution of the inferior process. If STEP is nozero, then
1058 just single step it. If SIGNAL is nonzero, restart it with that
1063 It may not be absolutely necessary to specify the PC value for
1064 restarting, but to be safe we use the value that gdb considers
1065 to be current. One case where this might be necessary is if the
1066 user explicitly changes the PC value that gdb considers to be
1067 current. FIXME: Investigate if this is necessary or not.
1071 child_resume (step
, signal
)
1076 pi
.prrun
.pr_flags
= PRSVADDR
| PRSTRACE
| PRSFAULT
| PRCFAULT
;
1077 pi
.prrun
.pr_vaddr
= (caddr_t
) *(int *) ®isters
[REGISTER_BYTE (PC_REGNUM
)];
1080 set_proc_siginfo (&pi
, signal
);
1084 pi
.prrun
.pr_flags
|= PRCSIG
;
1088 pi
.prrun
.pr_flags
|= PRSTEP
;
1090 if (ioctl (pi
.fd
, PIOCRUN
, &pi
.prrun
) != 0)
1092 perror_with_name (pi
.pathname
);
1101 fetch_inferior_registers -- fetch current registers from inferior
1105 void fetch_inferior_registers (int regno)
1109 Read the current values of the inferior's registers, both the
1110 general register set and floating point registers (if supported)
1111 and update gdb's idea of their current values.
1116 fetch_inferior_registers (regno
)
1119 if (ioctl (pi
.fd
, PIOCGREG
, &pi
.gregset
) != -1)
1121 supply_gregset (&pi
.gregset
);
1123 #if defined (FP0_REGNUM)
1124 if (ioctl (pi
.fd
, PIOCGFPREG
, &pi
.fpregset
) != -1)
1126 supply_fpregset (&pi
.fpregset
);
1135 fetch_core_registers -- fetch current registers from core file data
1139 void fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
1140 int which, unsigned in reg_addr)
1144 Read the values of either the general register set (WHICH equals 0)
1145 or the floating point register set (WHICH equals 2) from the core
1146 file data (pointed to by CORE_REG_SECT), and update gdb's idea of
1147 their current values. The CORE_REG_SIZE parameter is ignored.
1151 Use the indicated sizes to validate the gregset and fpregset
1156 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
1157 char *core_reg_sect
;
1158 unsigned core_reg_size
;
1160 unsigned int reg_addr
; /* Unused in this version */
1165 if (core_reg_size
!= sizeof (pi
.gregset
))
1167 warning ("wrong size gregset struct in core file");
1171 (void) memcpy ((char *) &pi
.gregset
, core_reg_sect
,
1172 sizeof (pi
.gregset
));
1173 supply_gregset (&pi
.gregset
);
1176 else if (which
== 2)
1178 if (core_reg_size
!= sizeof (pi
.fpregset
))
1180 warning ("wrong size fpregset struct in core file");
1184 (void) memcpy ((char *) &pi
.fpregset
, core_reg_sect
,
1185 sizeof (pi
.fpregset
));
1186 #if defined (FP0_REGNUM)
1187 supply_fpregset (&pi
.fpregset
);
1197 proc_init_failed - called whenever /proc access initialization fails
1201 static void proc_init_failed (char *why)
1205 This function is called whenever initialization of access to a /proc
1206 entry fails. It prints a suitable error message, does some cleanup,
1207 and then invokes the standard error processing routine which dumps
1208 us back into the command loop.
1212 proc_init_failed (why
)
1215 print_sys_errmsg (pi
.pathname
, errno
);
1216 (void) kill (pi
.pid
, SIGKILL
);
1217 close_proc_file (&pi
);
1226 close_proc_file - close any currently open /proc entry
1230 static void close_proc_file (struct procinfo *pip)
1234 Close any currently open /proc entry and mark the process information
1235 entry as invalid. In order to ensure that we don't try to reuse any
1236 stale information, the pid, fd, and pathnames are explicitly
1237 invalidated, which may be overkill.
1242 close_proc_file (pip
)
1243 struct procinfo
*pip
;
1248 (void) close (pip
-> fd
);
1251 if (pip
-> pathname
)
1253 free (pip
-> pathname
);
1254 pip
-> pathname
= NULL
;
1263 open_proc_file - open a /proc entry for a given process id
1267 static int open_proc_file (pid, struct procinfo *pip)
1271 Given a process id, close the existing open /proc entry (if any)
1272 and open one for the new process id. Once it is open, then
1273 mark the local process information structure as valid, which
1274 guarantees that the pid, fd, and pathname fields match an open
1275 /proc entry. Returns zero if the open fails, nonzero otherwise.
1277 Note that the pathname is left intact, even when the open fails,
1278 so that callers can use it to construct meaningful error messages
1279 rather than just "file open failed".
1283 open_proc_file (pid
, pip
)
1285 struct procinfo
*pip
;
1290 (void) close (pip
-> fd
);
1292 if (pip
-> pathname
== NULL
)
1294 pip
-> pathname
= xmalloc (32);
1296 sprintf (pip
-> pathname
, PROC_NAME_FMT
, pid
);
1297 if ((pip
-> fd
= open (pip
-> pathname
, O_RDWR
)) >= 0)
1304 (void) ioctl (pip
-> fd
, PIOCRESET
, &pr_flags
);
1306 return (pip
-> valid
);
1310 mappingflags (flags
)
1313 static char asciiflags
[7];
1315 strcpy (asciiflags
, "------");
1316 if (flags
& MA_STACK
) asciiflags
[0] = 's';
1317 if (flags
& MA_BREAK
) asciiflags
[1] = 'b';
1318 if (flags
& MA_SHARED
) asciiflags
[2] = 's';
1319 if (flags
& MA_READ
) asciiflags
[3] = 'r';
1320 if (flags
& MA_WRITE
) asciiflags
[4] = 'w';
1321 if (flags
& MA_EXEC
) asciiflags
[5] = 'x';
1322 return (asciiflags
);
1326 proc_info_address_map (pip
, verbose
)
1327 struct procinfo
*pip
;
1331 struct prmap
*prmaps
;
1332 struct prmap
*prmap
;
1334 printf_filtered ("Mapped address spaces:\n\n");
1335 printf_filtered ("\t%10s %10s %10s %10s %6s\n",
1341 if (ioctl (pip
-> fd
, PIOCNMAP
, &nmap
) == 0)
1343 prmaps
= (struct prmap
*) alloca ((nmap
+ 1) * sizeof (*prmaps
));
1344 if (ioctl (pip
-> fd
, PIOCMAP
, prmaps
) == 0)
1346 for (prmap
= prmaps
; prmap
-> pr_size
; ++prmap
)
1348 printf_filtered ("\t%#10x %#10x %#10x %#10x %6s\n",
1350 prmap
-> pr_vaddr
+ prmap
-> pr_size
- 1,
1353 mappingflags (prmap
-> pr_mflags
));
1357 printf_filtered ("\n\n");
1364 proc_info -- implement the "info proc" command
1368 void proc_info (char *args, int from_tty)
1372 Implement gdb's "info proc" command by using the /proc interface
1373 to print status information about any currently running process.
1375 Examples of the use of "info proc" are:
1377 info proc Print short info about current inferior.
1378 info proc verbose Print verbose info about current inferior.
1379 info proc 123 Print short info about process pid 123.
1380 info proc 123 verbose Print verbose info about process pid 123.
1385 proc_info (args
, from_tty
)
1391 struct procinfo pii
;
1392 struct procinfo
*pip
;
1393 struct cleanup
*old_chain
;
1396 old_chain
= make_cleanup (null_cleanup
, 0);
1398 /* Default to using the current inferior if no pid specified */
1402 /* Parse the args string, looking for "verbose" (or any abbrev) and
1403 for a specific pid. If a specific pid is found, the process
1408 while ((nexttok
= strtok (args
, " \t")) != NULL
)
1411 if (strncmp (nexttok
, "verbose", strlen (nexttok
)) == 0)
1415 else if ((pii
.pid
= atoi (nexttok
)) > 0)
1419 (void) memset (&pii
, 0, sizeof (pii
));
1420 if (!open_proc_file (pid
, pip
))
1422 perror_with_name (pip
-> pathname
);
1425 make_cleanup (close_proc_file
, pip
);
1430 /* If we don't have a valid open process at this point, then we have no
1431 inferior or didn't specify a specific pid. */
1435 error ("No process. Run an inferior or specify an explicit pid.");
1437 if (ioctl (pip
-> fd
, PIOCSTATUS
, &(pip
-> prstatus
)) < 0)
1439 print_sys_errmsg (pip
-> pathname
, errno
);
1440 error ("PIOCSTATUS failed");
1443 printf_filtered ("\nStatus information for %s:\n\n", pip
-> pathname
);
1444 proc_info_address_map (pip
, verbose
);
1446 proc_info_flags (pip
, verbose
);
1447 proc_info_why (pip
, verbose
);
1448 proc_info_what (pip
, verbose
);
1449 proc_info_info (pip
, verbose
);
1450 proc_info_cursig (pip
, verbose
);
1451 proc_info_sigpend (pip
, verbose
);
1452 proc_info_sighold (pip
, verbose
);
1453 proc_info_altstack (pip
, verbose
);
1454 proc_info_action (pip
, verbose
);
1455 proc_info_id (pip
, verbose
);
1456 proc_info_times (pip
, verbose
);
1457 proc_info_clname (pip
,verbose
);
1458 proc_info_instr (pip
, verbose
);
1459 proc_info_reg (pip
, verbose
);
1462 /* All done, deal with closing any temporary process info structure,
1463 freeing temporary memory , etc. */
1465 do_cleanups (old_chain
);
1472 _initialize_proc_fs -- initialize the process file system stuff
1476 void _initialize_proc_fs (void)
1480 Do required initializations during gdb startup for using the
1481 /proc file system interface.
1485 static char *proc_desc
=
1486 "Show current process status information using /proc entry.\n\
1487 With no arguments, prints short form. With 'verbose' prints long form.";
1490 _initialize_proc_fs ()
1492 add_info ("proc", proc_info
, proc_desc
);
1495 #endif /* USE_PROC_FS */