198944Sobrien/* Machine independent support for SVR4 /proc (process file system) for GDB.
298944Sobrien   Copyright 1999, 2000 Free Software Foundation, Inc.
398944Sobrien   Written by Michael Snyder at Cygnus Solutions.
498944Sobrien   Based on work by Fred Fish, Stu Grossman, Geoff Noer, and others.
598944Sobrien
698944SobrienThis file is part of GDB.
798944Sobrien
898944SobrienThis program is free software; you can redistribute it and/or modify
998944Sobrienit under the terms of the GNU General Public License as published by
1098944Sobrienthe Free Software Foundation; either version 2 of the License, or
1198944Sobrien(at your option) any later version.
1298944Sobrien
1398944SobrienThis program is distributed in the hope that it will be useful,
1498944Sobrienbut WITHOUT ANY WARRANTY; without even the implied warranty of
1598944SobrienMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1698944SobrienGNU General Public License for more details.
1798944Sobrien
1898944SobrienYou should have received a copy of the GNU General Public License
1998944Sobrienalong with this program; if not, write to the Free Software Foundation,
2098944SobrienInc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
2198944Sobrien
2298944Sobrien/*
2398944Sobrien * Pretty-print the pr_why value.
2498944Sobrien *
2598944Sobrien * Arguments: unsigned long flags, int verbose
2698944Sobrien *
2798944Sobrien */
2898944Sobrien
2998944Sobrien#include "defs.h"
3098944Sobrien
3198944Sobrien#if defined(NEW_PROC_API)
3298944Sobrien#define _STRUCTURED_PROC 1
3398944Sobrien#endif
3498944Sobrien
3598944Sobrien#include <stdio.h>
3698944Sobrien#include <sys/types.h>
3798944Sobrien#include <sys/procfs.h>
3898944Sobrien
3998944Sobrien#include "proc-utils.h"
4098944Sobrien
4198944Sobrien/*  Much of the information used in the /proc interface, particularly for
4298944Sobrien    printing status information, is kept as tables of structures of the
4398944Sobrien    following form.  These tables can be used to map numeric values to
4498944Sobrien    their symbolic names and to a string that describes their specific use. */
4598944Sobrien
4698944Sobrienstruct trans {
4798944Sobrien  int value;                    /* The numeric value */
4898944Sobrien  char *name;                   /* The equivalent symbolic value */
4998944Sobrien  char *desc;                   /* Short description of value */
5098944Sobrien};
5198944Sobrien
5298944Sobrien/*  Translate values in the pr_why field of the prstatus struct. */
5398944Sobrien
5498944Sobrienstatic struct trans pr_why_table[] =
5598944Sobrien{
5698944Sobrien#if defined (PR_REQUESTED)
5798944Sobrien  /* All platforms */
5898944Sobrien  { PR_REQUESTED, "PR_REQUESTED",
5998944Sobrien    "Directed to stop by debugger via P(IO)CSTOP or P(IO)CWSTOP" },
6098944Sobrien#endif
6198944Sobrien#if defined (PR_SIGNALLED)
6298944Sobrien  /* All platforms */
6398944Sobrien  { PR_SIGNALLED, "PR_SIGNALLED", "Receipt of a traced signal" },
6498944Sobrien#endif
6598944Sobrien#if defined (PR_SYSENTRY)
6698944Sobrien  /* All platforms */
6798944Sobrien  { PR_SYSENTRY, "PR_SYSENTRY", "Entry to a traced system call" },
6898944Sobrien#endif
6998944Sobrien#if defined (PR_SYSEXIT)
7098944Sobrien  /* All platforms */
7198944Sobrien  { PR_SYSEXIT, "PR_SYSEXIT", "Exit from a traced system call" },
7298944Sobrien#endif
7398944Sobrien#if defined (PR_JOBCONTROL)
7498944Sobrien  /* All platforms */
7598944Sobrien  { PR_JOBCONTROL, "PR_JOBCONTROL", "Default job control stop signal action" },
7698944Sobrien#endif
7798944Sobrien#if defined (PR_FAULTED)
7898944Sobrien  /* All platforms */
7998944Sobrien  { PR_FAULTED, "PR_FAULTED", "Incurred a traced hardware fault" },
8098944Sobrien#endif
8198944Sobrien#if defined (PR_SUSPENDED)
8298944Sobrien  /* Solaris and UnixWare */
8398944Sobrien  { PR_SUSPENDED, "PR_SUSPENDED", "Process suspended" },
8498944Sobrien#endif
8598944Sobrien#if defined (PR_CHECKPOINT)
8698944Sobrien  /* Solaris only */
8798944Sobrien  { PR_CHECKPOINT, "PR_CHECKPOINT", "Process stopped at checkpoint" },
8898944Sobrien#endif
8998944Sobrien#if defined (PR_FORKSTOP)
9098944Sobrien  /* OSF only */
9198944Sobrien  { PR_FORKSTOP, "PR_FORKSTOP", "Process stopped at end of fork call" },
9298944Sobrien#endif
9398944Sobrien#if defined (PR_TCRSTOP)
9498944Sobrien  /* OSF only */
9598944Sobrien  { PR_TCRSTOP, "PR_TCRSTOP", "Process stopped on thread creation" },
9698944Sobrien#endif
9798944Sobrien#if defined (PR_TTSTOP)
9898944Sobrien  /* OSF only */
9998944Sobrien  { PR_TTSTOP, "PR_TTSTOP", "Process stopped on thread termination" },
10098944Sobrien#endif
10198944Sobrien#if defined (PR_DEAD)
10298944Sobrien  /* OSF only */
10398944Sobrien  { PR_DEAD, "PR_DEAD", "Process stopped in exit system call" },
10498944Sobrien#endif
10598944Sobrien};
10698944Sobrien
10798944Sobrienvoid
10898944Sobrienproc_prettyfprint_why (FILE *file, unsigned long why, unsigned long what,
10998944Sobrien		       int verbose)
11098944Sobrien{
11198944Sobrien  int i;
11298944Sobrien
11398944Sobrien  if (why == 0)
11498944Sobrien    return;
11598944Sobrien
11698944Sobrien  for (i = 0; i < sizeof (pr_why_table) / sizeof (pr_why_table[0]); i++)
11798944Sobrien    if (why == pr_why_table[i].value)
11898944Sobrien      {
11998944Sobrien	fprintf (file, "%s ", pr_why_table[i].name);
12098944Sobrien	if (verbose)
12198944Sobrien	  fprintf (file, ": %s ", pr_why_table[i].desc);
12298944Sobrien
12398944Sobrien	switch (why) {
12498944Sobrien#ifdef PR_REQUESTED
12598944Sobrien	case PR_REQUESTED:
12698944Sobrien	  break;	/* Nothing more to print. */
12798944Sobrien#endif
12898944Sobrien#ifdef PR_SIGNALLED
12998944Sobrien	case PR_SIGNALLED:
13098944Sobrien	  proc_prettyfprint_signal (file, what, verbose);
13198944Sobrien	  break;
13298944Sobrien#endif
13398944Sobrien#ifdef PR_FAULTED
13498944Sobrien	case PR_FAULTED:
13598944Sobrien	  proc_prettyfprint_fault (file, what, verbose);
13698944Sobrien	  break;
13798944Sobrien#endif
13898944Sobrien#ifdef PR_SYSENTRY
13998944Sobrien	case PR_SYSENTRY:
14098944Sobrien	  fprintf (file, "Entry to ");
14198944Sobrien	  proc_prettyfprint_syscall (file, what, verbose);
14298944Sobrien	  break;
14398944Sobrien#endif
14498944Sobrien#ifdef PR_SYSEXIT
14598944Sobrien	case PR_SYSEXIT:
14698944Sobrien	  fprintf (file, "Exit from ");
14798944Sobrien	  proc_prettyfprint_syscall (file, what, verbose);
14898944Sobrien	  break;
14998944Sobrien#endif
15098944Sobrien#ifdef PR_JOBCONTROL
15198944Sobrien	case PR_JOBCONTROL:
15298944Sobrien	  proc_prettyfprint_signal (file, what, verbose);
15398944Sobrien	  break;
15498944Sobrien#endif
15598944Sobrien#ifdef PR_DEAD
15698944Sobrien	case PR_DEAD:
15798944Sobrien	  fprintf (file, "Exit status: %d\n", what);
15898944Sobrien	  break;
15998944Sobrien#endif
16098944Sobrien	default:
16198944Sobrien	  fprintf (file, "Unknown why %ld, what %ld\n", why, what);
16298944Sobrien	  break;
16398944Sobrien	}
16498944Sobrien	fprintf (file, "\n");
16598944Sobrien
16698944Sobrien	return;
16798944Sobrien      }
16898944Sobrien  fprintf (file, "Unknown pr_why.\n");
16998944Sobrien}
17098944Sobrien
17198944Sobrienvoid
17298944Sobrienproc_prettyprint_why (unsigned long why, unsigned long what, int verbose)
17398944Sobrien{
17498944Sobrien  proc_prettyfprint_why (stdout, why, what, verbose);
17598944Sobrien}
176