public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix htab_t pretty-printer for NULL values
@ 2023-03-08 20:56 Tom Tromey
  2023-03-11  3:15 ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2023-03-08 20:56 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

I was debugging gdb and was surprised to see this in a
compunit_symtab:

  m_call_site_htab = <error reading variable: Cannot access memory at address 0x28>,

Debugging showed that the field was not uninitialized; rather, the
htab_t pretty-printer did not cope with NULL.
---
 gdb/gdb-gdb.py.in                       | 5 +++++
 gdb/testsuite/gdb.gdb/python-helper.exp | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in
index 56d063cd506..567ec41b305 100644
--- a/gdb/gdb-gdb.py.in
+++ b/gdb/gdb-gdb.py.in
@@ -379,10 +379,15 @@ class HtabPrinter:
         return "array"
 
     def to_string(self):
+        if int(self._val) == 0:
+            return "(null)"
         n = int(self._val["n_elements"]) - int(self._val["n_deleted"])
         return "htab_t with {} elements".format(n)
 
     def children(self):
+        if int(self._val) == 0:
+            return
+
         size = int(self._val["size"])
         entries = self._val["entries"]
 
diff --git a/gdb/testsuite/gdb.gdb/python-helper.exp b/gdb/testsuite/gdb.gdb/python-helper.exp
index 16b419984cf..be0b311e8ca 100644
--- a/gdb/testsuite/gdb.gdb/python-helper.exp
+++ b/gdb/testsuite/gdb.gdb/python-helper.exp
@@ -211,6 +211,8 @@ proc test_python_helper {} {
     # Test the htab_t pretty-printer.
     gdb_test -prompt $outer_prompt_re "print all_bfds" "htab_t with ${::decimal} elements = \\{${::hex}.*\\}"
 
+    gdb_test -prompt $outer_prompt_re "print (htab_t) 0x0" \
+	[string_to_regexp " = (null)"]
     return 0
 }
 
-- 
2.39.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-11 15:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-08 20:56 [PATCH] Fix htab_t pretty-printer for NULL values Tom Tromey
2023-03-11  3:15 ` Simon Marchi
2023-03-11 15:09   ` Tom Tromey

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).