Commit | Line | Data |
---|---|---|
c3f6f71d JM |
1 | /* |
2 | * Pretty-print the pr_why value. | |
3 | * | |
4 | * Arguments: unsigned long flags, int verbose | |
5 | * | |
6 | */ | |
7 | ||
8 | #include "defs.h" | |
9 | ||
10 | #if defined(NEW_PROC_API) | |
11 | #define _STRUCTURED_PROC 1 | |
12 | #endif | |
13 | ||
14 | #include <stdio.h> | |
15 | #include <sys/types.h> | |
16 | #include <sys/procfs.h> | |
17 | ||
18 | /* Much of the information used in the /proc interface, particularly for | |
19 | printing status information, is kept as tables of structures of the | |
20 | following form. These tables can be used to map numeric values to | |
21 | their symbolic names and to a string that describes their specific use. */ | |
22 | ||
23 | struct trans { | |
24 | int value; /* The numeric value */ | |
25 | char *name; /* The equivalent symbolic value */ | |
26 | char *desc; /* Short description of value */ | |
27 | }; | |
28 | ||
29 | /* Translate values in the pr_why field of the prstatus struct. */ | |
30 | ||
31 | static struct trans pr_why_table[] = | |
32 | { | |
33 | #if defined (PR_REQUESTED) | |
34 | /* All platforms */ | |
35 | { PR_REQUESTED, "PR_REQUESTED", | |
36 | "Directed to stop by debugger via P(IO)CSTOP or P(IO)CWSTOP" }, | |
37 | #endif | |
38 | #if defined (PR_SIGNALLED) | |
39 | /* All platforms */ | |
40 | { PR_SIGNALLED, "PR_SIGNALLED", "Receipt of a traced signal" }, | |
41 | #endif | |
42 | #if defined (PR_SYSENTRY) | |
43 | /* All platforms */ | |
44 | { PR_SYSENTRY, "PR_SYSENTRY", "Entry to a traced system call" }, | |
45 | #endif | |
46 | #if defined (PR_SYSEXIT) | |
47 | /* All platforms */ | |
48 | { PR_SYSEXIT, "PR_SYSEXIT", "Exit from a traced system call" }, | |
49 | #endif | |
50 | #if defined (PR_JOBCONTROL) | |
51 | /* All platforms */ | |
52 | { PR_JOBCONTROL, "PR_JOBCONTROL", "Default job control stop signal action" }, | |
53 | #endif | |
54 | #if defined (PR_FAULTED) | |
55 | /* All platforms */ | |
56 | { PR_FAULTED, "PR_FAULTED", "Incurred a traced hardware fault" }, | |
57 | #endif | |
58 | #if defined (PR_SUSPENDED) | |
59 | /* Solaris and UnixWare */ | |
60 | { PR_SUSPENDED, "PR_SUSPENDED", "Process suspended" }, | |
61 | #endif | |
62 | #if defined (PR_CHECKPOINT) | |
63 | /* Solaris only */ | |
64 | { PR_CHECKPOINT, "PR_CHECKPOINT", "Process stopped at checkpoint" }, | |
65 | #endif | |
66 | #if defined (PR_FORKSTOP) | |
67 | /* OSF only */ | |
68 | { PR_FORKSTOP, "PR_FORKSTOP", "Process stopped at end of fork call" }, | |
69 | #endif | |
70 | #if defined (PR_TCRSTOP) | |
71 | /* OSF only */ | |
72 | { PR_TCRSTOP, "PR_TCRSTOP", "Process stopped on thread creation" }, | |
73 | #endif | |
74 | #if defined (PR_TTSTOP) | |
75 | /* OSF only */ | |
76 | { PR_TTSTOP, "PR_TTSTOP", "Process stopped on thread termination" }, | |
77 | #endif | |
78 | #if defined (PR_DEAD) | |
79 | /* OSF only */ | |
80 | { PR_DEAD, "PR_DEAD", "Process stopped in exit system call" }, | |
81 | #endif | |
82 | }; | |
83 | ||
84 | void | |
85 | proc_prettyfprint_why (file, why, what, verbose) | |
86 | FILE *file; | |
87 | unsigned long why; | |
88 | unsigned long what; | |
89 | int verbose; | |
90 | { | |
91 | int i; | |
92 | ||
93 | if (why == 0) | |
94 | return; | |
95 | ||
96 | for (i = 0; i < sizeof (pr_why_table) / sizeof (pr_why_table[0]); i++) | |
97 | if (why == pr_why_table[i].value) | |
98 | { | |
99 | fprintf (file, "%s ", pr_why_table[i].name); | |
100 | if (verbose) | |
101 | fprintf (file, ": %s ", pr_why_table[i].desc); | |
102 | ||
103 | switch (why) { | |
104 | #ifdef PR_REQUESTED | |
105 | case PR_REQUESTED: | |
106 | break; /* Nothing more to print. */ | |
107 | #endif | |
108 | #ifdef PR_SIGNALLED | |
109 | case PR_SIGNALLED: | |
110 | proc_prettyfprint_signal (file, what, verbose); | |
111 | break; | |
112 | #endif | |
113 | #ifdef PR_FAULTED | |
114 | case PR_FAULTED: | |
115 | proc_prettyfprint_fault (file, what, verbose); | |
116 | break; | |
117 | #endif | |
118 | #ifdef PR_SYSENTRY | |
119 | case PR_SYSENTRY: | |
120 | fprintf (file, "Entry to "); | |
121 | proc_prettyfprint_syscall (file, what, verbose); | |
122 | break; | |
123 | #endif | |
124 | #ifdef PR_SYSEXIT | |
125 | case PR_SYSEXIT: | |
126 | fprintf (file, "Exit from "); | |
127 | proc_prettyfprint_syscall (file, what, verbose); | |
128 | break; | |
129 | #endif | |
130 | #ifdef PR_JOBCONTROL | |
131 | case PR_JOBCONTROL: | |
132 | proc_prettyfprint_signal (file, what, verbose); | |
133 | break; | |
134 | #endif | |
135 | #ifdef PR_DEAD | |
136 | case PR_DEAD: | |
137 | fprintf (file, "Exit status: %d\n", what); | |
138 | break; | |
139 | #endif | |
140 | default: | |
141 | fprintf (file, "Unknown why %d, what %d\n", why, what); | |
142 | break; | |
143 | } | |
144 | fprintf (file, "\n"); | |
145 | ||
146 | return; | |
147 | } | |
148 | fprintf (file, "Unknown pr_why.\n"); | |
149 | } | |
150 | ||
151 | void | |
152 | proc_prettyprint_why (why, what, verbose) | |
153 | unsigned long why; | |
154 | unsigned long what; | |
155 | int verbose; | |
156 | { | |
157 | proc_prettyfprint_why (stdout, why, what, verbose); | |
158 | } |