Skip to content

Commit fcfcc37

Browse files
committed
Fix qualified name lookup for Rust
In rust-lang/rust#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 <[email protected]> * rust-lang.c (rust_lookup_symbol_nonlocal): Look up qualified symbols in the static and global blocks. 2018-01-19 Tom Tromey <[email protected]> * gdb.rust/modules.rs (TWENTY_THREE): New global. * gdb.rust/modules.exp: Add ::-qualified lookup test.
1 parent 634c1c3 commit fcfcc37

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

gdb/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2018-01-19 Tom Tromey <[email protected]>
2+
3+
* rust-lang.c (rust_lookup_symbol_nonlocal): Look up qualified
4+
symbols in the static and global blocks.
5+
16
2018-01-19 James Clarke <[email protected]>
27

38
* nat/linux-ptrace.c: Remove unnecessary reinclusion of

gdb/rust-lang.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,19 +2201,25 @@ rust_lookup_symbol_nonlocal (const struct language_defn *langdef,
22012201
}
22022202

22032203
/* Look up bare names in the block's scope. */
2204+
std::string scopedname;
22042205
if (name[cp_find_first_component (name)] == '\0')
22052206
{
22062207
const char *scope = block_scope (block);
22072208

22082209
if (scope[0] != '\0')
22092210
{
2210-
std::string scopedname = std::string (scope) + "::" + name;
2211-
2212-
result = lookup_symbol_in_static_block (scopedname.c_str (), block,
2213-
domain);
2214-
if (result.symbol == NULL)
2215-
result = lookup_global_symbol (scopedname.c_str (), block, domain);
2211+
scopedname = std::string (scope) + "::" + name;
2212+
name = scopedname.c_str ();
22162213
}
2214+
else
2215+
name = NULL;
2216+
}
2217+
2218+
if (name != NULL)
2219+
{
2220+
result = lookup_symbol_in_static_block (name, block, domain);
2221+
if (result.symbol == NULL)
2222+
result = lookup_global_symbol (name, block, domain);
22172223
}
22182224
return result;
22192225
}

gdb/testsuite/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2018-01-19 Tom Tromey <[email protected]>
2+
3+
* gdb.rust/modules.rs (TWENTY_THREE): New global.
4+
* gdb.rust/modules.exp: Add ::-qualified lookup test.
5+
16
2018-01-19 Andreas Arnez <[email protected]>
27

38
* gdb.arch/s390-vregs.exp: Explicitly cast the return values of

gdb/testsuite/gdb.rust/modules.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,5 @@ foreach mod {mod1::inner::innest mod1::inner mod1 {}} {
8989
gdb_breakpoint modules::${mod}f2 message
9090
gdb_breakpoint "*::${mod}f2" message
9191
}
92+
93+
gdb_test "print ::TWENTY_THREE" " = 23"

gdb/testsuite/gdb.rust/modules.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ fn f2() {
2121
println!("::f2");
2222
}
2323

24+
// See https://github.com/rust-lang/rust/pull/46457
25+
#[no_mangle]
26+
pub static TWENTY_THREE : u16 = 23;
27+
2428
pub struct Generic<T>(T);
2529

2630
pub struct Type;
@@ -56,6 +60,8 @@ pub mod mod1 {
5660

5761
let f2 = || println!("lambda f2");
5862

63+
let copy = ::TWENTY_THREE;
64+
5965
f2(); // set breakpoint here
6066
f3();
6167
self::f2();

0 commit comments

Comments
 (0)