xref: /openbsd/gnu/usr.bin/binutils/gdb/proc-why.c (revision 11efff7f)
1 /* Machine independent support for SVR4 /proc (process file system) for GDB.
2    Copyright 1999, 2000 Free Software Foundation, Inc.
3    Written by Michael Snyder at Cygnus Solutions.
4    Based on work by Fred Fish, Stu Grossman, Geoff Noer, and others.
5 
6 This file is part of GDB.
7 
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.
12 
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.
17 
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 Foundation,
20 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
21 
22 /*
23  * Pretty-print the pr_why value.
24  *
25  * Arguments: unsigned long flags, int verbose
26  *
27  */
28 
29 #include "defs.h"
30 
31 #if defined(NEW_PROC_API)
32 #define _STRUCTURED_PROC 1
33 #endif
34 
35 #include <stdio.h>
36 #include <sys/types.h>
37 #include <sys/procfs.h>
38 
39 #include "proc-utils.h"
40 
41 /*  Much of the information used in the /proc interface, particularly for
42     printing status information, is kept as tables of structures of the
43     following form.  These tables can be used to map numeric values to
44     their symbolic names and to a string that describes their specific use. */
45 
46 struct trans {
47   int value;                    /* The numeric value */
48   char *name;                   /* The equivalent symbolic value */
49   char *desc;                   /* Short description of value */
50 };
51 
52 /*  Translate values in the pr_why field of the prstatus struct. */
53 
54 static struct trans pr_why_table[] =
55 {
56 #if defined (PR_REQUESTED)
57   /* All platforms */
58   { PR_REQUESTED, "PR_REQUESTED",
59     "Directed to stop by debugger via P(IO)CSTOP or P(IO)CWSTOP" },
60 #endif
61 #if defined (PR_SIGNALLED)
62   /* All platforms */
63   { PR_SIGNALLED, "PR_SIGNALLED", "Receipt of a traced signal" },
64 #endif
65 #if defined (PR_SYSENTRY)
66   /* All platforms */
67   { PR_SYSENTRY, "PR_SYSENTRY", "Entry to a traced system call" },
68 #endif
69 #if defined (PR_SYSEXIT)
70   /* All platforms */
71   { PR_SYSEXIT, "PR_SYSEXIT", "Exit from a traced system call" },
72 #endif
73 #if defined (PR_JOBCONTROL)
74   /* All platforms */
75   { PR_JOBCONTROL, "PR_JOBCONTROL", "Default job control stop signal action" },
76 #endif
77 #if defined (PR_FAULTED)
78   /* All platforms */
79   { PR_FAULTED, "PR_FAULTED", "Incurred a traced hardware fault" },
80 #endif
81 #if defined (PR_SUSPENDED)
82   /* Solaris and UnixWare */
83   { PR_SUSPENDED, "PR_SUSPENDED", "Process suspended" },
84 #endif
85 #if defined (PR_CHECKPOINT)
86   /* Solaris only */
87   { PR_CHECKPOINT, "PR_CHECKPOINT", "Process stopped at checkpoint" },
88 #endif
89 #if defined (PR_FORKSTOP)
90   /* OSF only */
91   { PR_FORKSTOP, "PR_FORKSTOP", "Process stopped at end of fork call" },
92 #endif
93 #if defined (PR_TCRSTOP)
94   /* OSF only */
95   { PR_TCRSTOP, "PR_TCRSTOP", "Process stopped on thread creation" },
96 #endif
97 #if defined (PR_TTSTOP)
98   /* OSF only */
99   { PR_TTSTOP, "PR_TTSTOP", "Process stopped on thread termination" },
100 #endif
101 #if defined (PR_DEAD)
102   /* OSF only */
103   { PR_DEAD, "PR_DEAD", "Process stopped in exit system call" },
104 #endif
105 };
106 
107 void
proc_prettyfprint_why(FILE * file,unsigned long why,unsigned long what,int verbose)108 proc_prettyfprint_why (FILE *file, unsigned long why, unsigned long what,
109 		       int verbose)
110 {
111   int i;
112 
113   if (why == 0)
114     return;
115 
116   for (i = 0; i < sizeof (pr_why_table) / sizeof (pr_why_table[0]); i++)
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:
126 	  break;	/* Nothing more to print. */
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:
157 	  fprintf (file, "Exit status: %ld\n", what);
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       }
168   fprintf (file, "Unknown pr_why.\n");
169 }
170 
171 void
proc_prettyprint_why(unsigned long why,unsigned long what,int verbose)172 proc_prettyprint_why (unsigned long why, unsigned long what, int verbose)
173 {
174   proc_prettyfprint_why (stdout, why, what, verbose);
175 }
176