Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [commit/Ada] print null array pointer as `0x0' rather than `(null)'
@ 2010-12-29 10:21 Joel Brobecker
  2010-12-30  1:54 ` Andreas Schwab
  0 siblings, 1 reply; 3+ messages in thread
From: Joel Brobecker @ 2010-12-29 10:21 UTC (permalink / raw)
  To: gdb-patches; +Cc: Joel Brobecker

This is a minor followup on the previous patch.  Now that we are
correctly printing pointer-to-array types correctly as addresses
while arrays are correctly printed as arrays, we should also print
null pointer arrays as addresses...

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.

Tested on x86_64-linux.  Checked in.

---
 gdb/ChangeLog                          |    5 +++++
 gdb/ada-valprint.c                     |    3 ++-
 gdb/testsuite/ChangeLog                |    5 +++++
 gdb/testsuite/gdb.ada/arrayptr.exp     |    1 +
 gdb/testsuite/gdb.ada/arrayptr/foo.adb |    2 ++
 5 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e1f238e..7d3e3ce 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2010-12-29  Joel Brobecker  <brobecker@adacore.com>
 
+	* ada-valprint.c (ada_val_print_1): Print null array pointers as
+	`0x0' rather than `(null)'.  Add assertion.
+
+2010-12-29  Joel Brobecker  <brobecker@adacore.com>
+
 	* ada-lang.h (ada_coerce_to_simple_array): Add declaration.
 	* ada-lang.c (ada_typedef_target_type): New function.
 	(desc_base_type): Add handling of fat pointer typedefs.
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index b5d4b02..7c74838 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 5124dbb..4580f60 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
 2010-12-29  Joel Brobecker  <brobecker@adacore.com>
 
+	* 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  <brobecker@adacore.com>
+
 	* gdb.ada/lang_switch.exp: Correct expected parameter value.
 
 2010-12-25  Andreas Schwab  <schwab@linux-m68k.org>
diff --git a/gdb/testsuite/gdb.ada/arrayptr.exp b/gdb/testsuite/gdb.ada/arrayptr.exp
index 0f450a0..43a04c1 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 8cedd87..c11ccfb 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;
-- 
1.7.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [commit/Ada] print null array pointer as `0x0' rather than `(null)'
  2010-12-29 10:21 [commit/Ada] print null array pointer as `0x0' rather than `(null)' Joel Brobecker
@ 2010-12-30  1:54 ` Andreas Schwab
  2010-12-30 10:59   ` Joel Brobecker
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Schwab @ 2010-12-30  1:54 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

Joel Brobecker <brobecker@adacore.com> writes:

> gdb/ChangeLog:
>
>         * ada-valprint.c (ada_val_print_1): Print null array pointers as
>         `0x0' rather than `(null)'.  Add assertion.

Why not `null'?

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [commit/Ada] print null array pointer as `0x0' rather than `(null)'
  2010-12-30  1:54 ` Andreas Schwab
@ 2010-12-30 10:59   ` Joel Brobecker
  0 siblings, 0 replies; 3+ messages in thread
From: Joel Brobecker @ 2010-12-30 10:59 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: gdb-patches

> > gdb/ChangeLog:
> >
> >         * ada-valprint.c (ada_val_print_1): Print null array pointers as
> >         `0x0' rather than `(null)'.  Add assertion.
> 
> Why not `null'?

`null' would indeed be more Ada-like.  But two reasons lead to use
plain `0x0' for now: First, it is more consistent with the way we
display all other pointer (we delegate the printing of a pointer
to the common code with prints null pointers as 0x0). And the second
reason is that the language parser in the debugger does not handle
`null' yet.  When GDB prints a value, I try to print it in a way that
the user can copy-paste it in a expression that you can feed back
to GDB.

All the above is on my list of minor little improvements to make
some rainy day, but there are so many more important things I want
to get to, it's not likely to be done anytime soon.

-- 
Joel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-12-30  4:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-29 10:21 [commit/Ada] print null array pointer as `0x0' rather than `(null)' Joel Brobecker
2010-12-30  1:54 ` Andreas Schwab
2010-12-30 10:59   ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox