Re: ttrace: Protocal error

Pedro Alves
2008-08-09T22:48:55Z

[-- Attachment #1: Type: text/plain, Size: 660 bytes --]

On Saturday 09 August 2008 15:51:16, Pedro Alves wrote:
> Also, when we detect a TTEVT_LWP_CREATE, TTEVT_LWP_EXIT or
> TTEVT_LWP_TERMINATE, The ttrace docs indicate that only one lwp is
> stopped.  There's no reason to stop all lwps, and return
> TARGET_WAITKING_SPURIOUS, only to resume all lwps again.
> This just adds overhead and messes more with the
> scheduling of the inferior than needed.  We could just resume
> the stopped lwp, and return TARGET_WAITKIND_IGNORE.

Here's a patch to do this. It applies on top of the other I just sent,
which itself applied on top of my other patch to always register
the main thread.

--
Pedro Alves

[-- Attachment #2: fix_daves_bug_part_2.diff --]
[-- Type: text/x-diff, Size: 2720 bytes --]

2008-08-09 Pedro Alves <pedro@codesourcery.com>

* inf-ttrace.c (inf_ttrace_wait): On TTEVT_LWP_CREATE and
LWP_TERMINATE, resume the caller thread. On TTEVT_LWP_CREATE,
TTEVT_LWP_EXIT and TTEVT_LWP_TERMINATE, don't stop the whole
process, and return TARGET_WAITKIND_IGNORE.

---
gdb/inf-ttrace.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)

Index: src/gdb/inf-ttrace.c
===================================================================
--- src.orig/gdb/inf-ttrace.c 2008-08-09 23:15:40.000000000 +0100
+++ src/gdb/inf-ttrace.c 2008-08-09 23:15:53.000000000 +0100
@@ -1041,7 +1041,12 @@ inf_ttrace_wait (ptid_t ptid, struct tar
sizeof (struct inf_ttrace_private_thread_info));
inf_ttrace_num_lwps++;
ptid = ptid_build (tts.tts_pid, tts.tts_lwpid, 0);
- break;
+ /* Let the lwp_create-caller thread continue. */
+ ttrace (TT_LWP_CONTINUE, ptid_get_pid (ptid),
+ ptid_get_lwp (ptid), TT_NOPC, 0, 0);
+ /* Return without stopping the whole process. */
+ ourstatus->kind = TARGET_WAITKIND_IGNORE;
+ return ptid;

case TTEVT_LWP_EXIT:
if (print_thread_events)
@@ -1050,22 +1055,31 @@ inf_ttrace_wait (ptid_t ptid, struct tar
gdb_assert (ti != NULL);
((struct inf_ttrace_private_thread_info *)ti->private)->dying = 1;
inf_ttrace_num_lwps--;
+ /* Let the thread really exit. */
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;
+ /* Return without stopping the whole process. */
+ ourstatus->kind = TARGET_WAITKIND_IGNORE;
+ return ptid;

case TTEVT_LWP_TERMINATE:
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));
+ if (print_thread_events)
+ printf_unfiltered(_("[%s has been terminated]\n")
+ target_pid_to_str (ptid));
ti = find_thread_pid (ptid);
gdb_assert (ti != NULL);
((struct inf_ttrace_private_thread_info *)ti->private)->dying = 1;
inf_ttrace_num_lwps--;
+
+ /* Resume the lwp_terminate-caller thread. */
ptid = ptid_build (tts.tts_pid, tts.tts_lwpid, 0);
- break;
+ ttrace (TT_LWP_CONTINUE, ptid_get_pid (ptid),
+ ptid_get_lwp (ptid), TT_NOPC, 0, 0);
+ /* Return without stopping the whole process. */
+ ourstatus->kind = TARGET_WAITKIND_IGNORE;
+ return ptid;

case TTEVT_SIGNAL:
ourstatus->kind = TARGET_WAITKIND_STOPPED;