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