]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix qualified name lookup for Rust
authorTom Tromey <tom@tromey.com>
Fri, 19 Jan 2018 22:25:19 +0000 (15:25 -0700)
committerTom Tromey <tom@tromey.com>
Fri, 19 Jan 2018 22:30:28 +0000 (15:30 -0700)
In https://github.com/rust-lang/rust/pull/46457, "m4b" pointed out
that the Rust support in gdb doesn't properly handle the lookup of
qualified names.

In particular, as shown in the test case in this patch, something like
"::NAME" should be found in the global scope, but is not.

This turns out to happen because rust_lookup_symbol_nonlocal does not
search the global scope unless the name in question is unqualified.
However, lookup_symbol_aux does not search the global scope, and
appears to search the static scope only as a fallback (I wonder if
this is needed?).

This patch fixes the problem by changing rust_lookup_symbol_nonlocal
to search the static and global blocks in more cases.

Regression tested against various versions of the rust compiler on
Fedora 26 x86-64.  (Note that there are unrelated failures with newer
versions of rustc; I will be addressing those separately.)

2018-01-19  Tom Tromey  <tom@tromey.com>

* rust-lang.c (rust_lookup_symbol_nonlocal): Look up qualified
symbols in the static and global blocks.

2018-01-19  Tom Tromey  <tom@tromey.com>

* gdb.rust/modules.rs (TWENTY_THREE): New global.
* gdb.rust/modules.exp: Add ::-qualified lookup test.

gdb/ChangeLog
gdb/rust-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.rust/modules.exp
gdb/testsuite/gdb.rust/modules.rs

index e274caa4255cea9fcb9710ab2915aeb251fd99aa..d2d44725a024640d8f51505940fb09d456a4c25f 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-19  Tom Tromey  <tom@tromey.com>
+
+       * rust-lang.c (rust_lookup_symbol_nonlocal): Look up qualified
+       symbols in the static and global blocks.
+
 2018-01-19  James Clarke  <jrtc27@jrtc27.com>
 
        * nat/linux-ptrace.c: Remove unnecessary reinclusion of
index f7bec33a422d82054b93b043c08f646bc78b925a..5ff80b249bd2668de69ada69edbd7be2ae54eddc 100644 (file)
@@ -2201,19 +2201,25 @@ rust_lookup_symbol_nonlocal (const struct language_defn *langdef,
     }
 
   /* Look up bare names in the block's scope.  */
+  std::string scopedname;
   if (name[cp_find_first_component (name)] == '\0')
     {
       const char *scope = block_scope (block);
 
       if (scope[0] != '\0')
        {
-         std::string scopedname = std::string (scope) + "::" + name;
-
-         result = lookup_symbol_in_static_block (scopedname.c_str (), block,
-                                                 domain);
-         if (result.symbol == NULL)
-           result = lookup_global_symbol (scopedname.c_str (), block, domain);
+         scopedname = std::string (scope) + "::" + name;
+         name = scopedname.c_str ();
        }
+      else
+       name = NULL;
+    }
+
+  if (name != NULL)
+    {
+      result = lookup_symbol_in_static_block (name, block, domain);
+      if (result.symbol == NULL)
+       result = lookup_global_symbol (name, block, domain);
     }
   return result;
 }
index 36c49243425574ab0664ffeaae80fc358b30c2c3..2b968010fd54432964116d10a49b23768c4ce655 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-19  Tom Tromey  <tom@tromey.com>
+
+       * gdb.rust/modules.rs (TWENTY_THREE): New global.
+       * gdb.rust/modules.exp: Add ::-qualified lookup test.
+
 2018-01-19  Andreas Arnez  <arnez@linux.vnet.ibm.com>
 
        * gdb.arch/s390-vregs.exp: Explicitly cast the return values of
index ced2eb8eb15c17cee732b593f9a4e9c2a072b4f6..6a50e9fe041856be1295f969518ace2ae912c7da 100644 (file)
@@ -89,3 +89,5 @@ foreach mod {mod1::inner::innest mod1::inner mod1 {}} {
     gdb_breakpoint modules::${mod}f2 message
     gdb_breakpoint "*::${mod}f2" message
 }
+
+gdb_test "print ::TWENTY_THREE" " = 23"
index e00586533dd364fcbc60478aab3ed290b4d6ae29..3ba125370d30efcca81c788da4c2099258563f10 100644 (file)
@@ -21,6 +21,10 @@ fn f2() {
     println!("::f2");
 }
 
+// See https://github.com/rust-lang/rust/pull/46457
+#[no_mangle]
+pub static TWENTY_THREE : u16 = 23;
+
 pub struct Generic<T>(T);
 
 pub struct Type;
@@ -56,6 +60,8 @@ pub mod mod1 {
 
                 let f2 = || println!("lambda f2");
 
+                let copy = ::TWENTY_THREE;
+
                 f2();           // set breakpoint here
                 f3();
                 self::f2();