Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [2/5] make print_address_demangle use hex for 0
@ 2012-05-14 19:50 Tom Tromey
  2012-05-16 20:58 ` Pedro Alves
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2012-05-14 19:50 UTC (permalink / raw)
  To: gdb-patches

This changes print_address_demangle to print 0 as "0x0" rather than just
"0".

I made this change primarily for uniformity.  Right now, depending on
the code path, the 0 address can be printed either way, which seems odd.
And, "set print symbol on" changed which path was taken by default.
It seemed better to me that we just print 0x0 rather than adding special
checks for addr==0 to all the language printers.


2012-05-14  Tom Tromey  <tromey@redhat.com>

	* printcmd.c (print_address_demangle): Print "0x0", not "0".

2012-05-14  Tom Tromey  <tromey@redhat.com>

	* gdb.mi/mi2-var-display.exp: Update.
	* gdb.mi/mi-var-display.exp: Update.
	* gdb.mi/mi-var-child.exp: Update.
	* gdb.cp/expand-psymtabs-cxx.exp: Update.
	* gdb.cp/cp-relocate.exp (get_func_address): Handle 0x0 result.
---
 gdb/ChangeLog                                |    4 ++++
 gdb/printcmd.c                               |    2 +-
 gdb/testsuite/ChangeLog                      |    8 ++++++++
 gdb/testsuite/gdb.cp/cp-relocate.exp         |    4 ++--
 gdb/testsuite/gdb.cp/expand-psymtabs-cxx.exp |    6 +++---
 gdb/testsuite/gdb.mi/mi-var-child.exp        |    4 ++--
 gdb/testsuite/gdb.mi/mi-var-display.exp      |    2 +-
 gdb/testsuite/gdb.mi/mi2-var-display.exp     |    2 +-
 8 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index da6a1b3..b2e031e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@
 2012-05-14  Tom Tromey  <tromey@redhat.com>
 
+	* printcmd.c (print_address_demangle): Print "0x0", not "0".
+
+2012-05-14  Tom Tromey  <tromey@redhat.com>
+
 	* printcmd.c (print_address_demangle): Add 'opts' argument.
 	* p-valprint.c (pascal_val_print): Update.
 	* jv-valprint.c (java_val_print): Update.
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 3bb43bd..5f08e06 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -773,7 +773,7 @@ print_address_demangle (const struct value_print_options *opts,
 {
   if (addr == 0)
     {
-      fprintf_filtered (stream, "0");
+      fprintf_filtered (stream, "0x0");
     }
   else if (opts->addressprint)
     {
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 67192d9..b7520dd 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2012-05-14  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.mi/mi2-var-display.exp: Update.
+	* gdb.mi/mi-var-display.exp: Update.
+	* gdb.mi/mi-var-child.exp: Update.
+	* gdb.cp/expand-psymtabs-cxx.exp: Update.
+	* gdb.cp/cp-relocate.exp (get_func_address): Handle 0x0 result.
+
 2012-05-10  Joel Brobecker  <brobecker@adacore.com>
 
 	* config/djgpp/fnchange.lst: Add entries for print-file-var-lib1.c,
diff --git a/gdb/testsuite/gdb.cp/cp-relocate.exp b/gdb/testsuite/gdb.cp/cp-relocate.exp
index 172f24e..9b9fb34 100644
--- a/gdb/testsuite/gdb.cp/cp-relocate.exp
+++ b/gdb/testsuite/gdb.cp/cp-relocate.exp
@@ -31,11 +31,11 @@ proc get_func_address { func } {
 
     set rfunc [string_to_regexp $func]
     gdb_test_multiple "print ${func}" "get address of ${func}" {
-	-re "\\\$\[0-9\]+ = \\{.*\\} (0|($hex) <${rfunc}>)\[\r\n\]+${gdb_prompt} $" {
+	-re "\\\$\[0-9\]+ = \\{.*\\} (0x0|($hex) <${rfunc}>)\[\r\n\]+${gdb_prompt} $" {
 	    # $1 = {int ()} 0x24 <function_bar>
 	    # But if the function is at zero, the name may be omitted.
 	    pass "get address of ${func}"
-	    if { $expect_out(1,string) == "0" } {
+	    if { $expect_out(1,string) == "0x0" } {
 		return "0x0"
 	    } else {
 		return $expect_out(2,string)
diff --git a/gdb/testsuite/gdb.cp/expand-psymtabs-cxx.exp b/gdb/testsuite/gdb.cp/expand-psymtabs-cxx.exp
index 226d0b8..5f60e51 100644
--- a/gdb/testsuite/gdb.cp/expand-psymtabs-cxx.exp
+++ b/gdb/testsuite/gdb.cp/expand-psymtabs-cxx.exp
@@ -32,6 +32,6 @@ gdb_test_no_output "set language c++"
 
 # FAIL was:
 # $1 = {<text variable, no debug info>} 0
-gdb_test "p 'method(long)'" { = {void \(long\)} 0} "before expand"
-gdb_test "p method" { = {void \(long\)} 0} "force expand"
-gdb_test "p 'method(long)'" { = {void \(long\)} 0} "after expand"
+gdb_test "p 'method(long)'" { = {void \(long\)} 0x0} "before expand"
+gdb_test "p method" { = {void \(long\)} 0x0} "force expand"
+gdb_test "p 'method(long)'" { = {void \(long\)} 0x0} "after expand"
diff --git a/gdb/testsuite/gdb.mi/mi-var-child.exp b/gdb/testsuite/gdb.mi/mi-var-child.exp
index 7e58ad7..fb98c1d 100644
--- a/gdb/testsuite/gdb.mi/mi-var-child.exp
+++ b/gdb/testsuite/gdb.mi/mi-var-child.exp
@@ -808,9 +808,9 @@ mi_list_varobj_children {struct_declarations --simple-values} \
          {struct_declarations.long_array long_array 12 "long int \\[12\\]"} \
          [list struct_declarations.func_ptr func_ptr 0 "void \\(\\*\\)\\((void)?\\)" "(@$hex: |)$hex <nothing>"] \
          {struct_declarations.func_ptr_struct func_ptr_struct 0 \
-              "struct _struct_decl \\(\\*\\)(\\(int, char \\*, long int\\))?" 0} \
+              "struct _struct_decl \\(\\*\\)(\\(int, char \\*, long int\\))?" 0x0} \
          {struct_declarations.func_ptr_ptr func_ptr_ptr 0 \
-              "struct _struct_decl \\*\\(\\*\\)\\((int, char \\*, long int)?\\)" 0} \
+              "struct _struct_decl \\*\\(\\*\\)\\((int, char \\*, long int)?\\)" 0x0} \
          {struct_declarations.u1 u1 4 "union \\{\\.\\.\\.\\}"} \
          {struct_declarations.s2 s2 4 "struct \\{\\.\\.\\.\\}"} \
 ] "listing of children, simple types: names, type and values, complex types: names and types"
diff --git a/gdb/testsuite/gdb.mi/mi-var-display.exp b/gdb/testsuite/gdb.mi/mi-var-display.exp
index b3ae2c5..bc770d9 100644
--- a/gdb/testsuite/gdb.mi/mi-var-display.exp
+++ b/gdb/testsuite/gdb.mi/mi-var-display.exp
@@ -286,7 +286,7 @@ mi_gdb_test "-var-set-format weird.func_ptr_struct hexadecimal" \
 	"set format variable weird.func_ptr_struct"
 
 mi_gdb_test "-var-set-format weird.func_ptr_ptr natural" \
-	"\\^done,format=\"natural\",value=\"0\"" \
+	"\\^done,format=\"natural\",value=\"0x0\"" \
 	"set format variable weird.func_ptr_ptr"
 
 mi_gdb_test "-var-set-format weird.u1 natural" \
diff --git a/gdb/testsuite/gdb.mi/mi2-var-display.exp b/gdb/testsuite/gdb.mi/mi2-var-display.exp
index f5c69ab..d1429c8 100644
--- a/gdb/testsuite/gdb.mi/mi2-var-display.exp
+++ b/gdb/testsuite/gdb.mi/mi2-var-display.exp
@@ -285,7 +285,7 @@ mi_gdb_test "-var-set-format weird.func_ptr_struct hexadecimal" \
 	"set format variable weird.func_ptr_struct"
 
 mi_gdb_test "-var-set-format weird.func_ptr_ptr natural" \
-	"\\^done,format=\"natural\",value=\"0\"" \
+	"\\^done,format=\"natural\",value=\"0x0\"" \
 	"set format variable weird.func_ptr_ptr"
 
 mi_gdb_test "-var-set-format weird.u1 natural" \
-- 
1.7.7.6


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

* Re: [2/5] make print_address_demangle use hex for 0
  2012-05-14 19:50 [2/5] make print_address_demangle use hex for 0 Tom Tromey
@ 2012-05-16 20:58 ` Pedro Alves
  2012-05-16 21:04   ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2012-05-16 20:58 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 05/14/2012 08:50 PM, Tom Tromey wrote:

