public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 4/4] Fix bug in -var-evaluate-expression
Date: Fri, 01 Sep 2023 08:47:14 -0600	[thread overview]
Message-ID: <20230901-varobj-fixes-v1-4-b9a1f8139ca7@adacore.com> (raw)
In-Reply-To: <20230901-varobj-fixes-v1-0-b9a1f8139ca7@adacore.com>

This bug points out that if one uses -var-set-visualizer with "None"
-- to disable a pretty-printer for a varobj -- then
-var-evaluate-expression will still use pretty-printing.

This is a combination of bugs.  First, setting the visualizer does not
update the display text; and second, computing the display text should
use "raw" when Python is available but no visualizer is desired.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=11738
---
 gdb/testsuite/gdb.python/py-varobj.c   |  2 ++
 gdb/testsuite/gdb.python/py-varobj.exp | 12 ++++++++++++
 gdb/testsuite/gdb.python/py-varobj.py  |  4 +++-
 gdb/varobj.c                           |  9 +++++++++
 4 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.python/py-varobj.c b/gdb/testsuite/gdb.python/py-varobj.c
index 894ce8fca06..88d0e74b7e0 100644
--- a/gdb/testsuite/gdb.python/py-varobj.c
+++ b/gdb/testsuite/gdb.python/py-varobj.c
@@ -21,6 +21,8 @@ struct test {
 
 struct test tval = {23};
 
+struct test *test_ptr = &tval;
+
 int main () {
   return 0;
 }
diff --git a/gdb/testsuite/gdb.python/py-varobj.exp b/gdb/testsuite/gdb.python/py-varobj.exp
index 0e0978352a5..f1eb35265b0 100644
--- a/gdb/testsuite/gdb.python/py-varobj.exp
+++ b/gdb/testsuite/gdb.python/py-varobj.exp
@@ -47,3 +47,15 @@ mi_gdb_test "-var-create tval * tval" \
 
 mi_gdb_test "-var-list-children --all-values tval" \
     ".*value=.*flicker.*"
+
+mi_gdb_test "-var-create test_ptr * test_ptr" \
+   "\\^done.*"
+
+mi_gdb_test "-var-evaluate-expression test_ptr" \
+   "\\^done,value=\"map\""
+mi_gdb_test "-var-set-visualizer test_ptr None" \
+    "\\^done.*"
+# mi_gdb_test "-var-update test_ptr" ".*"
+mi_gdb_test "-var-evaluate-expression test_ptr" \
+   "\\^done,value=\"$hex.*\"" \
+    "evaluate without visualizer"
diff --git a/gdb/testsuite/gdb.python/py-varobj.py b/gdb/testsuite/gdb.python/py-varobj.py
index bc31a198297..578ad14d4df 100644
--- a/gdb/testsuite/gdb.python/py-varobj.py
+++ b/gdb/testsuite/gdb.python/py-varobj.py
@@ -12,6 +12,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+import gdb
 import gdb.printing
 
 
@@ -30,6 +31,7 @@ def str_lookup_function(val):
     lookup_tag = val.type.tag
     if lookup_tag == "test":
         return TestPrinter(val)
-
+    if val.type.code == gdb.TYPE_CODE_PTR and val.type.target().tag == "test":
+        return TestPrinter(val.dereference())
 
 gdb.printing.register_pretty_printer(None, str_lookup_function)
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 3ae8d728e82..a4fcbffc311 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -1393,6 +1393,9 @@ varobj_set_visualizer (struct varobj *var, const char *visualizer)
   /* If there are any children now, wipe them.  */
   varobj_delete (var, 1 /* children only */);
   var->num_children = -1;
+
+  /* Also be sure to reset the print value.  */
+  varobj_set_display_format (var, var->format);
 #else
   error (_("Python support required"));
 #endif
@@ -2212,6 +2215,12 @@ varobj_value_get_print_value (struct value *value,
 		return "{...}";
 	    }
 	}
+      else
+	{
+	  /* If we've made it here, we don't want a pretty-printer --
+	     if we had one, it would already have been used.  */
+	  opts.raw = true;
+	}
     }
 #endif
 

-- 
2.40.1


  parent reply	other threads:[~2023-09-01 14:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-01 14:47 [PATCH 0/4] Fix two varobj bugs Tom Tromey
2023-09-01 14:47 ` [PATCH 1/4] Allow pretty-printer 'children' method to return strings Tom Tromey
2023-09-01 14:47 ` [PATCH 2/4] Remove dead code from varobj_set_display_format Tom Tromey
2023-09-01 14:47 ` [PATCH 3/4] Remove variable_default_display Tom Tromey
2023-09-01 14:47 ` Tom Tromey [this message]
2023-09-01 17:34 ` [PATCH 0/4] Fix two varobj bugs Keith Seitz
2023-09-07 19:40   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230901-varobj-fixes-v1-4-b9a1f8139ca7@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).