[PATCH RFC] process/thread/lwp id patch - phase 3

Kevin Buettner kevinb@cygnus.com
Fri May 4 02:07:00 GMT 2001


The patch below represents the third and final phase for integrating the
mega-patch which introduces a wider process/thread/lwp id type (ptid_t).
The mega-patch is at:

    http://sources.redhat.com/ml/gdb-patches/2001-04/msg00240.html

The motivation behind this activity can be found in the prefatory
remarks in an earlier version of the mega-patch that I posted last
October:

    http://sources.redhat.com/ml/gdb-patches/2000-10/msg00014.html

This phase 3 patch is intended to be applied over the phase 2 patch
that I posted recently:

    http://sources.redhat.com/ml/gdb-patches/2001-05/msg00042.html

Now, as for what it does...

The patch below changes the representation of ptid_t from an int to a
struct.  In particular, I've chosen to represent ptid_t using the
following struct:

    struct ptid
      {
	/* Process id */
	int pid;

	/* Lightweight process id */
	long lwp;

	/* Thread id */
	long tid;
      };

I know from conversations with some of my colleagues that this
representation is not unanimously favored.  One of the alternate
suggestions was to make struct ptid somewhat more opaque by making it
more difficult to associate meaning with the various components.  (I
guess this could be called "opacity through obscurity".)  Such a
representation might look like this:

    struct ptid
      {
        long ids[3];
      }

It was felt that such a representation would discourage poor coding
habits in which the struct members are used directly instead of
obtaining them via the provided accessor functions.  E.g,

    int pid = ptid.pid;			/* bad */

vs.

    int pid = ptid_get_pid (ptid);	/* good */

or even

    int pid = PIDGET (ptid);		/* also good */

In contrast, the "bad" code using the "opacity through obscurity"
approach might look like this:

    int pid = ptid.ids[0];

(Or it might not; if we *really* wanted to discourage such practices
we could change the ordering of the ids every few months. ;-)

Another suggestion was to make the pid and these other ids live in
struct thread_info and make ptid_t a key into the threads database for
finding the thread under consideration.  Then, PIDGET would be defined
in such a way so that it would look up the thread and ask for the pid
member from struct thread_info.  The problem with this approach is
that GDB is far too unruly at the moment in its treatment of ptid_t. 
A lifetime analysis of ptids and threads reveals that ptids are
created before the corresonding thread object and also outlive the
thread object.  Also, GDB will need to be revised to avoid constructs
like this:

    pid_to_ptid (GET_LWP (lp->ptid))

This expression creates a ptid for which we would not wish to create
(another) thread object for.  (The thread object already exists and is
associated with another ptid entirely.)

In the long run, I do think this approach has merit, but I also think
that it'd be better to just use a thread object in the place of ptids. 
However, for either of these to happen, GDB will need to be cleaned up
a lot.  As noted in past messages on this topic, those of us engaged
in taming GDB can now (since phase 1 has been committed) search for
ptid to help us locate the problem areas.

....

I plan to wait a week for review and discussion before committing this
patch (or something like it).  I happen to like the representation for
ptid_t that I've chosen, but I am willing to implement the "opacity
through obscurity" approach if there is a consensus that this is a
better approach.  Please note that I've attempted to ward off poor
coding habits by documenting the ptid manipulation functions at the
point at which struct ptid is defined (in defs.h).  (I'll also add
something to gdbint.texinfo once the dust settles.)

Finally, I'll note that the representation of ptid_t is not cast
in stone.  Since we're using a typedef, we can easily change
the represenation in the future.

Kevin

	* 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.
	* config/i386/tm-i386sol2.h (PIDGET0, PIDGET, TIDGET, MERGEPID):
	Likewise.
	* config/sparc/tm-sun4sol2.h (PIDGET0, PIDGET, TIDGET, MERGEPID):
	Likewise.
	* 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.

	* 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.

diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/arm-linux-nat.c /saguaro1/sourceware-ptid-phase3/src/gdb/arm-linux-nat.c
--- /saguaro1/sourceware-ptid-phase2/src/gdb/arm-linux-nat.c	Fri Apr 27 17:12:26 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/arm-linux-nat.c	Thu May  3 22:17:03 2001
@@ -79,14 +79,8 @@ static unsigned int os_version, os_major
 /* 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)
diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/config/i386/tm-i386sol2.h /saguaro1/sourceware-ptid-phase3/src/gdb/config/i386/tm-i386sol2.h
--- /saguaro1/sourceware-ptid-phase2/src/gdb/config/i386/tm-i386sol2.h	Fri Apr 27 16:01:36 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/config/i386/tm-i386sol2.h	Thu May  3 22:17:03 2001
@@ -51,12 +51,4 @@ extern char *sunpro_static_transform_nam
 
 #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 */
diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/config/i386/tm-i386v42mp.h /saguaro1/sourceware-ptid-phase3/src/gdb/config/i386/tm-i386v42mp.h
--- /saguaro1/sourceware-ptid-phase2/src/gdb/config/i386/tm-i386v42mp.h	Fri Apr 27 16:04:46 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/config/i386/tm-i386v42mp.h	Thu May  3 22:17:03 2001
@@ -30,6 +30,7 @@
 
 #define UNIXWARE
 
+#if 0
 /* The following macros extract process and lwp/thread ids from a
    composite id.
 
@@ -43,8 +44,7 @@
 #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)
@@ -61,5 +61,33 @@
 
 /* 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 */
diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/config/nm-linux.h /saguaro1/sourceware-ptid-phase3/src/gdb/config/nm-linux.h
--- /saguaro1/sourceware-ptid-phase2/src/gdb/config/nm-linux.h	Fri Apr 27 13:30:45 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/config/nm-linux.h	Thu May  3 22:17:03 2001
@@ -49,14 +49,6 @@ extern int linuxthreads_prepare_to_proce
 /* 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.  */
 
diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/config/sparc/tm-sun4sol2.h /saguaro1/sourceware-ptid-phase3/src/gdb/config/sparc/tm-sun4sol2.h
--- /saguaro1/sourceware-ptid-phase2/src/gdb/config/sparc/tm-sun4sol2.h	Fri Apr 27 16:00:48 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/config/sparc/tm-sun4sol2.h	Thu May  3 22:17:03 2001
@@ -80,9 +80,3 @@ extern char *sunpro_static_transform_nam
 
 /* 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))
diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/corelow.c /saguaro1/sourceware-ptid-phase3/src/gdb/corelow.c
--- /saguaro1/sourceware-ptid-phase2/src/gdb/corelow.c	Sun Apr 29 12:05:25 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/corelow.c	Thu May  3 22:17:03 2001
@@ -248,14 +248,7 @@ add_to_thread_list (bfd *abfd, asection 
 
   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.  */
@@ -413,16 +406,8 @@ get_core_register_section (char *name,
   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);
 
diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/defs.h /saguaro1/sourceware-ptid-phase3/src/gdb/defs.h
--- /saguaro1/sourceware-ptid-phase2/src/gdb/defs.h	Thu Apr 26 00:38:29 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/defs.h	Fri May  4 01:22:54 2001
@@ -844,36 +844,37 @@ enum val_prettyprint
     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 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).  */
 
-   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.  */
+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;
 
 
 
@@ -1391,15 +1392,16 @@ extern int use_windows;
 #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.  */
diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/i386-linux-nat.c /saguaro1/sourceware-ptid-phase3/src/gdb/i386-linux-nat.c
--- /saguaro1/sourceware-ptid-phase2/src/gdb/i386-linux-nat.c	Fri Apr 27 17:12:36 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/i386-linux-nat.c	Thu May  3 22:17:03 2001
@@ -61,17 +61,6 @@
 /* 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
 
 
 /* The register sets used in Linux ELF core-dumps are identical to the
diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/inferior.h /saguaro1/sourceware-ptid-phase3/src/gdb/inferior.h
--- /saguaro1/sourceware-ptid-phase2/src/gdb/inferior.h	Thu May  3 22:20:57 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/inferior.h	Thu May  3 22:20:07 2001
@@ -51,6 +51,33 @@ extern void write_inferior_status_regist
 					    *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.  */
diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/infptrace.c /saguaro1/sourceware-ptid-phase3/src/gdb/infptrace.c
--- /saguaro1/sourceware-ptid-phase2/src/gdb/infptrace.c	Wed Apr 25 19:31:43 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/infptrace.c	Thu May  3 22:17:03 2001
@@ -110,22 +110,6 @@ static void fetch_register (int);
 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);
 
diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/infrun.c /saguaro1/sourceware-ptid-phase3/src/gdb/infrun.c
--- /saguaro1/sourceware-ptid-phase2/src/gdb/infrun.c	Fri May  4 00:07:32 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/infrun.c	Thu May  3 22:34:12 2001
@@ -4192,7 +4192,67 @@ discard_inferior_status (struct inferior
   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)
@@ -4400,4 +4460,10 @@ instruction of that function. Otherwise,
 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;
 }
diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/lin-lwp.c /saguaro1/sourceware-ptid-phase3/src/gdb/lin-lwp.c
--- /saguaro1/sourceware-ptid-phase2/src/gdb/lin-lwp.c	Fri May  4 00:11:04 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/lin-lwp.c	Thu May  3 22:17:03 2001
@@ -102,18 +102,10 @@ static int num_lwps;
 static int threaded;
 
 
-#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))
 
@@ -628,7 +620,7 @@ lin_lwp_wait (ptid_t ptid, struct target
       if (debug_lin_lwp)
 	fprintf_unfiltered (gdb_stdlog, 
 			    "Waiting for specific LWP %d.\n",
-			    GET_LWP (ptid));
+			    (int) GET_LWP (ptid));
 
       /* We have a specific LWP to check.  */
       lp = find_lwp_pid (ptid);
@@ -640,7 +632,7 @@ lin_lwp_wait (ptid_t ptid, struct target
 	if (status)
 	  fprintf_unfiltered (gdb_stdlog, 
 			      "Using pending wait status for LWP %d.\n",
-			      GET_LWP (lp->ptid));
+			      (int) GET_LWP (lp->ptid));
 
       /* If we have to wait, take into account whether PID is a cloned
          process or not.  And we have to convert it to something that
diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/lin-thread.c /saguaro1/sourceware-ptid-phase3/src/gdb/lin-thread.c
--- /saguaro1/sourceware-ptid-phase2/src/gdb/lin-thread.c	Thu May  3 21:58:01 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/lin-thread.c	Thu May  3 22:17:03 2001
@@ -125,21 +125,25 @@
 /* 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.
diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/proc-service.c /saguaro1/sourceware-ptid-phase3/src/gdb/proc-service.c
--- /saguaro1/sourceware-ptid-phase2/src/gdb/proc-service.c	Thu May  3 22:52:22 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/proc-service.c	Thu May  3 21:58:01 2001
@@ -51,10 +51,6 @@ typedef size_t gdb_ps_size_t;
 
 /* Building process ids.  */
 
-#ifndef MERGEPID
-#define MERGEPID(PID, TID)	(((PID) & 0xffff) | ((TID) << 16))
-#endif
-
 #define BUILD_LWP(tid, pid)	MERGEPID (pid, tid)
 
 
diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/procfs.c /saguaro1/sourceware-ptid-phase3/src/gdb/procfs.c
--- /saguaro1/sourceware-ptid-phase2/src/gdb/procfs.c	Wed Apr 25 19:31:43 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/procfs.c	Thu May  3 22:36:48 2001
@@ -315,18 +315,6 @@ typedef prstatus_t gdb_prstatus_t;
 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    */
diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/sol-thread.c /saguaro1/sourceware-ptid-phase3/src/gdb/sol-thread.c
--- /saguaro1/sourceware-ptid-phase2/src/gdb/sol-thread.c	Thu May  3 21:58:01 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/sol-thread.c	Thu May  3 22:17:03 2001
@@ -111,14 +111,15 @@ static void init_sol_core_ops (void);
 /* 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 GET_PID(ptid)		ptid_get_pid (ptid)
+#define GET_LWP(ptid)		ptid_get_lwp (ptid)
+#define GET_THREAD(ptid)	ptid_get_tid (ptid)
 
-#define BUILD_THREAD(TID, PID)	(MERGEPID (PID, TID) | THREAD_FLAG)
+#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() */
 
diff -upr /saguaro1/sourceware-ptid-phase2/src/gdb/thread-db.c /saguaro1/sourceware-ptid-phase3/src/gdb/thread-db.c
--- /saguaro1/sourceware-ptid-phase2/src/gdb/thread-db.c	Thu May  3 21:58:01 2001
+++ /saguaro1/sourceware-ptid-phase3/src/gdb/thread-db.c	Thu May  3 22:17:03 2001
@@ -122,24 +122,17 @@ static void thread_db_find_new_threads (
 
 /* 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)
 
 
 struct private_thread_info



More information about the Gdb-patches mailing list