> --- a/gdb/printcmd.c
> +++ b/gdb/printcmd.c
> @@ -773,7 +773,7 @@ print_address_demangle (const struct value_print_options *opts,
>  {
>    if (addr == 0)
>      {
> -      fprintf_filtered (stream, "0");
> +      fprintf_filtered (stream, "0x0");
>      }
>    else if (opts->addressprint)


Do you know why we special case 0 at all?  (There are targets where 0 is a valid address.)

-- 
Pedro Alves


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

* Re: [2/5] make print_address_demangle use hex for 0
  2012-05-16 20:58 ` Pedro Alves
@ 2012-05-16 21:04   ` Tom Tromey
  2012-05-18 15:26     ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2012-05-16 21:04 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> Do you know why we special case 0 at all?  (There are targets where 0
Pedro> is a valid address.)

No idea.
I can try dropping the condition entirely if you want.
I don't think I have ready access to a target where 0 is valid, though.

Tom


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

* Re: [2/5] make print_address_demangle use hex for 0
  2012-05-16 21:04   ` Tom Tromey
@ 2012-05-18 15:26     ` Tom Tromey
  2012-05-18 15:42       ` Pedro Alves
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2012-05-18 15:26 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:

Tom> I can try dropping the condition entirely if you want.
Tom> I don't think I have ready access to a target where 0 is valid, though.

I tried this.  It seemed to work ok; I didn't need to find a funny
target since a couple of test cases (expand-psymtabs-cxx.exp and
cp-relocate.exp) exercise this code.

Here's the updated patch.

Tom

2012-05-18  Tom Tromey  <tromey@redhat.com>

	* printcmd.c (print_address_demangle): Remove special case for 0.

2012-05-18  Tom Tromey  <tromey@redhat.com>

	* gdb.mi/mi2-var-display.exp: Update.
	* gdb.mi/mi-var-display.exp: Update.
	* gdb.mi/mi-var-child.exp: Update.
	* gdb.cp/expand-psymtabs-cxx.exp: Update.
	* gdb.cp/cp-relocate.exp (get_func_address): Update.

From c8816c37c023be94e77afc21fcf0dd0b3fc07df2 Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Fri, 11 May 2012 12:59:31 -0600
Subject: [PATCH 2/4] remove print_address_demangle special case for 0

	* printcmd.c (print_address_demangle): Remove special case for 0.

	* gdb.mi/mi2-var-display.exp: Update.
	* gdb.mi/mi-var-display.exp: Update.
	* gdb.mi/mi-var-child.exp: Update.
	* gdb.cp/expand-psymtabs-cxx.exp: Update.
	* gdb.cp/cp-relocate.exp (get_func_address): Update.
---
 gdb/ChangeLog                                |    4 ++++
 gdb/printcmd.c                               |    6 +-----
 gdb/testsuite/ChangeLog                      |    8 ++++++++
 gdb/testsuite/gdb.cp/cp-relocate.exp         |    4 ++--
 gdb/testsuite/gdb.cp/expand-psymtabs-cxx.exp |    9 ++++++---
 gdb/testsuite/gdb.mi/mi-var-child.exp        |    4 ++--
 gdb/testsuite/gdb.mi/mi-var-display.exp      |    2 +-
 gdb/testsuite/gdb.mi/mi2-var-display.exp     |    2 +-
 8 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 3bb43bd..523fad2 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -771,11 +771,7 @@ print_address_demangle (const struct value_print_options *opts,
 			struct gdbarch *gdbarch, CORE_ADDR addr,
 			struct ui_file *stream, int do_demangle)
 {
-  if (addr == 0)
-    {
-      fprintf_filtered (stream, "0");
-    }
-  else if (opts->addressprint)
+  if (opts->addressprint)
     {
       fputs_filtered (paddress (gdbarch, addr), stream);
       print_address_symbolic (gdbarch, addr, stream, do_demangle, " ");
diff --git a/gdb/testsuite/gdb.cp/cp-relocate.exp b/gdb/testsuite/gdb.cp/cp-relocate.exp
index 172f24e..2981228 100644
--- a/gdb/testsuite/gdb.cp/cp-relocate.exp
+++ b/gdb/testsuite/gdb.cp/cp-relocate.exp
@@ -31,11 +31,11 @@ proc get_func_address { func } {
 
     set rfunc [string_to_regexp $func]
     gdb_test_multiple "print ${func}" "get address of ${func}" {
-	-re "\\\$\[0-9\]+ = \\{.*\\} (0|($hex) <${rfunc}>)\[\r\n\]+${gdb_prompt} $" {
+	-re "\\\$\[0-9\]+ = \\{.*\\} (($hex) <${rfunc}.*>)\[\r\n\]+${gdb_prompt} $" {
 	    # $1 = {int ()} 0x24 <function_bar>
 	    # But if the function is at zero, the name may be omitted.
 	    pass "get address of ${func}"
-	    if { $expect_out(1,string) == "0" } {
+	    if { $expect_out(1,string) == "0x0" } {
 		return "0x0"
 	    } else {
 		return $expect_out(2,string)
diff --git a/gdb/testsuite/gdb.cp/expand-psymtabs-cxx.exp b/gdb/testsuite/gdb.cp/expand-psymtabs-cxx.exp
index 226d0b8..2614fb7 100644
--- a/gdb/testsuite/gdb.cp/expand-psymtabs-cxx.exp
+++ b/gdb/testsuite/gdb.cp/expand-psymtabs-cxx.exp
@@ -32,6 +32,9 @@ gdb_test_no_output "set language c++"
 
 # FAIL was:
 # $1 = {<text variable, no debug info>} 0
-gdb_test "p 'method(long)'" { = {void \(long\)} 0} "before expand"
-gdb_test "p method" { = {void \(long\)} 0} "force expand"
-gdb_test "p 'method(long)'" { = {void \(long\)} 0} "after expand"
+gdb_test "p 'method(long)'" { = {void \(long\)} 0x0 <method.long.>} \
+    "before expand"
+gdb_test "p method" { = {void \(long\)} 0x0 <method.long.>} \
+    "force expand"
+gdb_test "p 'method(long)'" { = {void \(long\)} 0x0 <method.long.>} \
+    "after expand"
diff --git a/gdb/testsuite/gdb.mi/mi-var-child.exp b/gdb/testsuite/gdb.mi/mi-var-child.exp
index 7e58ad7..fb98c1d 100644
--- a/gdb/testsuite/gdb.mi/mi-var-child.exp
+++ b/gdb/testsuite/gdb.mi/mi-var-child.exp
@@ -808,9 +808,9 @@ mi_list_varobj_children {struct_declarations --simple-values} \
          {struct_declarations.long_array long_array 12 "long int \\[12\\]"} \
          [list struct_declarations.func_ptr func_ptr 0 "void \\(\\*\\)\\((void)?\\)" "(@$hex: |)$hex <nothing>"] \
          {struct_declarations.func_ptr_struct func_ptr_struct 0 \
-              "struct _struct_decl \\(\\*\\)(\\(int, char \\*, long int\\))?" 0} \
+              "struct _struct_decl \\(\\*\\)(\\(int, char \\*, long int\\))?" 0x0} \
          {struct_declarations.func_ptr_ptr func_ptr_ptr 0 \
-              "struct _struct_decl \\*\\(\\*\\)\\((int, char \\*, long int)?\\)" 0} \
+              "struct _struct_decl \\*\\(\\*\\)\\((int, char \\*, long int)?\\)" 0x0} \
          {struct_declarations.u1 u1 4 "union \\{\\.\\.\\.\\}"} \
          {struct_declarations.s2 s2 4 "struct \\{\\.\\.\\.\\}"} \
 ] "listing of children, simple types: names, type and values, complex types: names and types"
diff --git a/gdb/testsuite/gdb.mi/mi-var-display.exp b/gdb/testsuite/gdb.mi/mi-var-display.exp
index b3ae2c5..bc770d9 100644
--- a/gdb/testsuite/gdb.mi/mi-var-display.exp
+++ b/gdb/testsuite/gdb.mi/mi-var-display.exp
@@ -286,7 +286,7 @@ mi_gdb_test "-var-set-format weird.func_ptr_struct hexadecimal" \
 	"set format variable weird.func_ptr_struct"
 
 mi_gdb_test "-var-set-format weird.func_ptr_ptr natural" \
-	"\\^done,format=\"natural\",value=\"0\"" \
+	"\\^done,format=\"natural\",value=\"0x0\"" \
 	"set format variable weird.func_ptr_ptr"
 
 mi_gdb_test "-var-set-format weird.u1 natural" \
diff --git a/gdb/testsuite/gdb.mi/mi2-var-display.exp b/gdb/testsuite/gdb.mi/mi2-var-display.exp
index f5c69ab..d1429c8 100644
--- a/gdb/testsuite/gdb.mi/mi2-var-display.exp
+++ b/gdb/testsuite/gdb.mi/mi2-var-display.exp
@@ -285,7 +285,7 @@ mi_gdb_test "-var-set-format weird.func_ptr_struct hexadecimal" \
 	"set format variable weird.func_ptr_struct"
 
 mi_gdb_test "-var-set-format weird.func_ptr_ptr natural" \
-	"\\^done,format=\"natural\",value=\"0\"" \
+	"\\^done,format=\"natural\",value=\"0x0\"" \
 	"set format variable weird.func_ptr_ptr"
 
 mi_gdb_test "-var-set-format weird.u1 natural" \
-- 
1.7.7.6


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

* Re: [2/5] make print_address_demangle use hex for 0
  2012-05-18 15:26     ` Tom Tromey
@ 2012-05-18 15:42       ` Pedro Alves
  0 siblings, 0 replies; 5+ messages in thread
From: Pedro Alves @ 2012-05-18 15:42 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 05/18/2012 04:26 PM, Tom Tromey wrote:

>>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
> 
> Tom> I can try dropping the condition entirely if you want.
> Tom> I don't think I have ready access to a target where 0 is valid, though.
> 
> I tried this.  It seemed to work ok; I didn't need to find a funny
> target since a couple of test cases (expand-psymtabs-cxx.exp and
> cp-relocate.exp) exercise this code.


Thanks.

-- 
Pedro Alves


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

end of thread, other threads:[~2012-05-18 15:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-14 19:50 [2/5] make print_address_demangle use hex for 0 Tom Tromey
2012-05-16 20:58 ` Pedro Alves
2012-05-16 21:04   ` Tom Tromey
2012-05-18 15:26     ` Tom Tromey
2012-05-18 15:42       ` Pedro Alves

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