This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] PR 11417


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,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]