public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [FYI] Handle TYPE_CODE_PTR when printing Rust types
@ 2018-11-16 22:33 Tom Tromey
  2018-11-16 22:35 ` Tom Tromey
  2018-11-16 23:21 ` Sergio Durigan Junior
  0 siblings, 2 replies; 4+ messages in thread
From: Tom Tromey @ 2018-11-16 22:33 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes the Rust type printers to handle TYPE_CODE_PTR.  The
current approach is not ideal, because currently the code can't
distinguish between mut and const, or between pointers and references.
(These are debuginfo deficiencies, for which there are rustc bugs on
file.)

Meanwhile, this at least clears up the case seen in PR rust/23625.

Tested on x86-64 Fedora 28 using the current Rust stable compiler.

gdb/ChangeLog
2018-11-16  Tom Tromey  <tom@tromey.com>

	PR rust/23625:
	* rust-lang.c (rust_internal_print_type): Handle TYPE_CODE_PTR.

gdb/testsuite/ChangeLog
2018-11-16  Tom Tromey  <tom@tromey.com>

	PR rust/23625:
	* gdb.rust/simple.exp: Add ptype test.
---
 gdb/ChangeLog                     |  5 +++++
 gdb/rust-lang.c                   | 14 ++++++++++++++
 gdb/testsuite/ChangeLog           |  5 +++++
 gdb/testsuite/gdb.rust/simple.exp |  1 +
 4 files changed, 25 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4995d551979..ed5123d6b22 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2018-11-16  Tom Tromey  <tom@tromey.com>
+
+	PR rust/23625:
+	* rust-lang.c (rust_internal_print_type): Handle TYPE_CODE_PTR.
+
 2018-11-16  Alan Hayward  <alan.hayward@arm.com>
 
 	PR gdb/22736:
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 152413a612f..12a9c0b4895 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -918,6 +918,20 @@ rust_internal_print_type (struct type *type, const char *varstring,
       }
       break;
 
+    case TYPE_CODE_PTR:
+      {
+	if (TYPE_NAME (type) != nullptr)
+	  fputs_filtered (TYPE_NAME (type), stream);
+	else
+	  {
+	    /* We currently can distinguish between pointers and
+	       references.  */
+	    fputs_filtered ("*mut ", stream);
+	    type_print (TYPE_TARGET_TYPE (type), "", stream, 0);
+	  }
+      }
+      break;
+
     default:
     c_printer:
       c_print_type (type, varstring, stream, show, level, flags);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index c0de6f2d6cd..4aa9bceb545 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2018-11-16  Tom Tromey  <tom@tromey.com>
+
+	PR rust/23625:
+	* gdb.rust/simple.exp: Add ptype test.
+
 2018-11-16  Alan Hayward  <alan.hayward@arm.com>
 
 	PR gdb/22736:
diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/simple.exp
index 956a6ca6fee..e26435abb29 100644
--- a/gdb/testsuite/gdb.rust/simple.exp
+++ b/gdb/testsuite/gdb.rust/simple.exp
@@ -54,6 +54,7 @@ gdb_test "print *&c" " = 0"
 gdb_test "print *(&c as &i32)" " = 0"
 gdb_test "print *(&c as *const i32)" " = 0"
 gdb_test "print *(&c as *mut i32)" " = 0"
+gdb_test "ptype &c as *mut i32" "\\*mut i32"
 
 gdb_test "print/c f\[0\]" " = 104 'h'"
 
-- 
2.17.2

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

* Re: [FYI] Handle TYPE_CODE_PTR when printing Rust types
  2018-11-16 22:33 [FYI] Handle TYPE_CODE_PTR when printing Rust types Tom Tromey
@ 2018-11-16 22:35 ` Tom Tromey
  2018-11-16 23:21 ` Sergio Durigan Junior
  1 sibling, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2018-11-16 22:35 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

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

Tom> gdb/ChangeLog
Tom> 2018-11-16  Tom Tromey  <tom@tromey.com>
Tom> 	PR rust/23625:
Tom> 	* rust-lang.c (rust_internal_print_type): Handle TYPE_CODE_PTR.

I sent this too soon -- it's not actually ready.
I'll resend next week.

Tom

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

* Re: [FYI] Handle TYPE_CODE_PTR when printing Rust types
  2018-11-16 22:33 [FYI] Handle TYPE_CODE_PTR when printing Rust types Tom Tromey
  2018-11-16 22:35 ` Tom Tromey
@ 2018-11-16 23:21 ` Sergio Durigan Junior
  2018-11-19 18:23   ` Tom Tromey
  1 sibling, 1 reply; 4+ messages in thread
From: Sergio Durigan Junior @ 2018-11-16 23:21 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On Friday, November 16 2018, Tom Tromey wrote:

> This changes the Rust type printers to handle TYPE_CODE_PTR.  The
> current approach is not ideal, because currently the code can't
> distinguish between mut and const, or between pointers and references.
> (These are debuginfo deficiencies, for which there are rustc bugs on
> file.)
>
> Meanwhile, this at least clears up the case seen in PR rust/23625.
>
> Tested on x86-64 Fedora 28 using the current Rust stable compiler.
>
> gdb/ChangeLog
> 2018-11-16  Tom Tromey  <tom@tromey.com>
>
> 	PR rust/23625:
> 	* rust-lang.c (rust_internal_print_type): Handle TYPE_CODE_PTR.
>
> gdb/testsuite/ChangeLog
> 2018-11-16  Tom Tromey  <tom@tromey.com>
>
> 	PR rust/23625:
> 	* gdb.rust/simple.exp: Add ptype test.
> ---
>  gdb/ChangeLog                     |  5 +++++
>  gdb/rust-lang.c                   | 14 ++++++++++++++
>  gdb/testsuite/ChangeLog           |  5 +++++
>  gdb/testsuite/gdb.rust/simple.exp |  1 +
>  4 files changed, 25 insertions(+)
>
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 4995d551979..ed5123d6b22 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,8 @@
> +2018-11-16  Tom Tromey  <tom@tromey.com>
> +
> +	PR rust/23625:
> +	* rust-lang.c (rust_internal_print_type): Handle TYPE_CODE_PTR.
> +
>  2018-11-16  Alan Hayward  <alan.hayward@arm.com>
>  
>  	PR gdb/22736:
> diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
> index 152413a612f..12a9c0b4895 100644
> --- a/gdb/rust-lang.c
> +++ b/gdb/rust-lang.c
> @@ -918,6 +918,20 @@ rust_internal_print_type (struct type *type, const char *varstring,
>        }
>        break;
>  
> +    case TYPE_CODE_PTR:
> +      {
> +	if (TYPE_NAME (type) != nullptr)
> +	  fputs_filtered (TYPE_NAME (type), stream);
> +	else
> +	  {
> +	    /* We currently can distinguish between pointers and
> +	       references.  */

I understand you'll send a new version of the patch soon, but this
caught my attention.  I think you meant to say "... can't
distinguish...", right?  At least that's what I understand from the code
below.

Thanks.

> +	    fputs_filtered ("*mut ", stream);
> +	    type_print (TYPE_TARGET_TYPE (type), "", stream, 0);
> +	  }
> +      }
> +      break;
> +
>      default:
>      c_printer:
>        c_print_type (type, varstring, stream, show, level, flags);
> diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
> index c0de6f2d6cd..4aa9bceb545 100644
> --- a/gdb/testsuite/ChangeLog
> +++ b/gdb/testsuite/ChangeLog
> @@ -1,3 +1,8 @@
> +2018-11-16  Tom Tromey  <tom@tromey.com>
> +
> +	PR rust/23625:
> +	* gdb.rust/simple.exp: Add ptype test.
> +
>  2018-11-16  Alan Hayward  <alan.hayward@arm.com>
>  
>  	PR gdb/22736:
> diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/simple.exp
> index 956a6ca6fee..e26435abb29 100644
> --- a/gdb/testsuite/gdb.rust/simple.exp
> +++ b/gdb/testsuite/gdb.rust/simple.exp
> @@ -54,6 +54,7 @@ gdb_test "print *&c" " = 0"
>  gdb_test "print *(&c as &i32)" " = 0"
>  gdb_test "print *(&c as *const i32)" " = 0"
>  gdb_test "print *(&c as *mut i32)" " = 0"
> +gdb_test "ptype &c as *mut i32" "\\*mut i32"
>  
>  gdb_test "print/c f\[0\]" " = 104 'h'"
>  
> -- 
> 2.17.2

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

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

* Re: [FYI] Handle TYPE_CODE_PTR when printing Rust types
  2018-11-16 23:21 ` Sergio Durigan Junior
@ 2018-11-19 18:23   ` Tom Tromey
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2018-11-19 18:23 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: Tom Tromey, gdb-patches

>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:

>> +	    /* We currently can distinguish between pointers and
>> +	       references.  */

Sergio> I understand you'll send a new version of the patch soon, but this
Sergio> caught my attention.  I think you meant to say "... can't
Sergio> distinguish...", right?  At least that's what I understand from the code
Sergio> below.

Thanks, Keith noticed this too :)
I've fixed it for the next version.

Tom

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

end of thread, other threads:[~2018-11-19 18:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-16 22:33 [FYI] Handle TYPE_CODE_PTR when printing Rust types Tom Tromey
2018-11-16 22:35 ` Tom Tromey
2018-11-16 23:21 ` Sergio Durigan Junior
2018-11-19 18:23   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).