Handle TYPE_CODE_PTR when printing Rust types
authorTom Tromey <tom@tromey.com>
Fri, 16 Nov 2018 22:30:35 +0000 (15:30 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 19 Nov 2018 18:19:01 +0000 (11:19 -0700)
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.  The nightly compiler gives the best
results, but I regression-tested with stable and beta as well.

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-19  Tom Tromey  <tom@tromey.com>

PR rust/23625:
* gdb.rust/simple.exp: Add ptype test.  Update expected output.
* gdb.rust/expr.exp: Update expected output.  Change one test.

gdb/ChangeLog
gdb/rust-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.rust/expr.exp
gdb/testsuite/gdb.rust/simple.exp

index 436446c9f0b2684b837a62798443630d25c1b59a..3939d235cfc667b9a4fe52305dd80ed6f47927ee 100644 (file)
@@ -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-19  Simon Marchi  <simon.marchi@ericsson.com>
 
        * infrun.c (displaced_step_inferior_states): Change type to
index 152413a612f660d66b5cd54ed5731b714c62f170..0a327ee619573dc65a06f58cf3fb6160200896c2 100644 (file)
@@ -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't 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);
index e7693a07f546ab57ed09b86044b2658a0dc4d581..daa283994c27b900264e0b131b3c347a68e360a5 100644 (file)
@@ -1,3 +1,9 @@
+2018-11-19  Tom Tromey  <tom@tromey.com>
+
+       PR rust/23625:
+       * gdb.rust/simple.exp: Add ptype test.  Update expected output.
+       * gdb.rust/expr.exp: Update expected output.  Change one test.
+
 2018-11-19  Tom Tromey  <tom@tromey.com>
 
        * gdb.rust/simple.rs: Don't initialize empty_enum_value.
index 22e6b49b5421468ef28534134962b7e875a7cc73..ec230c1a1a8a943e7720d275cfd8897d8370db30 100644 (file)
@@ -134,8 +134,8 @@ gdb_test "ptype \[23usize; 4\]" " = \\\[usize; 4\\\]"
 gdb_test "print \[mut 23usize; 4\]" " = \\\[23, 23, 23, 23\\\]"
 
 # Test lexer corner cases.
-gdb_test "print 0x0 as *const ()" " = \\\(\\\(\\\) \\*\\\) 0x0"
-gdb_test "print 0x0 as fn(i64) -> ()" " = \\\(\\\(\\\) \\\(\\*\\\)\\\(i64\\\)\\\) 0x0"
+gdb_test "print 0x0 as *mut ()" " = \\\(\\*mut \\\(\\\)\\\) 0x0"
+gdb_test "print 0x0 as fn(i64) -> ()" " = \\\(\\*mut fn \\\(i64\\\) -> \\\(\\\)\\\) 0x0"
 gdb_test "print r#" "syntax error in expression, near `#'\\."
 
 gdb_test "printf \"%d %d\\n\", 23+1, 23-1" "24 22"
index 956a6ca6fee6034b766302973904903fff6765fb..f02ff676db658d8193958dba9ae386b147a82c6a 100644 (file)
@@ -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'"
 
@@ -68,8 +69,8 @@ gdb_test "print f" " = \"hi bob\""
 gdb_test "print fslice" " = \"bob\""
 gdb_test "print &f\[3..\]" " = \"bob\""
 
-gdb_test "print g" " = \\(u8 \\(\\*\\)\\\[6\\\]\\) $hex b\"hi bob\""
-gdb_test "ptype g" " = u8 \\(\\*\\)\\\[6\\\]"
+gdb_test "print g" " = \\(\\*mut \\\[u8; 6\\\]\\) $hex b\"hi bob\""
+gdb_test "ptype g" " = \\*mut \\\[u8; 6\\\]"
 
 gdb_test "print v" " = simple::Something::Three"
 gdb_test_sequence "ptype v" "" {
@@ -91,19 +92,19 @@ gdb_test "print slice as &\[i32\]\[0\]" " = 3"
 
 gdb_test_sequence "ptype slice" "" {
     " = struct &\\\[i32\\\] \\{"
-    "  data_ptr: i32 \\*,"
+    "  data_ptr: \\*mut i32,"
     "  length: usize,"
     "\\}"
 }
 gdb_test_sequence "ptype &slice\[..\]" "" {
     " = struct &\\\[i32\\\] \\{"
-    "  data_ptr: i32 \\*,"
+    "  data_ptr: \\*mut i32,"
     "  length: usize,"
     "\\}"
 }
 gdb_test_sequence "ptype &b\[..\]" "" {
     " = struct &\\\[\\*gdb\\*\\\] \\{"
-    "  data_ptr: i32 \\*,"
+    "  data_ptr: \\*mut i32,"
     "  length: usize,"
     "\\}"
 }
@@ -281,7 +282,7 @@ gdb_test "print 23..97.0" "Range expression with different types"
 gdb_test "print (*parametrized.next.val)" \
     " = simple::ParametrizedStruct<i32> {next: simple::ParametrizedEnum<\[a-z:\]*Box<simple::ParametrizedStruct<i32>>>::Empty, value: 1}"
 gdb_test "print parametrized.next.val" \
-    " = \\(simple::ParametrizedStruct<i32> \\*\\) $hex"
+    " = \\(\\*mut simple::ParametrizedStruct<i32>\\) $hex"
 gdb_test "print parametrized" \
     " = simple::ParametrizedStruct<i32> \\{next: simple::ParametrizedEnum<\[a-z:\]*Box<simple::ParametrizedStruct<i32>>>::Val\\{val: $hex\\}, value: 0\\}"
 
This page took 0.038461 seconds and 4 git commands to generate.