Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch] PR 11417
@ 2010-03-30 14:46 Phil Muldoon
  2010-03-30 18:05 ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Phil Muldoon @ 2010-03-30 14:46 UTC (permalink / raw)
  To: gdb-patches ml

http://sourceware.org/bugzilla/show_bug.cgi?id=11417

The OP of that bug posts an interesting issue.  If the address of a
value in the inferior is 0x0, should the user still be able to create
a Python lazy string from that value?  My first reaction was no --
purely for the reason that anything with an address of 0x0 can ever be
lazily fetched.  But the problem here is compatibility with
Value.string, and the enormous pain in the neck it would be to check
for NULL on every value before a lazy string could be created.  Maybe
we should just handle lazy strings with no address? And when printing
occurs print nothing (or in this case, with GDB, print ""). I created a
patch to do that and have attached it.  While this is technically
incorrect, I think it will make life a little easier.  One of the side
effects of this change is that if you want to convert a lazy string
back into a value, GDB will raise an exception with address 0x0. I
gated that one side effect by raising an exception.

Tested on x86_64 with no regressions

What do you think?

Cheers,

Phil

--

2010-03-30  Phil Muldoon  <pmuldoon@redhat.com>

	PR python/11417

	* python/py-lazy-string.c (stpy_convert_to_value): Check for
          a NULL address.
	  (gdbpy_create_lazy_string_object): Allow strings with a NULL
          address.

--


diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index 8309527..a7a4046 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -94,6 +94,13 @@ stpy_convert_to_value  (PyObject *self, PyObject *args)
   lazy_string_object *self_string = (lazy_string_object *) self;
   struct value *val;
 
+  if (self_string->address == 0)
+    {
+      PyErr_SetString (PyExc_MemoryError,
+		       "Cannot create a value from NULL");
+      return NULL;
+    }
+
   val = value_at_lazy (self_string->type, self_string->address);
   return value_to_value_object (val);
 }
@@ -111,13 +118,6 @@ gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
 {
   lazy_string_object *str_obj = NULL;
 
-  if (address == 0)
-    {
-      PyErr_SetString (PyExc_MemoryError,
-		       "Cannot create a lazy string from a GDB-side string.");
-      return NULL;
-    }
-
   if (!type)
     {
       PyErr_SetString (PyExc_RuntimeError,


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

end of thread, other threads:[~2010-04-08 12:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-30 14:46 [patch] PR 11417 Phil Muldoon
2010-03-30 18:05 ` Tom Tromey
2010-03-31 10:07   ` Phil Muldoon
2010-04-07 20:58     ` Tom Tromey
2010-04-08 12:38       ` Phil Muldoon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox