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