From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11186 invoked by alias); 24 Jan 2008 04:32:01 -0000 Received: (qmail 11150 invoked by uid 22791); 24 Jan 2008 04:31:59 -0000 X-Spam-Check-By: sourceware.org Received: from viper.snap.net.nz (HELO viper.snap.net.nz) (202.37.101.8) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 24 Jan 2008 04:31:33 +0000 Received: from kahikatea.snap.net.nz (32.31.255.123.static.snap.net.nz [123.255.31.32]) by viper.snap.net.nz (Postfix) with ESMTP id 33EBB3DA601 for ; Thu, 24 Jan 2008 17:31:30 +1300 (NZDT) Received: by kahikatea.snap.net.nz (Postfix, from userid 1000) id 8F2C38FC6D; Thu, 24 Jan 2008 17:31:26 +1300 (NZDT) From: Nick Roberts MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <18328.5277.85018.374650@kahikatea.snap.net.nz> Date: Thu, 24 Jan 2008 04:32:00 -0000 To: gdb-patches@sources.redhat.com Subject: [PATCH] Variable objects in multi-threaded programs X-Mailer: VM 7.19 under Emacs 23.0.50.36 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-01/txt/msg00576.txt.bz2 Currently GDB thinks variable objects have gone out of scope if the thread changes. This patch corrects that. --- Nick http://www.inet.net.nz/~nickrob 2008-01-24 Nick Roberts * thread.c (make_cleanup_restore_current_thread) (do_restore_current_thread_cleanup): Don't make static (struct current_thread_cleanup): Move to gdbthread.h * gdbthread.h: Declare above functions as externs here. * varobj.c (look_for_frame): New function. (c_value_of_root): Use it to iterate over threads. *** varobj.c.~1.99.~ 2008-01-04 10:24:29.000000000 +1300 --- varobj.c 2008-01-24 16:42:41.000000000 +1300 *************** *** 24,30 **** --- 24,32 ---- #include "language.h" #include "wrapper.h" #include "gdbcmd.h" + #include "gdbthread.h" #include "block.h" + #include "inferior.h" #include "gdb_assert.h" #include "gdb_string.h" *************** c_path_expr_of_child (struct varobj *chi *** 2153,2164 **** --- 2155,2181 ---- return child->path_expr; } + static int + look_for_frame (struct thread_info *thr, void* arg) + { + struct frame_id *id = arg; + struct frame_info *fi; + switch_to_thread (thr->ptid); + fi = frame_find_by_id (*id); + if (fi) + return 1; + else + return 0; + } + static struct value * c_value_of_root (struct varobj **var_handle) { struct value *new_val = NULL; struct varobj *var = *var_handle; struct frame_info *fi; + struct frame_id saved_frame_id; + struct cleanup *old_cleanups = NULL; int within_scope; /* Only root variables can be updated... */ *************** c_value_of_root (struct varobj **var_han *** 2172,2179 **** within_scope = 1; else { fi = frame_find_by_id (var->root->frame); ! within_scope = fi != NULL; /* FIXME: select_frame could fail */ if (fi) { --- 2189,2203 ---- within_scope = 1; else { + saved_frame_id = get_frame_id (get_selected_frame (NULL)); + old_cleanups + = make_cleanup_restore_current_thread (inferior_ptid, saved_frame_id); + + if (iterate_over_threads (look_for_frame, &var->root->frame)) + within_scope = 1; + fi = frame_find_by_id (var->root->frame); ! /* FIXME: select_frame could fail */ if (fi) { *************** c_value_of_root (struct varobj **var_han *** 2194,2199 **** --- 2218,2225 ---- return new_val; } + do_cleanups (old_cleanups); + return NULL; } *** thread.c.~1.59.~ 2008-01-24 09:47:31.000000000 +1300 --- thread.c 2008-01-24 15:38:41.000000000 +1300 *************** static void info_threads_command (char * *** 60,67 **** static void thread_apply_command (char *, int); static void restore_current_thread (ptid_t); static void prune_threads (void); - static struct cleanup *make_cleanup_restore_current_thread (ptid_t, - struct frame_id); void delete_step_resume_breakpoint (void *arg) --- 60,65 ---- *************** restore_selected_frame (struct frame_id *** 496,508 **** } } ! struct current_thread_cleanup ! { ! ptid_t inferior_ptid; ! struct frame_id selected_frame_id; ! }; ! ! static void do_restore_current_thread_cleanup (void *arg) { struct current_thread_cleanup *old = arg; --- 494,500 ---- } } ! void do_restore_current_thread_cleanup (void *arg) { struct current_thread_cleanup *old = arg; *************** do_restore_current_thread_cleanup (void *** 511,517 **** xfree (old); } ! static struct cleanup * make_cleanup_restore_current_thread (ptid_t inferior_ptid, struct frame_id a_frame_id) { --- 503,509 ---- xfree (old); } ! struct cleanup * make_cleanup_restore_current_thread (ptid_t inferior_ptid, struct frame_id a_frame_id) { *** gdbthread.h.~1.19.~ 2008-01-24 09:47:30.000000000 +1300 --- gdbthread.h 2008-01-24 15:37:19.000000000 +1300 *************** extern void load_infrun_state (ptid_t pt *** 143,148 **** --- 143,159 ---- /* Switch from one thread to another. */ extern void switch_to_thread (ptid_t ptid); + struct current_thread_cleanup + { + ptid_t inferior_ptid; + struct frame_id selected_frame_id; + }; + + extern void do_restore_current_thread_cleanup (void *arg); + + extern struct cleanup * make_cleanup_restore_current_thread + (ptid_t inferior_ptid, struct frame_id a_frame_id); + /* Commands with a prefix of `thread'. */ extern struct cmd_list_element *thread_cmd_list;