]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Make gdb.lookup_typename work for Rust types
authorTom Tromey <tom@tromey.com>
Thu, 13 Jul 2017 21:03:27 +0000 (15:03 -0600)
committerTom Tromey <tom@tromey.com>
Fri, 14 Jul 2017 16:16:39 +0000 (10:16 -0600)
PR rust/21763 points out that gdb.lookup_typename does not work properly
for (some) Rust types.  I tracked this down to a missing case in
symbol_matches_domain.

Tested by the buildbot.

2017-07-14  Tom Tromey  <tom@tromey.com>

PR rust/21763:
* symtab.c (symbol_matches_domain): Add language_rust to special
case.
* rust-exp.y (convert_ast_to_expression) <OP_VAR_VALUE>: Don't
treat LOC_TYPEDEF symbols as variables.

2017-07-14  Tom Tromey  <tom@tromey.com>

* gdb.rust/simple.exp: Add regression test for PR rust/21763.

gdb/ChangeLog
gdb/rust-exp.y
gdb/symtab.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.rust/simple.exp

index 8c6a4f4e90f4693ba7c527cb08e346ddb81436e7..513cb6b0bcb56327aa837ed371819ef7e82b1e94 100644 (file)
@@ -1,3 +1,11 @@
+2017-07-14  Tom Tromey  <tom@tromey.com>
+
+       PR rust/21763:
+       * symtab.c (symbol_matches_domain): Add language_rust to special
+       case.
+       * rust-exp.y (convert_ast_to_expression) <OP_VAR_VALUE>: Don't
+       treat LOC_TYPEDEF symbols as variables.
+
 2017-07-14  Pedro Alves  <palves@redhat.com>
 
        * symtab.c (make_file_symbol_completion_list_1): Iterate over
index c7361bcd3666eb25dae4b0a645e638477a2eff8e..821abcdca2f899043f4b4d5b2434c791cd17384c 100644 (file)
@@ -2316,7 +2316,7 @@ convert_ast_to_expression (struct parser_state *state,
        varname = convert_name (state, operation);
        sym = rust_lookup_symbol (varname, expression_context_block,
                                  VAR_DOMAIN);
-       if (sym.symbol != NULL)
+       if (sym.symbol != NULL && SYMBOL_CLASS (sym.symbol) != LOC_TYPEDEF)
          {
            write_exp_elt_opcode (state, OP_VAR_VALUE);
            write_exp_elt_block (state, sym.block);
@@ -2325,9 +2325,15 @@ convert_ast_to_expression (struct parser_state *state,
          }
        else
          {
-           struct type *type;
+           struct type *type = NULL;
 
-           type = rust_lookup_type (varname, expression_context_block);
+           if (sym.symbol != NULL)
+             {
+               gdb_assert (SYMBOL_CLASS (sym.symbol) == LOC_TYPEDEF);
+               type = SYMBOL_TYPE (sym.symbol);
+             }
+           if (type == NULL)
+             type = rust_lookup_type (varname, expression_context_block);
            if (type == NULL)
              error (_("No symbol '%s' in current context"), varname);
 
index c7f1311c709993d074d92dd794de05ea2605635f..519b7dd6f2d1bfd03c49bb425b8d59911cf03f78 100644 (file)
@@ -2625,7 +2625,8 @@ symbol_matches_domain (enum language symbol_language,
      Similarly, any Ada type declaration implicitly defines a typedef.  */
   if (symbol_language == language_cplus
       || symbol_language == language_d
-      || symbol_language == language_ada)
+      || symbol_language == language_ada
+      || symbol_language == language_rust)
     {
       if ((domain == VAR_DOMAIN || domain == STRUCT_DOMAIN)
          && symbol_domain == STRUCT_DOMAIN)
index 07c5a52f64dff795fbcf837a8fc0f2e5ff6889b3..b715bfd7fe1bb542fae9744724309ba1931e7a7a 100644 (file)
@@ -1,3 +1,7 @@
+2017-07-14  Tom Tromey  <tom@tromey.com>
+
+       * gdb.rust/simple.exp: Add regression test for PR rust/21763.
+
 2017-07-14  Pedro Alves  <palves@redhat.com>
 
        * gdb.linespec/base/one/thefile.cc (z1): New function.
index 872b22c2fe781ad034ec81d415f133bd163decd4..db231623a4d262cb091aa69e0ded394d4764c90a 100644 (file)
@@ -246,3 +246,11 @@ gdb_test "print parametrized.next.val" \
     " = \\(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\\}"
+
+
+load_lib gdb-python.exp
+if {[skip_python_tests]} {
+    continue
+}
+
+gdb_test "python print(gdb.lookup_type('simple::HiBob'))" "simple::HiBob"