gdb/proc-why.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /* Machine-independent support for SVR4 /proc (process file system)

  2.    Copyright (C) 1999-2015 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.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 3 of the License, or
  8.    (at your option) any later version.

  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.

  13.    You should have received a copy of the GNU General Public License
  14.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  15. #include "defs.h"

  16. #ifdef NEW_PROC_API
  17. #define _STRUCTURED_PROC 1
  18. #endif

  19. #include <sys/types.h>
  20. #include <sys/procfs.h>

  21. #include "proc-utils.h"

  22. /* Much of the information used in the /proc interface, particularly
  23.    for printing status information, is kept as tables of structures of
  24.    the following form.  These tables can be used to map numeric values
  25.    to their symbolic names and to a string that describes their
  26.    specific use.  */

  27. struct trans
  28. {
  29.   int value;                    /* The numeric value.  */
  30.   char *name;                   /* The equivalent symbolic value.  */
  31.   char *desc;                   /* Short description of value.  */
  32. };

  33. /* Translate values in the pr_why field of a `struct prstatus' or
  34.    `struct lwpstatus'.  */

  35. static struct trans pr_why_table[] =
  36. {
  37. #if defined (PR_REQUESTED)
  38.   /* All platforms.  */
  39.   { PR_REQUESTED, "PR_REQUESTED",
  40.     "Directed to stop by debugger via P(IO)CSTOP or P(IO)CWSTOP" },
  41. #endif
  42. #if defined (PR_SIGNALLED)
  43.   /* All platforms.  */
  44.   { PR_SIGNALLED, "PR_SIGNALLED", "Receipt of a traced signal" },
  45. #endif
  46. #if defined (PR_SYSENTRY)
  47.   /* All platforms.  */
  48.   { PR_SYSENTRY, "PR_SYSENTRY", "Entry to a traced system call" },
  49. #endif
  50. #if defined (PR_SYSEXIT)
  51.   /* All platforms.  */
  52.   { PR_SYSEXIT, "PR_SYSEXIT", "Exit from a traced system call" },
  53. #endif
  54. #if defined (PR_JOBCONTROL)
  55.   /* All platforms.  */
  56.   { PR_JOBCONTROL, "PR_JOBCONTROL", "Default job control stop signal action" },
  57. #endif
  58. #if defined (PR_FAULTED)
  59.   /* All platforms.  */
  60.   { PR_FAULTED, "PR_FAULTED", "Incurred a traced hardware fault" },
  61. #endif
  62. #if defined (PR_SUSPENDED)
  63.   /* Solaris only.  */
  64.   { PR_SUSPENDED, "PR_SUSPENDED", "Process suspended" },
  65. #endif
  66. #if defined (PR_CHECKPOINT)
  67.   /* Solaris only.  */
  68.   { PR_CHECKPOINT, "PR_CHECKPOINT", "Process stopped at checkpoint" },
  69. #endif
  70. #if defined (PR_FORKSTOP)
  71.   /* OSF/1 only.  */
  72.   { PR_FORKSTOP, "PR_FORKSTOP", "Process stopped at end of fork call" },
  73. #endif
  74. #if defined (PR_TCRSTOP)
  75.   /* OSF/1 only.  */
  76.   { PR_TCRSTOP, "PR_TCRSTOP", "Process stopped on thread creation" },
  77. #endif
  78. #if defined (PR_TTSTOP)
  79.   /* OSF/1 only.  */
  80.   { PR_TTSTOP, "PR_TTSTOP", "Process stopped on thread termination" },
  81. #endif
  82. #if defined (PR_DEAD)
  83.   /* OSF/1 only.  */
  84.   { PR_DEAD, "PR_DEAD", "Process stopped in exit system call" },
  85. #endif
  86. };

  87. /* Pretty-print the pr_why field of a `struct prstatus' or `struct
  88.    lwpstatus'.  */

  89. void
  90. proc_prettyfprint_why (FILE *file, unsigned long why, unsigned long what,
  91.                        int verbose)
  92. {
  93.   int i;

  94.   if (why == 0)
  95.     return;

  96.   for (i = 0; i < ARRAY_SIZE (pr_why_table); 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.         switch (why) {
  103. #ifdef PR_REQUESTED
  104.         case PR_REQUESTED:
  105.           break;                /* Nothing more to print.  */
  106. #endif
  107. #ifdef PR_SIGNALLED
  108.         case PR_SIGNALLED:
  109.           proc_prettyfprint_signal (file, what, verbose);
  110.           break;
  111. #endif
  112. #ifdef PR_FAULTED
  113.         case PR_FAULTED:
  114.           proc_prettyfprint_fault (file, what, verbose);
  115.           break;
  116. #endif
  117. #ifdef PR_SYSENTRY
  118.         case PR_SYSENTRY:
  119.           fprintf (file, "Entry to ");
  120.           proc_prettyfprint_syscall (file, what, verbose);
  121.           break;
  122. #endif
  123. #ifdef PR_SYSEXIT
  124.         case PR_SYSEXIT:
  125.           fprintf (file, "Exit from ");
  126.           proc_prettyfprint_syscall (file, what, verbose);
  127.           break;
  128. #endif
  129. #ifdef PR_JOBCONTROL
  130.         case PR_JOBCONTROL:
  131.           proc_prettyfprint_signal (file, what, verbose);
  132.           break;
  133. #endif
  134. #ifdef PR_DEAD
  135.         case PR_DEAD:
  136.           fprintf (file, "Exit status: %ld\n", what);
  137.           break;
  138. #endif
  139.         default:
  140.           fprintf (file, "Unknown why %ld, what %ld\n", why, what);
  141.           break;
  142.         }
  143.         fprintf (file, "\n");

  144.         return;
  145.       }

  146.   fprintf (file, "Unknown pr_why.\n");
  147. }

  148. void
  149. proc_prettyprint_why (unsigned long why, unsigned long what, int verbose)
  150. {
  151.   proc_prettyfprint_why (stdout, why, what, verbose);
  152. }