GDB (API)
|
00001 /* Machine-independent support for SVR4 /proc (process file system) 00002 00003 Copyright (C) 1999-2013 Free Software Foundation, Inc. 00004 00005 Written by Michael Snyder at Cygnus Solutions. 00006 Based on work by Fred Fish, Stu Grossman, Geoff Noer, and others. 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00020 00021 #include "defs.h" 00022 00023 #ifdef NEW_PROC_API 00024 #define _STRUCTURED_PROC 1 00025 #endif 00026 00027 #include <stdio.h> 00028 #include <sys/types.h> 00029 #include <sys/procfs.h> 00030 00031 #include "proc-utils.h" 00032 00033 /* Much of the information used in the /proc interface, particularly 00034 for printing status information, is kept as tables of structures of 00035 the following form. These tables can be used to map numeric values 00036 to their symbolic names and to a string that describes their 00037 specific use. */ 00038 00039 struct trans 00040 { 00041 int value; /* The numeric value. */ 00042 char *name; /* The equivalent symbolic value. */ 00043 char *desc; /* Short description of value. */ 00044 }; 00045 00046 /* Translate values in the pr_why field of a `struct prstatus' or 00047 `struct lwpstatus'. */ 00048 00049 static struct trans pr_why_table[] = 00050 { 00051 #if defined (PR_REQUESTED) 00052 /* All platforms. */ 00053 { PR_REQUESTED, "PR_REQUESTED", 00054 "Directed to stop by debugger via P(IO)CSTOP or P(IO)CWSTOP" }, 00055 #endif 00056 #if defined (PR_SIGNALLED) 00057 /* All platforms. */ 00058 { PR_SIGNALLED, "PR_SIGNALLED", "Receipt of a traced signal" }, 00059 #endif 00060 #if defined (PR_SYSENTRY) 00061 /* All platforms. */ 00062 { PR_SYSENTRY, "PR_SYSENTRY", "Entry to a traced system call" }, 00063 #endif 00064 #if defined (PR_SYSEXIT) 00065 /* All platforms. */ 00066 { PR_SYSEXIT, "PR_SYSEXIT", "Exit from a traced system call" }, 00067 #endif 00068 #if defined (PR_JOBCONTROL) 00069 /* All platforms. */ 00070 { PR_JOBCONTROL, "PR_JOBCONTROL", "Default job control stop signal action" }, 00071 #endif 00072 #if defined (PR_FAULTED) 00073 /* All platforms. */ 00074 { PR_FAULTED, "PR_FAULTED", "Incurred a traced hardware fault" }, 00075 #endif 00076 #if defined (PR_SUSPENDED) 00077 /* Solaris only. */ 00078 { PR_SUSPENDED, "PR_SUSPENDED", "Process suspended" }, 00079 #endif 00080 #if defined (PR_CHECKPOINT) 00081 /* Solaris only. */ 00082 { PR_CHECKPOINT, "PR_CHECKPOINT", "Process stopped at checkpoint" }, 00083 #endif 00084 #if defined (PR_FORKSTOP) 00085 /* OSF/1 only. */ 00086 { PR_FORKSTOP, "PR_FORKSTOP", "Process stopped at end of fork call" }, 00087 #endif 00088 #if defined (PR_TCRSTOP) 00089 /* OSF/1 only. */ 00090 { PR_TCRSTOP, "PR_TCRSTOP", "Process stopped on thread creation" }, 00091 #endif 00092 #if defined (PR_TTSTOP) 00093 /* OSF/1 only. */ 00094 { PR_TTSTOP, "PR_TTSTOP", "Process stopped on thread termination" }, 00095 #endif 00096 #if defined (PR_DEAD) 00097 /* OSF/1 only. */ 00098 { PR_DEAD, "PR_DEAD", "Process stopped in exit system call" }, 00099 #endif 00100 }; 00101 00102 /* Pretty-print the pr_why field of a `struct prstatus' or `struct 00103 lwpstatus'. */ 00104 00105 void 00106 proc_prettyfprint_why (FILE *file, unsigned long why, unsigned long what, 00107 int verbose) 00108 { 00109 int i; 00110 00111 if (why == 0) 00112 return; 00113 00114 for (i = 0; i < ARRAY_SIZE (pr_why_table); i++) 00115 if (why == pr_why_table[i].value) 00116 { 00117 fprintf (file, "%s ", pr_why_table[i].name); 00118 if (verbose) 00119 fprintf (file, ": %s ", pr_why_table[i].desc); 00120 00121 switch (why) { 00122 #ifdef PR_REQUESTED 00123 case PR_REQUESTED: 00124 break; /* Nothing more to print. */ 00125 #endif 00126 #ifdef PR_SIGNALLED 00127 case PR_SIGNALLED: 00128 proc_prettyfprint_signal (file, what, verbose); 00129 break; 00130 #endif 00131 #ifdef PR_FAULTED 00132 case PR_FAULTED: 00133 proc_prettyfprint_fault (file, what, verbose); 00134 break; 00135 #endif 00136 #ifdef PR_SYSENTRY 00137 case PR_SYSENTRY: 00138 fprintf (file, "Entry to "); 00139 proc_prettyfprint_syscall (file, what, verbose); 00140 break; 00141 #endif 00142 #ifdef PR_SYSEXIT 00143 case PR_SYSEXIT: 00144 fprintf (file, "Exit from "); 00145 proc_prettyfprint_syscall (file, what, verbose); 00146 break; 00147 #endif 00148 #ifdef PR_JOBCONTROL 00149 case PR_JOBCONTROL: 00150 proc_prettyfprint_signal (file, what, verbose); 00151 break; 00152 #endif 00153 #ifdef PR_DEAD 00154 case PR_DEAD: 00155 fprintf (file, "Exit status: %ld\n", what); 00156 break; 00157 #endif 00158 default: 00159 fprintf (file, "Unknown why %ld, what %ld\n", why, what); 00160 break; 00161 } 00162 fprintf (file, "\n"); 00163 00164 return; 00165 } 00166 00167 fprintf (file, "Unknown pr_why.\n"); 00168 } 00169 00170 void 00171 proc_prettyprint_why (unsigned long why, unsigned long what, int verbose) 00172 { 00173 proc_prettyfprint_why (stdout, why, what, verbose); 00174 }