Commit | Line | Data |
---|---|---|
7a952542 | 1 | /* Machine-independent support for SVR4 /proc (process file system) |
0fda6bd2 | 2 | |
7a952542 | 3 | Copyright 1999, 2000, 2004 Free Software Foundation, Inc. |
0fda6bd2 | 4 | |
7a952542 MK |
5 | Written by Michael Snyder at Cygnus Solutions. |
6 | Based on work by Fred Fish, Stu Grossman, Geoff Noer, and others. | |
0fda6bd2 | 7 | |
7a952542 MK |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
0fda6bd2 | 12 | |
7a952542 MK |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
0fda6bd2 | 17 | |
7a952542 MK |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
0fda6bd2 JM |
22 | |
23 | #include "defs.h" | |
24 | ||
7a952542 | 25 | #ifdef NEW_PROC_API |
0fda6bd2 JM |
26 | #define _STRUCTURED_PROC 1 |
27 | #endif | |
28 | ||
29 | #include <stdio.h> | |
30 | #include <sys/types.h> | |
31 | #include <sys/procfs.h> | |
32 | ||
33 | #include "proc-utils.h" | |
34 | ||
7a952542 MK |
35 | /* Much of the information used in the /proc interface, particularly |
36 | for printing status information, is kept as tables of structures of | |
37 | the following form. These tables can be used to map numeric values | |
38 | to their symbolic names and to a string that describes their | |
39 | specific use. */ | |
0fda6bd2 | 40 | |
7a952542 MK |
41 | struct trans |
42 | { | |
43 | int value; /* The numeric value. */ | |
44 | char *name; /* The equivalent symbolic value. */ | |
45 | char *desc; /* Short description of value. */ | |
0fda6bd2 JM |
46 | }; |
47 | ||
7a952542 MK |
48 | /* Translate values in the pr_why field of a `struct prstatus' or |
49 | `struct lwpstatus'. */ | |
0fda6bd2 JM |
50 | |
51 | static struct trans pr_why_table[] = | |
52 | { | |
53 | #if defined (PR_REQUESTED) | |
7a952542 | 54 | /* All platforms. */ |
0fda6bd2 JM |
55 | { PR_REQUESTED, "PR_REQUESTED", |
56 | "Directed to stop by debugger via P(IO)CSTOP or P(IO)CWSTOP" }, | |
57 | #endif | |
58 | #if defined (PR_SIGNALLED) | |
7a952542 | 59 | /* All platforms. */ |
0fda6bd2 JM |
60 | { PR_SIGNALLED, "PR_SIGNALLED", "Receipt of a traced signal" }, |
61 | #endif | |
62 | #if defined (PR_SYSENTRY) | |
7a952542 | 63 | /* All platforms. */ |
0fda6bd2 JM |
64 | { PR_SYSENTRY, "PR_SYSENTRY", "Entry to a traced system call" }, |
65 | #endif | |
66 | #if defined (PR_SYSEXIT) | |
7a952542 | 67 | /* All platforms. */ |
0fda6bd2 JM |
68 | { PR_SYSEXIT, "PR_SYSEXIT", "Exit from a traced system call" }, |
69 | #endif | |
70 | #if defined (PR_JOBCONTROL) | |
7a952542 | 71 | /* All platforms. */ |
0fda6bd2 JM |
72 | { PR_JOBCONTROL, "PR_JOBCONTROL", "Default job control stop signal action" }, |
73 | #endif | |
74 | #if defined (PR_FAULTED) | |
7a952542 | 75 | /* All platforms. */ |
0fda6bd2 JM |
76 | { PR_FAULTED, "PR_FAULTED", "Incurred a traced hardware fault" }, |
77 | #endif | |
78 | #if defined (PR_SUSPENDED) | |
7a952542 | 79 | /* Solaris and UnixWare. */ |
0fda6bd2 JM |
80 | { PR_SUSPENDED, "PR_SUSPENDED", "Process suspended" }, |
81 | #endif | |
82 | #if defined (PR_CHECKPOINT) | |
7a952542 | 83 | /* Solaris only. */ |
0fda6bd2 JM |
84 | { PR_CHECKPOINT, "PR_CHECKPOINT", "Process stopped at checkpoint" }, |
85 | #endif | |
86 | #if defined (PR_FORKSTOP) | |
7a952542 | 87 | /* OSF/1 only. */ |
0fda6bd2 JM |
88 | { PR_FORKSTOP, "PR_FORKSTOP", "Process stopped at end of fork call" }, |
89 | #endif | |
90 | #if defined (PR_TCRSTOP) | |
7a952542 | 91 | /* OSF/1 only. */ |
0fda6bd2 JM |
92 | { PR_TCRSTOP, "PR_TCRSTOP", "Process stopped on thread creation" }, |
93 | #endif | |
94 | #if defined (PR_TTSTOP) | |
7a952542 | 95 | /* OSF/1 only. */ |
0fda6bd2 JM |
96 | { PR_TTSTOP, "PR_TTSTOP", "Process stopped on thread termination" }, |
97 | #endif | |
98 | #if defined (PR_DEAD) | |
7a952542 | 99 | /* OSF/1 only. */ |
0fda6bd2 JM |
100 | { PR_DEAD, "PR_DEAD", "Process stopped in exit system call" }, |
101 | #endif | |
102 | }; | |
103 | ||
7a952542 MK |
104 | /* Pretty-print the pr_why field of a `struct prstatus' or `struct |
105 | lwpstatus'. */ | |
106 | ||
0fda6bd2 | 107 | void |
fba45db2 KB |
108 | proc_prettyfprint_why (FILE *file, unsigned long why, unsigned long what, |
109 | int verbose) | |
0fda6bd2 JM |
110 | { |
111 | int i; | |
112 | ||
113 | if (why == 0) | |
114 | return; | |
115 | ||
7a952542 | 116 | for (i = 0; i < ARRAY_SIZE (pr_why_table); i++) |
0fda6bd2 JM |
117 | if (why == pr_why_table[i].value) |
118 | { | |
119 | fprintf (file, "%s ", pr_why_table[i].name); | |
120 | if (verbose) | |
121 | fprintf (file, ": %s ", pr_why_table[i].desc); | |
122 | ||
123 | switch (why) { | |
124 | #ifdef PR_REQUESTED | |
125 | case PR_REQUESTED: | |
7a952542 | 126 | break; /* Nothing more to print. */ |
0fda6bd2 JM |
127 | #endif |
128 | #ifdef PR_SIGNALLED | |
129 | case PR_SIGNALLED: | |
130 | proc_prettyfprint_signal (file, what, verbose); | |
131 | break; | |
132 | #endif | |
133 | #ifdef PR_FAULTED | |
134 | case PR_FAULTED: | |
135 | proc_prettyfprint_fault (file, what, verbose); | |
136 | break; | |
137 | #endif | |
138 | #ifdef PR_SYSENTRY | |
139 | case PR_SYSENTRY: | |
140 | fprintf (file, "Entry to "); | |
141 | proc_prettyfprint_syscall (file, what, verbose); | |
142 | break; | |
143 | #endif | |
144 | #ifdef PR_SYSEXIT | |
145 | case PR_SYSEXIT: | |
146 | fprintf (file, "Exit from "); | |
147 | proc_prettyfprint_syscall (file, what, verbose); | |
148 | break; | |
149 | #endif | |
150 | #ifdef PR_JOBCONTROL | |
151 | case PR_JOBCONTROL: | |
152 | proc_prettyfprint_signal (file, what, verbose); | |
153 | break; | |
154 | #endif | |
155 | #ifdef PR_DEAD | |
156 | case PR_DEAD: | |
849a1d7c | 157 | fprintf (file, "Exit status: %ld\n", what); |
0fda6bd2 JM |
158 | break; |
159 | #endif | |
160 | default: | |
161 | fprintf (file, "Unknown why %ld, what %ld\n", why, what); | |
162 | break; | |
163 | } | |
164 | fprintf (file, "\n"); | |
165 | ||
166 | return; | |
167 | } | |
7a952542 | 168 | |
0fda6bd2 JM |
169 | fprintf (file, "Unknown pr_why.\n"); |
170 | } | |
171 | ||
172 | void | |
fba45db2 | 173 | proc_prettyprint_why (unsigned long why, unsigned long what, int verbose) |
0fda6bd2 JM |
174 | { |
175 | proc_prettyfprint_why (stdout, why, what, verbose); | |
176 | } |