1130812Smarcel/* Common things used by the various *gnu-nat.c files 2130812Smarcel Copyright 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc. 3130812Smarcel 4130812Smarcel Written by Miles Bader <miles@gnu.ai.mit.edu> 5130812Smarcel 6130812Smarcel The GNU Hurd is free software; you can redistribute it and/or 7130812Smarcel modify it under the terms of the GNU General Public License as 8130812Smarcel published by the Free Software Foundation; either version 2, or (at 9130812Smarcel your option) any later version. 10130812Smarcel 11130812Smarcel The GNU Hurd is distributed in the hope that it will be useful, but 12130812Smarcel WITHOUT ANY WARRANTY; without even the implied warranty of 13130812Smarcel MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14130812Smarcel General Public License for more details. 15130812Smarcel 16130812Smarcel You should have received a copy of the GNU General Public License 17130812Smarcel along with this program; if not, write to the Free Software 18130812Smarcel Foundation, Inc., 59 Temple Place - Suite 330, 19130812Smarcel Boston, MA 02111-1307, USA. */ 20130812Smarcel 21130812Smarcel#ifndef __GNU_NAT_H__ 22130812Smarcel#define __GNU_NAT_H__ 23130812Smarcel 24130812Smarcel#include <unistd.h> 25130812Smarcel#include <mach.h> 26130812Smarcel 27130812Smarcelstruct inf; 28130812Smarcel 29130812Smarcelextern struct inf *current_inferior; 30130812Smarcel 31130812Smarcel/* Converts a GDB pid to a struct proc. */ 32130812Smarcelstruct proc *inf_tid_to_thread (struct inf *inf, int tid); 33130812Smarcel 34130812Smarcel/* Makes sure that INF's thread list is synced with the actual process. */ 35130812Smarcelint inf_update_procs (struct inf *inf); 36130812Smarcel 37130812Smarcel/* A proc is either a thread, or the task (there can only be one task proc 38130812Smarcel because it always has the same TID, PROC_TID_TASK). */ 39130812Smarcelstruct proc 40130812Smarcel { 41130812Smarcel thread_t port; /* The task or thread port. */ 42130812Smarcel int tid; /* The GDB pid (actually a thread id). */ 43130812Smarcel int num; /* An id number for threads, to print. */ 44130812Smarcel 45130812Smarcel mach_port_t saved_exc_port; /* The task/thread's real exception port. */ 46130812Smarcel mach_port_t exc_port; /* Our replacement, which for. */ 47130812Smarcel 48130812Smarcel int sc; /* Desired suspend count. */ 49130812Smarcel int cur_sc; /* Implemented suspend count. */ 50130812Smarcel int run_sc; /* Default sc when the program is running. */ 51130812Smarcel int pause_sc; /* Default sc when gdb has control. */ 52130812Smarcel int resume_sc; /* Sc resulting from the last resume. */ 53130812Smarcel int detach_sc; /* SC to leave around when detaching 54130812Smarcel from program. */ 55130812Smarcel 56130812Smarcel thread_state_data_t state; /* Registers, &c. */ 57130812Smarcel int state_valid:1; /* True if STATE is up to date. */ 58130812Smarcel int state_changed:1; 59130812Smarcel 60130812Smarcel int aborted:1; /* True if thread_abort has been called. */ 61130812Smarcel int dead:1; /* We happen to know it's actually dead. */ 62130812Smarcel 63130812Smarcel /* Bit mask of registers fetched by gdb. This is used when we re-fetch 64130812Smarcel STATE after aborting the thread, to detect that gdb may have out-of-date 65130812Smarcel information. */ 66130812Smarcel unsigned long fetched_regs; 67130812Smarcel 68130812Smarcel struct inf *inf; /* Where we come from. */ 69130812Smarcel 70130812Smarcel struct proc *next; 71130812Smarcel }; 72130812Smarcel 73130812Smarcel/* The task has a thread entry with this TID. */ 74130812Smarcel#define PROC_TID_TASK (-1) 75130812Smarcel 76130812Smarcel#define proc_is_task(proc) ((proc)->tid == PROC_TID_TASK) 77130812Smarcel#define proc_is_thread(proc) ((proc)->tid != PROC_TID_TASK) 78130812Smarcel 79130812Smarcelextern int __proc_pid (struct proc *proc); 80130812Smarcel 81130812Smarcel/* Make sure that the state field in PROC is up to date, and return a 82130812Smarcel pointer to it, or 0 if something is wrong. If WILL_MODIFY is true, 83130812Smarcel makes sure that the thread is stopped and aborted first, and sets 84130812Smarcel the state_changed field in PROC to true. */ 85130812Smarcelextern thread_state_t proc_get_state (struct proc *proc, int will_modify); 86130812Smarcel 87130812Smarcel/* Return printable description of proc. */ 88130812Smarcelextern char *proc_string (struct proc *proc); 89130812Smarcel 90130812Smarcel#define proc_debug(_proc, msg, args...) \ 91130812Smarcel do { struct proc *__proc = (_proc); \ 92130812Smarcel debug ("{proc %d/%d %p}: " msg, \ 93130812Smarcel __proc_pid (__proc), __proc->tid, __proc , ##args); } while (0) 94130812Smarcel 95130812Smarcelextern int gnu_debug_flag; 96130812Smarcel 97130812Smarcel#define debug(msg, args...) \ 98130812Smarcel do { if (gnu_debug_flag) \ 99130812Smarcel fprintf_unfiltered (gdb_stdlog, "%s:%d: " msg "\r\n", __FILE__ , __LINE__ , ##args); } while (0) 100130812Smarcel 101130812Smarcel#endif /* __GNU_NAT_H__ */ 102