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