From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org
Subject: [4/7] Adjust the ttrace target (HP-UX) to always register the main thread
Date: Fri, 08 Aug 2008 01:36:00 -0000 [thread overview]
Message-ID: <200808080236.55396.pedro@codesourcery.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 643 bytes --]
This patch adjusts the inf-ttrace target to always register the main
thread in GDB's thread table. Again, I'm using the new thread_change_ptid
function to update inferior_ptid.
( I haven't touched the hpux-thread.c target, as it is still
waiting for someone to rewrite it as a thread_stratum target, and
remove its dependency on deprecated_child_ops. That is, it's dead broken
code currently. While we're on to it, does anyone still care for
HP-UX / ptrace (not ttrace) ? )
I have no means to test this. Can anybody with HP-UX access check
if I didn't break anything? This patch only depends on patch 1 of
the series.
--
Pedro Alves
[-- Attachment #2: 004-ttrace_always_a_thread.diff --]
[-- Type: text/x-diff, Size: 5413 bytes --]
2008-08-08 Pedro Alves <pedro@codesourcery.com>
* inf-ttrace.c (inf_ttrace_follow_fork): Register the main thread
of the child fork.
(inf_ttrace_attach): Add the main thread.
(inf_ttrace_resume_callback): Check for exited threads. Adjust
for always a thread.
(inf_ttrace_wait): Decorate the main thread's ptid with lwp info
using thread_change_ptid. Don't add the main thread here.
(inf_ttrace_pid_to_str): Adjust.
---
gdb/inf-ttrace.c | 78 +++++++++++++++++++++++++++++++++----------------------
1 file changed, 47 insertions(+), 31 deletions(-)
Index: src/gdb/inf-ttrace.c
===================================================================
--- src.orig/gdb/inf-ttrace.c 2008-08-05 19:40:06.000000000 +0100
+++ src/gdb/inf-ttrace.c 2008-08-05 23:04:02.000000000 +0100
@@ -513,10 +513,22 @@ Detaching after fork from child process
if (follow_child)
{
+ struct thread_info *ti;
+
/* The child will start out single-threaded. */
- inf_ttrace_num_lwps = 0;
+ inf_ttrace_num_lwps = 1;
inf_ttrace_num_lwps_in_syscall = 0;
+ /* Delete parent. */
+ delete_thread_silent (ptid_build (pid, lwpid, 0);
+
+ /* Add child. inferior_ptid was already set above. */
+ ti = add_thread_silent (inferior_ptid);
+ ti->private =
+ xmalloc (sizeof (struct inf_ttrace_private_thread_info));
+ memset (ti->private, 0,
+ sizeof (struct inf_ttrace_private_thread_info));
+
/* Reset breakpoints in the child as appropriate. */
follow_inferior_reset_breakpoints ();
}
@@ -675,6 +687,7 @@ inf_ttrace_attach (char *args, int from_
pid_t pid;
char *dummy;
ttevent_t tte;
+ struct thread_info *ti;
if (!args)
error_no_arg (_("process-id to attach"));
@@ -721,8 +734,18 @@ inf_ttrace_attach (char *args, int from_
(uintptr_t)&tte, sizeof tte, 0) == -1)
perror_with_name (("ttrace"));
- inferior_ptid = pid_to_ptid (pid);
push_target (ttrace_ops_hack);
+
+ /* We'll bump inf_ttrace_num_lwps up 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);
+ ti = add_thread_silent (inferior_ptid);
+ ti->private =
+ xmalloc (sizeof (struct inf_ttrace_private_thread_info));
+ memset (ti->private, 0,
+ sizeof (struct inf_ttrace_private_thread_info));
}
static void
@@ -787,7 +810,7 @@ inf_ttrace_kill (void)
static int
inf_ttrace_resume_callback (struct thread_info *info, void *arg)
{
- if (!ptid_equal (info->ptid, inferior_ptid))
+ if (!ptid_equal (info->ptid, inferior_ptid) && !is_exited (info->ptid))
{
pid_t pid = ptid_get_pid (info->ptid);
lwpid_t lwpid = ptid_get_lwp (info->ptid);
@@ -824,7 +847,7 @@ inf_ttrace_resume (ptid_t ptid, int step
if (ttrace (request, pid, lwpid, TT_NOPC, sig, 0) == -1)
perror_with_name (("ttrace"));
- if (ptid_equal (ptid, minus_one_ptid) && inf_ttrace_num_lwps > 0)
+ if (ptid_equal (ptid, minus_one_ptid))
{
/* Let all the other threads run too. */
iterate_over_threads (inf_ttrace_resume_callback, NULL);
@@ -886,6 +909,16 @@ inf_ttrace_wait (ptid_t ptid, struct tar
ptid = ptid_build (tts.tts_pid, tts.tts_lwpid, 0);
+ if (inf_ttrace_num_lwps == 0)
+ {
+ inf_ttrace_num_lwps = 1;
+
+ /* This is the earliest we hear about the lwp member of
+ INFERIOR_PTID, after an attach or fork-child. */
+ if (ptid_get_lwp (inferior_ptid) == 0)
+ thread_change_ptid (inferior_ptid, ptid);
+ }
+
switch (tts.tts_event)
{
#ifdef TTEVT_BPT_SSTEP
@@ -958,17 +991,6 @@ inf_ttrace_wait (ptid_t ptid, struct tar
case TTEVT_LWP_CREATE:
lwpid = tts.tts_u.tts_thread.tts_target_lwpid;
ptid = ptid_build (tts.tts_pid, lwpid, 0);
- if (inf_ttrace_num_lwps == 0)
- {
- /* Now that we're going to be multi-threaded, add the
- original thread to the list first. */
- ti = add_thread (ptid_build (tts.tts_pid, tts.tts_lwpid, 0));
- ti->private =
- xmalloc (sizeof (struct inf_ttrace_private_thread_info));
- memset (ti->private, 0,
- sizeof (struct inf_ttrace_private_thread_info));
- inf_ttrace_num_lwps++;
- }
ti = add_thread (ptid);
ti->private =
xmalloc (sizeof (struct inf_ttrace_private_thread_info));
@@ -1045,11 +1067,6 @@ inf_ttrace_wait (ptid_t ptid, struct tar
if (ttrace (TT_PROC_STOP, tts.tts_pid, 0, 0, 0, 0) == -1)
perror_with_name (("ttrace"));
- /* HACK: Twiddle INFERIOR_PTID such that the initial thread of a
- process isn't recognized as a new thread. */
- if (ptid_get_lwp (inferior_ptid) == 0)
- inferior_ptid = ptid;
-
return ptid;
}
@@ -1128,18 +1145,17 @@ inf_ttrace_thread_alive (ptid_t ptid)
static char *
inf_ttrace_pid_to_str (ptid_t ptid)
{
- if (inf_ttrace_num_lwps > 0)
- {
- pid_t pid = ptid_get_pid (ptid);
- lwpid_t lwpid = ptid_get_lwp (ptid);
- static char buf[128];
-
- xsnprintf (buf, sizeof buf, "process %ld, lwp %ld",
- (long)pid, (long)lwpid);
- return buf;
- }
+ pid_t pid = ptid_get_pid (ptid);
+ lwpid_t lwpid = ptid_get_lwp (ptid);
+ static char buf[128];
- return normal_pid_to_str (ptid);
+ if (lwpid == 0)
+ xsnprintf (buf, sizeof buf, "process %ld",
+ (long) pid);
+ else
+ xsnprintf (buf, sizeof buf, "process %ld, lwp %ld",
+ (long) pid, (long) lwpid);
+ return buf;
}
\f
next reply other threads:[~2008-08-08 1:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-08 1:36 Pedro Alves [this message]
2008-08-08 16:41 ` John David Anglin
2008-08-08 17:24 ` Pedro Alves
2008-08-08 17:49 ` John David Anglin
2008-08-08 18:34 ` ttrace: Protocal error John David Anglin
2008-08-08 20:02 ` Pedro Alves
2008-08-08 20:49 ` John David Anglin
2008-08-10 0:15 ` [4/7] Adjust the ttrace target (HP-UX) to always register the main thread Daniel Jacobowitz
2008-08-10 0:36 ` [4/7] Adjust the ttrace target (HP-UX) to always register the John David Anglin
2008-08-10 21:05 ` Pedro Alves
2008-08-10 21:16 ` John David Anglin
2008-08-10 21:04 ` John David Anglin
2008-08-14 17:55 ` Daniel Jacobowitz
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=200808080236.55396.pedro@codesourcery.com \
--to=pedro@codesourcery.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