From: Joel Brobecker Date: Wed, 29 Dec 2010 08:02:59 +0000 (+0000) Subject: [Ada] print null array pointer as `0x0' rather than `(null)' X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9e87a40907128affbb3c7bbfe2bee68fdd34fa0a;p=binutils-gdb.git [Ada] print null array pointer as `0x0' rather than `(null)' Trying to print a variable defined as an access to an unconstrained array: type String_Access is access String; S1 : String_Access; If that variable is null, then GDB prints its value in an odd way: (gdb) print S1 $1 = (string_bug.string_access) (null) ^^^^^^ This patch changes the debugger behavior to print the pointer using the same output we'd use for any null pointer: (gdb) print S1 $1 = (string_bug.string_access) 0x0 It also adds an assert, helping us verify an assumption. gdb/ChangeLog: * ada-valprint.c (ada_val_print_1): Print null array pointers as `0x0' rather than `(null)'. Add assertion. gdb/testsuite/ChangeLog: * gdb.ada/arrayptr/foo.adb: Add new local variable Null_String. * gdb.ada/arrayptr.exp: Add test printing that new variable. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e1f238e4c64..7d3e3ce0f86 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2010-12-29 Joel Brobecker + + * ada-valprint.c (ada_val_print_1): Print null array pointers as + `0x0' rather than `(null)'. Add assertion. + 2010-12-29 Joel Brobecker * ada-lang.h (ada_coerce_to_simple_array): Add declaration. diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index b5d4b02329c..7c748380cb3 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -690,7 +690,8 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0, val = ada_coerce_to_simple_array (val); if (val == NULL) { - fprintf_filtered (stream, "(null)"); + gdb_assert (TYPE_CODE (type) == TYPE_CODE_TYPEDEF); + fprintf_filtered (stream, "0x0"); retn = 0; } else diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 5124dbb8b65..4580f60021b 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-12-29 Joel Brobecker + + * gdb.ada/arrayptr/foo.adb: Add new local variable Null_String. + * gdb.ada/arrayptr.exp: Add test printing that new variable. + 2010-12-29 Joel Brobecker * gdb.ada/lang_switch.exp: Correct expected parameter value. diff --git a/gdb/testsuite/gdb.ada/arrayptr.exp b/gdb/testsuite/gdb.ada/arrayptr.exp index 0f450a0f476..43a04c1c064 100644 --- a/gdb/testsuite/gdb.ada/arrayptr.exp +++ b/gdb/testsuite/gdb.ada/arrayptr.exp @@ -44,3 +44,4 @@ gdb_test "print string_p" \ "= \\(foo\\.string_access\\) 0x\[0-9a-zA-Z\]+" \ "print string_p" +gdb_test "print null_string" "= \\(foo\\.string_access\\) 0x0" diff --git a/gdb/testsuite/gdb.ada/arrayptr/foo.adb b/gdb/testsuite/gdb.ada/arrayptr/foo.adb index 8cedd870138..c11ccfb2a86 100644 --- a/gdb/testsuite/gdb.ada/arrayptr/foo.adb +++ b/gdb/testsuite/gdb.ada/arrayptr/foo.adb @@ -19,6 +19,8 @@ procedure Foo is type String_Access is access String; String_P : String_Access := new String'("Hello"); + Null_String : String_Access := null; begin Do_Nothing (String_P'Address); -- STOP + Do_Nothing (Null_String'Address); end Foo;