From fff5cc649e7498fe4618557c13b1f98692c2d1f7 Mon Sep 17 00:00:00 2001 From: Phil Muldoon Date: Thu, 8 Apr 2010 10:28:42 +0000 Subject: [PATCH] 2010-04-08 Phil Muldoon 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-04-08 Phil Muldoon * gdb.python/py-value: Add null string variable. (test_lazy_string): Test zero length, NULL address lazy strings. --- gdb/ChangeLog | 9 +++++++++ gdb/python/py-lazy-string.c | 12 ++++++++++-- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.python/py-value.c | 2 +- gdb/testsuite/gdb.python/py-value.exp | 6 ++++++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 33f1556972..05cfec64ab 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2010-04-08 Phil Muldoon + + 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-04-08 Hui Zhu * i386-tdep.c (i386_process_record): Add support for insn diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c index 8309527527..a2faa0eb91 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/ChangeLog b/gdb/testsuite/ChangeLog index b4a9dd92ff..2be54d7623 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2010-04-08 Phil Muldoon + + * gdb.python/py-value: Add null string variable. + (test_lazy_string): Test zero length, NULL address lazy + strings. + 2010-04-07 H.J. Lu * gdb.arch/i386-avx.c: New. diff --git a/gdb/testsuite/gdb.python/py-value.c b/gdb/testsuite/gdb.python/py-value.c index 80bc1e974f..be933b3148 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 2b18e02c41..3bfa17317c 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" } -- 2.34.1