* [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* Re: [patch] PR 11417
2010-03-30 14:46 [patch] PR 11417 Phil Muldoon
@ 2010-03-30 18:05 ` Tom Tromey
2010-03-31 10:07 ` Phil Muldoon
0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2010-03-30 18:05 UTC (permalink / raw)
To: Phil Muldoon; +Cc: gdb-patches ml
>>>>> "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.
thanks,
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [patch] PR 11417
2010-03-30 18:05 ` Tom Tromey
@ 2010-03-31 10:07 ` Phil Muldoon
2010-04-07 20:58 ` Tom Tromey
0 siblings, 1 reply; 5+ messages in thread
From: Phil Muldoon @ 2010-03-31 10:07 UTC (permalink / raw)
To: tromey; +Cc: gdb-patches ml
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"
}
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [patch] PR 11417
2010-03-31 10:07 ` Phil Muldoon
@ 2010-04-07 20:58 ` Tom Tromey
2010-04-08 12:38 ` Phil Muldoon
0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2010-04-07 20:58 UTC (permalink / raw)
To: Phil Muldoon; +Cc: gdb-patches ml
>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
Phil> + if (self_string->address == 0)
Phil> + {
Phil> + PyErr_SetString (PyExc_MemoryError,
Phil> + "Cannot create a value from NULL");
As Joel pointed out in another thread, this should have _().
This is ok with that change. Thanks.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [patch] PR 11417
2010-04-07 20:58 ` Tom Tromey
@ 2010-04-08 12:38 ` Phil Muldoon
0 siblings, 0 replies; 5+ messages in thread
From: Phil Muldoon @ 2010-04-08 12:38 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches ml
On 04/07/2010 09:58 PM, Tom Tromey wrote:
>>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
>
> Phil> + if (self_string->address == 0)
> Phil> + {
> Phil> + PyErr_SetString (PyExc_MemoryError,
> Phil> + "Cannot create a value from NULL");
>
> As Joel pointed out in another thread, this should have _().
>
> This is ok with that change. Thanks.
So committed with that change.
Cheers,
Phil
^ 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