This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] wait_for_inferior and errors thrown from target_wait


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e6f5c25b57546cbd88daccea4f1739c3f90f7560

commit e6f5c25b57546cbd88daccea4f1739c3f90f7560
Author: Pedro Alves <palves@redhat.com>
Date:   Wed Apr 1 14:58:56 2015 +0100

    wait_for_inferior and errors thrown from target_wait
    
    Noticed that if an error is thrown out of target_wait, we miss running
    finish_thread_state_cleanup.
    
    Tested on x86_64 Fedora 20, with "maint set target-async off".
    
    gdb/ChangeLog:
    2015-04-01  Pedro Alves  <palves@redhat.com>
    
    	* infrun.c (wait_for_inferior): Install the
    	finish_thread_state_cleanup cleanup across the whole function, not
    	just around handle_inferior_event.

Diff:
---
 gdb/ChangeLog |  6 ++++++
 gdb/infrun.c  | 18 +++++++++---------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5353e34..8e1bd11 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 2015-04-01  Pedro Alves  <palves@redhat.com>
 
+	* infrun.c (wait_for_inferior): Install the
+	finish_thread_state_cleanup cleanup across the whole function, not
+	just around handle_inferior_event.
+
+2015-04-01  Pedro Alves  <palves@redhat.com>
+
 	* infrun.c (resume) <step past permanent breakpoint>: Use
 	do_target_resume.
 
diff --git a/gdb/infrun.c b/gdb/infrun.c
index d7c250e..18ce036 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -3132,6 +3132,7 @@ void
 wait_for_inferior (void)
 {
   struct cleanup *old_cleanups;
+  struct cleanup *thread_state_chain;
 
   if (debug_infrun)
     fprintf_unfiltered
@@ -3141,11 +3142,15 @@ wait_for_inferior (void)
     = make_cleanup (delete_just_stopped_threads_infrun_breakpoints_cleanup,
 		    NULL);
 
+  /* If an error happens while handling the event, propagate GDB's
+     knowledge of the executing state to the frontend/user running
+     state.  */
+  thread_state_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
+
   while (1)
     {
       struct execution_control_state ecss;
       struct execution_control_state *ecs = &ecss;
-      struct cleanup *old_chain;
       ptid_t waiton_ptid = minus_one_ptid;
 
       memset (ecs, 0, sizeof (*ecs));
@@ -3166,21 +3171,16 @@ wait_for_inferior (void)
       if (debug_infrun)
 	print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
 
-      /* If an error happens while handling the event, propagate GDB's
-	 knowledge of the executing state to the frontend/user running
-	 state.  */
-      old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
-
       /* Now figure out what to do with the result of the result.  */
       handle_inferior_event (ecs);
 
-      /* No error, don't finish the state yet.  */
-      discard_cleanups (old_chain);
-
       if (!ecs->wait_some_more)
 	break;
     }
 
+  /* No error, don't finish the state yet.  */
+  discard_cleanups (thread_state_chain);
+
   do_cleanups (old_cleanups);
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]