summaryrefslogtreecommitdiff
path: root/gdb/varobj.c
diff options
context:
space:
mode:
authorLancelot SIX <lancelot.six@amd.com>2022-07-08 11:37:19 +0100
committerLancelot SIX <lsix@lancelotsix.com>2022-07-26 08:27:27 +0100
commit6c96b937df01064526470694da9b6d24761e57fc (patch)
treec7c8f92c90cc142dc259846a8695c191cb4f4fb1 /gdb/varobj.c
parentbc20e562ec0436b6117b989c0e3d8f66c9d4d979 (diff)
downloadbinutils-gdb-6c96b937df01064526470694da9b6d24761e57fc.tar.gz
gdb/varobj: Fix varobj_invalidate_iter
The varobj_invalidate function is meant to be called when restarting a process, and check at this point if some of the previously existing varobj can be recreated in the context of the new process. Two kind of varobj are subject to re-creation: global varobj (i.e. varobj which reference a global variable), and floating varobj (i.e. varobj which are always re-evaluated in the context of whatever is the currently selected frame at the time of evaluation). However, in the re-creation process, the varobj_invalidate_iter recreates floating varobj as non-floating, due to an invalid parameter. This patches fixes this and adds an assertion to check that if a varobj is indeed recreated, it matches the original varobj "floating" property. Another issue is that if at this recreation time the expression watched by the floating varobj is not in scope, then the varobj is marked as invalid. If later the user selects a frame where the expression becomes valid, the varobj remains invalid and this is wrong. This patch also make sure that floating varobj are not invalidated if they cannot be evaluated. The last important thing to note is that due to the previous patch, when varobj_invalidate is executed (in the context of a new process), any global var have already been invalidated (this has been done when the objfile it referred to got invalidated). As a consequence, varobj_invalidate tries to recreate vars which are already marked as invalid. This does not entirely feels right, but I keep this behavior for backward compatibility. Tested on x86_64-linux
Diffstat (limited to 'gdb/varobj.c')
-rw-r--r--gdb/varobj.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 2b6dfff6888..e558794617a 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -2359,22 +2359,28 @@ static void
varobj_invalidate_iter (struct varobj *var)
{
/* global and floating var must be re-evaluated. */
- if (var->root->floating || var->root->valid_block == NULL)
+ if (var->root->floating || var->root->valid_block == nullptr)
{
struct varobj *tmp_var;
/* Try to create a varobj with same expression. If we succeed
replace the old varobj, otherwise invalidate it. */
- tmp_var = varobj_create (NULL, var->name.c_str (), (CORE_ADDR) 0,
- USE_CURRENT_FRAME);
- if (tmp_var != NULL)
- {
+ tmp_var = varobj_create (nullptr, var->name.c_str (), (CORE_ADDR) 0,
+ var->root->floating
+ ? USE_SELECTED_FRAME : USE_CURRENT_FRAME);
+ if (tmp_var != nullptr)
+ {
+ gdb_assert (var->root->floating == tmp_var->root->floating);
tmp_var->obj_name = var->obj_name;
varobj_delete (var, 0);
install_variable (tmp_var);
}
- else
- var->root->is_valid = false;
+ else if (!var->root->floating)
+ {
+ /* Only invalidate globals as floating vars might still be valid in
+ some other frame. */
+ var->root->is_valid = false;
+ }
}
else /* locals must be invalidated. */
var->root->is_valid = false;