Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Phil Muldoon <pmuldoon@redhat.com>
To: tromey@redhat.com
Cc: gdb-patches ml <gdb-patches@sourceware.org>
Subject: Re: [patch] PR 11417
Date: Wed, 31 Mar 2010 10:07:00 -0000	[thread overview]
Message-ID: <4BB31ECC.10104@redhat.com> (raw)
In-Reply-To: <m34ojxwuq0.fsf@fleche.redhat.com>

On 03/30/2010 07:05 PM, Tom Tromey wrote:
>>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
> 
> Phil> -  if (address == 0)
> Phil> -    {
> Phil> -      PyErr_SetString (PyExc_MemoryError,
> Phil> -		       "Cannot create a lazy string from a GDB-side string.");
> Phil> -      return NULL;
> Phil> -    }
> 
> I agree that we should change lazy_string to be like string here.
> However, I think we should only allow a NULL lazy_string with length==0.
> Other situations don't really make sense.
> 
> This also needs a test case.

Ok, makes sense.  Here is an updated patch.

Cheers,

Phil

--

2010-03-31  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 and a zero length.

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


	* gdb.python/py-value: Add null string variable.
	  (test_lazy_string): Test zero length, NULL address lazy
	  strings.
--

diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index 8309527..a2faa0e 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,10 +118,11 @@ gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
 {
   lazy_string_object *str_obj = NULL;
 
-  if (address == 0)
+  if (address == 0 && length != 0)
     {
       PyErr_SetString (PyExc_MemoryError,
-		       "Cannot create a lazy string from a GDB-side string.");
+		       _("Cannot create a lazy string with address 0x0, " \
+			 "and a non-zero length."));
       return NULL;
     }
 
diff --git a/gdb/testsuite/gdb.python/py-value.c b/gdb/testsuite/gdb.python/py-value.c
index 80bc1e9..be933b3 100644
--- a/gdb/testsuite/gdb.python/py-value.c
+++ b/gdb/testsuite/gdb.python/py-value.c
@@ -59,7 +59,7 @@ main (int argc, char *argv[])
   int *p = a;
   int i = 2;
   int *ptr_i = &i;
-
+  const char *sn = 0;
   s.a = 3;
   s.b = 5;
   u.a = 7;
diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
index 2b18e02..3bfa173 100644
--- a/gdb/testsuite/gdb.python/py-value.exp
+++ b/gdb/testsuite/gdb.python/py-value.exp
@@ -267,6 +267,12 @@ proc test_lazy_strings {} {
   gdb_py_test_silent_cmd "python lstr = sptr.lazy_string()" "Aquire lazy string" 1
   gdb_test "python print lstr.type" "const char \*." "Test type name equality"
   gdb_test "python print sptr.type" "const char \*." "Test type name equality"
+  gdb_test "print sn" "0x0"
+  gdb_py_test_silent_cmd "python snptr = gdb.history (0)" "Get value from history" 1
+  gdb_test "python snstr = snptr.lazy_string(length=5)" ".*Cannot create a lazy string with address.*" "Test lazy string"
+  gdb_py_test_silent_cmd "python snstr = snptr.lazy_string(length=0)" "Succesfully create a lazy string" 1
+  gdb_test "python print snstr.length" "0" "Test lazy string length"
+  gdb_test "python print snstr.address" "0" "Test lazy string address"
 }
 
 





  reply	other threads:[~2010-03-31 10:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-30 14:46 Phil Muldoon
2010-03-30 18:05 ` Tom Tromey
2010-03-31 10:07   ` Phil Muldoon [this message]
2010-04-07 20:58     ` Tom Tromey
2010-04-08 12:38       ` Phil Muldoon

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=4BB31ECC.10104@redhat.com \
    --to=pmuldoon@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /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