public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Don't allow NULL as an argument to block_scope
@ 2023-02-19 23:37 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2023-02-19 23:37 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=683aecac8c37c11d63203c96455a3d9ecf50bbe9

commit 683aecac8c37c11d63203c96455a3d9ecf50bbe9
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Jan 19 17:37:15 2023 -0700

    Don't allow NULL as an argument to block_scope
    
    block_scope has special behavior when the block is NULL.
    Remove this and patch up the callers instead.

Diff:
---
 gdb/d-namespace.c | 2 +-
 gdb/rust-lang.h   | 5 ++---
 gdb/rust-parse.c  | 4 +++-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/gdb/d-namespace.c b/gdb/d-namespace.c
index b6184034d5d..2978e5fecaf 100644
--- a/gdb/d-namespace.c
+++ b/gdb/d-namespace.c
@@ -511,7 +511,7 @@ d_lookup_symbol_nonlocal (const struct language_defn *langdef,
 			  const domain_enum domain)
 {
   struct block_symbol sym;
-  const char *scope = block_scope (block);
+  const char *scope = block == nullptr ? "" : block_scope (block);
 
   sym = lookup_module_scope (langdef, name, block, domain, scope, 0);
   if (sym.symbol != NULL)
diff --git a/gdb/rust-lang.h b/gdb/rust-lang.h
index 89e03550fb7..497342d4ef3 100644
--- a/gdb/rust-lang.h
+++ b/gdb/rust-lang.h
@@ -148,17 +148,16 @@ public:
   {
     struct block_symbol result = {};
 
+    const char *scope = block == nullptr ? "" : block_scope (block);
     symbol_lookup_debug_printf
       ("rust_lookup_symbol_non_local (%s, %s (scope %s), %s)",
-       name, host_address_to_string (block), block_scope (block),
+       name, host_address_to_string (block), scope,
        domain_name (domain));
 
     /* 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')
 	  {
 	    scopedname = std::string (scope) + "::" + name;
diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c
index 489be4b87e3..72b843ef40c 100644
--- a/gdb/rust-parse.c
+++ b/gdb/rust-parse.c
@@ -373,7 +373,9 @@ rust_parser::crate_name (const std::string &name)
 std::string
 rust_parser::super_name (const std::string &ident, unsigned int n_supers)
 {
-  const char *scope = block_scope (pstate->expression_context_block);
+  const char *scope = "";
+  if (pstate->expression_context_block != nullptr)
+    scope = block_scope (pstate->expression_context_block);
   int offset;
 
   if (scope[0] == '\0')

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-19 23:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-19 23:37 [binutils-gdb] Don't allow NULL as an argument to block_scope Tom Tromey

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).