2009-07-10 Phil Muldoon <pmuldoon@redhat.com>

* python/python-internal.h (apply_varobj_pretty_printer): Update
	definition.
	(python_string_to_target_python_string): Add definition.
	* python/python-utils.c (unicode_to_encoded_python_string)
	(unicode_to_target_python_string)
	(python_string_to_target_python_string): New Functions.
	* python/python-prettyprint.c (pretty_print_one_value): Likewise.
	(print_string_repr): Refactor to logic to account for PyObject
	returned strings.
	(apply_varobj_pretty_printer): Likewise.
	* python/python-value.c (valpy_string): Parse length keyword. Use
	length keyword in LA_GET_STRING.
	* varobj.c (value_get_print_value): Refactor logic to account for
	PyObject returned strings.
	* c-lang.c (c_get_string): If the length parameter is specified,
	use that. Return value in characters. Update comments.
	* language.h: Update c_get_string prototype comments.

2009-07-10  Phil Muldoon  <pmuldoon@redhat.com>

	* gdb.texinfo (Values From Inferior): Add length parameter
	description.

2009-07-10 Phil Muldoon  <pmuldoon@redhat.com>

	* gdb.python/python-prettyprint.c: Add counted null string
	structure.
	* gdb.python/python-prettyprint.exp: Print null string. Test for
	embedded nulls.
	* gdb.python/python-prettyprint.py (pp_ns): New Function.
	* gdb.python/python-value.exp (test_value_in_inferior): Add
	variable length string fetch tests.
	* gdb.python/python-value.c (main): Add strings for string fetch tests.
This commit is contained in:
Phil Muldoon 2009-07-10 10:35:17 +00:00
parent 041de40dc8
commit fbb8f2990c
16 changed files with 267 additions and 83 deletions

View file

@ -27,6 +27,11 @@ struct ss
struct s b;
};
struct ns {
const char *null_str;
int length;
};
#ifdef __cplusplus
struct S : public s {
int zs;
@ -156,6 +161,10 @@ main ()
init_ss(ssa+0, 3, 4);
init_ss(ssa+1, 5, 6);
struct ns ns;
ns.null_str = "embedded\0null\0string";
ns.length = 20;
#ifdef __cplusplus
S cps;

View file

@ -78,6 +78,7 @@ proc run_lang_tests {lang} {
gdb_test "print ref" "= a=<15> b=< a=<8> b=<$hex>>"
gdb_test "print derived" \
" = \{.*<Vbase1> = pp class name: Vbase1.*<Vbase2> = \{.*<VirtualTest> = pp value variable is: 1,.*members of Vbase2:.*_vptr.Vbase2 = $hex.*<Vbase3> = \{.*members of Vbase3.*members of Derived:.*value = 2.*"
gdb_test "print ns " "\"embedded\\\\000null\\\\000string\""
}
gdb_test "print x" " = $hex \"this is x\""

View file

@ -92,6 +92,19 @@ class pp_vbase1:
def to_string (self):
return "pp class name: " + self.val.type.tag
class pp_ns:
"Print a std::basic_string of some kind"
def __init__(self, val):
self.val = val
def to_string(self):
len = self.val['length']
return self.val['null_str'].string (gdb.parameter ('target-charset'), length = len)
def display_hint (self):
return 'string'
def lookup_function (val):
"Look-up and return a pretty-printer that can print val."
@ -145,6 +158,8 @@ def register_pretty_printers ():
pretty_printers_dict[re.compile ('^string_repr$')] = string_print
pretty_printers_dict[re.compile ('^container$')] = ContainerPrinter
pretty_printers_dict[re.compile ('^struct ns$')] = pp_ns
pretty_printers_dict[re.compile ('^ns$')] = pp_ns
pretty_printers_dict = {}
register_pretty_printers ()

View file

@ -44,6 +44,8 @@ main (int argc, char *argv[])
struct s s;
union u u;
PTR x = &s;
char st[17] = "divide et impera";
char nullst[17] = "divide\0et\0impera";
s.a = 3;
s.b = 5;

View file

@ -234,6 +234,25 @@ proc test_value_in_inferior {} {
# Test address attribute
gdb_test "python print 'result =', arg0.address" "= 0x\[\[:xdigit:\]\]+" "Test address attribute"
# Test string fetches, both partial and whole.
gdb_test "print st" "\"divide et impera\""
gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value from history" 1
gdb_test "python print st.string ()" "divide et impera" "Test string with no length"
gdb_test "python print st.string (length = -1)" "divide et impera" "Test string (length = -1) is all of the string"
gdb_test "python print st.string (length = 6)" "divide"
gdb_test "python print \"---\"+st.string (length = 0)+\"---\"" "------" "Test string (length = 0) is empty"
gdb_test "python print len(st.string (length = 0))" "0" "Test length is 0"
# Fetch a string that has embedded nulls.
gdb_test "print nullst" "\"divide\\\\000et\\\\000impera\".*"
gdb_py_test_silent_cmd "python nullst = gdb.history (0)" "get value from history" 1
gdb_test "python print nullst.string ()" "divide" "Test string to first null"
# Python cannot print strings that contain the null (\0) character.
# For the purposes of this test, use repr()
gdb_py_test_silent_cmd "python nullst = nullst.string (length = 9)" "get string beyond null" 1
gdb_test "python print repr(nullst)" "u'divide\\\\x00et'"
}
# A few objfile tests.