+2001-05-14 Kevin Buettner <kevinb@redhat.com>
+
+ * inferior.h (null_ptid, minus_one_ptid): New variable declarations.
+ (ptid_build, pid_to_ptid, ptid_get_pid, ptid_get_lwp)
+ (ptid_get_tid, ptid_equal): New function declarations.
+ * infrun.c (null_ptid, minus_one_ptid): New variables.
+ (ptid_build, pid_to_ptid, ptid_get_pid, ptid_get_lwp)
+ (ptid_get_tid, ptid_equal): New functions.
+ (_initialize_infrun): Initialize null_ptid, minus_one_ptid,
+ inferior_ptid, and target_last_wait_ptid.
+
+ * defs.h (ptid_t): Redefine to be a struct rather than an int.
+ (pid_to_ptid, null_ptid, ptid_equal): Delete these macros.
+ (PIDGET, TIDGET, MERGEPID): Redefine these macros using the
+ new ptid accessors and constructor.
+
+ * config/i386/tm-i386v42mp.h (PIDGET, TIDGET, LIDGET, MERGEPID,
+ MKLID, MKTID, ISTID): Provide new definitions for these macros.
+ The old macros are retained, but disabled via #if 0 in order
+ to aid in future restructuring. See FIXME.
+
+ * arm-linux-nat.c (PIDGET, TIDGET): Delete macro definitions.
+ * i386-linux-nat.c (PIDGET, TIDGET): Likewise.
+ * infptrace.c (PIDGET, TIDGET): Likewise.
+ * lin-lwp.c (PIDGET0, PIDGET, TIDGET, MERGEPID): Likewise.
+ * lin-thread.c (PIDGET0, PIDGET, TIDGET, MERGEPID): Likewise.
+ * proc-service.c (MERGEPID): Likewise.
+ * procfs.c (PIDGET, TIDGET, MERGEPID): Likewise.
+ * thread-db.c (PIDGET0, PIDGET, TIDGET, MERGEPID): Likewise.
+ * config/nm-linux.h (PIDGET0, PIDGET, TIDGET, MERGEPID): Likewise.
+ * config/i386/tm-i386sol2.h (PIDGET0, PIDGET, TIDGET, MERGEPID):
+ Likewise.
+ * config/sparc/tm-sun4sol2.h (PIDGET0, PIDGET, TIDGET, MERGEPID):
+ Likewise.
+
+ * lin-lwp.c (THREAD_FLAG): Delete macro definition.
+ (GET_LWP): Redefine in terms of ptid_get_lwp().
+ (GET_PID): Redefine in terms of ptid_get_pid().
+ (is_lwp): Redefine without the need for THREAD_FLAG.
+ (BUILD_LWP): Redefine in terms of ptid_build().
+ * lin-thread.c (THREAD_FLAG): Delete macro definition.
+ (GET_LWP): Redefine in terms of ptid_get_lwp().
+ (GET_PID): Redefine in terms of ptid_get_pid().
+ (GET_THREAD): Redefine in terms of ptid_get_tid().
+ (BUILD_THREAD, BUILD_LWP): Redefine in terms of ptid_build().
+ (is_lwp, is_thread): Redefine.
+ (linux_child_wait, check_all_signal_numbers)
+ (linuxthreads_discard_global_state, attach_thread): Declare these
+ functions to squash warnings about missing declarations.
+ * sol-thread.c (THREAD_FLAG): Delete macro definition.
+ (GET_PID): Redefine in terms of ptid_get_pid().
+ (GET_LWP): Redefine in terms of ptid_get_lwp().
+ (GET_THREAD): Redefine in terms of ptid_get_tid().
+ (BUILD_THREAD, BUILD_LWP): Redefine in terms of ptid_build().
+ (is_lwp, is_thread): Redefine.
+ * thread-db.c (THREAD_FLAG): Delete macro definition.
+ (GET_PID): Redefine in terms of ptid_get_pid().
+ (GET_LWP): Redefine in terms of ptid_get_lwp().
+ (GET_THREAD): Redefine in terms of ptid_get_tid().
+ (BUILD_THREAD, BUILD_LWP): Redefine in terms of ptid_build().
+ (is_lwp, is_thread): Redefine.
+
+ * corelow.c (add_to_thread_list, get_core_register_section):
+ Eliminate hacks needed to prevent regressions when inferior_ptid
+ wasn't wide enough to hold the core file thread id in the pid
+ component of inferior_ptid.
+
2001-05-14 Michael Snyder <msnyder@redhat.com>
* remote.c (hex2bin): Make first argument const.
/* On Linux, threads are implemented as pseudo-processes, in which
case we may be tracing more than one process at a time. In that
case, inferior_ptid will contain the main process ID and the
- individual thread (process) ID mashed together. These macros are
- used to separate them out. These definitions should be overridden
- if thread support is included. */
-
-#if !defined (PIDGET) /* Default definition for PIDGET/TIDGET. */
-#define PIDGET(PID) PID
-#define TIDGET(PID) 0
-#endif
+ individual thread (process) ID. get_thread_id () is used to
+ get the thread id if it's available, and the process id otherwise. */
int
get_thread_id (ptid_t ptid)
#define FAULTED_USE_SIGINFO
-/* Macros to extract process id and thread id from a composite pid/tid.
- Allocate lower 16 bits for process id, next 15 bits for thread id, and
- one bit for a flag to indicate a user thread vs. a kernel thread. */
-#define PIDGET0(PID) (((PID) & 0xffff))
-#define PIDGET(PID) ((PIDGET0 (PID) == 0xffff) ? -1 : PIDGET0 (PID))
-#define TIDGET(PID) (((PID) & 0x7fffffff) >> 16)
-#define MERGEPID(PID, TID) (((PID) & 0xffff) | ((TID) << 16))
-
#endif /* ifndef TM_I386SOL2_H */
#define UNIXWARE
+#if 0
/* The following macros extract process and lwp/thread ids from a
composite id.
#define PIDBITS 16
/* Return the process id stored in composite PID. */
-#define PIDGET0(PID) (((PID) & ((1 << PIDBITS) - 1)))
-#define PIDGET(PID) ((PIDGET0 (PID) == ((1 << PIDBITS) -1)) ? -1 : PIDGET0 (PID))
+#define PIDGET(PID) (((PID) & ((1 << PIDBITS) - 1)))
/* Return the thread or lwp id stored in composite PID. */
#define TIDGET(PID) (((PID) & 0x3fffffff) >> PIDBITS)
/* Return whether PID contains a user-space thread id. */
#define ISTID(PID) ((PID) & 0x40000000)
+#endif
+
+/* New definitions of the ptid stuff. Due to the way the
+ code is structured in uw-thread.c, I'm overloading the thread id
+ and lwp id onto the lwp field. The tid field is used to indicate
+ whether the lwp is a tid or not.
+
+ FIXME: Check that core file support is not broken. (See original
+ #if 0'd comments above.)
+ FIXME: Restructure uw-thread.c so that the struct ptid fields
+ can be used as intended. */
+
+/* Return the process id stored in composite PID. */
+#define PIDGET(PID) (ptid_get_pid (PID))
+
+/* Return the thread or lwp id stored in composite PID. */
+#define TIDGET(PID) (ptid_get_lwp (PID))
+#define LIDGET(PID) TIDGET(PID)
+
+#define MERGEPID(PID, LID) (ptid_build ((PID), (LID), 0))
+#define MKLID(PID, LID) (ptid_build ((PID), (LID), 0))
+
+/* Construct a composite id from thread TID and the process portion of
+ composite PID. */
+#define MKTID(PID, TID) (ptid_build ((PID), (TID), 1))
+
+/* Return whether PID contains a user-space thread id. */
+#define ISTID(PID) (ptid_get_tid (PID))
#endif /* ifndef TM_I386V42MP_H */
/* Defined to make stepping-over-breakpoints be thread-atomic. */
#define USE_THREAD_STEP_NEEDED 1
-/* Macros to extract process id and thread id from a composite pid/tid.
- Allocate lower 19 bits for process id, next 12 bits for thread id, and
- one bit for a flag to indicate a user thread vs. a kernel thread. */
-#define PIDGET0(PID) (((PID) & 0xffff))
-#define PIDGET(PID) ((PIDGET0 (PID) == 0xffff) ? -1 : PIDGET0 (PID))
-#define TIDGET(PID) (((PID) & 0x7fffffff) >> 16)
-#define MERGEPID(PID, TID) (((PID) & 0xffff) | ((TID) << 16))
-
/* Use elf_gregset_t and elf_fpregset_t, rather than
gregset_t and fpregset_t. */
/* Enable handling of shared libraries for a.out executables. */
#define HANDLE_SVR4_EXEC_EMULATORS
-
-/* Macros to extract process id and thread id from a composite pid/tid */
-#define PIDGET0(PID) (((PID) & 0xffff))
-#define PIDGET(PID) ((PIDGET0 (PID) == 0xffff) ? -1 : PIDGET0 (PID))
-#define TIDGET(PID) (((PID) & 0x7fffffff) >> 16)
-#define MERGEPID(PID, TID) (((PID) & 0xffff) | ((TID) << 16))
if (reg_sect != NULL
&& asect->filepos == reg_sect->filepos) /* Did we find .reg? */
-#ifdef pid_to_ptid
- /* Needed to prevent regressions in ptid conversion phase 1. This
- bit of code will be deleted in favor of the #else branch in
- phase 3. */
- inferior_ptid = thread_id; /* Yes, make it current */
-#else
inferior_ptid = pid_to_ptid (thread_id); /* Yes, make it current */
-#endif
}
/* This routine opens and sets up the core file bfd. */
bfd_size_type size;
char *contents;
-#ifdef pid_to_ptid
- /* Needed to prevent regressions in ptid conversion phase 1. This
- bit of code will be deleted in favor of the #else branch in
- phase 3. */
- if (inferior_ptid)
- sprintf (section_name, "%s/%d", name, inferior_ptid);
-#else
if (PIDGET (inferior_ptid))
sprintf (section_name, "%s/%d", name, PIDGET (inferior_ptid));
-#endif
else
strcpy (section_name, name);
Val_pretty_default
};
-/* A collection of the various "ids" necessary for identifying
- the inferior. This consists of the process id (pid, thread
- id (tid), and other fields necessary for uniquely identifying
- the inferior process/thread being debugged.
-
- The present typedef is obviously quite naive with respect to
- the magnitudes that real life pids and tids can take on and
- will be replaced with something more robust shortly. */
-
-typedef int ptid_t;
-
-/* Convert a pid to a ptid_t. This macro is temporary and will
- be replaced shortly. */
-
-#define pid_to_ptid(PID) ((ptid_t) MERGEPID ((PID),0))
-
-/* Define a value for the null (or zero) pid. This macro is temporary
- and will go away shortly. */
-
-#define null_ptid (pid_to_ptid (0))
-
-/* Define a value for the -1 pid. This macro is temporary and will go
- away shortly. */
+/* The ptid struct is a collection of the various "ids" necessary
+ for identifying the inferior. This consists of the process id
+ (pid), thread id (tid), and other fields necessary for uniquely
+ identifying the inferior process/thread being debugged. When
+ manipulating ptids, the constructors, accessors, and predicate
+ declared in inferior.h should be used. These are as follows:
+
+ ptid_build - Make a new ptid from a pid, lwp, and tid.
+ pid_to_ptid - Make a new ptid from just a pid.
+ ptid_get_pid - Fetch the pid component of a ptid.
+ ptid_get_lwp - Fetch the lwp component of a ptid.
+ ptid_get_tid - Fetch the tid component of a ptid.
+ ptid_equal - Test to see if two ptids are equal.
+
+ Please do NOT access the struct ptid members directly (except, of
+ course, in the implementation of the above ptid manipulation
+ functions). */
+
+struct ptid
+ {
+ /* Process id */
+ int pid;
-#define minus_one_ptid (pid_to_ptid (-1))
+ /* Lightweight process id */
+ long lwp;
-/* Define a ptid comparison operator. This macro is temporary and will
- be replaced with a real function shortly. */
+ /* Thread id */
+ long tid;
+ };
-#define ptid_equal(PTID1,PTID2) ((PTID1) == (PTID2))
+typedef struct ptid ptid_t;
\f
#define ROOTED_P(X) (SLASH_P((X)[0]))
#endif
-/* On some systems, PIDGET is defined to extract the inferior pid from
- an internal pid that has the thread id and pid in seperate bit
- fields. If not defined, then just use the entire internal pid as
- the actual pid. */
+/* Provide default definitions of PIDGET, TIDGET, and MERGEPID.
+ The name ``TIDGET'' is a historical accident. Many uses of TIDGET
+ in the code actually refer to a lightweight process id, i.e,
+ something that can be considered a process id in its own right for
+ certain purposes. */
#ifndef PIDGET
-#define PIDGET(PID) (PID)
-#define TIDGET(PID) 0
-#define MERGEPID(PID, TID) (PID)
+#define PIDGET(PTID) (ptid_get_pid (PTID))
+#define TIDGET(PTID) (ptid_get_lwp (PTID))
+#define MERGEPID(PID, TID) ptid_build (PID, TID, 0)
#endif
/* Define well known filenos if the system does not define them. */
/* Prototypes for local functions. */
static void dummy_sse_values (void);
-/* On Linux, threads are implemented as pseudo-processes, in which
- case we may be tracing more than one process at a time. In that
- case, inferior_ptid will contain the main process ID and the
- individual thread (process) ID mashed together. These macros are
- used to separate them out. These definitions should be overridden
- if thread support is included. */
-
-#if !defined (PIDGET) /* Default definition for PIDGET/TIDGET. */
-#define PIDGET(PID) PID
-#define TIDGET(PID) 0
-#endif
\f
/* The register sets used in Linux ELF core-dumps are identical to the
*inf_status, int regno,
LONGEST val);
+/* The -1 ptid, often used to indicate either an error condition
+ or a "don't care" condition, i.e, "run all threads." */
+extern ptid_t minus_one_ptid;
+
+/* The null or zero ptid, often used to indicate no process. */
+extern ptid_t null_ptid;
+
+/* Attempt to find and return an existing ptid with the given PID, LWP,
+ and TID components. If none exists, create a new one and return
+ that. */
+ptid_t ptid_build (int pid, long lwp, long tid);
+
+/* Find/Create a ptid from just a pid. */
+ptid_t pid_to_ptid (int pid);
+
+/* Fetch the pid (process id) component from a ptid. */
+int ptid_get_pid (ptid_t ptid);
+
+/* Fetch the lwp (lightweight process) component from a ptid. */
+long ptid_get_lwp (ptid_t ptid);
+
+/* Fetch the tid (thread id) component from a ptid. */
+long ptid_get_tid (ptid_t ptid);
+
+/* Compare two ptids to see if they are equal */
+extern int ptid_equal (ptid_t p1, ptid_t p2);
+
/* Save value of inferior_ptid so that it may be restored by
a later call to do_cleanups(). Returns the struct cleanup
pointer needed for later doing the cleanup. */
static void store_register (int);
#endif
-/*
- * Some systems (Linux) may have threads implemented as pseudo-processes,
- * in which case we may be tracing more than one process at a time.
- * In that case, inferior_pid will contain the main process ID and the
- * individual thread (process) id mashed together. These macros are
- * used to separate them out. The definitions may be overridden in tm.h
- *
- * NOTE: default definitions here are for systems with no threads.
- * Useful definitions MUST be provided in tm.h
- */
-
-#if !defined (PIDGET) /* Default definition for PIDGET/TIDGET. */
-#define PIDGET(PID) PID
-#define TIDGET(PID) 0
-#endif
-
void _initialize_kernel_u_addr (void);
void _initialize_infptrace (void);
\f
free_inferior_status (inf_status);
}
-/* Helper function for save_inferior_ptid */
+/* Oft used ptids */
+ptid_t null_ptid;
+ptid_t minus_one_ptid;
+
+/* Create a ptid given the necessary PID, LWP, and TID components. */
+
+ptid_t
+ptid_build (int pid, long lwp, long tid)
+{
+ ptid_t ptid;
+
+ ptid.pid = pid;
+ ptid.lwp = lwp;
+ ptid.tid = tid;
+ return ptid;
+}
+
+/* Create a ptid from just a pid. */
+
+ptid_t
+pid_to_ptid (int pid)
+{
+ return ptid_build (pid, 0, 0);
+}
+
+/* Fetch the pid (process id) component from a ptid. */
+
+int
+ptid_get_pid (ptid_t ptid)
+{
+ return ptid.pid;
+}
+
+/* Fetch the lwp (lightweight process) component from a ptid. */
+
+long
+ptid_get_lwp (ptid_t ptid)
+{
+ return ptid.lwp;
+}
+
+/* Fetch the tid (thread id) component from a ptid. */
+
+long
+ptid_get_tid (ptid_t ptid)
+{
+ return ptid.tid;
+}
+
+/* ptid_equal() is used to test equality of two ptids. */
+
+int
+ptid_equal (ptid_t ptid1, ptid_t ptid2)
+{
+ return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp
+ && ptid1.tid == ptid2.tid);
+}
+
+/* restore_inferior_ptid() will be used by the cleanup machinery
+ to restore the inferior_ptid value saved in a call to
+ save_inferior_ptid(). */
static void
restore_inferior_ptid (void *arg)
the step command stops at a different source line.",
&setlist);
add_show_from_set (c, &showlist);
+
+ /* ptid initializations */
+ null_ptid = ptid_build (0, 0, 0);
+ minus_one_ptid = ptid_build (-1, 0, 0);
+ inferior_ptid = null_ptid;
+ target_last_wait_ptid = minus_one_ptid;
}
static int threaded;
\f
-#ifndef TIDGET
-#define TIDGET(PID) (((PID) & 0x7fffffff) >> 16)
-#define PIDGET0(PID) (((PID) & 0xffff))
-#define PIDGET(PID) ((PIDGET0 (PID) == 0xffff) ? -1 : PIDGET0 (PID))
-#define MERGEPID(PID, TID) (((PID) & 0xffff) | ((TID) << 16))
-#endif
-
-#define THREAD_FLAG 0x80000000
-#define is_lwp(pid) (((pid) & THREAD_FLAG) == 0 && TIDGET (pid))
-#define GET_LWP(pid) TIDGET (pid)
-#define GET_PID(pid) PIDGET (pid)
-#define BUILD_LWP(tid, pid) MERGEPID (pid, tid)
+#define GET_LWP(ptid) ptid_get_lwp (ptid)
+#define GET_PID(ptid) ptid_get_pid (ptid)
+#define is_lwp(ptid) (GET_LWP (ptid) != 0)
+#define BUILD_LWP(lwp, pid) ptid_build (pid, lwp, 0)
#define is_cloned(pid) (GET_LWP (pid) != GET_PID (pid))
/* Prototypes for supply_gregset etc. */
#include "gregset.h"
-#ifndef TIDGET
-#define TIDGET(PID) (((PID) & 0x7fffffff) >> 16)
-#define PIDGET0(PID) (((PID) & 0xffff))
-#define PIDGET(PID) ((PIDGET0 (PID) == 0xffff) ? -1 : PIDGET0 (PID))
-#define MERGEPID(PID, TID) (((PID) & 0xffff) | ((TID) << 16))
-#endif
-
/* Macros for superimposing PID and TID into inferior_ptid. */
-#define THREAD_FLAG 0x80000000
-#define is_thread(ARG) (((ARG) & THREAD_FLAG) != 0)
-#define is_lwp(ARG) (((ARG) & THREAD_FLAG) == 0)
-#define GET_LWP(PID) TIDGET (PID)
-#define GET_THREAD(PID) TIDGET (PID)
-#define BUILD_LWP(TID, PID) MERGEPID (PID, TID)
-#define BUILD_THREAD(TID, PID) (MERGEPID (PID, TID) | THREAD_FLAG)
+#define GET_PID(ptid) ptid_get_pid (ptid)
+#define GET_LWP(ptid) ptid_get_lwp (ptid)
+#define GET_THREAD(ptid) ptid_get_tid (ptid)
+
+#define is_lwp(ptid) (GET_LWP (ptid) != 0)
+#define is_thread(ptid) (GET_THREAD (ptid) != 0)
+
+#define BUILD_LWP(lwp, pid) ptid_build (pid, lwp, 0)
+#define BUILD_THREAD(tid, pid) ptid_build (pid, 0, tid)
+
+/* From linux-thread.c. FIXME: These should go in a separate header
+ file, but I'm told that the life expectancy of lin-thread.c and
+ linux-thread.c isn't very long... */
+
+extern int linux_child_wait (int, int *, int *);
+extern void check_all_signal_numbers (void);
+extern void linuxthreads_discard_global_state (void);
+extern void attach_thread (int);
/*
* target_beneath is a pointer to the target_ops underlying this one.
/* Building process ids. */
-#ifndef MERGEPID
-#define MERGEPID(PID, TID) (((PID) & 0xffff) | ((TID) << 16))
-#endif
-
#define BUILD_LWP(tid, pid) MERGEPID (pid, tid)
\f
typedef prstatus_t gdb_lwpstatus_t;
#endif /* NEW_PROC_API */
-
-/* Provide default composite pid manipulation macros for systems that
- don't have threads. */
-
-#ifndef PIDGET
-#define PIDGET(PID) (PID)
-#define TIDGET(PID) (PID)
-#endif
-#ifndef MERGEPID
-#define MERGEPID(PID, TID) (PID)
-#endif
-
typedef struct procinfo {
struct procinfo *next;
int pid; /* Process ID */
/* Default definitions: These must be defined in tm.h
if they are to be shared with a process module such as procfs. */
-#define THREAD_FLAG 0x80000000
-#define is_thread(ARG) (((ARG) & THREAD_FLAG) != 0)
-#define is_lwp(ARG) (((ARG) & THREAD_FLAG) == 0)
-#define GET_LWP(PID) TIDGET (PID)
-#define GET_THREAD(PID) TIDGET (PID)
-#define BUILD_LWP(TID, PID) MERGEPID (PID, TID)
-
-#define BUILD_THREAD(TID, PID) (MERGEPID (PID, TID) | THREAD_FLAG)
+#define GET_PID(ptid) ptid_get_pid (ptid)
+#define GET_LWP(ptid) ptid_get_lwp (ptid)
+#define GET_THREAD(ptid) ptid_get_tid (ptid)
+
+#define is_lwp(ptid) (GET_LWP (ptid) != 0)
+#define is_thread(ptid) (GET_THREAD (ptid) != 0)
+
+#define BUILD_LWP(lwp, pid) ptid_build (pid, lwp, 0)
+#define BUILD_THREAD(tid, pid) ptid_build (pid, 0, tid)
/* Pointers to routines from lithread_db resolved by dlopen() */
/* Building process ids. */
-#ifndef TIDGET
-#define TIDGET(PID) (((PID) & 0x7fffffff) >> 16)
-#define PIDGET0(PID) (((PID) & 0xffff))
-#define PIDGET(PID) ((PIDGET0 (PID) == 0xffff) ? -1 : PIDGET0 (PID))
-#define MERGEPID(PID, TID) (((PID) & 0xffff) | ((TID) << 16))
-#endif
-#define THREAD_FLAG 0x80000000
+#define GET_PID(ptid) ptid_get_pid (ptid)
+#define GET_LWP(ptid) ptid_get_lwp (ptid)
+#define GET_THREAD(ptid) ptid_get_tid (ptid)
-#define is_lwp(pid) (((pid) & THREAD_FLAG) == 0 && TIDGET (pid))
-#define is_thread(pid) ((pid) & THREAD_FLAG)
+#define is_lwp(ptid) (GET_LWP (ptid) != 0)
+#define is_thread(ptid) (GET_THREAD (ptid) != 0)
-#define GET_PID(pid) PIDGET (pid)
-#define GET_LWP(pid) TIDGET (pid)
-#define GET_THREAD(pid) TIDGET (pid)
+#define BUILD_LWP(lwp, pid) ptid_build (pid, lwp, 0)
+#define BUILD_THREAD(tid, pid) ptid_build (pid, 0, tid)
-#define BUILD_LWP(tid, pid) MERGEPID (pid, tid)
-#define BUILD_THREAD(tid, pid) (MERGEPID (pid, tid) | THREAD_FLAG)
\f
struct private_thread_info