Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Cc: Joel Brobecker <brobecker@adacore.com>
Subject: [PATCH 5/8] inf-ttrace: Determine attached process LWP immediately after attaching.
Date: Tue, 28 Dec 2010 04:44:00 -0000	[thread overview]
Message-ID: <1293511386-7384-6-git-send-email-brobecker@adacore.com> (raw)
In-Reply-To: <1293511386-7384-1-git-send-email-brobecker@adacore.com>

When attaching to a process, the ttrace interface was creating a ptid
with a null LWP, because it did not have it yet.  This LWP was then
set as soon as we received our first event from our inferior, during
our first wait.  Similarly, the allocation of the thread private info
was also defered.

This works on PA/HP-UX, because we immediately perform a wait to pop
the event triggered by the attach.  We can use that event to extract
the thread's LWP.  But this does not work for IA64/HP-UX, because
the attach no longer triggers an event, and thus a wait should NOT
be performed (such a wait would simply block indefinitely).

It is actually possible, however, to determine the thread's LWP.
This change therefore adjusts the attach code to create a thread with
the correct LWP set, as well as with its private info allocated.
Same thing for all the other threads.

gdb/ChangeLog:

        [ttrace] Compute thread list immediately after attach.
        * inf_ttrace_attach (inf_ttrace_create_threads_after_attach):
        New subprogram.
        (inf_ttrace_attach): Use it.

---
 gdb/inf-ttrace.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/gdb/inf-ttrace.c b/gdb/inf-ttrace.c
index fd394c6..24dc0f9 100644
--- a/gdb/inf-ttrace.c
+++ b/gdb/inf-ttrace.c
@@ -688,6 +688,53 @@ inf_ttrace_mourn_inferior (struct target_ops *ops)
   generic_mourn_inferior ();
 }
 
+/* Assuming we just attached the debugger to a new inferior, create
+   a new thread_info structure for each thread, and add it to our
+   list of threads.  */
+
+static void
+inf_ttrace_create_threads_after_attach (int pid)
+{
+  int status;
+  ptid_t ptid;
+  ttstate_t tts;
+  struct thread_info *ti;
+
+  status = ttrace (TT_PROC_GET_FIRST_LWP_STATE, pid, 0,
+		   (uintptr_t) &tts, sizeof (ttstate_t), 0);
+  if (status < 0)
+    perror_with_name (_("TT_PROC_GET_FIRST_LWP_STATE ttrace call failed"));
+  gdb_assert (tts.tts_pid == pid);
+
+  /* Add the stopped thread.  */
+  ptid = ptid_build (pid, tts.tts_lwpid, 0);
+  ti = add_thread (ptid);
+  ti->private = xzalloc (sizeof (struct inf_ttrace_private_thread_info));
+  inf_ttrace_num_lwps++;
+
+  /* We use the "first stopped thread" as the currently active thread.  */
+  inferior_ptid = ptid;
+
+  /* Iterative over all the remaining threads.  */
+
+  for (;;)
+    {
+      ptid_t ptid;
+
+      status = ttrace (TT_PROC_GET_NEXT_LWP_STATE, pid, 0,
+		       (uintptr_t) &tts, sizeof (ttstate_t), 0);
+      if (status < 0)
+	perror_with_name (_("TT_PROC_GET_NEXT_LWP_STATE ttrace call failed"));
+      if (status == 0)
+        break;  /* End of list.  */
+
+      ptid = ptid_build (tts.tts_pid, tts.tts_lwpid, 0);
+      ti = add_thread (ptid);
+      ti->private = xzalloc (sizeof (struct inf_ttrace_private_thread_info));
+      inf_ttrace_num_lwps++;
+    }
+}
+
 static void
 inf_ttrace_attach (struct target_ops *ops, char *args, int from_tty)
 {
@@ -740,11 +787,7 @@ inf_ttrace_attach (struct target_ops *ops, char *args, int from_tty)
 
   push_target (ops);
 
-  /* We'll bump inf_ttrace_num_lwps up and add the private data to the
-     thread as soon as we get to inf_ttrace_wait.  At this point, we
-     don't have lwpid info yet.  */
-  inferior_ptid = pid_to_ptid (pid);
-  add_thread_silent (inferior_ptid);
+  inf_ttrace_create_threads_after_attach (pid);
 }
 
 static void
-- 
1.7.1


  parent reply	other threads:[~2010-12-28  4:43 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-28  4:43 Porting GDB to ia64-hpux Joel Brobecker
2010-12-28  4:43 ` [PATCH 4/8] libunwind-frame.c: handle functions with no minimal symbol/debug info Joel Brobecker
2010-12-28  4:43 ` [PATCH 1/8] Add a big-endian version of the ia64-ext floatformat Joel Brobecker
2010-12-28  4:43 ` [PATCH 2/8] small integral parameters and return values Joel Brobecker
2010-12-28  4:44 ` [PATCH 3/8] Make sure __LITTLE_ENDIAN/__BIG_ENDIAN are defined in libunwind-frame.c Joel Brobecker
2010-12-28  4:44 ` Joel Brobecker [this message]
2010-12-28 11:04   ` [PATCH 5/8] inf-ttrace: Determine attached process LWP immediately after attaching Pedro Alves
2010-12-28 11:26     ` Joel Brobecker
2010-12-28  4:44 ` [PATCH 6/8] port GDB to ia64-hpux (native) Joel Brobecker
2011-01-11 23:26   ` Steve Ellcey
2011-01-12  1:26     ` Joel Brobecker
2011-01-12 16:57       ` Steve Ellcey
2011-01-12 20:11         ` Joel Brobecker
2011-01-13  1:01     ` Joel Brobecker
2011-01-13  5:13       ` Steve Ellcey
     [not found]       ` <1299014508.30497.20.camel@hpsje.cup.hp.com>
     [not found]         ` <20110302044549.GU2513@adacore.com>
     [not found]           ` <1299171098.30497.88.camel@hpsje.cup.hp.com>
     [not found]             ` <20110303172717.GJ2513@adacore.com>
     [not found]               ` <1299173882.30497.114.camel@hpsje.cup.hp.com>
2011-06-17 16:30                 ` Joel Brobecker
2011-01-13 18:07   ` Joel Brobecker
2010-12-28  4:54 ` [PATCH 7/8] ia64-hpux: unwinding bsp value from system call Joel Brobecker
2010-12-28 11:35   ` Pedro Alves
2010-12-28 12:01     ` Joel Brobecker
2010-12-28 16:17       ` Pedro Alves
2010-12-29  5:49         ` Joel Brobecker
2010-12-29 12:05           ` Pedro Alves
2010-12-29 13:16             ` Joel Brobecker
2010-12-31 18:15             ` Joel Brobecker
2010-12-28 15:29     ` [RFA/commit] Add documentation for TARGET_OBJECT_OSDATA Joel Brobecker
2010-12-28 15:46       ` Pedro Alves
2010-12-29  3:29       ` Joel Brobecker
2010-12-28  5:00 ` [PATCH 8/8] [ia64-hpux] inferior function call support Joel Brobecker
2010-12-31 19:18   ` Joel Brobecker
2011-01-13 16:53 ` Porting GDB to ia64-hpux Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1293511386-7384-6-git-send-email-brobecker@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox