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 prstatus flags. 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/* Much of the information used in the /proc interface, particularly for 4098944Sobrien printing status information, is kept as tables of structures of the 4198944Sobrien following form. These tables can be used to map numeric values to 4298944Sobrien their symbolic names and to a string that describes their specific use. */ 4398944Sobrien 4498944Sobrienstruct trans { 4598944Sobrien int value; /* The numeric value */ 4698944Sobrien char *name; /* The equivalent symbolic value */ 4798944Sobrien char *desc; /* Short description of value */ 4898944Sobrien}; 4998944Sobrien 5098944Sobrien/* Translate bits in the pr_flags member of the prstatus structure, 5198944Sobrien into the names and desc information. */ 5298944Sobrien 5398944Sobrienstatic struct trans pr_flag_table[] = 5498944Sobrien{ 5598944Sobrien#if defined (PR_STOPPED) 5698944Sobrien /* Sol2.5: lwp is stopped 5798944Sobrien * Sol2.6: lwp is stopped 5898944Sobrien * Sol2.7: lwp is stopped 5998944Sobrien * IRIX6: process is stopped 6098944Sobrien * OSF: task/thread is stopped 6198944Sobrien * UW: LWP is stopped 6298944Sobrien */ 6398944Sobrien { PR_STOPPED, "PR_STOPPED", "Process (LWP) is stopped" }, 6498944Sobrien#endif 6598944Sobrien#if defined (PR_ISTOP) 6698944Sobrien /* Sol2.5: lwp is stopped on an event of interest 6798944Sobrien * Sol2.6: lwp is stopped on an event of interest 6898944Sobrien * Sol2.7: lwp is stopped on an event of interest 6998944Sobrien * IRIX6: process is stopped on event of interest 7098944Sobrien * OSF: task/thread stopped on event of interest 7198944Sobrien * UW: LWP stopped on an event of interest 7298944Sobrien */ 7398944Sobrien { PR_ISTOP, "PR_ISTOP", "Stopped on an event of interest" }, 7498944Sobrien#endif 7598944Sobrien#if defined (PR_DSTOP) 7698944Sobrien /* Sol2.5: lwp has a stop directive in effect 7798944Sobrien * Sol2.6: lwp has a stop directive in effect 7898944Sobrien * Sol2.7: lwp has a stop directive in effect 7998944Sobrien * IRIX6: process has stop directive in effect 8098944Sobrien * OSF: task/thread has stop directive in effect 8198944Sobrien * UW: A stop directive is in effect 8298944Sobrien */ 8398944Sobrien { PR_DSTOP, "PR_DSTOP", "A stop directive is in effect" }, 8498944Sobrien#endif 8598944Sobrien#if defined (PR_STEP) 8698944Sobrien /* Sol2.5: lwp has a single-step directive in effect 8798944Sobrien * Sol2.6: lwp has a single-step directive in effect 8898944Sobrien * Sol2.7: lwp has a single-step directive in effect 8998944Sobrien * IRIX6: process has single step pending 9098944Sobrien */ 9198944Sobrien { PR_STEP, "PR_STEP", "A single step directive is in effect" }, 9298944Sobrien#endif 9398944Sobrien#if defined (PR_ASLEEP) 9498944Sobrien /* Sol2.5: lwp is sleeping in a system call 9598944Sobrien * Sol2.6: lwp is sleeping in a system call 9698944Sobrien * Sol2.7: lwp is sleeping in a system call 9798944Sobrien * IRIX6: process is in an interruptible sleep 9898944Sobrien * OSF: task/thread is asleep within a system call 9998944Sobrien * UW: LWP is sleep()ing in a system call 10098944Sobrien */ 10198944Sobrien { PR_ASLEEP, "PR_ASLEEP", "Sleeping in an (interruptible) system call" }, 10298944Sobrien#endif 10398944Sobrien#if defined (PR_PCINVAL) 10498944Sobrien /* Sol2.5: contents of pr_instr undefined 10598944Sobrien * Sol2.6: contents of pr_instr undefined 10698944Sobrien * Sol2.7: contents of pr_instr undefined 10798944Sobrien * IRIX6: current pc is invalid 10898944Sobrien * OSF: program counter contains invalid address 10998944Sobrien * UW: %pc refers to an invalid virtual address 11098944Sobrien */ 11198944Sobrien { PR_PCINVAL, "PR_PCINVAL", "PC (pr_instr) is invalid" }, 11298944Sobrien#endif 11398944Sobrien#if defined (PR_ASLWP) 11498944Sobrien /* Sol2.5: this lwp is the aslwp 11598944Sobrien * Sol2.6: this lwp is the aslwp 11698944Sobrien * Sol2.7: this lwp is the aslwp 11798944Sobrien */ 11898944Sobrien { PR_ASLWP, "PR_ASLWP", "This is the asynchronous signal LWP" }, 11998944Sobrien#endif 12098944Sobrien#if defined (PR_AGENT) 12198944Sobrien /* Sol2.6: this lwp is the /proc agent lwp 12298944Sobrien * Sol2.7: this lwp is the /proc agent lwp 12398944Sobrien */ 12498944Sobrien { PR_AGENT, "PR_AGENT", "This is the /proc agent LWP" }, 12598944Sobrien#endif 12698944Sobrien#if defined (PR_ISSYS) 12798944Sobrien /* Sol2.5: system process 12898944Sobrien * Sol2.6: this is a system process 12998944Sobrien * Sol2.7: this is a system process 13098944Sobrien * IRIX6: process is a system process 13198944Sobrien * OSF: task/thread is a system task/thread 13298944Sobrien * UW: System process 13398944Sobrien */ 13498944Sobrien { PR_ISSYS, "PR_ISSYS", "Is a system process/thread" }, 13598944Sobrien#endif 13698944Sobrien#if defined (PR_VFORKP) 13798944Sobrien /* Sol2.6: process is the parent of a vfork()d child 13898944Sobrien * Sol2.7: process is the parent of a vfork()d child 13998944Sobrien */ 14098944Sobrien { PR_VFORKP, "PR_VFORKP", "Process is the parent of a vforked child" }, 14198944Sobrien#endif 14298944Sobrien#ifdef PR_ORPHAN 14398944Sobrien /* Sol2.6: process's process group is orphaned 14498944Sobrien * Sol2.7: process's process group is orphaned 14598944Sobrien */ 14698944Sobrien { PR_ORPHAN, "PR_ORPHAN", "Process's process group is orphaned" }, 14798944Sobrien#endif 14898944Sobrien#if defined (PR_FORK) 14998944Sobrien /* Sol2.5: inherit-on-fork is in effect 15098944Sobrien * Sol2.6: inherit-on-fork is in effect 15198944Sobrien * Sol2.7: inherit-on-fork is in effect 15298944Sobrien * IRIX6: process has inherit-on-fork flag set 15398944Sobrien * OSF: task/thread has inherit-on-fork flag set 15498944Sobrien * UW: inherit-on-fork is in effect 15598944Sobrien */ 15698944Sobrien { PR_FORK, "PR_FORK", "Inherit-on-fork is in effect" }, 15798944Sobrien#endif 15898944Sobrien#if defined (PR_RLC) 15998944Sobrien /* Sol2.5: run-on-last-close is in effect 16098944Sobrien * Sol2.6: run-on-last-close is in effect 16198944Sobrien * Sol2.7: run-on-last-close is in effect 16298944Sobrien * IRIX6: process has run-on-last-close flag set 16398944Sobrien * OSF: task/thread has run-on-last-close flag set 16498944Sobrien * UW: Run-on-last-close is in effect 16598944Sobrien */ 16698944Sobrien { PR_RLC, "PR_RLC", "Run-on-last-close is in effect" }, 16798944Sobrien#endif 16898944Sobrien#if defined (PR_KLC) 16998944Sobrien /* Sol2.5: kill-on-last-close is in effect 17098944Sobrien * Sol2.6: kill-on-last-close is in effect 17198944Sobrien * Sol2.7: kill-on-last-close is in effect 17298944Sobrien * IRIX6: process has kill-on-last-close flag set 17398944Sobrien * OSF: kill-on-last-close, superceeds RLC 17498944Sobrien * UW: kill-on-last-close is in effect 17598944Sobrien */ 17698944Sobrien { PR_KLC, "PR_KLC", "Kill-on-last-close is in effect" }, 17798944Sobrien#endif 17898944Sobrien#if defined (PR_ASYNC) 17998944Sobrien /* Sol2.5: asynchronous-stop is in effect 18098944Sobrien * Sol2.6: asynchronous-stop is in effect 18198944Sobrien * Sol2.7: asynchronous-stop is in effect 18298944Sobrien * OSF: asynchronous stop mode is in effect 18398944Sobrien * UW: asynchronous stop mode is in effect 18498944Sobrien */ 18598944Sobrien { PR_ASYNC, "PR_ASYNC", "Asynchronous stop is in effect" }, 18698944Sobrien#endif 18798944Sobrien#if defined (PR_MSACCT) 18898944Sobrien /* Sol2.5: micro-state usage accounting is in effect 18998944Sobrien * Sol2.6: micro-state usage accounting is in effect 19098944Sobrien * Sol2.7: micro-state usage accounting is in effect 19198944Sobrien */ 19298944Sobrien { PR_MSACCT, "PR_MSACCT", "Microstate accounting enabled" }, 19398944Sobrien#endif 19498944Sobrien#if defined (PR_BPTADJ) 19598944Sobrien /* Sol2.5: breakpoint trap pc adjustment is in effect 19698944Sobrien * Sol2.6: breakpoint trap pc adjustment is in effect 19798944Sobrien * Sol2.7: breakpoint trap pc adjustment is in effect 19898944Sobrien */ 19998944Sobrien { PR_BPTADJ, "PR_BPTADJ", "Breakpoint PC adjustment in effect" }, 20098944Sobrien#endif 20198944Sobrien#if defined (PR_PTRACE) 20298944Sobrien /* Note: different meanings on Solaris and Irix 6 20398944Sobrien * Sol2.5: obsolete, never set in SunOS5.0 20498944Sobrien * Sol2.6: ptrace-compatibility mode is in effect 20598944Sobrien * Sol2.7: ptrace-compatibility mode is in effect 20698944Sobrien * IRIX6: process is traced with ptrace() too 20798944Sobrien * OSF: task/thread is being traced by ptrace 20898944Sobrien * UW: Process is being controlled by ptrace(2) 20998944Sobrien */ 21098944Sobrien { PR_PTRACE, "PR_PTRACE", "Process is being controlled by ptrace" }, 21198944Sobrien#endif 21298944Sobrien#if defined (PR_PCOMPAT) 21398944Sobrien /* Note: PCOMPAT on Sol2.5 means same thing as PTRACE on Sol2.6 21498944Sobrien * Sol2.5 (only): ptrace-compatibility mode is in effect 21598944Sobrien */ 21698944Sobrien { PR_PCOMPAT, "PR_PCOMPAT", "Ptrace compatibility mode in effect" }, 21798944Sobrien#endif 21898944Sobrien#ifdef PR_MSFORK 21998944Sobrien /* Sol2.6: micro-state accounting inherited on fork 22098944Sobrien * Sol2.7: micro-state accounting inherited on fork 22198944Sobrien */ 22298944Sobrien { PR_MSFORK, "PR_PCOMPAT", "Micro-state accounting inherited on fork" }, 22398944Sobrien#endif 22498944Sobrien 22598944Sobrien#ifdef PR_ISKTHREAD 22698944Sobrien /* Irix6: process is a kernel thread */ 22798944Sobrien { PR_ISKTHREAD, "PR_KTHREAD", "Process is a kernel thread" }, 22898944Sobrien#endif 22998944Sobrien 23098944Sobrien#ifdef PR_ABORT 23198944Sobrien /* OSF (only): abort the current stop condition */ 23298944Sobrien { PR_ABORT, "PR_ABORT", "Abort the current stop condition" }, 23398944Sobrien#endif 23498944Sobrien 23598944Sobrien#ifdef PR_TRACING 23698944Sobrien /* OSF: task is traced */ 23798944Sobrien { PR_TRACING, "PR_TRACING", "Task is traced" }, 23898944Sobrien#endif 23998944Sobrien 24098944Sobrien#ifdef PR_STOPFORK 24198944Sobrien /* OSF: stop child on fork */ 24298944Sobrien { PR_STOPFORK, "PR_STOPFORK", "Stop child on fork" }, 24398944Sobrien#endif 24498944Sobrien 24598944Sobrien#ifdef PR_STOPEXEC 24698944Sobrien /* OSF: stop on exec */ 24798944Sobrien { PR_STOPEXEC, "PR_STOPEXEC", "Stop on exec" }, 24898944Sobrien#endif 24998944Sobrien 25098944Sobrien#ifdef PR_STOPTERM 25198944Sobrien /* OSF: stop on task exit */ 25298944Sobrien { PR_STOPTERM, "PR_STOPTERM", "Stop on task exit" }, 25398944Sobrien#endif 25498944Sobrien 25598944Sobrien#ifdef PR_STOPTCR 25698944Sobrien /* OSF: stop on thread creation */ 25798944Sobrien { PR_STOPTCR, "PR_STOPTCR", "Stop on thread creation" }, 25898944Sobrien#endif 25998944Sobrien 26098944Sobrien#ifdef PR_STOPTTERM 26198944Sobrien /* OSF: stop on thread exit */ 26298944Sobrien { PR_STOPTTERM, "PR_STOPTTERM", "Stop on thread exit" }, 26398944Sobrien#endif 26498944Sobrien 26598944Sobrien#ifdef PR_USCHED 26698944Sobrien /* OSF: user level scheduling is in effect */ 26798944Sobrien { PR_USCHED, "PR_USCHED", "User level scheduling is in effect" }, 26898944Sobrien#endif 26998944Sobrien}; 27098944Sobrien 27198944Sobrienvoid 27298944Sobrienproc_prettyfprint_flags (FILE *file, unsigned long flags, int verbose) 27398944Sobrien{ 27498944Sobrien int i; 27598944Sobrien 27698944Sobrien for (i = 0; i < sizeof (pr_flag_table) / sizeof (pr_flag_table[0]); i++) 27798944Sobrien if (flags & pr_flag_table[i].value) 27898944Sobrien { 27998944Sobrien fprintf (file, "%s ", pr_flag_table[i].name); 28098944Sobrien if (verbose) 28198944Sobrien fprintf (file, "%s\n", pr_flag_table[i].desc); 28298944Sobrien } 28398944Sobrien if (!verbose) 28498944Sobrien fprintf (file, "\n"); 28598944Sobrien} 28698944Sobrien 28798944Sobrienvoid 28898944Sobrienproc_prettyprint_flags (unsigned long flags, int verbose) 28998944Sobrien{ 29098944Sobrien proc_prettyfprint_flags (stdout, flags, verbose); 29198944Sobrien} 292