public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [FYI] Fix qualified name lookup for Rust
Date: Fri, 19 Jan 2018 22:31:00 -0000	[thread overview]
Message-ID: <20180119223049.26156-1-tom@tromey.com> (raw)

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                      |  5 +++++
 gdb/rust-lang.c                    | 18 ++++++++++++------
 gdb/testsuite/ChangeLog            |  5 +++++
 gdb/testsuite/gdb.rust/modules.exp |  2 ++
 gdb/testsuite/gdb.rust/modules.rs  |  6 ++++++
 5 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e274caa425..d2d44725a0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index f7bec33a42..5ff80b249b 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -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;
 }
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 36c4924342..2b968010fd 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -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
diff --git a/gdb/testsuite/gdb.rust/modules.exp b/gdb/testsuite/gdb.rust/modules.exp
index ced2eb8eb1..6a50e9fe04 100644
--- a/gdb/testsuite/gdb.rust/modules.exp
+++ b/gdb/testsuite/gdb.rust/modules.exp
@@ -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"
diff --git a/gdb/testsuite/gdb.rust/modules.rs b/gdb/testsuite/gdb.rust/modules.rs
index e00586533d..3ba125370d 100644
--- a/gdb/testsuite/gdb.rust/modules.rs
+++ b/gdb/testsuite/gdb.rust/modules.rs
@@ -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();
-- 
2.13.6

                 reply	other threads:[~2018-01-19 22:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180119223049.26156-1-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).