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