public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] gdb/DAP Fix LazyString not serializable exception
@ 2023-06-23  8:48 Simon Farre
  2023-06-23 17:25 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Farre @ 2023-06-23  8:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: tom, Simon Farre

v2.

Apparently str(some_lazy_string) does not make LazyString eagerly fetch
it's value. However, this v2 patch *does* work for LazyStrings and as
such, this v2 is now identical to the previously referenced patch
(where this part was removed).

v1

Fixed this bug in v1 of a patch that later got removed.

I couldn't reproduce the issue, but now I've found out what it is.

I've reproduced it by basically sending two evaluate requests, "source
prettyprinter.py" (the stdlib pretty printer, to be exact) and "py
register_libstdcxx_printers(gdb.current_objfile())" - i.e. the standard
library pretty printer registering.

That's when an exception is raised by the DAP Python code. It is most
likely because the pretty printers somewhere, for something, returns a
LazyString instead of string.

This patch will make variable references value always be str(...) to
make sure that it converts it to a value that can be serialiable by
json.dumps.
---
 gdb/python/lib/gdb/dap/varref.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gdb/python/lib/gdb/dap/varref.py b/gdb/python/lib/gdb/dap/varref.py
index 213151fd3d3..8dc6cf97613 100644
--- a/gdb/python/lib/gdb/dap/varref.py
+++ b/gdb/python/lib/gdb/dap/varref.py
@@ -152,7 +152,9 @@ class VariableReference(BaseReference):
 
     def to_object(self):
         result = super().to_object()
-        result[self.result_name] = self.printer.to_string()
+        result[self.result_name] = (
+            str(self.value) if self.ref == 0 else str(self.printer.to_string())
+        )
         num_children = self.child_count()
         if num_children is not None:
             if (
-- 
2.41.0


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

* Re: [PATCH v2] gdb/DAP Fix LazyString not serializable exception
  2023-06-23  8:48 [PATCH v2] gdb/DAP Fix LazyString not serializable exception Simon Farre
@ 2023-06-23 17:25 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2023-06-23 17:25 UTC (permalink / raw)
  To: Simon Farre via Gdb-patches; +Cc: Simon Farre, tom

>>>>> "Simon" == Simon Farre via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> Apparently str(some_lazy_string) does not make LazyString eagerly fetch
Simon> it's value.

It seems like it ought to, though.

Tom

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

end of thread, other threads:[~2023-06-23 17:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-23  8:48 [PATCH v2] gdb/DAP Fix LazyString not serializable exception Simon Farre
2023-06-23 17:25 ` 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).