From: Jerome Guitton <guitton@adacore.com>
To: gdb-patches@sourceware.org
Subject: [RFA/hpux] acknowledging TTEVT_LWP_EXIT
Date: Tue, 18 Sep 2007 09:48:00 -0000 [thread overview]
Message-ID: <20070918094806.GA1859@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1353 bytes --]
In inf-ttrace, when a TTEVT_LWP_EXIT event is received (thread
exiting), the corresponding thread is removed from the thread list
and never resumed. Which is wrong ; the ttrace man page reads:
TTEVT_LWP_EXIT This event flag indicates that the debugger wants to
be notified when a thread is exiting via the
lwp_exit() system call. The thread stops upon entry
to the system call.
So the dying thread is stopped, it should be resumed one last time.
Otherwise, any other thread waiting for its death on pthread_join
would be blocked forever (e.g. in attachment, a simple program which
freezes when it is run under GDB).
Also in attachement, a patch that fixes this issue. It also fixes 3
unexpected failures of the testsuite on HPUX 11.11.
2007-09-18 Jerome Guitton <guitton@adacore.com>
* inf-ttrace.c (inf_ttrace_private_thread_info): New structure type.
(inf_ttrace_delete_dying_threads_callback): New function.
(inf_ttrace_resume): After resuming the execution, iterate over
the dying threads to delete them for the thread list.
(inf_ttrace_wait): on TTEVT_LWP_EXIT and TTEVT_LWP_TERMINATE,
mark the corresponding thread as dying instead of removing it
from the thread list.
(inf_ttrace_thread_alive): return 0 for dying threads.
[-- Attachment #2: inf-ttrace.c.diff --]
[-- Type: text/x-diff, Size: 3723 bytes --]
Index: inf-ttrace.c
===================================================================
RCS file: /cvs/src/src/gdb/inf-ttrace.c,v
retrieving revision 1.23
diff -u -p -r1.23 inf-ttrace.c
--- inf-ttrace.c 23 Aug 2007 18:08:35 -0000 1.23
+++ inf-ttrace.c 17 Sep 2007 16:02:42 -0000
@@ -76,6 +76,11 @@ struct inf_ttrace_page_dict
int count; /* Number of pages in this dictionary. */
} inf_ttrace_page_dict;
+struct inf_ttrace_private_thread_info
+{
+ int dying;
+};
+
/* Number of lwps that are currently in a system call. */
static int inf_ttrace_num_lwps_in_syscall;
@@ -794,6 +799,14 @@ inf_ttrace_resume_callback (struct threa
return 0;
}
+static int
+inf_ttrace_delete_dying_threads_callback (struct thread_info *info, void *arg)
+{
+ if (((struct inf_ttrace_private_thread_info *)info->private)->dying == 1)
+ delete_thread (info->ptid);
+ return 0;
+}
+
static void
inf_ttrace_resume (ptid_t ptid, int step, enum target_signal signal)
{
@@ -815,6 +828,7 @@ inf_ttrace_resume (ptid_t ptid, int step
{
/* Let all the other threads run too. */
iterate_over_threads (inf_ttrace_resume_callback, NULL);
+ iterate_over_threads (inf_ttrace_delete_dying_threads_callback, NULL);
}
}
@@ -824,6 +838,7 @@ inf_ttrace_wait (ptid_t ptid, struct tar
pid_t pid = ptid_get_pid (ptid);
lwpid_t lwpid = ptid_get_lwp (ptid);
ttstate_t tts;
+ struct thread_info *ti;
/* Until proven otherwise. */
ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
@@ -940,19 +955,31 @@ inf_ttrace_wait (ptid_t ptid, struct tar
{
/* Now that we're going to be multi-threaded, add the
original thread to the list first. */
- add_thread (ptid_build (tts.tts_pid, tts.tts_lwpid, 0));
+ 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++;
}
printf_filtered (_("[New %s]\n"), target_pid_to_str (ptid));
- add_thread (ptid);
+ ti = add_thread (ptid);
+ 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++;
ptid = ptid_build (tts.tts_pid, tts.tts_lwpid, 0);
break;
case TTEVT_LWP_EXIT:
printf_filtered(_("[%s exited]\n"), target_pid_to_str (ptid));
- delete_thread (ptid);
+ ti = find_thread_pid (ptid);
+ gdb_assert (ti != NULL);
+ ((struct inf_ttrace_private_thread_info *)ti->private)->dying = 1;
inf_ttrace_num_lwps--;
+ ttrace (TT_LWP_CONTINUE, ptid_get_pid (ptid),
+ ptid_get_lwp (ptid), TT_NOPC, 0, 0);
/* If we don't return -1 here, core GDB will re-add the thread. */
ptid = minus_one_ptid;
break;
@@ -961,7 +988,9 @@ inf_ttrace_wait (ptid_t ptid, struct tar
lwpid = tts.tts_u.tts_thread.tts_target_lwpid;
ptid = ptid_build (tts.tts_pid, lwpid, 0);
printf_filtered(_("[%s has been terminated]\n"), target_pid_to_str (ptid));
- delete_thread (ptid);
+ ti = find_thread_pid (ptid);
+ gdb_assert (ti != NULL);
+ ((struct inf_ttrace_private_thread_info *)ti->private)->dying = 1;
inf_ttrace_num_lwps--;
ptid = ptid_build (tts.tts_pid, tts.tts_lwpid, 0);
break;
@@ -1084,7 +1113,9 @@ inf_ttrace_files_info (struct target_ops
static int
inf_ttrace_thread_alive (ptid_t ptid)
{
- return 1;
+ struct thread_info *ti;
+ ti = find_thread_pid (ptid);
+ return !(((struct inf_ttrace_private_thread_info *)ti->private)->dying);
}
static char *
[-- Attachment #3: my_lock.c --]
[-- Type: text/x-csrc, Size: 373 bytes --]
# include <pthread.h>
static void *
dummy_thread_func (void *arg)
{
return arg;
}
void
glthread_in_use (void)
{
pthread_t thread;
if (!pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0)
{
void *retval;
if (pthread_join (thread, &retval) != 0)
{
abort ();
}
}
}
void
main ()
{
glthread_in_use();
}
next reply other threads:[~2007-09-18 9:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-18 9:48 Jerome Guitton [this message]
2007-09-18 10:20 ` Mark Kettenis
2007-09-18 12:44 ` Jerome Guitton
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=20070918094806.GA1859@adacore.com \
--to=guitton@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