+/* If frame associated with VAR can be found, switch
+ to it and return 1. Otherwise, return 0. */
+
+static int
+check_scope (struct varobj *var)
+{
+ struct frame_info *fi;
+ int scope;
+
+ fi = frame_find_by_id (var->root->frame);
+ scope = fi != NULL;
+
+ if (fi)
+ {
+ CORE_ADDR pc = get_frame_pc (fi);
+
+ if (pc < BLOCK_START (var->root->valid_block) ||
+ pc >= BLOCK_END (var->root->valid_block))
+ scope = 0;
+ else
+ select_frame (fi);
+ }
+ return scope;
+}
+
+/* Helper function to value_of_root. */
+
+static struct value *
+value_of_root_1 (struct varobj **var_handle)
+{
+ struct value *new_val = NULL;
+ struct varobj *var = *var_handle;
+ int within_scope = 0;
+ struct cleanup *back_to;
+
+ /* Only root variables can be updated... */
+ if (!is_root_p (var))
+ /* Not a root var. */
+ return NULL;
+
+ back_to = make_cleanup_restore_current_thread ();
+
+ /* Determine whether the variable is still around. */
+ if (var->root->valid_block == NULL || var->root->floating)
+ within_scope = 1;
+ else if (var->root->thread_id == 0)
+ {
+ /* The program was single-threaded when the variable object was
+ created. Technically, it's possible that the program became
+ multi-threaded since then, but we don't support such
+ scenario yet. */
+ within_scope = check_scope (var);
+ }
+ else
+ {
+ ptid_t ptid = thread_id_to_pid (var->root->thread_id);
+ if (in_thread_list (ptid))
+ {
+ switch_to_thread (ptid);
+ within_scope = check_scope (var);
+ }
+ }
+
+ if (within_scope)
+ {
+ volatile struct gdb_exception except;
+
+ /* We need to catch errors here, because if evaluate
+ expression fails we want to just return NULL. */
+ TRY_CATCH (except, RETURN_MASK_ERROR)
+ {
+ new_val = evaluate_expression (var->root->exp);
+ }
+ }
+
+ do_cleanups (back_to);
+
+ return new_val;
+}
+