public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 00/31] Baby step for objfile splitting
@ 2023-11-05 18:11 Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 01/31] Introduce block-symbol.h Tom Tromey
                   ` (31 more replies)
  0 siblings, 32 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

Every year or so, I take a stab at the objfile splitting work.  This
always fails and I end up not sending anything.

This year, I decided to take a baby step instead, thinking maybe it
would be possible to slowly grind away at the problem.

This series is the first such step.  It spreads the use of
block_symbol through a bunch of code, trying to eliminate calls to
symbol::value_address.

The longer term idea here is to then add an objfile member to
block_symbol.  After this, it would be relatively simple to change
symbols to be relocated at point of use.  (This would be a significant
step toward objfile splitting, but there's even more to do after
that...)

Regression tested on x86-64 Fedora 38.

---
Changes in v2:
- Updated per review
- Added bound_symbol patch, converted some patches to use it
- More comprehensive change in ada-lang.c
- Link to v1: https://inbox.sourceware.org/gdb-patches/20231029-split-objfile-2023-bound-sym-october-v1-0-612531df2734@tromey.com

---
Tom Tromey (31):
      Introduce block-symbol.h
      Add block_symbol::address
      Add bound_symbol
      Easy conversions to use block_symbol::address
      Use block_symbol::address in ada-tasks.c
      Use block_symbol::address in printcmd.c
      Use bound_symbol::address in tracepoint.c
      Use block_symbol::address in tracepoint.c
      Use block_symbol::address in ax-gdb.c
      Use block_symbol::address in linespec.c
      Use block_symbol::address in ada-lang.c
      Use bound_symbol::address in symmisc.c
      Introduce read_var_value overload
      Use read_var_value in gdb/compile
      Return a block_symbol from find_pc_sect_function
      Use read_var_value overload in finish_command_fsm
      Use block_symbol in overload-handling code
      Change evaluate_var_value to accept a block_symbol
      Change value_of_variable to take a block_symbol
      Return a block_symbol from get_frame_function
      Use read_var_value overload in return_command
      Use read_var_value overload in py-finishbreakpoint.c
      Use read_var_value overload in py-framefilter.c
      Use read_var_value overload in Guile
      Use read_var_value in read_frame_arg and read_frame_local
      Change print_variable_and_value to take a block_symbol
      Change find_frame_funname to return a block_symbol
      Change btrace_function::sym to a block_symbol
      Use read_var_value overload in Python
      Remove the old read_var_value
      Change language_defn::read_var_value to accept block_symbol

 gdb/ada-lang.c                      | 116 +++++++++++++----------------
 gdb/ada-tasks.c                     |  19 ++---
 gdb/ax-gdb.c                        |  28 +++----
 gdb/ax-gdb.h                        |   2 +-
 gdb/block-symbol.h                  |  42 +++++++++++
 gdb/blockframe.c                    |  18 ++---
 gdb/breakpoint.c                    |   4 +-
 gdb/btrace.c                        |  38 +++++-----
 gdb/btrace.h                        |   5 +-
 gdb/cli/cli-cmds.c                  |   4 +-
 gdb/compile/compile-c-symbols.c     |  18 +++--
 gdb/compile/compile-cplus-symbols.c |   6 +-
 gdb/compile/compile-cplus-types.c   |   2 +-
 gdb/compile/compile-loc2c.c         |  14 ++--
 gdb/compile/compile.h               |   6 +-
 gdb/cp-support.c                    |  46 +++++++-----
 gdb/cp-support.h                    |   6 +-
 gdb/dwarf2/ada-imported.c           |   2 +-
 gdb/dwarf2/loc.c                    |  16 ++--
 gdb/dwarf2/loc.h                    |   3 +-
 gdb/eval.c                          |  62 +++++++---------
 gdb/expop.h                         |   5 ++
 gdb/f-valprint.c                    |   4 +-
 gdb/findvar.c                       |  24 +++---
 gdb/frame.c                         |   2 +-
 gdb/frame.h                         |   9 ++-
 gdb/guile/guile-internal.h          |   2 +-
 gdb/guile/scm-block.c               |   6 +-
 gdb/guile/scm-frame.c               |   7 +-
 gdb/guile/scm-symbol.c              |  78 ++++++++++----------
 gdb/infcall.c                       |   4 +-
 gdb/infcmd.c                        |  29 ++++----
 gdb/infrun.c                        |  10 +--
 gdb/inline-frame.c                  |   2 +-
 gdb/language.h                      |  14 +---
 gdb/linespec.c                      |  15 ++--
 gdb/mi/mi-cmd-stack.c               |  20 ++---
 gdb/printcmd.c                      |  22 +++---
 gdb/python/py-block.c               |   6 +-
 gdb/python/py-finishbreakpoint.c    |  11 +--
 gdb/python/py-frame.c               |  15 ++--
 gdb/python/py-framefilter.c         |  64 +++++++---------
 gdb/python/py-objfile.c             |  16 ++--
 gdb/python/py-record-btrace.c       |   2 +-
 gdb/python/py-symbol.c              | 143 ++++++++++++++++++------------------
 gdb/python/py-type.c                |   2 +-
 gdb/python/py-unwind.c              |   4 +-
 gdb/python/python-internal.h        |   4 +-
 gdb/record-btrace.c                 |   8 +-
 gdb/rust-lang.c                     |   2 +-
 gdb/skip.c                          |   2 +-
 gdb/solib-frv.c                     |   2 +-
 gdb/sparc-tdep.c                    |   4 +-
 gdb/stack.c                         |  59 ++++++++-------
 gdb/stack.h                         |   2 +-
 gdb/symmisc.c                       |  15 ++--
 gdb/symtab.c                        |   4 +-
 gdb/symtab.h                        |  38 +++++++---
 gdb/tracepoint.c                    |  26 ++++---
 gdb/tracepoint.h                    |   2 +-
 gdb/valarith.c                      |   9 +--
 gdb/valops.c                        |  75 ++++++++++---------
 gdb/value.c                         |   2 +-
 gdb/value.h                         |  18 ++---
 64 files changed, 647 insertions(+), 598 deletions(-)
---
base-commit: 0a845aef62b8813275616bd399e8fca679161cfc
change-id: 20231029-split-objfile-2023-bound-sym-october-8da7ff1061cc

Best regards,
-- 
Tom Tromey <tom@tromey.com>


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 01/31] Introduce block-symbol.h
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 02/31] Add block_symbol::address Tom Tromey
                   ` (30 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This adds a new header file, block-symbol.h.  This is needed to break
include cycles in later patches.
---
 gdb/block-symbol.h | 39 +++++++++++++++++++++++++++++++++++++++
 gdb/symtab.h       | 14 +-------------
 2 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/gdb/block-symbol.h b/gdb/block-symbol.h
new file mode 100644
index 00000000000..35bc40c1986
--- /dev/null
+++ b/gdb/block-symbol.h
@@ -0,0 +1,39 @@
+/* The block_symbol type
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GDB_BLOCK_SYMBOL_H
+#define GDB_BLOCK_SYMBOL_H
+
+struct block;
+struct symbol;
+
+/* Several lookup functions return both a symbol and the block in which the
+   symbol is found.  This structure is used in these cases.  */
+
+struct block_symbol
+{
+  /* The symbol that was found, or NULL if no symbol was found.  */
+  struct symbol *symbol;
+
+  /* If SYMBOL is not NULL, then this is the block in which the symbol is
+     defined.  */
+  const struct block *block;
+};
+
+#endif /* GDB_BLOCK_SYMBOL_H */
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 8dfc873b1c9..0b3ca3964b6 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -38,6 +38,7 @@
 #include "gdb-demangle.h"
 #include "split-name.h"
 #include "frame.h"
+#include "block-symbol.h"
 
 /* Opaque declarations.  */
 struct ui_file;
@@ -1521,19 +1522,6 @@ struct symbol : public general_symbol_info, public allocate_on_obstack
  CORE_ADDR get_maybe_copied_address () const;
 };
 
-/* Several lookup functions return both a symbol and the block in which the
-   symbol is found.  This structure is used in these cases.  */
-
-struct block_symbol
-{
-  /* The symbol that was found, or NULL if no symbol was found.  */
-  struct symbol *symbol;
-
-  /* If SYMBOL is not NULL, then this is the block in which the symbol is
-     defined.  */
-  const struct block *block;
-};
-
 /* Note: There is no accessor macro for symbol.owner because it is
    "private".  */
 

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 02/31] Add block_symbol::address
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 01/31] Introduce block-symbol.h Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 03/31] Add bound_symbol Tom Tromey
                   ` (29 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This adds a new block_symbol::address method.  The long-term goal here
is to change most existing calls to symbol::value_address to call
block_symbol::address instead.

Then, at some future date, we can add an objfile to block_symbol and
change this method to relocate the address when called -- making a
symbol independent of the objfile, as we've already done for minimal
symbols and partial symbols.
---
 gdb/block-symbol.h | 3 +++
 gdb/symtab.h       | 7 +++++++
 2 files changed, 10 insertions(+)

diff --git a/gdb/block-symbol.h b/gdb/block-symbol.h
index 35bc40c1986..6cb48945dbc 100644
--- a/gdb/block-symbol.h
+++ b/gdb/block-symbol.h
@@ -34,6 +34,9 @@ struct block_symbol
   /* If SYMBOL is not NULL, then this is the block in which the symbol is
      defined.  */
   const struct block *block;
+
+  /* Return the address of the symbol.  */
+  CORE_ADDR address () const;
 };
 
 #endif /* GDB_BLOCK_SYMBOL_H */
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 0b3ca3964b6..042f9dd4621 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1522,6 +1522,13 @@ struct symbol : public general_symbol_info, public allocate_on_obstack
  CORE_ADDR get_maybe_copied_address () const;
 };
 
+/* See block-symbol.h.  */
+inline CORE_ADDR
+block_symbol::address () const
+{
+  return symbol->value_address ();
+}
+
 /* Note: There is no accessor macro for symbol.owner because it is
    "private".  */
 

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 03/31] Add bound_symbol
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 01/31] Introduce block-symbol.h Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 02/31] Add block_symbol::address Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 04/31] Easy conversions to use block_symbol::address Tom Tromey
                   ` (28 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This adds a new bound_symbol type, analogous to bound_minimal_symbol.
That is, it carries a symbol and an objfile and will eventually be
used to relocate an address at point of use when computing a symbol's
value.
---
 gdb/symtab.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/gdb/symtab.h b/gdb/symtab.h
index 042f9dd4621..a518ed83622 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1522,6 +1522,27 @@ struct symbol : public general_symbol_info, public allocate_on_obstack
  CORE_ADDR get_maybe_copied_address () const;
 };
 
+/* A bound symbol is a symbol that is bound to a particular objfile.
+   (Currently all symbols are intrinsically bound, but as part of the
+   objfile-splitting project, eventually they will not have this
+   backlink.)  */
+struct bound_symbol
+{
+  /* The symbol.  Can be NULL.  */
+  struct symbol *symbol;
+
+  /* The objfile.  If SYMBOL is non-NULL, then this must be as well.  */
+  struct objfile *objfile;
+
+  /* Compute the address of the symbol.  */
+  CORE_ADDR address () const
+  { return symbol->value_address (); }
+
+  /* Convenience method to access symbol contents.  */
+  struct symbol *operator-> () const
+  { return symbol; }
+};
+
 /* See block-symbol.h.  */
 inline CORE_ADDR
 block_symbol::address () const

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 04/31] Easy conversions to use block_symbol::address
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (2 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 03/31] Add bound_symbol Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 05/31] Use block_symbol::address in ada-tasks.c Tom Tromey
                   ` (27 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This changes a few obvious spots to use block_symbol::address.
---
 gdb/ada-lang.c                      | 3 +--
 gdb/compile/compile-c-symbols.c     | 4 ++--
 gdb/compile/compile-cplus-symbols.c | 4 ++--
 gdb/compile/compile-cplus-types.c   | 2 +-
 4 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 9bb649e901d..3391aaeccb3 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5101,8 +5101,7 @@ remove_extra_symbols (std::vector<struct block_symbol> &syms)
 			     syms[j].symbol->linkage_name ()) == 0
 		  && (syms[i].symbol->aclass ()
 		      == syms[j].symbol->aclass ())
-		  && syms[i].symbol->value_address ()
-		  == syms[j].symbol->value_address ())
+		  && syms[i].address () == syms[j].address ())
 		remove_p = true;
 	    }
 	}
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index 5982178170c..2d49ead249e 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -88,7 +88,7 @@ convert_one_symbol (compile_c_instance *context,
 
 	case LOC_LABEL:
 	  kind = GCC_C_SYMBOL_LABEL;
-	  addr = sym.symbol->value_address ();
+	  addr = sym.address ();
 	  break;
 
 	case LOC_BLOCK:
@@ -179,7 +179,7 @@ convert_one_symbol (compile_c_instance *context,
 
 	case LOC_STATIC:
 	  kind = GCC_C_SYMBOL_VARIABLE;
-	  addr = sym.symbol->value_address ();
+	  addr = sym.address ();
 	  break;
 
 	case LOC_FINAL_VALUE:
diff --git a/gdb/compile/compile-cplus-symbols.c b/gdb/compile/compile-cplus-symbols.c
index 1edbf8f64b5..dec0260bf7a 100644
--- a/gdb/compile/compile-cplus-symbols.c
+++ b/gdb/compile/compile-cplus-symbols.c
@@ -82,7 +82,7 @@ convert_one_symbol (compile_cplus_instance *instance,
 
 	case LOC_LABEL:
 	  kind = GCC_CP_SYMBOL_LABEL;
-	  addr = sym.symbol->value_address ();
+	  addr = sym.address ();
 	  break;
 
 	case LOC_BLOCK:
@@ -175,7 +175,7 @@ convert_one_symbol (compile_cplus_instance *instance,
 
 	case LOC_STATIC:
 	  kind = GCC_CP_SYMBOL_VARIABLE;
-	  addr = sym.symbol->value_address ();
+	  addr = sym.address ();
 	  break;
 
 	case LOC_FINAL_VALUE:
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index ac27e83618b..53a98b432f4 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -627,7 +627,7 @@ compile_cplus_convert_struct_or_union_members
 		const char *filename = sym.symbol->symtab ()->filename;
 		unsigned int line = sym.symbol->line ();
 
-		physaddr = sym.symbol->value_address ();
+		physaddr = sym.address ();
 		instance->plugin ().build_decl
 		  ("field physname", field_name,
 		   (GCC_CP_SYMBOL_VARIABLE| get_field_access_flag (type, i)),

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 05/31] Use block_symbol::address in ada-tasks.c
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (3 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 04/31] Easy conversions to use block_symbol::address Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 06/31] Use block_symbol::address in printcmd.c Tom Tromey
                   ` (26 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This changes ada-tasks.c to use block_symbol::address.
---
 gdb/ada-tasks.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index 047566e6228..e217fd4b3f4 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -914,7 +914,6 @@ static void
 ada_tasks_inferior_data_sniffer (struct ada_tasks_inferior_data *data)
 {
   struct bound_minimal_symbol msym;
-  struct symbol *sym;
 
   /* Return now if already set.  */
   if (data->known_tasks_kind != ADA_TASKS_UNKNOWN)
@@ -929,12 +928,13 @@ ada_tasks_inferior_data_sniffer (struct ada_tasks_inferior_data *data)
       data->known_tasks_addr = msym.value_address ();
 
       /* Try to get pointer type and array length from the symtab.  */
-      sym = lookup_symbol_in_language (KNOWN_TASKS_NAME, NULL, VAR_DOMAIN,
-				       language_c, NULL).symbol;
-      if (sym != NULL)
+      block_symbol sym
+	= lookup_symbol_in_language (KNOWN_TASKS_NAME, nullptr, VAR_DOMAIN,
+				     language_c, nullptr);
+      if (sym.symbol != nullptr)
 	{
 	  /* Validate.  */
-	  struct type *type = check_typedef (sym->type ());
+	  struct type *type = check_typedef (sym.symbol->type ());
 	  struct type *eltype = NULL;
 	  struct type *idxtype = NULL;
 
@@ -975,12 +975,13 @@ ada_tasks_inferior_data_sniffer (struct ada_tasks_inferior_data *data)
       data->known_tasks_addr = msym.value_address ();
       data->known_tasks_length = 1;
 
-      sym = lookup_symbol_in_language (KNOWN_TASKS_LIST, NULL, VAR_DOMAIN,
-				       language_c, NULL).symbol;
-      if (sym != NULL && sym->value_address () != 0)
+      block_symbol sym
+	= lookup_symbol_in_language (KNOWN_TASKS_LIST, nullptr, VAR_DOMAIN,
+				     language_c, nullptr);
+      if (sym.symbol != nullptr && sym.address () != 0)
 	{
 	  /* Validate.  */
-	  struct type *type = check_typedef (sym->type ());
+	  struct type *type = check_typedef (sym.symbol->type ());
 
 	  if (type->code () == TYPE_CODE_PTR)
 	    {

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 06/31] Use block_symbol::address in printcmd.c
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (4 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 05/31] Use block_symbol::address in ada-tasks.c Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 07/31] Use bound_symbol::address in tracepoint.c Tom Tromey
                   ` (25 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This changes printcmd.c to use block_symbol::address.
---
 gdb/printcmd.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 06cc5316eec..2dbaaf0fffe 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1637,7 +1637,6 @@ info_address_command (const char *exp, int from_tty)
 {
   struct gdbarch *gdbarch;
   int regno;
-  struct symbol *sym;
   struct bound_minimal_symbol msymbol;
   long val;
   struct obj_section *section;
@@ -1647,8 +1646,10 @@ info_address_command (const char *exp, int from_tty)
   if (exp == 0)
     error (_("Argument required."));
 
-  sym = lookup_symbol (exp, get_selected_block (&context_pc), VAR_DOMAIN,
-		       &is_a_field_of_this).symbol;
+  block_symbol bsym = lookup_symbol (exp, get_selected_block (&context_pc),
+				     VAR_DOMAIN,
+				     &is_a_field_of_this);
+  symbol *sym = bsym.symbol;
   if (sym == NULL)
     {
       if (is_a_field_of_this.type != NULL)
@@ -1725,7 +1726,7 @@ info_address_command (const char *exp, int from_tty)
 
     case LOC_LABEL:
       gdb_printf ("a label at address ");
-      load_addr = sym->value_address ();
+      load_addr = bsym.address ();
       fputs_styled (paddress (gdbarch, load_addr), address_style.style (),
 		    gdb_stdout);
       if (section_is_overlay (section))
@@ -1761,7 +1762,7 @@ info_address_command (const char *exp, int from_tty)
 
     case LOC_STATIC:
       gdb_printf (_("static storage at address "));
-      load_addr = sym->value_address ();
+      load_addr = bsym.address ();
       fputs_styled (paddress (gdbarch, load_addr), address_style.style (),
 		    gdb_stdout);
       if (section_is_overlay (section))

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 07/31] Use bound_symbol::address in tracepoint.c
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (5 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 06/31] Use block_symbol::address in printcmd.c Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 08/31] Use block_symbol::address " Tom Tromey
                   ` (24 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This changes the easy spots in tracepoint.c to use
bound_symbol::address.
---
 gdb/tracepoint.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 2c548688570..6eb40153e24 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -2484,11 +2484,15 @@ info_scope_command (const char *args_in, int from_tty)
   resolve_sal_pc (&sals[0]);
   block = block_for_pc (sals[0].pc);
 
+  struct objfile *objfile = block->objfile ();
+
   while (block != 0)
     {
       QUIT;			/* Allow user to bail out with ^C.  */
       for (struct symbol *sym : block_iterator_range (block))
 	{
+	  bound_symbol bsym { sym, objfile };
+
 	  QUIT;			/* Allow user to bail out with ^C.  */
 	  if (count == 0)
 	    gdb_printf ("Scope for %s:\n", save_args);
@@ -2529,7 +2533,7 @@ info_scope_command (const char *args_in, int from_tty)
 		  break;
 		case LOC_STATIC:
 		  gdb_printf ("in static storage at address ");
-		  gdb_printf ("%s", paddress (gdbarch, sym->value_address ()));
+		  gdb_printf ("%s", paddress (gdbarch, bsym.address ()));
 		  break;
 		case LOC_REGISTER:
 		  /* GDBARCH is the architecture associated with the objfile
@@ -2573,7 +2577,7 @@ info_scope_command (const char *args_in, int from_tty)
 		  continue;
 		case LOC_LABEL:
 		  gdb_printf ("a label at address ");
-		  gdb_printf ("%s", paddress (gdbarch, sym->value_address ()));
+		  gdb_printf ("%s", paddress (gdbarch, bsym.address ()));
 		  break;
 		case LOC_BLOCK:
 		  gdb_printf ("a function at address ");

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 08/31] Use block_symbol::address in tracepoint.c
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (6 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 07/31] Use bound_symbol::address in tracepoint.c Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 09/31] Use block_symbol::address in ax-gdb.c Tom Tromey
                   ` (23 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This changes some spots in tracepoint.c to use block_symbol::address.
---
 gdb/expop.h      |  5 +++++
 gdb/tracepoint.c | 12 +++++++-----
 gdb/tracepoint.h |  2 +-
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/gdb/expop.h b/gdb/expop.h
index 25769d5b810..433c92c9a00 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -667,6 +667,11 @@ class var_value_operation
     return std::get<0> (m_storage).symbol;
   }
 
+  block_symbol get_block_symbol () const
+  {
+    return std::get<0> (m_storage);
+  }
+
 protected:
 
   void do_generate_ax (struct expression *exp,
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 6eb40153e24..a273ea0a328 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -905,7 +905,7 @@ collection_list::add_memrange (struct gdbarch *gdbarch,
 /* Add a symbol to a collection list.  */
 
 void
-collection_list::collect_symbol (struct symbol *sym,
+collection_list::collect_symbol (block_symbol bsym,
 				 struct gdbarch *gdbarch,
 				 long frame_regno, long frame_offset,
 				 CORE_ADDR scope,
@@ -916,6 +916,7 @@ collection_list::collect_symbol (struct symbol *sym,
   bfd_signed_vma offset;
   int treat_as_expr = 0;
 
+  symbol *sym = bsym.symbol;
   len = check_typedef (sym->type ())->length ();
   switch (sym->aclass ())
     {
@@ -928,7 +929,7 @@ collection_list::collect_symbol (struct symbol *sym,
 		  sym->print_name (), plongest (sym->value_longest ()));
       break;
     case LOC_STATIC:
-      offset = sym->value_address ();
+      offset = bsym.address ();
       if (info_verbose)
 	{
 	  gdb_printf ("LOC_STATIC %s: collect %ld bytes at %s.\n",
@@ -1049,7 +1050,8 @@ collection_list::add_local_symbols (struct gdbarch *gdbarch, CORE_ADDR pc,
   auto do_collect_symbol = [&] (const char *print_name,
 				struct symbol *sym)
     {
-      collect_symbol (sym, gdbarch, frame_regno,
+      block_symbol bsym { sym, block };
+      collect_symbol (bsym, gdbarch, frame_regno,
 		      frame_offset, pc, trace_string);
       count++;
       add_wholly_collected (print_name);
@@ -1392,8 +1394,8 @@ encode_actions_1 (struct command_line *action,
 			expr::var_value_operation *vvo
 			  = (gdb::checked_static_cast<expr::var_value_operation *>
 			     (exp->op.get ()));
-			struct symbol *sym = vvo->get_symbol ();
-			const char *name = sym->natural_name ();
+			block_symbol sym = vvo->get_block_symbol ();
+			const char *name = sym.symbol->natural_name ();
 
 			collect->collect_symbol (sym,
 						 arch,
diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h
index b9ff31fa0f6..8c94f1d9fc2 100644
--- a/gdb/tracepoint.h
+++ b/gdb/tracepoint.h
@@ -270,7 +270,7 @@ class collection_list
   void add_memrange (struct gdbarch *gdbarch,
 		     int type, bfd_signed_vma base,
 		     unsigned long len, CORE_ADDR scope);
-  void collect_symbol (struct symbol *sym,
+  void collect_symbol (block_symbol sym,
 		       struct gdbarch *gdbarch,
 		       long frame_regno, long frame_offset,
 		       CORE_ADDR scope,

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 09/31] Use block_symbol::address in ax-gdb.c
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (7 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 08/31] Use block_symbol::address " Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 10/31] Use block_symbol::address in linespec.c Tom Tromey
                   ` (22 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This changes ax-gdb.c to use block_symbol::address.
---
 gdb/ax-gdb.c     | 28 +++++++++++++++-------------
 gdb/ax-gdb.h     |  2 +-
 gdb/tracepoint.c |  2 +-
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index a679c864915..dc3ac14078f 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -86,7 +86,7 @@ static void gen_frame_locals_address (struct agent_expr *);
 static void gen_offset (struct agent_expr *ax, int offset);
 static void gen_sym_offset (struct agent_expr *, struct symbol *);
 static void gen_var_ref (struct agent_expr *ax, struct axs_value *value,
-			 struct symbol *var);
+			 block_symbol var);
 
 
 static void gen_int_literal (struct agent_expr *ax,
@@ -515,8 +515,10 @@ gen_sym_offset (struct agent_expr *ax, struct symbol *var)
    symbol VAR.  Set VALUE to describe the result.  */
 
 static void
-gen_var_ref (struct agent_expr *ax, struct axs_value *value, struct symbol *var)
+gen_var_ref (struct agent_expr *ax, struct axs_value *value, block_symbol bvar)
 {
+  symbol *var = bvar.symbol;
+
   /* Dereference any typedefs.  */
   value->type = check_typedef (var->type ());
   value->optimized_out = 0;
@@ -536,7 +538,7 @@ gen_var_ref (struct agent_expr *ax, struct axs_value *value, struct symbol *var)
       break;
 
     case LOC_LABEL:		/* A goto label, being used as a value.  */
-      ax_const_l (ax, (LONGEST) var->value_address ());
+      ax_const_l (ax, (LONGEST) bvar.address ());
       value->kind = axs_rvalue;
       break;
 
@@ -547,7 +549,7 @@ gen_var_ref (struct agent_expr *ax, struct axs_value *value, struct symbol *var)
       /* Variable at a fixed location in memory.  Easy.  */
     case LOC_STATIC:
       /* Push the address of the variable.  */
-      ax_const_l (ax, var->value_address ());
+      ax_const_l (ax, bvar.address ());
       value->kind = axs_lvalue_memory;
       break;
 
@@ -1457,9 +1459,9 @@ gen_static_field (struct agent_expr *ax, struct axs_value *value,
   else
     {
       const char *phys_name = type->field (fieldno).loc_physname ();
-      struct symbol *sym = lookup_symbol (phys_name, 0, VAR_DOMAIN, 0).symbol;
+      block_symbol sym = lookup_symbol (phys_name, 0, VAR_DOMAIN, 0);
 
-      if (sym)
+      if (sym.symbol != nullptr)
 	{
 	  gen_var_ref (ax, value, sym);
   
@@ -1553,7 +1555,7 @@ gen_maybe_namespace_elt (struct agent_expr *ax, struct axs_value *value,
   if (sym.symbol == NULL)
     return 0;
 
-  gen_var_ref (ax, value, sym.symbol);
+  gen_var_ref (ax, value, sym);
 
   if (value->optimized_out)
     error (_("`%s' has been optimized out, cannot use"),
@@ -1896,7 +1898,7 @@ op_this_operation::do_generate_ax (struct expression *exp,
 				   struct axs_value *value,
 				   struct type *cast_type)
 {
-  struct symbol *sym, *func;
+  struct symbol *func;
   const struct block *b;
   const struct language_defn *lang;
 
@@ -1904,15 +1906,15 @@ op_this_operation::do_generate_ax (struct expression *exp,
   func = b->linkage_function ();
   lang = language_def (func->language ());
 
-  sym = lookup_language_this (lang, b).symbol;
-  if (!sym)
+  block_symbol sym = lookup_language_this (lang, b);
+  if (sym.symbol == nullptr)
     error (_("no `%s' found"), lang->name_of_this ());
 
   gen_var_ref (ax, value, sym);
 
   if (value->optimized_out)
     error (_("`%s' has been optimized out, cannot use"),
-	   sym->print_name ());
+	   sym.symbol->print_name ());
 }
 
 void
@@ -2003,7 +2005,7 @@ var_value_operation::do_generate_ax (struct expression *exp,
 				     struct axs_value *value,
 				     struct type *cast_type)
 {
-  gen_var_ref (ax, value, std::get<0> (m_storage).symbol);
+  gen_var_ref (ax, value, std::get<0> (m_storage));
 
   if (value->optimized_out)
     error (_("`%s' has been optimized out, cannot use"),
@@ -2330,7 +2332,7 @@ gen_expr_unop (struct expression *exp,
 
 agent_expr_up
 gen_trace_for_var (CORE_ADDR scope, struct gdbarch *gdbarch,
-		   struct symbol *var, int trace_string)
+		   block_symbol var, int trace_string)
 {
   agent_expr_up ax (new agent_expr (gdbarch, scope));
   struct axs_value value;
diff --git a/gdb/ax-gdb.h b/gdb/ax-gdb.h
index 4f73385208c..8376d7ee29e 100644
--- a/gdb/ax-gdb.h
+++ b/gdb/ax-gdb.h
@@ -106,7 +106,7 @@ extern agent_expr_up gen_trace_for_expr (CORE_ADDR, struct expression *,
 					 int);
 
 extern agent_expr_up gen_trace_for_var (CORE_ADDR, struct gdbarch *,
-					struct symbol *, int);
+					block_symbol, int);
 
 extern agent_expr_up gen_trace_for_return_address (CORE_ADDR,
 						   struct gdbarch *,
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index a273ea0a328..713fb387857 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -1010,7 +1010,7 @@ collection_list::collect_symbol (block_symbol bsym,
   if (treat_as_expr)
     {
       agent_expr_up aexpr = gen_trace_for_var (scope, gdbarch,
-					       sym, trace_string);
+					       bsym, trace_string);
 
       /* It can happen that the symbol is recorded as a computed
 	 location, but it's been optimized away and doesn't actually

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 10/31] Use block_symbol::address in linespec.c
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (8 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 09/31] Use block_symbol::address in ax-gdb.c Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 11/31] Use block_symbol::address in ada-lang.c Tom Tromey
                   ` (21 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This changes linespec.c to use block_symbol::address.
---
 gdb/linespec.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/gdb/linespec.c b/gdb/linespec.c
index fa733d880e3..a118a20cade 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -383,7 +383,7 @@ static struct line_offset
 			      const char *variable);
 
 static int symbol_to_sal (struct symtab_and_line *result,
-			  int funfirstline, struct symbol *sym);
+			  int funfirstline, block_symbol sym);
 
 static void add_matching_symbols_to_info (const char *name,
 					  symbol_name_match_type name_match_type,
@@ -2187,7 +2187,7 @@ convert_linespec_to_sals (struct linespec_state *state, linespec *ls)
 	  struct program_space *pspace
 	    = sym.symbol->symtab ()->compunit ()->objfile ()->pspace;
 
-	  if (symbol_to_sal (&sal, state->funfirstline, sym.symbol)
+	  if (symbol_to_sal (&sal, state->funfirstline, sym)
 	      && maybe_add_address (state->addr_set, pspace, sal.pc))
 	    add_sal_to_sals (state, &sals, &sal,
 			     sym.symbol->natural_name (), 0);
@@ -2252,7 +2252,7 @@ convert_linespec_to_sals (struct linespec_state *state, linespec *ls)
 	      if (!found_ifunc)
 		{
 		  symtab_and_line sal;
-		  if (symbol_to_sal (&sal, state->funfirstline, sym.symbol)
+		  if (symbol_to_sal (&sal, state->funfirstline, sym)
 		      && maybe_add_address (state->addr_set, pspace, sal.pc))
 		    add_sal_to_sals (state, &sals, &sal,
 				     sym.symbol->natural_name (), 0);
@@ -4358,8 +4358,9 @@ add_matching_symbols_to_info (const char *name,
 
 static int
 symbol_to_sal (struct symtab_and_line *result,
-	       int funfirstline, struct symbol *sym)
+	       int funfirstline, block_symbol bsym)
 {
+  symbol *sym = bsym.symbol;
   if (sym->aclass () == LOC_BLOCK)
     {
       *result = find_function_start_sal (sym, funfirstline);
@@ -4367,13 +4368,13 @@ symbol_to_sal (struct symtab_and_line *result,
     }
   else
     {
-      if (sym->aclass () == LOC_LABEL && sym->value_address () != 0)
+      if (sym->aclass () == LOC_LABEL && bsym.address () != 0)
 	{
 	  *result = {};
 	  result->symtab = sym->symtab ();
 	  result->symbol = sym;
 	  result->line = sym->line ();
-	  result->pc = sym->value_address ();
+	  result->pc = bsym.address ();
 	  result->pspace = result->symtab->compunit ()->objfile ()->pspace;
 	  result->explicit_pc = 1;
 	  return 1;
@@ -4389,7 +4390,7 @@ symbol_to_sal (struct symtab_and_line *result,
 	  result->symtab = sym->symtab ();
 	  result->symbol = sym;
 	  result->line = sym->line ();
-	  result->pc = sym->value_address ();
+	  result->pc = bsym.address ();
 	  result->pspace = result->symtab->compunit ()->objfile ()->pspace;
 	  return 1;
 	}

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 11/31] Use block_symbol::address in ada-lang.c
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (9 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 10/31] Use block_symbol::address in linespec.c Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 12/31] Use bound_symbol::address in symmisc.c Tom Tromey
                   ` (20 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This changes ada-lang.c to use block_symbol::address.
---
 gdb/ada-lang.c | 98 ++++++++++++++++++++++++++--------------------------------
 1 file changed, 43 insertions(+), 55 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3391aaeccb3..03f405778e6 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -108,8 +108,7 @@ static void ada_add_all_symbols (std::vector<struct block_symbol> &,
 static int is_nonfunction (const std::vector<struct block_symbol> &);
 
 static void add_defn_to_vec (std::vector<struct block_symbol> &,
-			     struct symbol *,
-			     const struct block *);
+			     block_symbol);
 
 static int possible_user_operator_p (enum exp_opcode, struct value **);
 
@@ -160,8 +159,6 @@ static struct value *value_subscript_packed (struct value *, int,
 static struct value *coerce_unspec_val_to_type (struct value *,
 						struct type *);
 
-static int lesseq_defined_than (struct symbol *, struct symbol *);
-
 static int equiv_types (struct type *, struct type *);
 
 static int is_name_suffix (const char *);
@@ -336,12 +333,9 @@ struct cache_entry
   std::string name;
   /* The namespace used during the lookup.  */
   domain_enum domain = UNDEF_DOMAIN;
-  /* The symbol returned by the lookup, or NULL if no matching symbol
-     was found.  */
-  struct symbol *sym = nullptr;
-  /* The block where the symbol was found, or NULL if no matching
-     symbol was found.  */
-  const struct block *block = nullptr;
+  /* The symbol returned by the lookup.  The 'symbol' field will be
+     NULL if no matching symbol was found.  */
+  block_symbol sym = {};
 };
 
 /* The symbol cache uses this type when searching.  */
@@ -4685,8 +4679,7 @@ ada_clear_symbol_cache (program_space *pspace)
    SYM.  Same principle for BLOCK if not NULL.  */
 
 static int
-lookup_cached_symbol (const char *name, domain_enum domain,
-		      struct symbol **sym, const struct block **block)
+lookup_cached_symbol (const char *name, domain_enum domain, block_symbol *sym)
 {
   htab_t tab = get_ada_pspace_data (current_program_space);
   cache_entry_search search;
@@ -4699,18 +4692,17 @@ lookup_cached_symbol (const char *name, domain_enum domain,
     return 0;
   if (sym != nullptr)
     *sym = e->sym;
-  if (block != nullptr)
-    *block = e->block;
   return 1;
 }
 
-/* Assuming that (SYM, BLOCK) is the result of the lookup of NAME
+/* Assuming that SYM is the result of the lookup of NAME
    in domain DOMAIN, save this result in our symbol cache.  */
 
 static void
-cache_symbol (const char *name, domain_enum domain, struct symbol *sym,
-	      const struct block *block)
+cache_symbol (const char *name, domain_enum domain, block_symbol bsym)
 {
+  symbol *sym = bsym.symbol;
+
   /* Symbols for builtin types don't have a block.
      For now don't cache such symbols.  */
   if (sym != NULL && !sym->is_objfile_owned ())
@@ -4724,7 +4716,7 @@ cache_symbol (const char *name, domain_enum domain, struct symbol *sym,
     {
       const blockvector &bv = *sym->symtab ()->compunit ()->blockvector ();
 
-      if (bv.global_block () != block && bv.static_block () != block)
+      if (bv.global_block () != bsym.block && bv.static_block () != bsym.block)
 	return;
     }
 
@@ -4739,8 +4731,7 @@ cache_symbol (const char *name, domain_enum domain, struct symbol *sym,
   cache_entry *e = new cache_entry;
   e->name = name;
   e->domain = domain;
-  e->sym = sym;
-  e->block = block;
+  e->sym = bsym;
 
   *slot = e;
 }
@@ -4768,13 +4759,12 @@ static struct symbol *
 standard_lookup (const char *name, const struct block *block,
 		 domain_enum domain)
 {
-  /* Initialize it just to avoid a GCC false warning.  */
-  struct block_symbol sym = {};
+  struct block_symbol sym;
 
-  if (lookup_cached_symbol (name, domain, &sym.symbol, NULL))
+  if (lookup_cached_symbol (name, domain, &sym))
     return sym.symbol;
   ada_lookup_encoded_symbol (name, block, domain, &sym);
-  cache_symbol (name, domain, sym.symbol, sym.block);
+  cache_symbol (name, domain, sym);
   return sym.symbol;
 }
 
@@ -4814,12 +4804,15 @@ equiv_types (struct type *type0, struct type *type1)
   return 0;
 }
 
-/* True iff SYM0 represents the same entity as SYM1, or one that is
-   no more defined than that of SYM1.  */
+/* True iff BSYM0 represents the same entity as BSYM1, or one that is
+   no more defined than that of BSYM1.  */
 
 static int
-lesseq_defined_than (struct symbol *sym0, struct symbol *sym1)
+lesseq_defined_than (block_symbol bsym0, block_symbol bsym1)
 {
+  symbol *sym0 = bsym0.symbol;
+  symbol *sym1 = bsym1.symbol;
+
   if (sym0 == sym1)
     return 1;
   if (sym0->domain () != sym1->domain ()
@@ -4853,7 +4846,7 @@ lesseq_defined_than (struct symbol *sym0, struct symbol *sym1)
 	const char *name0 = sym0->linkage_name ();
 	const char *name1 = sym1->linkage_name ();
 	return (strcmp (name0, name1) == 0
-		&& sym0->value_address () == sym1->value_address ());
+		&& bsym0.address () == bsym1.address ());
       }
 
     default:
@@ -4866,8 +4859,7 @@ lesseq_defined_than (struct symbol *sym0, struct symbol *sym1)
 
 static void
 add_defn_to_vec (std::vector<struct block_symbol> &result,
-		 struct symbol *sym,
-		 const struct block *block)
+		 block_symbol info)
 {
   /* Do not try to complete stub types, as the debugger is probably
      already scanning all symbols matching a certain name at the
@@ -4880,19 +4872,15 @@ add_defn_to_vec (std::vector<struct block_symbol> &result,
 
   for (int i = result.size () - 1; i >= 0; i -= 1)
     {
-      if (lesseq_defined_than (sym, result[i].symbol))
+      if (lesseq_defined_than (info, result[i]))
 	return;
-      else if (lesseq_defined_than (result[i].symbol, sym))
+      else if (lesseq_defined_than (result[i], info))
 	{
-	  result[i].symbol = sym;
-	  result[i].block = block;
+	  result[i] = info;
 	  return;
 	}
     }
 
-  struct block_symbol info;
-  info.symbol = sym;
-  info.block = block;
   result.push_back (info);
 }
 
@@ -5382,13 +5370,12 @@ struct match_data
 bool
 match_data::operator() (struct block_symbol *bsym)
 {
-  const struct block *block = bsym->block;
   struct symbol *sym = bsym->symbol;
 
   if (sym == NULL)
     {
       if (!found_sym && arg_sym != NULL)
-	add_defn_to_vec (*resultp, arg_sym, block);
+	add_defn_to_vec (*resultp, { arg_sym, bsym->block });
       found_sym = false;
       arg_sym = NULL;
     }
@@ -5401,7 +5388,7 @@ match_data::operator() (struct block_symbol *bsym)
       else
 	{
 	  found_sym = true;
-	  add_defn_to_vec (*resultp, sym, block);
+	  add_defn_to_vec (*resultp, *bsym);
 	}
     }
   return true;
@@ -5651,8 +5638,6 @@ ada_add_all_symbols (std::vector<struct block_symbol> &result,
 		     int full_search,
 		     int *made_global_lookup_p)
 {
-  struct symbol *sym;
-
   if (made_global_lookup_p)
     *made_global_lookup_p = 0;
 
@@ -5687,11 +5672,11 @@ ada_add_all_symbols (std::vector<struct block_symbol> &result,
      already performed this search before.  If we have, then return
      the same result.  */
 
-  if (lookup_cached_symbol (ada_lookup_name (lookup_name),
-			    domain, &sym, &block))
+  block_symbol sym;
+  if (lookup_cached_symbol (ada_lookup_name (lookup_name), domain, &sym))
     {
-      if (sym != NULL)
-	add_defn_to_vec (result, sym, block);
+      if (sym.symbol != nullptr)
+	add_defn_to_vec (result, sym);
       return;
     }
 
@@ -5739,11 +5724,10 @@ ada_lookup_symbol_list_worker (const lookup_name_info &lookup_name,
   remove_extra_symbols (results);
 
   if (results.empty () && full_search && syms_from_global_search)
-    cache_symbol (ada_lookup_name (lookup_name), domain, NULL, NULL);
+    cache_symbol (ada_lookup_name (lookup_name), domain, {});
 
   if (results.size () == 1 && full_search && syms_from_global_search)
-    cache_symbol (ada_lookup_name (lookup_name), domain,
-		  results[0].symbol, results[0].block);
+    cache_symbol (ada_lookup_name (lookup_name), domain, results[0]);
 
   remove_irrelevant_renamings (&results, block);
   return results;
@@ -6087,7 +6071,7 @@ ada_add_block_symbols (std::vector<struct block_symbol> &result,
 	      else
 		{
 		  found_sym = true;
-		  add_defn_to_vec (result, sym, block);
+		  add_defn_to_vec (result, { sym, block });
 		}
 	    }
 	}
@@ -6100,7 +6084,7 @@ ada_add_block_symbols (std::vector<struct block_symbol> &result,
 
   if (!found_sym && arg_sym != NULL)
     {
-      add_defn_to_vec (result, arg_sym, block);
+      add_defn_to_vec (result, { arg_sym, block });
     }
 
   if (!lookup_name.ada ().wild_match_p ())
@@ -6136,7 +6120,7 @@ ada_add_block_symbols (std::vector<struct block_symbol> &result,
 		    else
 		      {
 			found_sym = true;
-			add_defn_to_vec (result, sym, block);
+			add_defn_to_vec (result, { sym, block });
 		      }
 		  }
 	      }
@@ -6147,7 +6131,7 @@ ada_add_block_symbols (std::vector<struct block_symbol> &result,
 	 They aren't parameters, right?  */
       if (!found_sym && arg_sym != NULL)
 	{
-	  add_defn_to_vec (result, arg_sym, block);
+	  add_defn_to_vec (result, { arg_sym, block });
 	}
     }
 }
@@ -12999,8 +12983,10 @@ ada_add_exceptions_from_frame (compiled_regex *preg,
 	    default:
 	      if (ada_is_exception_sym (sym))
 		{
+		  block_symbol bsym { sym, block };
+
 		  struct ada_exc_info info = {sym->print_name (),
-					      sym->value_address ()};
+					      bsym.address ()};
 
 		  exceptions->push_back (info);
 		}
@@ -13075,8 +13061,10 @@ ada_add_global_exceptions (compiled_regex *preg,
 		if (ada_is_non_standard_exception_sym (sym)
 		    && name_matches_regex (sym->natural_name (), preg))
 		  {
+		    block_symbol bsym { sym, b };
+
 		    struct ada_exc_info info
-		      = {sym->print_name (), sym->value_address ()};
+		      = {sym->print_name (), bsym.address ()};
 
 		    exceptions->push_back (info);
 		  }

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 12/31] Use bound_symbol::address in symmisc.c
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (10 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 11/31] Use block_symbol::address in ada-lang.c Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 13/31] Introduce read_var_value overload Tom Tromey
                   ` (19 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This changes symmisc.c to use bound_symbol::address.
---
 gdb/symmisc.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index c1a6ab5cd7d..e84dd2ce049 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -44,7 +44,7 @@
 
 static int block_depth (const struct block *);
 
-static void print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
+static void print_symbol (struct gdbarch *gdbarch, bound_symbol symbol,
 			  int depth, ui_file *outfile);
 \f
 
@@ -309,7 +309,8 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
 	    {
 	      try
 		{
-		  print_symbol (gdbarch, sym, depth + 1, outfile);
+		  bound_symbol bsym { sym, objfile };
+		  print_symbol (gdbarch, bsym, depth + 1, outfile);
 		}
 	      catch (const gdb_exception_error &ex)
 		{
@@ -489,11 +490,13 @@ maintenance_print_symbols (const char *args, int from_tty)
 /* Print symbol SYMBOL on OUTFILE.  DEPTH says how far to indent.  */
 
 static void
-print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
+print_symbol (struct gdbarch *gdbarch, bound_symbol bsymbol,
 	      int depth, ui_file *outfile)
 {
   struct obj_section *section;
 
+  symbol *symbol = bsymbol.symbol;
+
   if (symbol->is_objfile_owned ())
     section = symbol->obj_section (symbol->objfile ());
   else
@@ -503,7 +506,7 @@ print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
   if (symbol->domain () == LABEL_DOMAIN)
     {
       gdb_printf (outfile, "label %s at ", symbol->print_name ());
-      gdb_puts (paddress (gdbarch, symbol->value_address ()),
+      gdb_puts (paddress (gdbarch, bsymbol.address ()),
 		outfile);
       if (section)
 	gdb_printf (outfile, " section %s\n",
@@ -573,7 +576,7 @@ print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
 
 	case LOC_STATIC:
 	  gdb_printf (outfile, "static at ");
-	  gdb_puts (paddress (gdbarch, symbol->value_address ()), outfile);
+	  gdb_puts (paddress (gdbarch, bsymbol.address ()), outfile);
 	  if (section)
 	    gdb_printf (outfile, " section %s",
 			bfd_section_name (section->the_bfd_section));
@@ -613,7 +616,7 @@ print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
 
 	case LOC_LABEL:
 	  gdb_printf (outfile, "label at ");
-	  gdb_puts (paddress (gdbarch, symbol->value_address ()), outfile);
+	  gdb_puts (paddress (gdbarch, bsymbol.address ()), outfile);
 	  if (section)
 	    gdb_printf (outfile, " section %s",
 			bfd_section_name (section->the_bfd_section));

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 13/31] Introduce read_var_value overload
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (11 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 12/31] Use bound_symbol::address in symmisc.c Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 14/31] Use read_var_value in gdb/compile Tom Tromey
                   ` (18 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This adds an overload of read_var_value that accepts a block_symbol.
The next batch of patches concern rewriting gdb to use this overload,
in the end allowing us to remove a use of value_address.
---
 gdb/compile/compile-c-symbols.c     |  2 +-
 gdb/compile/compile-cplus-symbols.c |  2 +-
 gdb/findvar.c                       | 12 ++++++++++++
 gdb/infrun.c                        |  2 +-
 gdb/valops.c                        | 26 ++++++++++++--------------
 gdb/value.h                         |  3 +++
 6 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index 2d49ead249e..40578bf36f4 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -155,7 +155,7 @@ convert_one_symbol (compile_c_instance *context,
 			 sym.symbol->print_name ());
 	      }
 
-	    val = read_var_value (sym.symbol, sym.block, frame);
+	    val = read_var_value (sym, frame);
 	    if (val->lval () != lval_memory)
 	      error (_("Symbol \"%s\" cannot be used for compilation "
 		       "evaluation as its address has not been found."),
diff --git a/gdb/compile/compile-cplus-symbols.c b/gdb/compile/compile-cplus-symbols.c
index dec0260bf7a..1288225f08e 100644
--- a/gdb/compile/compile-cplus-symbols.c
+++ b/gdb/compile/compile-cplus-symbols.c
@@ -151,7 +151,7 @@ convert_one_symbol (compile_cplus_instance *instance,
 			 sym.symbol->print_name ());
 	      }
 
-	    val = read_var_value (sym.symbol, sym.block, frame);
+	    val = read_var_value (sym, frame);
 	    if (val->lval () != lval_memory)
 	      error (_("Symbol \"%s\" cannot be used for compilation "
 		       "evaluation as its address has not been found."),
diff --git a/gdb/findvar.c b/gdb/findvar.c
index 4e992ecdcc7..909dca65532 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -794,6 +794,18 @@ read_var_value (struct symbol *var, const struct block *var_block,
   return lang->read_var_value (var, var_block, frame);
 }
 
+/* Calls VAR's language read_var_value hook with the given arguments.  */
+
+struct value *
+read_var_value (block_symbol var, frame_info_ptr frame)
+{
+  const struct language_defn *lang = language_def (var.symbol->language ());
+
+  gdb_assert (lang != NULL);
+
+  return lang->read_var_value (var.symbol, var.block, frame);
+}
+
 /* Install default attributes for register values.  */
 
 struct value *
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 4fde96800fb..a7cb02c958e 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -8311,7 +8311,7 @@ insert_exception_resume_breakpoint (struct thread_info *tp,
 
       vsym = lookup_symbol_search_name (sym->search_name (),
 					b, VAR_DOMAIN);
-      value = read_var_value (vsym.symbol, vsym.block, frame);
+      value = read_var_value (vsym, frame);
       /* If the value was optimized out, revert to the old behavior.  */
       if (! value->optimized_out ())
 	{
diff --git a/gdb/valops.c b/gdb/valops.c
index 70851cd40b4..b7ed458a649 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3711,17 +3711,16 @@ value_struct_elt_for_reference (struct type *domain, int offset,
 
 	  if (TYPE_FN_FIELD_STATIC_P (f, j))
 	    {
-	      struct symbol *s = 
-		lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
-			       0, VAR_DOMAIN, 0).symbol;
+	      block_symbol s = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
+					      0, VAR_DOMAIN, 0);
 
-	      if (s == NULL)
-		return NULL;
+	      if (s.symbol == nullptr)
+		return nullptr;
 
 	      if (want_address)
-		return value_addr (read_var_value (s, 0, 0));
+		return value_addr (read_var_value (s, 0));
 	      else
-		return read_var_value (s, 0, 0);
+		return read_var_value (s, 0);
 	    }
 
 	  if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
@@ -3742,14 +3741,13 @@ value_struct_elt_for_reference (struct type *domain, int offset,
 	    }
 	  else
 	    {
-	      struct symbol *s = 
-		lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
-			       0, VAR_DOMAIN, 0).symbol;
+	      block_symbol s = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
+					      0, VAR_DOMAIN, 0);
 
-	      if (s == NULL)
-		return NULL;
+	      if (s.symbol == nullptr)
+		return nullptr;
 
-	      struct value *v = read_var_value (s, 0, 0);
+	      struct value *v = read_var_value (s, 0);
 	      if (!want_address)
 		result = v;
 	      else
@@ -4000,7 +3998,7 @@ value_of_this (const struct language_defn *lang)
     error (_("current stack frame does not contain a variable named `%s'"),
 	   lang->name_of_this ());
 
-  return read_var_value (sym.symbol, sym.block, frame);
+  return read_var_value (sym, frame);
 }
 
 /* Return the value of the local variable, if one exists.  Return NULL
diff --git a/gdb/value.h b/gdb/value.h
index e4912717684..b683cbf5f90 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1140,6 +1140,9 @@ extern struct value *read_var_value (struct symbol *var,
 				     const struct block *var_block,
 				     frame_info_ptr frame);
 
+extern struct value *read_var_value (block_symbol var,
+				     frame_info_ptr frame);
+
 extern struct value *allocate_repeat_value (struct type *type, int count);
 
 extern struct value *value_mark (void);

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 14/31] Use read_var_value in gdb/compile
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (12 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 13/31] Introduce read_var_value overload Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 15/31] Return a block_symbol from find_pc_sect_function Tom Tromey
                   ` (17 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This changes the code in gdb/compile to use the new read_var_value
overload.
---
 gdb/compile/compile-c-symbols.c | 12 +++++++-----
 gdb/compile/compile-loc2c.c     | 14 ++++++++------
 gdb/compile/compile.h           |  6 +++---
 gdb/dwarf2/ada-imported.c       |  2 +-
 gdb/dwarf2/loc.c                | 12 +++++++-----
 gdb/dwarf2/loc.h                |  3 ++-
 gdb/symtab.h                    |  2 +-
 7 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index 40578bf36f4..b8632013909 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -493,7 +493,7 @@ generate_vla_size (compile_instance *compiler,
 		   std::vector<bool> &registers_used,
 		   CORE_ADDR pc,
 		   struct type *type,
-		   struct symbol *sym)
+		   block_symbol sym)
 {
   type = check_typedef (type);
 
@@ -546,8 +546,9 @@ generate_c_for_for_one_variable (compile_instance *compiler,
 				 struct gdbarch *gdbarch,
 				 std::vector<bool> &registers_used,
 				 CORE_ADDR pc,
-				 struct symbol *sym)
+				 block_symbol bsym)
 {
+  struct symbol *sym = bsym.symbol;
 
   try
     {
@@ -558,7 +559,7 @@ generate_c_for_for_one_variable (compile_instance *compiler,
 	  string_file local_file;
 
 	  generate_vla_size (compiler, &local_file, gdbarch, registers_used, pc,
-			     sym->type (), sym);
+			     sym->type (), bsym);
 
 	  stream->write (local_file.c_str (), local_file.size ());
 	}
@@ -571,7 +572,7 @@ generate_c_for_for_one_variable (compile_instance *compiler,
 	     occurs in the middle.  */
 	  string_file local_file;
 
-	  SYMBOL_COMPUTED_OPS (sym)->generate_c_location (sym, &local_file,
+	  SYMBOL_COMPUTED_OPS (sym)->generate_c_location (bsym, &local_file,
 							  gdbarch,
 							  registers_used,
 							  pc,
@@ -639,9 +640,10 @@ generate_c_for_variable_locations (compile_instance *compiler,
 	 compute the location of each local variable.  */
       for (struct symbol *sym : block_iterator_range (block))
 	{
+	  block_symbol bsym { sym, block };
 	  if (!symbol_seen (symhash.get (), sym))
 	    generate_c_for_for_one_variable (compiler, stream, gdbarch,
-					     registers_used, pc, sym);
+					     registers_used, pc, bsym);
 	}
 
       /* If we just finished the outermost block of a function, we're
diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c
index 8a5a0f5abc5..ef150e7c27e 100644
--- a/gdb/compile/compile-loc2c.c
+++ b/gdb/compile/compile-loc2c.c
@@ -592,7 +592,7 @@ static void
 do_compile_dwarf_expr_to_c (int indent, string_file *stream,
 			    const char *type_name,
 			    const char *result_name,
-			    struct symbol *sym, CORE_ADDR pc,
+			    block_symbol bsym, CORE_ADDR pc,
 			    struct gdbarch *arch,
 			    std::vector<bool> &registers_used,
 			    unsigned int addr_size,
@@ -605,6 +605,8 @@ do_compile_dwarf_expr_to_c (int indent, string_file *stream,
      unique names.  */
   static unsigned int scope;
 
+  struct symbol *sym = bsym.symbol;
+
   enum bfd_endian byte_order = gdbarch_byte_order (arch);
   const gdb_byte * const base = op_ptr;
   int need_tempvar = 0;
@@ -641,7 +643,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file *stream,
 		 "there is no selected frame"),
 	       sym->print_name ());
 
-      val = read_var_value (sym, NULL, frame);
+      val = read_var_value (bsym, frame);
       if (val->lval () != lval_memory)
 	error (_("Symbol \"%s\" cannot be used for compilation evaluation "
 		 "as its address has not been found."),
@@ -909,7 +911,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file *stream,
 
 	    do_compile_dwarf_expr_to_c (indent, stream,
 					GCC_UINTPTR, fb_name,
-					sym, pc,
+					bsym, pc,
 					arch, registers_used, addr_size,
 					datastart, datastart + datalen,
 					NULL, per_cu, per_objfile);
@@ -1097,7 +1099,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file *stream,
 
 		do_compile_dwarf_expr_to_c (indent, stream,
 					    GCC_UINTPTR, cfa_name,
-					    sym, pc, arch, registers_used,
+					    bsym, pc, arch, registers_used,
 					    addr_size,
 					    cfa_start, cfa_end,
 					    &text_offset, per_cu, per_objfile);
@@ -1143,7 +1145,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file *stream,
 
 void
 compile_dwarf_expr_to_c (string_file *stream, const char *result_name,
-			 struct symbol *sym, CORE_ADDR pc,
+			 block_symbol sym, CORE_ADDR pc,
 			 struct gdbarch *arch,
 			 std::vector<bool> &registers_used,
 			 unsigned int addr_size,
@@ -1162,7 +1164,7 @@ void
 compile_dwarf_bounds_to_c (string_file *stream,
 			   const char *result_name,
 			   const struct dynamic_prop *prop,
-			   struct symbol *sym, CORE_ADDR pc,
+			   block_symbol sym, CORE_ADDR pc,
 			   struct gdbarch *arch,
 			   std::vector<bool> &registers_used,
 			   unsigned int addr_size,
diff --git a/gdb/compile/compile.h b/gdb/compile/compile.h
index a3b6a18fe20..7cb38cb006c 100644
--- a/gdb/compile/compile.h
+++ b/gdb/compile/compile.h
@@ -19,12 +19,12 @@
 #define COMPILE_COMPILE_H
 
 #include "gcc-c-interface.h"
+#include "block-symbol.h"
 
 struct ui_file;
 struct gdbarch;
 struct dwarf2_per_cu_data;
 struct dwarf2_per_objfile;
-struct symbol;
 struct dynamic_prop;
 
 /* An object of this type holds state associated with a given
@@ -177,7 +177,7 @@ extern void eval_compile_command (struct command_line *cmd,
 
 extern void compile_dwarf_expr_to_c (string_file *stream,
 				     const char *result_name,
-				     struct symbol *sym,
+				     block_symbol sym,
 				     CORE_ADDR pc,
 				     struct gdbarch *arch,
 				     std::vector<bool> &registers_used,
@@ -217,7 +217,7 @@ extern void compile_dwarf_expr_to_c (string_file *stream,
 extern void compile_dwarf_bounds_to_c (string_file *stream,
 				       const char *result_name,
 				       const struct dynamic_prop *prop,
-				       struct symbol *sym, CORE_ADDR pc,
+				       block_symbol sym, CORE_ADDR pc,
 				       struct gdbarch *arch,
 				       std::vector<bool> &registers_used,
 				       unsigned int addr_size,
diff --git a/gdb/dwarf2/ada-imported.c b/gdb/dwarf2/ada-imported.c
index d1d99be6923..9947d8e04b7 100644
--- a/gdb/dwarf2/ada-imported.c
+++ b/gdb/dwarf2/ada-imported.c
@@ -75,7 +75,7 @@ ada_imported_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
    symbol_computed_ops.  */
 
 static void
-ada_imported_generate_c_location (struct symbol *symbol, string_file *stream,
+ada_imported_generate_c_location (block_symbol symbol, string_file *stream,
 				  struct gdbarch *gdbarch,
 				  std::vector<bool> &registers_used,
 				  CORE_ADDR pc, const char *result_name)
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index 5b2d58ab44e..53031aa809a 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -1786,7 +1786,7 @@ dwarf2_compile_property_to_c (string_file *stream,
 			      std::vector<bool> &registers_used,
 			      const struct dynamic_prop *prop,
 			      CORE_ADDR pc,
-			      struct symbol *sym)
+			      block_symbol sym)
 {
   const dwarf2_property_baton *baton = prop->baton ();
   const gdb_byte *data;
@@ -3847,11 +3847,12 @@ locexpr_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
 /* symbol_computed_ops 'generate_c_location' method.  */
 
 static void
-locexpr_generate_c_location (struct symbol *sym, string_file *stream,
+locexpr_generate_c_location (block_symbol bsym, string_file *stream,
 			     struct gdbarch *gdbarch,
 			     std::vector<bool> &registers_used,
 			     CORE_ADDR pc, const char *result_name)
 {
+  symbol *sym = bsym.symbol;
   struct dwarf2_locexpr_baton *dlbaton
     = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (sym);
   unsigned int addr_size = dlbaton->per_cu->addr_size ();
@@ -3860,7 +3861,7 @@ locexpr_generate_c_location (struct symbol *sym, string_file *stream,
     error (_("symbol \"%s\" is optimized out"), sym->natural_name ());
 
   compile_dwarf_expr_to_c (stream, result_name,
-			   sym, pc, gdbarch, registers_used, addr_size,
+			   bsym, pc, gdbarch, registers_used, addr_size,
 			   dlbaton->data, dlbaton->data + dlbaton->size,
 			   dlbaton->per_cu, dlbaton->per_objfile);
 }
@@ -4083,11 +4084,12 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
 /* symbol_computed_ops 'generate_c_location' method.  */
 
 static void
-loclist_generate_c_location (struct symbol *sym, string_file *stream,
+loclist_generate_c_location (block_symbol bsym, string_file *stream,
 			     struct gdbarch *gdbarch,
 			     std::vector<bool> &registers_used,
 			     CORE_ADDR pc, const char *result_name)
 {
+  symbol *sym = bsym.symbol;
   struct dwarf2_loclist_baton *dlbaton
     = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (sym);
   unsigned int addr_size = dlbaton->per_cu->addr_size ();
@@ -4099,7 +4101,7 @@ loclist_generate_c_location (struct symbol *sym, string_file *stream,
     error (_("symbol \"%s\" is optimized out"), sym->natural_name ());
 
   compile_dwarf_expr_to_c (stream, result_name,
-			   sym, pc, gdbarch, registers_used, addr_size,
+			   bsym, pc, gdbarch, registers_used, addr_size,
 			   data, data + size,
 			   dlbaton->per_cu,
 			   dlbaton->per_objfile);
diff --git a/gdb/dwarf2/loc.h b/gdb/dwarf2/loc.h
index 5cf824d3ae2..9722083cbeb 100644
--- a/gdb/dwarf2/loc.h
+++ b/gdb/dwarf2/loc.h
@@ -21,6 +21,7 @@
 #define DWARF2LOC_H
 
 #include "dwarf2/expr.h"
+#include "block-symbol.h"
 
 struct symbol_computed_ops;
 struct dwarf2_per_objfile;
@@ -144,7 +145,7 @@ void dwarf2_compile_property_to_c (string_file *stream,
 				   std::vector<bool> &registers_used,
 				   const struct dynamic_prop *prop,
 				   CORE_ADDR address,
-				   struct symbol *sym);
+				   block_symbol sym);
 
 /* The symbol location baton types used by the DWARF-2 reader (i.e.
    SYMBOL_LOCATION_BATON for a LOC_COMPUTED symbol).  "struct
diff --git a/gdb/symtab.h b/gdb/symtab.h
index a518ed83622..34ce10f5011 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1130,7 +1130,7 @@ struct symbol_computed_ops
      The generated C code must assign the location to a local
      variable; this variable's name is RESULT_NAME.  */
 
-  void (*generate_c_location) (struct symbol *symbol, string_file *stream,
+  void (*generate_c_location) (block_symbol symbol, string_file *stream,
 			       struct gdbarch *gdbarch,
 			       std::vector<bool> &registers_used,
 			       CORE_ADDR pc, const char *result_name);

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 15/31] Return a block_symbol from find_pc_sect_function
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (13 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 14/31] Use read_var_value in gdb/compile Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 16/31] Use read_var_value overload in finish_command_fsm Tom Tromey
                   ` (16 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This changes find_pc_sect_function to return a block_symbol and
updates all the callers in a minimal way.

A less intrusive approach might be possible -- but in the long run
we'll want to add an objfile into this result, so it makes sense to go
ahead with the conversion now.
---
 gdb/blockframe.c                 | 12 ++++++------
 gdb/breakpoint.c                 |  2 +-
 gdb/btrace.c                     |  2 +-
 gdb/cli/cli-cmds.c               |  4 ++--
 gdb/dwarf2/loc.c                 |  2 +-
 gdb/eval.c                       |  2 +-
 gdb/guile/scm-frame.c            |  2 +-
 gdb/infcall.c                    |  2 +-
 gdb/infcmd.c                     |  6 +++---
 gdb/infrun.c                     |  4 ++--
 gdb/printcmd.c                   |  2 +-
 gdb/python/py-finishbreakpoint.c |  2 +-
 gdb/solib-frv.c                  |  2 +-
 gdb/sparc-tdep.c                 |  4 ++--
 gdb/symtab.c                     |  4 ++--
 gdb/symtab.h                     |  4 ++--
 gdb/tracepoint.c                 |  4 ++--
 17 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/gdb/blockframe.c b/gdb/blockframe.c
index 633a9674d97..981094803ed 100644
--- a/gdb/blockframe.c
+++ b/gdb/blockframe.c
@@ -132,21 +132,21 @@ get_frame_function (frame_info_ptr frame)
 /* Return the function containing pc value PC in section SECTION.
    Returns 0 if function is not known.  */
 
-struct symbol *
+block_symbol
 find_pc_sect_function (CORE_ADDR pc, struct obj_section *section)
 {
   const struct block *b = block_for_pc_sect (pc, section);
 
   if (b == 0)
-    return 0;
-  return b->linkage_function ();
+    return {};
+  return { b->linkage_function (), b };
 }
 
 /* Return the function containing pc value PC.
    Returns 0 if function is not known.  
    Backward compatibility, no section */
 
-struct symbol *
+block_symbol
 find_pc_function (CORE_ADDR pc)
 {
   return find_pc_sect_function (pc, find_pc_mapped_section (pc));
@@ -251,7 +251,7 @@ find_pc_partial_function_sym (CORE_ADDR pc,
 	 address of the function.  This will happen when the function
 	 has more than one range and the entry pc is not within the
 	 lowest range of addresses.  */
-      f = find_pc_sect_function (mapped_pc, section);
+      f = find_pc_sect_function (mapped_pc, section).symbol;
       if (f != NULL
 	  && (msymbol.minsym == NULL
 	      || (f->value_block ()->entry_pc ()
@@ -421,7 +421,7 @@ find_function_entry_range_from_pc (CORE_ADDR pc, const char **name,
 struct type *
 find_function_type (CORE_ADDR pc)
 {
-  struct symbol *sym = find_pc_function (pc);
+  struct symbol *sym = find_pc_function (pc).symbol;
 
   if (sym != NULL && sym->value_block ()->entry_pc () == pc)
     return sym->type ();
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index fe09dbcbeee..52ce63afade 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -12862,7 +12862,7 @@ update_static_tracepoint (tracepoint *tp, struct symtab_and_line sal)
 		   tp->number, tp->static_trace_marker_id.c_str ());
 
 	  symtab_and_line sal2 = find_pc_line (tpmarker->address, 0);
-	  sym = find_pc_sect_function (tpmarker->address, NULL);
+	  sym = find_pc_sect_function (tpmarker->address, NULL).symbol;
 	  uiout->text ("Now in ");
 	  if (sym)
 	    {
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 3f72b9c91e5..ea18daa23e0 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -556,7 +556,7 @@ ftrace_update_function (struct btrace_thread_info *btinfo, CORE_ADDR pc)
   /* Try to determine the function we're in.  We use both types of symbols
      to avoid surprises when we sometimes get a full symbol and sometimes
      only a minimal symbol.  */
-  fun = find_pc_function (pc);
+  fun = find_pc_function (pc).symbol;
   bmfun = lookup_minimal_symbol_by_pc (pc);
   mfun = bmfun.minsym;
 
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 8cadd637151..cfd0ff15acb 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -1040,7 +1040,7 @@ edit_command (const char *arg, int from_tty)
 		   paddress (get_current_arch (), sal.pc));
 
 	  gdbarch = sal.symtab->compunit ()->objfile ()->arch ();
-	  sym = find_pc_function (sal.pc);
+	  sym = find_pc_function (sal.pc).symbol;
 	  if (sym)
 	    gdb_printf ("%s is in %s (%s:%d).\n",
 			paddress (gdbarch, sal.pc),
@@ -1424,7 +1424,7 @@ list_command (const char *arg, int from_tty)
 	       paddress (get_current_arch (), sal.pc));
 
       gdbarch = sal.symtab->compunit ()->objfile ()->arch ();
-      sym = find_pc_function (sal.pc);
+      sym = find_pc_function (sal.pc).symbol;
       if (sym)
 	gdb_printf ("%s is in %s (%s:%d).\n",
 		    paddress (gdbarch, sal.pc),
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index 53031aa809a..17509f81464 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -762,7 +762,7 @@ call_site_target::iterate_over_addresses
 static struct symbol *
 func_addr_to_tail_call_list (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  struct symbol *sym = find_pc_function (addr);
+  struct symbol *sym = find_pc_function (addr).symbol;
   struct type *type;
 
   if (sym == NULL || sym->value_block ()->entry_pc () != addr)
diff --git a/gdb/eval.c b/gdb/eval.c
index b859e825925..9b76d3d5376 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -2037,7 +2037,7 @@ eval_op_objc_msgcall (struct type *expect_type, struct expression *exp,
 	(exp->gdbarch, addr, current_inferior ()->top_target ());
 
       /* Is it a high_level symbol?  */
-      sym = find_pc_function (addr);
+      sym = find_pc_function (addr).symbol;
       if (sym != NULL)
 	method = value_of_variable (sym, 0);
     }
diff --git a/gdb/guile/scm-frame.c b/gdb/guile/scm-frame.c
index 45863c587c1..74012ffea4f 100644
--- a/gdb/guile/scm-frame.c
+++ b/gdb/guile/scm-frame.c
@@ -666,7 +666,7 @@ gdbscm_frame_function (SCM self)
       if (frame != NULL)
 	{
 	  found = true;
-	  sym = find_pc_function (get_frame_address_in_block (frame));
+	  sym = find_pc_function (get_frame_address_in_block (frame)).symbol;
 	}
     }
   catch (const gdb_exception &except)
diff --git a/gdb/infcall.c b/gdb/infcall.c
index 0f9ad34bbb4..a36a5e81b3a 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -413,7 +413,7 @@ static const char *
 get_function_name (CORE_ADDR funaddr, char *buf, int buf_size)
 {
   {
-    struct symbol *symbol = find_pc_function (funaddr);
+    struct symbol *symbol = find_pc_function (funaddr).symbol;
 
     if (symbol)
       return symbol->print_name ();
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index cf8cd527955..c50d9bcd47d 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -750,7 +750,7 @@ set_step_frame (thread_info *tp)
   set_step_info (tp, frame, sal);
 
   CORE_ADDR pc = get_frame_pc (frame);
-  tp->control.step_start_function = find_pc_function (pc);
+  tp->control.step_start_function = find_pc_function (pc).symbol;
 }
 
 /* Step until outside of current statement.  */
@@ -1343,7 +1343,7 @@ until_next_command (int from_tty)
      not).  */
 
   pc = get_frame_pc (frame);
-  func = find_pc_function (pc);
+  func = find_pc_function (pc).symbol;
 
   if (!func)
     {
@@ -1883,7 +1883,7 @@ finish_command (const char *arg, int from_tty)
 
   /* Find the function we will return from.  */
   frame_info_ptr callee_frame = get_selected_frame (nullptr);
-  sm->function = find_pc_function (get_frame_pc (callee_frame));
+  sm->function = find_pc_function (get_frame_pc (callee_frame)).symbol;
   sm->return_buf = 0;    /* Initialize buffer address is not available.  */
 
   /* Determine the return convention.  If it is RETURN_VALUE_STRUCT_CONVENTION,
diff --git a/gdb/infrun.c b/gdb/infrun.c
index a7cb02c958e..2a004690e67 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -7343,7 +7343,7 @@ process_event_stop_test (struct execution_control_state *ecs)
 	  && ((ecs->event_thread->control.step_stack_frame_id
 	       != outer_frame_id)
 	      || (ecs->event_thread->control.step_start_function
-		  != find_pc_function (ecs->event_thread->stop_pc ())))))
+		  != find_pc_function (ecs->event_thread->stop_pc ()).symbol))))
     {
       CORE_ADDR stop_pc = ecs->event_thread->stop_pc ();
       CORE_ADDR real_stop_pc;
@@ -8752,7 +8752,7 @@ print_stop_location (const target_waitstatus &ws)
 	  && (tp->control.step_frame_id
 	      == get_frame_id (get_current_frame ()))
 	  && (tp->control.step_start_function
-	      == find_pc_function (tp->stop_pc ())))
+	      == find_pc_function (tp->stop_pc ()).symbol))
 	{
 	  /* Finished step, just print source line.  */
 	  source_flag = SRC_LINE;
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 2dbaaf0fffe..57a7af67ffe 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -637,7 +637,7 @@ build_address_symbolic (struct gdbarch *gdbarch,
      anything/stabs--it would be inconvenient to eliminate those minimal
      symbols anyway).  */
   msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
-  symbol = find_pc_sect_function (addr, section);
+  symbol = find_pc_sect_function (addr, section).symbol;
 
   if (symbol)
     {
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index 627eb297542..04fc8c9e8a7 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -252,7 +252,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
     {
       if (get_frame_pc_if_available (frame, &pc))
 	{
-	  struct symbol *function = find_pc_function (pc);
+	  struct symbol *function = find_pc_function (pc).symbol;
 	  if (function != nullptr)
 	    {
 	      struct type *ret_type =
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index 0897bce2325..aeaf0044ba7 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -893,7 +893,7 @@ frv_fdpic_find_canonical_descriptor (CORE_ADDR entry_point)
   /* Attempt to find the name of the function.  If the name is available,
      it'll be used as an aid in finding matching functions in the dynamic
      symbol table.  */
-  sym = find_pc_function (entry_point);
+  sym = find_pc_function (entry_point).symbol;
   if (sym == 0)
     name = 0;
   else
diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
index 78f240db04e..48a1adb7553 100644
--- a/gdb/sparc-tdep.c
+++ b/gdb/sparc-tdep.c
@@ -1249,7 +1249,7 @@ sparc32_frame_cache (frame_info_ptr this_frame, void **this_cache)
 
   cache = sparc_frame_cache (this_frame, this_cache);
 
-  sym = find_pc_function (cache->pc);
+  sym = find_pc_function (cache->pc).symbol;
   if (sym)
     {
       cache->struct_return_p = sparc32_struct_return_from_sym (sym);
@@ -1552,7 +1552,7 @@ static int
 sparc32_dwarf2_struct_return_p (frame_info_ptr this_frame)
 {
   CORE_ADDR pc = get_frame_address_in_block (this_frame);
-  struct symbol *sym = find_pc_function (pc);
+  struct symbol *sym = find_pc_function (pc).symbol;
 
   if (sym)
     return sparc32_struct_return_from_sym (sym);
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 5ec56f4f2af..c1d78e1e2a6 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -3790,7 +3790,7 @@ skip_prologue_sal (struct symtab_and_line *sal)
 
   switch_to_program_space_and_thread (sal->pspace);
 
-  sym = find_pc_sect_function (sal->pc, sal->section);
+  sym = find_pc_sect_function (sal->pc, sal->section).symbol;
   if (sym != NULL)
     {
       objfile = sym->objfile ();
@@ -4069,7 +4069,7 @@ find_function_alias_target (bound_minimal_symbol msymbol)
   if (!msymbol_is_function (msymbol.objfile, msymbol.minsym, &func_addr))
     return NULL;
 
-  symbol *sym = find_pc_function (func_addr);
+  symbol *sym = find_pc_function (func_addr).symbol;
   if (sym != NULL
       && sym->aclass () == LOC_BLOCK
       && sym->value_block ()->entry_pc () == func_addr)
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 34ce10f5011..059f7cfe8a7 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2171,13 +2171,13 @@ extern struct type *lookup_enum (const char *, const struct block *);
    return value will not be an inlined function; the containing
    function will be returned instead.  */
 
-extern struct symbol *find_pc_function (CORE_ADDR);
+extern block_symbol find_pc_function (CORE_ADDR);
 
 /* lookup the function corresponding to the address and section.  The
    return value will not be an inlined function; the containing
    function will be returned instead.  */
 
-extern struct symbol *find_pc_sect_function (CORE_ADDR, struct obj_section *);
+extern block_symbol find_pc_sect_function (CORE_ADDR, struct obj_section *);
 
 /* lookup the function symbol corresponding to the address and
    section.  The return value will be the closest enclosing function,
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 713fb387857..2d65f7c7920 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -217,7 +217,7 @@ set_traceframe_context (frame_info_ptr trace_frame)
       && get_frame_pc_if_available (trace_frame, &trace_pc))
     {
       traceframe_sal = find_pc_line (trace_pc, 0);
-      traceframe_fun = find_pc_function (trace_pc);
+      traceframe_fun = find_pc_function (trace_pc).symbol;
 
       /* Save linenumber as "$trace_line", a debugger variable visible to
 	 users.  */
@@ -3623,7 +3623,7 @@ print_one_static_tracepoint_marker (int count,
   uiout->field_core_addr ("addr", marker.gdbarch, marker.address);
 
   sal = find_pc_line (marker.address, 0);
-  sym = find_pc_sect_function (marker.address, NULL);
+  sym = find_pc_sect_function (marker.address, NULL).symbol;
   if (sym)
     {
       uiout->text ("in ");

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 16/31] Use read_var_value overload in finish_command_fsm
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (14 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 15/31] Return a block_symbol from find_pc_sect_function Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 17/31] Use block_symbol in overload-handling code Tom Tromey
                   ` (15 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This changes finish_command_fsm to store a block_symbol, so that the
new read_var_value overload can be used.
---
 gdb/infcmd.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index c50d9bcd47d..03e54438686 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -1596,7 +1596,7 @@ struct finish_command_fsm : public thread_fsm
   breakpoint_up breakpoint;
 
   /* The function that we're stepping out of.  */
-  struct symbol *function = nullptr;
+  block_symbol function {};
 
   /* If the FSM finishes successfully, this stores the function's
      return value.  */
@@ -1629,14 +1629,14 @@ finish_command_fsm::should_stop (struct thread_info *tp)
 {
   struct return_value_info *rv = &return_value_info;
 
-  if (function != nullptr
+  if (function.symbol != nullptr
       && bpstat_find_breakpoint (tp->control.stop_bpstat,
 				 breakpoint.get ()) != nullptr)
     {
       /* We're done.  */
       set_finished ();
 
-      rv->type = function->type ()->target_type ();
+      rv->type = function.symbol->type ()->target_type ();
       if (rv->type == nullptr)
 	internal_error (_("finish_command: function has no target type"));
 
@@ -1644,13 +1644,13 @@ finish_command_fsm::should_stop (struct thread_info *tp)
 	{
 	  struct value *func;
 
-	  func = read_var_value (function, nullptr, get_current_frame ());
+	  func = read_var_value (function, get_current_frame ());
 
 	  if (return_buf != 0)
 	    /* Retrieve return value from the buffer where it was saved.  */
 	      rv->value = value_at (rv->type, return_buf);
 	  else
-	      rv->value = get_return_value (function, func);
+	      rv->value = get_return_value (function.symbol, func);
 
 	  if (rv->value != nullptr)
 	    rv->value_history_index = rv->value->record_latest ();
@@ -1883,22 +1883,22 @@ finish_command (const char *arg, int from_tty)
 
   /* Find the function we will return from.  */
   frame_info_ptr callee_frame = get_selected_frame (nullptr);
-  sm->function = find_pc_function (get_frame_pc (callee_frame)).symbol;
+  sm->function = find_pc_function (get_frame_pc (callee_frame));
   sm->return_buf = 0;    /* Initialize buffer address is not available.  */
 
   /* Determine the return convention.  If it is RETURN_VALUE_STRUCT_CONVENTION,
      attempt to determine the address of the return buffer.  */
-  if (sm->function != nullptr)
+  if (sm->function.symbol != nullptr)
     {
       enum return_value_convention return_value;
       struct gdbarch *gdbarch = get_frame_arch (callee_frame);
 
       struct type * val_type
-	= check_typedef (sm->function->type ()->target_type ());
+	= check_typedef (sm->function.symbol->type ()->target_type ());
 
       return_value
 	= gdbarch_return_value_as_value (gdbarch,
-					 read_var_value (sm->function, nullptr,
+					 read_var_value (sm->function,
 							 callee_frame),
 					 val_type, nullptr, nullptr, nullptr);
 
@@ -1916,10 +1916,11 @@ finish_command (const char *arg, int from_tty)
 	gdb_printf (_("Run back to call of "));
       else
 	{
-	  if (sm->function != nullptr && TYPE_NO_RETURN (sm->function->type ())
+	  if (sm->function.symbol != nullptr
+	      && TYPE_NO_RETURN (sm->function.symbol->type ())
 	      && !query (_("warning: Function %s does not return normally.\n"
 			   "Try to finish anyway? "),
-			 sm->function->print_name ()))
+			 sm->function.symbol->print_name ()))
 	    error (_("Not confirmed."));
 	  gdb_printf (_("Run till exit from "));
 	}

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 17/31] Use block_symbol in overload-handling code
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (15 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 16/31] Use read_var_value overload in finish_command_fsm Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 18/31] Change evaluate_var_value to accept a block_symbol Tom Tromey
                   ` (14 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This changes the overload-handling code to use block_symbol.  This is
needed to update one of its callers to use the new read_var_value
overload.
---
 gdb/cp-support.c | 46 ++++++++++++++++++++++++++--------------------
 gdb/cp-support.h |  6 +++---
 gdb/eval.c       | 35 ++++++++++++++++++-----------------
 gdb/infcall.c    |  2 +-
 gdb/valarith.c   |  9 ++++-----
 gdb/valops.c     | 34 +++++++++++++++++-----------------
 gdb/value.h      |  4 ++--
 7 files changed, 71 insertions(+), 65 deletions(-)

diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index e02e859b99a..4fbde37b280 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -57,17 +57,17 @@ static void demangled_name_complaint (const char *name);
 
 /* Functions related to overload resolution.  */
 
-static void overload_list_add_symbol (struct symbol *sym,
+static void overload_list_add_symbol (block_symbol sym,
 				      const char *oload_name,
-				      std::vector<symbol *> *overload_list);
+				      std::vector<block_symbol> *overload_list);
 
 static void add_symbol_overload_list_using
   (const char *func_name, const char *the_namespace,
-   std::vector<symbol *> *overload_list);
+   std::vector<block_symbol> *overload_list);
 
 static void add_symbol_overload_list_qualified
   (const char *func_name,
-   std::vector<symbol *> *overload_list);
+   std::vector<block_symbol> *overload_list);
 
 /* The list of "maint cplus" commands.  */
 
@@ -1210,18 +1210,20 @@ cp_entire_prefix_len (const char *name)
    OVERLOAD_LIST.  */
 
 static void
-overload_list_add_symbol (struct symbol *sym,
+overload_list_add_symbol (block_symbol bsym,
 			  const char *oload_name,
-			  std::vector<symbol *> *overload_list)
+			  std::vector<block_symbol> *overload_list)
 {
+  symbol *sym = bsym.symbol;
+
   /* If there is no type information, we can't do anything, so
      skip.  */
   if (sym->type () == NULL)
     return;
 
   /* skip any symbols that we've already considered.  */
-  for (symbol *listed_sym : *overload_list)
-    if (strcmp (sym->linkage_name (), listed_sym->linkage_name ()) == 0)
+  for (block_symbol listed_sym : *overload_list)
+    if (strcmp (sym->linkage_name (), listed_sym.symbol->linkage_name ()) == 0)
       return;
 
   /* Get the demangled name without parameters */
@@ -1234,18 +1236,18 @@ overload_list_add_symbol (struct symbol *sym,
   if (strcmp (sym_name.get (), oload_name) != 0)
     return;
 
-  overload_list->push_back (sym);
+  overload_list->push_back (bsym);
 }
 
 /* Return a null-terminated list of pointers to function symbols that
    are named FUNC_NAME and are visible within NAMESPACE.  */
 
-struct std::vector<symbol *>
+struct std::vector<block_symbol>
 make_symbol_overload_list (const char *func_name,
 			   const char *the_namespace)
 {
   const char *name;
-  std::vector<symbol *> overload_list;
+  std::vector<block_symbol> overload_list;
 
   overload_list.reserve (100);
 
@@ -1273,12 +1275,15 @@ make_symbol_overload_list (const char *func_name,
 static void
 add_symbol_overload_list_block (const char *name,
 				const struct block *block,
-				std::vector<symbol *> *overload_list)
+				std::vector<block_symbol> *overload_list)
 {
   lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
 
   for (struct symbol *sym : block_iterator_range (block, &lookup_name))
-    overload_list_add_symbol (sym, name, overload_list);
+    {
+      block_symbol bsym { sym, block };
+      overload_list_add_symbol (bsym, name, overload_list);
+    }
 }
 
 /* Adds the function FUNC_NAME from NAMESPACE to the overload set.  */
@@ -1286,7 +1291,7 @@ add_symbol_overload_list_block (const char *name,
 static void
 add_symbol_overload_list_namespace (const char *func_name,
 				    const char *the_namespace,
-				    std::vector<symbol *> *overload_list)
+				    std::vector<block_symbol> *overload_list)
 {
   const char *name;
   const struct block *block = NULL;
@@ -1322,9 +1327,10 @@ add_symbol_overload_list_namespace (const char *func_name,
    base types.  */
 
 static void
-add_symbol_overload_list_adl_namespace (struct type *type,
-					const char *func_name,
-					std::vector<symbol *> *overload_list)
+add_symbol_overload_list_adl_namespace
+     (struct type *type,
+      const char *func_name,
+      std::vector<block_symbol> *overload_list)
 {
   char *the_namespace;
   const char *type_name;
@@ -1374,7 +1380,7 @@ add_symbol_overload_list_adl_namespace (struct type *type,
 void
 add_symbol_overload_list_adl (gdb::array_view<type *> arg_types,
 			      const char *func_name,
-			      std::vector<symbol *> *overload_list)
+			      std::vector<block_symbol> *overload_list)
 {
   for (type *arg_type : arg_types)
     add_symbol_overload_list_adl_namespace (arg_type, func_name,
@@ -1389,7 +1395,7 @@ add_symbol_overload_list_adl (gdb::array_view<type *> arg_types,
 static void
 add_symbol_overload_list_using (const char *func_name,
 				const char *the_namespace,
-				std::vector<symbol *> *overload_list)
+				std::vector<block_symbol> *overload_list)
 {
   struct using_direct *current;
   const struct block *block;
@@ -1438,7 +1444,7 @@ add_symbol_overload_list_using (const char *func_name,
 
 static void
 add_symbol_overload_list_qualified (const char *func_name,
-				    std::vector<symbol *> *overload_list)
+				    std::vector<block_symbol> *overload_list)
 {
   const struct block *surrounding_static_block = 0;
 
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index 709dca46df1..7f27120a0fe 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -107,13 +107,13 @@ extern gdb::unique_xmalloc_ptr<char> cp_remove_params
 extern gdb::unique_xmalloc_ptr<char> cp_remove_params_if_any
   (const char *demangled_name, bool completion_mode);
 
-extern std::vector<symbol *> make_symbol_overload_list (const char *,
-							const char *);
+extern std::vector<block_symbol> make_symbol_overload_list (const char *,
+							    const char *);
 
 extern void add_symbol_overload_list_adl
   (gdb::array_view<type *> arg_types,
    const char *func_name,
-   std::vector<symbol *> *overload_list);
+   std::vector<block_symbol> *overload_list);
 
 extern struct type *cp_lookup_rtti_type (const char *name,
 					 const struct block *block);
diff --git a/gdb/eval.c b/gdb/eval.c
index 9b76d3d5376..ba09599b28a 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -693,15 +693,15 @@ var_value_operation::evaluate_funcall (struct type *expect_type,
   for (int i = 0; i < args.size (); ++i)
     argvec[i] = args[i]->evaluate_with_coercion (exp, noside);
 
-  struct symbol *symp;
+  block_symbol symp;
   find_overload_match (argvec, NULL, NON_METHOD,
-		       NULL, std::get<0> (m_storage).symbol,
+		       NULL, std::get<0> (m_storage),
 		       NULL, &symp, NULL, 0, noside);
 
-  if (symp->type ()->code () == TYPE_CODE_ERROR)
-    error_unknown_type (symp->print_name ());
+  if (symp.symbol->type ()->code () == TYPE_CODE_ERROR)
+    error_unknown_type (symp.symbol->print_name ());
   value *callee = evaluate_var_value (noside, std::get<0> (m_storage).block,
-				      symp);
+				      symp.symbol);
 
   return evaluate_subexp_do_call (exp, noside, callee, argvec,
 				  nullptr, expect_type);
@@ -722,7 +722,7 @@ scope_operation::evaluate_funcall (struct type *expect_type,
   const std::string &name = std::get<1> (m_storage);
   struct type *type = std::get<0> (m_storage);
 
-  symbol *function = NULL;
+  block_symbol function {};
   const char *function_name = NULL;
   std::vector<value *> argvec (1 + args.size ());
   if (type->code () == TYPE_CODE_NAMESPACE)
@@ -730,8 +730,8 @@ scope_operation::evaluate_funcall (struct type *expect_type,
       function = cp_lookup_symbol_namespace (type->name (),
 					     name.c_str (),
 					     get_selected_block (0),
-					     VAR_DOMAIN).symbol;
-      if (function == NULL)
+					     VAR_DOMAIN);
+      if (function.symbol == nullptr)
 	error (_("No symbol \"%s\" in namespace \"%s\"."),
 	       name.c_str (), type->name ());
     }
@@ -755,7 +755,7 @@ scope_operation::evaluate_funcall (struct type *expect_type,
       int static_memfuncp;
 
       find_overload_match (arg_view, function_name, METHOD,
-			   &argvec[0], nullptr, &callee, nullptr,
+			   &argvec[0], {}, &callee, nullptr,
 			   &static_memfuncp, 0, noside);
       if (!static_memfuncp)
 	{
@@ -769,12 +769,12 @@ scope_operation::evaluate_funcall (struct type *expect_type,
     }
   else
     {
-      symbol *symp;
+      block_symbol symp;
       arg_view = arg_view.slice (1);
       find_overload_match (arg_view, nullptr,
 			   NON_METHOD, nullptr, function,
 			   nullptr, &symp, nullptr, 1, noside);
-      callee = value_of_variable (symp, get_selected_block (0));
+      callee = value_of_variable (symp.symbol, get_selected_block (0));
     }
 
   return evaluate_subexp_do_call (exp, noside, callee, arg_view,
@@ -914,7 +914,7 @@ structop_base_operation::evaluate_funcall
 	 evaluation.  */
       value *val0 = vals[0];
       find_overload_match (arg_view, tstr, METHOD,
-			   &val0, nullptr, &callee, nullptr,
+			   &val0, {}, &callee, nullptr,
 			   &static_memfuncp, 0, noside);
       vals[0] = val0;
     }
@@ -2319,14 +2319,15 @@ adl_func_operation::evaluate (struct type *expect_type,
   for (int i = 0; i < arg_ops.size (); ++i)
     args[i] = arg_ops[i]->evaluate_with_coercion (exp, noside);
 
-  struct symbol *symp;
+  block_symbol symp;
   find_overload_match (args, std::get<0> (m_storage).c_str (),
 		       NON_METHOD,
-		       nullptr, nullptr,
+		       nullptr, {},
 		       nullptr, &symp, nullptr, 0, noside);
-  if (symp->type ()->code () == TYPE_CODE_ERROR)
-    error_unknown_type (symp->print_name ());
-  value *callee = evaluate_var_value (noside, std::get<1> (m_storage), symp);
+  if (symp.symbol->type ()->code () == TYPE_CODE_ERROR)
+    error_unknown_type (symp.symbol->print_name ());
+  value *callee = evaluate_var_value (noside, std::get<1> (m_storage),
+				      symp.symbol);
   return evaluate_subexp_do_call (exp, noside, callee, args,
 				  nullptr, expect_type);
 
diff --git a/gdb/infcall.c b/gdb/infcall.c
index a36a5e81b3a..54c14a097bc 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -1187,7 +1187,7 @@ call_function_by_hand_dummy (struct value *function,
 	  value *cctor_args[2] = { clone_ptr, original_arg };
 	  find_overload_match (gdb::make_array_view (cctor_args, 2),
 			       param_type->name (), METHOD,
-			       &clone_ptr, nullptr, &copy_ctor, nullptr,
+			       &clone_ptr, {}, &copy_ctor, nullptr,
 			       nullptr, 0, EVAL_NORMAL);
 
 	  if (copy_ctor == nullptr)
diff --git a/gdb/valarith.c b/gdb/valarith.c
index f3acf98c98b..5f9ecdf912c 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -338,25 +338,24 @@ static struct value *
 value_user_defined_cpp_op (gdb::array_view<value *> args, char *oper,
 			   int *static_memfuncp, enum noside noside)
 {
-
-  struct symbol *symp = NULL;
   struct value *valp = NULL;
 
+  block_symbol symp;
   find_overload_match (args, oper, BOTH /* could be method */,
 		       &args[0] /* objp */,
-		       NULL /* pass NULL symbol since symbol is unknown */,
+		       {} /* pass NULL symbol since symbol is unknown */,
 		       &valp, &symp, static_memfuncp, 0, noside);
 
   if (valp)
     return valp;
 
-  if (symp)
+  if (symp.symbol != nullptr)
     {
       /* This is a non member function and does not
 	 expect a reference as its first argument
 	 rather the explicit structure.  */
       args[0] = value_ind (args[0]);
-      return value_of_variable (symp, 0);
+      return value_of_variable (symp.symbol, symp.block);
     }
 
   error (_("Could not find %s."), oper);
diff --git a/gdb/valops.c b/gdb/valops.c
index b7ed458a649..9cb9a7147e2 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -57,13 +57,13 @@ static struct value *search_struct_method (const char *, struct value **,
 
 static int find_oload_champ_namespace (gdb::array_view<value *> args,
 				       const char *, const char *,
-				       std::vector<symbol *> *oload_syms,
+				       std::vector<block_symbol> *oload_syms,
 				       badness_vector *,
 				       const int no_adl);
 
 static int find_oload_champ_namespace_loop (gdb::array_view<value *> args,
-					    const char *, const char *,
-					    int, std::vector<symbol *> *oload_syms,
+					    const char *, const char *, int,
+					    std::vector<block_symbol> *oload_syms,
 					    badness_vector *, int *,
 					    const int no_adl);
 
@@ -71,7 +71,7 @@ static int find_oload_champ (gdb::array_view<value *> args,
 			     size_t num_fns,
 			     fn_field *methods,
 			     xmethod_worker_up *xmethods,
-			     symbol **functions,
+			     block_symbol *functions,
 			     badness_vector *oload_champ_bv);
 
 static int oload_method_static_p (struct fn_field *, int);
@@ -2709,8 +2709,8 @@ incomplete_type_hint (gdb::array_view<value *> args)
 int
 find_overload_match (gdb::array_view<value *> args,
 		     const char *name, enum oload_search_type method,
-		     struct value **objp, struct symbol *fsym,
-		     struct value **valp, struct symbol **symp, 
+		     struct value **objp, block_symbol fsym,
+		     struct value **valp, block_symbol *symp,
 		     int *staticp, const int no_adl,
 		     const enum noside noside)
 {
@@ -2732,7 +2732,7 @@ find_overload_match (gdb::array_view<value *> args,
   /* For methods, the list of overloaded methods.  */
   gdb::array_view<fn_field> methods;
   /* For non-methods, the list of overloaded function symbols.  */
-  std::vector<symbol *> functions;
+  std::vector<block_symbol> functions;
   /* For xmethods, the vector of xmethod workers.  */
   std::vector<xmethod_worker_up> xmethods;
   struct type *basetype = NULL;
@@ -2875,15 +2875,15 @@ find_overload_match (gdb::array_view<value *> args,
       if (method == BOTH)
 	args[0] = value_ind (args[0]);
 
-      if (fsym)
+      if (fsym.symbol != nullptr)
 	{
-	  qualified_name = fsym->natural_name ();
+	  qualified_name = fsym.symbol->natural_name ();
 
 	  /* If we have a function with a C++ name, try to extract just
 	     the function part.  Do not try this for non-functions (e.g.
 	     function pointers).  */
 	  if (qualified_name
-	      && (check_typedef (fsym->type ())->code ()
+	      && (check_typedef (fsym.symbol->type ())->code ()
 		  == TYPE_CODE_FUNC))
 	    {
 	      temp_func = cp_func_name (qualified_name);
@@ -3059,7 +3059,7 @@ static int
 find_oload_champ_namespace (gdb::array_view<value *> args,
 			    const char *func_name,
 			    const char *qualified_name,
-			    std::vector<symbol *> *oload_syms,
+			    std::vector<block_symbol> *oload_syms,
 			    badness_vector *oload_champ_bv,
 			    const int no_adl)
 {
@@ -3086,7 +3086,7 @@ find_oload_champ_namespace_loop (gdb::array_view<value *> args,
 				 const char *func_name,
 				 const char *qualified_name,
 				 int namespace_len,
-				 std::vector<symbol *> *oload_syms,
+				 std::vector<block_symbol> *oload_syms,
 				 badness_vector *oload_champ_bv,
 				 int *oload_champ,
 				 const int no_adl)
@@ -3133,7 +3133,7 @@ find_oload_champ_namespace_loop (gdb::array_view<value *> args,
   strncpy (new_namespace, qualified_name, namespace_len);
   new_namespace[namespace_len] = '\0';
 
-  std::vector<symbol *> new_oload_syms
+  std::vector<block_symbol> new_oload_syms
     = make_symbol_overload_list (func_name, new_namespace);
 
   /* If we have reached the deepest level perform argument
@@ -3202,7 +3202,7 @@ find_oload_champ (gdb::array_view<value *> args,
 		  size_t num_fns,
 		  fn_field *methods,
 		  xmethod_worker_up *xmethods,
-		  symbol **functions,
+		  block_symbol *functions,
 		  badness_vector *oload_champ_bv)
 {
   /* A measure of how good an overloaded instance is.  */
@@ -3238,14 +3238,14 @@ find_oload_champ (gdb::array_view<value *> args,
 	      static_offset = oload_method_static_p (methods, ix);
 	    }
 	  else
-	    nparms = functions[ix]->type ()->num_fields ();
+	    nparms = functions[ix].symbol->type ()->num_fields ();
 
 	  parm_types.reserve (nparms);
 	  for (jj = 0; jj < nparms; jj++)
 	    {
 	      type *t = (methods != NULL
 			 ? (TYPE_FN_FIELD_ARGS (methods, ix)[jj].type ())
-			 : functions[ix]->type ()->field (jj).type ());
+			 : functions[ix].symbol->type ()->field (jj).type ());
 	      parm_types.push_back (t);
 	    }
 	}
@@ -3269,7 +3269,7 @@ find_oload_champ (gdb::array_view<value *> args,
 	    gdb_printf (gdb_stderr,
 			"Overloaded function instance "
 			"%s # of parms %d\n",
-			functions[ix]->demangled_name (),
+			functions[ix].symbol->demangled_name (),
 			(int) parm_types.size ());
 
 	  gdb_printf (gdb_stderr,
diff --git a/gdb/value.h b/gdb/value.h
index b683cbf5f90..6f0b61a853d 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1294,8 +1294,8 @@ enum oload_search_type { NON_METHOD, METHOD, BOTH };
 extern int find_overload_match (gdb::array_view<value *> args,
 				const char *name,
 				enum oload_search_type method,
-				struct value **objp, struct symbol *fsym,
-				struct value **valp, struct symbol **symp,
+				struct value **objp, block_symbol fsym,
+				struct value **valp, block_symbol *symp,
 				int *staticp, const int no_adl,
 				enum noside noside);
 

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 18/31] Change evaluate_var_value to accept a block_symbol
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (16 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 17/31] Use block_symbol in overload-handling code Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 19/31] Change value_of_variable to take " Tom Tromey
                   ` (13 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This change evaluate_var_value to accept a block_symbol, preparing
some code to use the new read_var_value overload.
---
 gdb/ada-lang.c |  4 +---
 gdb/eval.c     | 20 ++++++++------------
 gdb/value.h    |  3 +--
 3 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 03f405778e6..ef7864b6770 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -10813,9 +10813,7 @@ ada_var_value_operation::evaluate_for_cast (struct type *expect_type,
 					    struct expression *exp,
 					    enum noside noside)
 {
-  value *val = evaluate_var_value (noside,
-				   std::get<0> (m_storage).block,
-				   std::get<0> (m_storage).symbol);
+  value *val = evaluate_var_value (noside, std::get<0> (m_storage));
 
   val = ada_value_cast (expect_type, val);
 
diff --git a/gdb/eval.c b/gdb/eval.c
index ba09599b28a..0f5e3c18a05 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -517,7 +517,7 @@ type_instance_operation::evaluate (struct type *expect_type,
 /* Helper for evaluating an OP_VAR_VALUE.  */
 
 value *
-evaluate_var_value (enum noside noside, const block *blk, symbol *var)
+evaluate_var_value (enum noside noside, block_symbol var)
 {
   /* JYG: We used to just return value::zero of the symbol type if
      we're asked to avoid side effects.  Otherwise we return
@@ -532,7 +532,7 @@ evaluate_var_value (enum noside noside, const block *blk, symbol *var)
 
   try
     {
-      ret = value_of_variable (var, blk);
+      ret = value_of_variable (var.symbol, var.block);
     }
 
   catch (const gdb_exception_error &except)
@@ -540,7 +540,7 @@ evaluate_var_value (enum noside noside, const block *blk, symbol *var)
       if (noside != EVAL_AVOID_SIDE_EFFECTS)
 	throw;
 
-      ret = value::zero (var->type (), not_lval);
+      ret = value::zero (var.symbol->type (), not_lval);
     }
 
   return ret;
@@ -558,7 +558,7 @@ var_value_operation::evaluate (struct type *expect_type,
   symbol *var = std::get<0> (m_storage).symbol;
   if (var->type ()->code () == TYPE_CODE_ERROR)
     error_unknown_type (var->print_name ());
-  return evaluate_var_value (noside, std::get<0> (m_storage).block, var);
+  return evaluate_var_value (noside, std::get<0> (m_storage));
 }
 
 } /* namespace expr */
@@ -700,8 +700,7 @@ var_value_operation::evaluate_funcall (struct type *expect_type,
 
   if (symp.symbol->type ()->code () == TYPE_CODE_ERROR)
     error_unknown_type (symp.symbol->print_name ());
-  value *callee = evaluate_var_value (noside, std::get<0> (m_storage).block,
-				      symp.symbol);
+  value *callee = evaluate_var_value (noside, symp);
 
   return evaluate_subexp_do_call (exp, noside, callee, argvec,
 				  nullptr, expect_type);
@@ -1108,7 +1107,7 @@ eval_op_func_static_var (struct type *expect_type, struct expression *exp,
   struct block_symbol sym = lookup_symbol (var, blk, VAR_DOMAIN, NULL);
   if (sym.symbol == NULL)
     error (_("No symbol \"%s\" in specified context."), var);
-  return evaluate_var_value (noside, sym.block, sym.symbol);
+  return evaluate_var_value (noside, sym);
 }
 
 /* Helper function that implements the body of OP_REGISTER.  */
@@ -2326,8 +2325,7 @@ adl_func_operation::evaluate (struct type *expect_type,
 		       nullptr, &symp, nullptr, 0, noside);
   if (symp.symbol->type ()->code () == TYPE_CODE_ERROR)
     error_unknown_type (symp.symbol->print_name ());
-  value *callee = evaluate_var_value (noside, std::get<1> (m_storage),
-				      symp.symbol);
+  value *callee = evaluate_var_value (noside, symp);
   return evaluate_subexp_do_call (exp, noside, callee, args,
 				  nullptr, expect_type);
 
@@ -2854,9 +2852,7 @@ var_value_operation::evaluate_for_cast (struct type *to_type,
 					struct expression *exp,
 					enum noside noside)
 {
-  value *val = evaluate_var_value (noside,
-				   std::get<0> (m_storage).block,
-				   std::get<0> (m_storage).symbol);
+  value *val = evaluate_var_value (noside, std::get<0> (m_storage));
 
   val = value_cast (to_type, val);
 
diff --git a/gdb/value.h b/gdb/value.h
index 6f0b61a853d..37c07a41205 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1344,8 +1344,7 @@ extern int using_struct_return (struct gdbarch *gdbarch,
 				struct value *function,
 				struct type *value_type);
 
-extern value *evaluate_var_value (enum noside noside, const block *blk,
-				  symbol *var);
+extern value *evaluate_var_value (enum noside noside, block_symbol var);
 
 extern value *evaluate_var_msym_value (enum noside noside,
 				       struct objfile *objfile,

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 19/31] Change value_of_variable to take a block_symbol
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (17 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 18/31] Change evaluate_var_value to accept a block_symbol Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 20/31] Return a block_symbol from get_frame_function Tom Tromey
                   ` (12 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This changes value_of_variable to take a block_symbol and to call the
new read_var_value overload.
---
 gdb/ada-lang.c       |  2 +-
 gdb/dwarf2/loc.c     |  2 +-
 gdb/eval.c           | 17 +++++++----------
 gdb/f-valprint.c     |  4 ++--
 gdb/python/py-type.c |  2 +-
 gdb/rust-lang.c      |  2 +-
 gdb/valarith.c       |  2 +-
 gdb/valops.c         | 15 ++++++++-------
 gdb/value.c          |  2 +-
 gdb/value.h          |  6 ++----
 10 files changed, 25 insertions(+), 29 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index ef7864b6770..6beadad568a 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -11374,7 +11374,7 @@ get_var_value (const char *name, const char *err_msg)
 	error (("%s"), err_msg);
     }
 
-  return value_of_variable (syms[0].symbol, syms[0].block);
+  return value_of_variable (syms[0]);
 }
 
 /* Value of integer variable named NAME in the current environment.
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index 17509f81464..fad32cfc27c 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -627,7 +627,7 @@ compute_var_value (const char *name)
   struct block_symbol sym = lookup_symbol (name, nullptr, VAR_DOMAIN,
 					   nullptr);
   if (sym.symbol != nullptr)
-    return value_of_variable (sym.symbol, sym.block);
+    return value_of_variable (sym);
   return nullptr;
 }
 
diff --git a/gdb/eval.c b/gdb/eval.c
index 0f5e3c18a05..5b40eed6799 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -532,7 +532,7 @@ evaluate_var_value (enum noside noside, block_symbol var)
 
   try
     {
-      ret = value_of_variable (var.symbol, var.block);
+      ret = value_of_variable (var);
     }
 
   catch (const gdb_exception_error &except)
@@ -773,7 +773,7 @@ scope_operation::evaluate_funcall (struct type *expect_type,
       find_overload_match (arg_view, nullptr,
 			   NON_METHOD, nullptr, function,
 			   nullptr, &symp, nullptr, 1, noside);
-      callee = value_of_variable (symp.symbol, get_selected_block (0));
+      callee = value_of_variable (symp);
     }
 
   return evaluate_subexp_do_call (exp, noside, callee, arg_view,
@@ -2028,17 +2028,15 @@ eval_op_objc_msgcall (struct type *expect_type, struct expression *exp,
   addr = value_as_long (ret);
   if (addr)
     {
-      struct symbol *sym = NULL;
-
       /* The address might point to a function descriptor;
 	 resolve it to the actual code address instead.  */
       addr = gdbarch_convert_from_func_ptr_addr
 	(exp->gdbarch, addr, current_inferior ()->top_target ());
 
       /* Is it a high_level symbol?  */
-      sym = find_pc_function (addr).symbol;
-      if (sym != NULL)
-	method = value_of_variable (sym, 0);
+      block_symbol sym = find_pc_function (addr);
+      if (sym.symbol != nullptr)
+	method = value_of_variable (sym);
     }
 
   /* If we found a method with symbol information, check to see
@@ -2668,7 +2666,7 @@ var_value_operation::evaluate_for_address (struct expression *exp,
       return value::zero (type, not_lval);
     }
   else
-    return address_of_variable (var, std::get<0> (m_storage).block);
+    return address_of_variable (std::get<0> (m_storage));
 }
 
 value *
@@ -2681,8 +2679,7 @@ var_value_operation::evaluate_with_coercion (struct expression *exp,
       && !type->is_vector ()
       && CAST_IS_CONVERSION (exp->language_defn))
     {
-      struct value *val = address_of_variable (var,
-					       std::get<0> (m_storage).block);
+      struct value *val = address_of_variable (std::get<0> (m_storage));
       return value_cast (lookup_pointer_type (type->target_type ()), val);
     }
   return evaluate (nullptr, exp, noside);
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index 2b7dafc4de3..5cafb5137e0 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -556,7 +556,7 @@ f_language::value_print_inner (struct value *val, struct ui_file *stream,
 		  if (sym.symbol == nullptr)
 		    error (_("failed to find symbol for name list component %s"),
 			   field_name);
-		  field = value_of_variable (sym.symbol, sym.block);
+		  field = value_of_variable (sym);
 		}
 	      else
 		field = value_field (val, index);
@@ -657,7 +657,7 @@ info_common_command_for_block (const struct block *block, const char *comname,
 
 	    try
 	      {
-		val = value_of_variable (common->contents[index], block);
+		val = value_of_variable ({ common->contents[index], block });
 		value_print (val, gdb_stdout, &opts);
 	      }
 
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index bfaa6d24d94..3c8b7f6c8b6 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1065,7 +1065,7 @@ typy_template_argument (PyObject *self, PyObject *args)
   try
     {
       scoped_value_mark free_values;
-      struct value *val = value_of_variable (sym, block);
+      struct value *val = value_of_variable ({ sym, block });
       result = value_to_value_object (val);
     }
   catch (const gdb_exception &except)
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index aa106b44bd9..841ca74137b 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1574,7 +1574,7 @@ rust_structop::evaluate_funcall (struct type *expect_type,
   if (fn_type->field (0).type ()->code () == TYPE_CODE_PTR)
     args[0] = value_addr (args[0]);
 
-  value *function = address_of_variable (sym.symbol, block);
+  value *function = address_of_variable (sym);
 
   for (int i = 0; i < ops.size (); ++i)
     args[i + 1] = ops[i]->evaluate (nullptr, exp, noside);
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 5f9ecdf912c..de77c757b04 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -355,7 +355,7 @@ value_user_defined_cpp_op (gdb::array_view<value *> args, char *oper,
 	 expect a reference as its first argument
 	 rather the explicit structure.  */
       args[0] = value_ind (args[0]);
-      return value_of_variable (symp.symbol, symp.block);
+      return value_of_variable (symp);
     }
 
   error (_("Could not find %s."), oper);
diff --git a/gdb/valops.c b/gdb/valops.c
index 9cb9a7147e2..07cc66b2a8d 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -130,7 +130,7 @@ find_function_in_inferior (const char *name, struct objfile **objf_p)
       if (objf_p)
 	*objf_p = sym.symbol->objfile ();
 
-      return value_of_variable (sym.symbol, sym.block);
+      return value_of_variable (sym);
     }
   else
     {
@@ -1383,26 +1383,27 @@ value_repeat (struct value *arg1, int count)
 }
 
 struct value *
-value_of_variable (struct symbol *var, const struct block *b)
+value_of_variable (block_symbol var)
 {
   frame_info_ptr frame = NULL;
 
-  if (symbol_read_needs_frame (var))
+  if (symbol_read_needs_frame (var.symbol))
     frame = get_selected_frame (_("No frame selected."));
 
-  return read_var_value (var, b, frame);
+  return read_var_value (var, frame);
 }
 
 struct value *
-address_of_variable (struct symbol *var, const struct block *b)
+address_of_variable (block_symbol bvar)
 {
+  symbol *var = bvar.symbol;
   struct type *type = var->type ();
   struct value *val;
 
   /* Evaluate it first; if the result is a memory address, we're fine.
      Lazy evaluation pays off here.  */
 
-  val = value_of_variable (var, b);
+  val = value_of_variable (bvar);
   type = val->type ();
 
   if ((val->lval () == lval_memory && val->lazy ())
@@ -3830,7 +3831,7 @@ value_maybe_namespace_elt (const struct type *curtype,
 	   && (sym.symbol->aclass () == LOC_TYPEDEF))
     result = value::allocate (sym.symbol->type ());
   else
-    result = value_of_variable (sym.symbol, sym.block);
+    result = value_of_variable (sym);
 
   if (want_address)
     result = value_addr (result);
diff --git a/gdb/value.c b/gdb/value.c
index 17b7c53d052..4fd77b774f6 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -2897,7 +2897,7 @@ value_static_field (struct type *type, int fieldno)
 	    retval = value_at_lazy (field_type, msym.value_address ());
 	}
       else
-	retval = value_of_variable (sym.symbol, sym.block);
+	retval = value_of_variable (sym);
       break;
     }
     default:
diff --git a/gdb/value.h b/gdb/value.h
index 37c07a41205..7cb830110fc 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1117,11 +1117,9 @@ extern struct value *value_from_register (struct type *type, int regnum,
 extern CORE_ADDR address_from_register (int regnum,
 					frame_info_ptr frame);
 
-extern struct value *value_of_variable (struct symbol *var,
-					const struct block *b);
+extern struct value *value_of_variable (block_symbol var);
 
-extern struct value *address_of_variable (struct symbol *var,
-					  const struct block *b);
+extern struct value *address_of_variable (block_symbol var);
 
 extern struct value *value_of_register (int regnum, frame_info_ptr frame);
 

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 20/31] Return a block_symbol from get_frame_function
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (18 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 19/31] Change value_of_variable to take " Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:11 ` [PATCH v2 21/31] Use read_var_value overload in return_command Tom Tromey
                   ` (11 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This changes get_frame_function to return a block_symbol, allowing
updates in other places.  Like some earlier patches, this change is
the direction the code should go anyway -- the return value will
eventually carry an objfile along with it.
---
 gdb/blockframe.c   | 6 +++---
 gdb/breakpoint.c   | 2 +-
 gdb/findvar.c      | 2 +-
 gdb/frame.c        | 2 +-
 gdb/frame.h        | 3 ++-
 gdb/infcmd.c       | 4 ++--
 gdb/infrun.c       | 4 ++--
 gdb/inline-frame.c | 2 +-
 gdb/skip.c         | 2 +-
 gdb/stack.c        | 8 ++++----
 10 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/gdb/blockframe.c b/gdb/blockframe.c
index 981094803ed..3977ecd6229 100644
--- a/gdb/blockframe.c
+++ b/gdb/blockframe.c
@@ -114,18 +114,18 @@ get_pc_function_start (CORE_ADDR pc)
 
 /* Return the symbol for the function executing in frame FRAME.  */
 
-struct symbol *
+block_symbol
 get_frame_function (frame_info_ptr frame)
 {
   const struct block *bl = get_frame_block (frame, 0);
 
   if (bl == NULL)
-    return NULL;
+    return {};
 
   while (bl->function () == NULL && bl->superblock () != NULL)
     bl = bl->superblock ();
 
-  return bl->function ();
+  return { bl->function (), bl };
 }
 \f
 
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 52ce63afade..e9dd942da4e 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5287,7 +5287,7 @@ watchpoint_check (bpstat *bs)
 	{
 	  struct symbol *function;
 
-	  function = get_frame_function (fr);
+	  function = get_frame_function (fr).symbol;
 	  if (function == NULL
 	      || !function->value_block ()->contains (b->exp_valid_block))
 	    within_current_scope = false;
diff --git a/gdb/findvar.c b/gdb/findvar.c
index 909dca65532..f3be783ec24 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -408,7 +408,7 @@ follow_static_link (frame_info_ptr frame,
      in.  */
   for (; frame != NULL; frame = get_prev_frame (frame))
     {
-      struct symbol *framefunc = get_frame_function (frame);
+      struct symbol *framefunc = get_frame_function (frame).symbol;
 
       /* Stacks can be quite deep: give the user a chance to stop this.  */
       QUIT;
diff --git a/gdb/frame.c b/gdb/frame.c
index 7077016ccba..315b94e4447 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -2833,7 +2833,7 @@ find_frame_sal (frame_info_ptr frame)
 	 function, which can not be inferred from get_frame_pc.  */
       next_frame = get_next_frame (frame);
       if (next_frame)
-	sym = get_frame_function (next_frame);
+	sym = get_frame_function (next_frame).symbol;
       else
 	sym = inline_skipped_symbol (inferior_thread ());
 
diff --git a/gdb/frame.h b/gdb/frame.h
index 1d7422cac32..0f1640c4a68 100644
--- a/gdb/frame.h
+++ b/gdb/frame.h
@@ -69,6 +69,7 @@
 
    */
 
+#include "block-symbol.h"
 #include "cli/cli-option.h"
 #include "frame-id.h"
 #include "gdbsupport/common-debug.h"
@@ -856,7 +857,7 @@ extern const struct block *get_frame_block (frame_info_ptr,
 
 extern const struct block *get_selected_block (CORE_ADDR *addr_in_block);
 
-extern struct symbol *get_frame_function (frame_info_ptr);
+extern block_symbol get_frame_function (frame_info_ptr);
 
 extern CORE_ADDR get_pc_function_start (CORE_ADDR);
 
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 03e54438686..2e9d913c41c 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -957,7 +957,7 @@ prepare_one_step (thread_info *tp, struct step_command_fsm *sm)
 
 	      frame = get_current_frame ();
 	      sal = find_frame_sal (frame);
-	      sym = get_frame_function (frame);
+	      sym = get_frame_function (frame).symbol;
 
 	      if (sym != nullptr)
 		fn = sym->print_name ();
@@ -1085,7 +1085,7 @@ jump_command (const char *arg, int from_tty)
   resolve_sal_pc (&sal);	/* May error out.  */
 
   /* See if we are trying to jump to another function.  */
-  fn = get_frame_function (get_current_frame ());
+  fn = get_frame_function (get_current_frame ()).symbol;
   sfn = find_pc_sect_containing_function (sal.pc,
 					  find_pc_mapped_section (sal.pc));
   if (fn != nullptr && sfn != fn)
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 2a004690e67..3c85cb5f481 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -4846,7 +4846,7 @@ inline_frame_is_marked_for_skip (bool prev_frame, struct thread_info *tp)
 	break;
 
       sal = find_frame_sal (frame);
-      sym = get_frame_function (frame);
+      sym = get_frame_function (frame).symbol;
 
       if (sym != nullptr)
 	fn = sym->print_name ();
@@ -8390,7 +8390,7 @@ check_exception_resume (struct execution_control_state *ecs,
       return;
     }
 
-  func = get_frame_function (frame);
+  func = get_frame_function (frame).symbol;
   if (!func)
     return;
 
diff --git a/gdb/inline-frame.c b/gdb/inline-frame.c
index 80765d5cca5..48ada3597bf 100644
--- a/gdb/inline-frame.c
+++ b/gdb/inline-frame.c
@@ -179,7 +179,7 @@ inline_frame_this_id (frame_info_ptr this_frame,
      which generates DW_AT_entry_pc for inlined functions when
      possible.  If this attribute is available, we should use it
      in the frame ID (and eventually, to set breakpoints).  */
-  func = get_frame_function (this_frame);
+  func = get_frame_function (this_frame).symbol;
   gdb_assert (func != NULL);
   (*this_id).code_addr = func->value_block ()->entry_pc ();
   (*this_id).artificial_depth++;
diff --git a/gdb/skip.c b/gdb/skip.c
index 28902a6d326..a11a35314e3 100644
--- a/gdb/skip.c
+++ b/gdb/skip.c
@@ -205,7 +205,7 @@ skip_function_command (const char *arg, int from_tty)
   if (arg == NULL)
     {
       frame_info_ptr fi = get_selected_frame (_("No default function now."));
-      struct symbol *sym = get_frame_function (fi);
+      struct symbol *sym = get_frame_function (fi).symbol;
       const char *name = NULL;
 
       if (sym != NULL)
diff --git a/gdb/stack.c b/gdb/stack.c
index 39dcefa87b8..a2ea7301394 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -1266,7 +1266,7 @@ find_frame_funname (frame_info_ptr frame, enum language *funlang,
   if (funcp)
     *funcp = NULL;
 
-  func = get_frame_function (frame);
+  func = get_frame_function (frame).symbol;
   if (func)
     {
       const char *print_name = func->print_name ();
@@ -1498,7 +1498,7 @@ info_frame_command_core (frame_info_ptr fi, bool selected_frame_p)
     pc_regname = "pc";
 
   frame_pc_p = get_frame_pc_if_available (fi, &frame_pc);
-  func = get_frame_function (fi);
+  func = get_frame_function (fi).symbol;
   symtab_and_line sal = find_frame_sal (fi);
   s = sal.symtab;
   gdb::unique_xmalloc_ptr<char> func_only;
@@ -2510,7 +2510,7 @@ print_frame_arg_vars (frame_info_ptr frame,
       return;
     }
 
-  func = get_frame_function (frame);
+  func = get_frame_function (frame).symbol;
   if (func == NULL)
     {
       if (!quiet)
@@ -2692,7 +2692,7 @@ return_command (const char *retval_exp, int from_tty)
   std::string query_prefix;
 
   thisframe = get_selected_frame ("No selected frame.");
-  thisfun = get_frame_function (thisframe);
+  thisfun = get_frame_function (thisframe).symbol;
   gdbarch = get_frame_arch (thisframe);
 
   if (get_frame_type (get_current_frame ()) == INLINE_FRAME)

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 21/31] Use read_var_value overload in return_command
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (19 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 20/31] Return a block_symbol from get_frame_function Tom Tromey
@ 2023-11-05 18:11 ` Tom Tromey
  2023-11-05 18:12 ` [PATCH v2 22/31] Use read_var_value overload in py-finishbreakpoint.c Tom Tromey
                   ` (10 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:11 UTC (permalink / raw)
  To: gdb-patches

This changes return_command to use the new read_var_value overload.
---
 gdb/stack.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gdb/stack.c b/gdb/stack.c
index a2ea7301394..f744baad61a 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -2692,7 +2692,8 @@ return_command (const char *retval_exp, int from_tty)
   std::string query_prefix;
 
   thisframe = get_selected_frame ("No selected frame.");
-  thisfun = get_frame_function (thisframe).symbol;
+  block_symbol b_fun = get_frame_function (thisframe);
+  thisfun = b_fun.symbol;
   gdbarch = get_frame_arch (thisframe);
 
   if (get_frame_type (get_current_frame ()) == INLINE_FRAME)
@@ -2733,7 +2734,7 @@ return_command (const char *retval_exp, int from_tty)
 	return_value->fetch_lazy ();
 
       if (thisfun != NULL)
-	function = read_var_value (thisfun, NULL, thisframe);
+	function = read_var_value (b_fun, thisframe);
 
       rv_conv = RETURN_VALUE_REGISTER_CONVENTION;
       if (return_type->code () == TYPE_CODE_VOID)

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 22/31] Use read_var_value overload in py-finishbreakpoint.c
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (20 preceding siblings ...)
  2023-11-05 18:11 ` [PATCH v2 21/31] Use read_var_value overload in return_command Tom Tromey
@ 2023-11-05 18:12 ` Tom Tromey
  2023-11-05 18:12 ` [PATCH v2 23/31] Use read_var_value overload in py-framefilter.c Tom Tromey
                   ` (9 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:12 UTC (permalink / raw)
  To: gdb-patches

This chanseg py-finishbreakpoint.c to use the new read_var_value
overload.
---
 gdb/python/py-finishbreakpoint.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index 04fc8c9e8a7..53ba41bd157 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -252,7 +252,8 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
     {
       if (get_frame_pc_if_available (frame, &pc))
 	{
-	  struct symbol *function = find_pc_function (pc).symbol;
+	  block_symbol b_fun = find_pc_function (pc);
+	  symbol *function = b_fun.symbol;
 	  if (function != nullptr)
 	    {
 	      struct type *ret_type =
@@ -264,7 +265,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 		  scoped_value_mark free_values;
 
 		  /* Ignore Python errors at this stage.  */
-		  value *func_value = read_var_value (function, NULL, frame);
+		  value *func_value = read_var_value (b_fun, frame);
 		  self_bpfinish->function_value
 		    = value_to_value_object (func_value);
 		  PyErr_Clear ();

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 23/31] Use read_var_value overload in py-framefilter.c
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (21 preceding siblings ...)
  2023-11-05 18:12 ` [PATCH v2 22/31] Use read_var_value overload in py-finishbreakpoint.c Tom Tromey
@ 2023-11-05 18:12 ` Tom Tromey
  2023-11-05 18:12 ` [PATCH v2 24/31] Use read_var_value overload in Guile Tom Tromey
                   ` (8 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:12 UTC (permalink / raw)
  To: gdb-patches

This changes py-framefilter.c to use the new read_var_value overload.
---
 gdb/python/py-framefilter.c | 54 ++++++++++++++++++++-------------------------
 1 file changed, 24 insertions(+), 30 deletions(-)

diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index e555dc3d879..07b30a587b1 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -41,24 +41,22 @@ enum mi_print_types
   MI_PRINT_LOCALS
 };
 
-/* Helper  function  to  extract  a  symbol, a  name  and  a  language
+/* Helper function to extract a symbol, a name and a language
    definition from a Python object that conforms to the "Symbol Value"
-   interface.  OBJ  is the Python  object to extract the  values from.
-   NAME is a  pass-through argument where the name of  the symbol will
-   be written.  NAME is allocated in  this function, but the caller is
+   interface.  OBJ is the Python object to extract the values from.
+   NAME is a pass-through argument where the name of the symbol will
+   be written.  NAME is allocated in this function, but the caller is
    responsible for clean up.  SYM is a pass-through argument where the
-   symbol will be written and  SYM_BLOCK is a pass-through argument to
-   write  the block where the symbol lies in.  In the case of the  API
-   returning a  string,  this will be set to NULL.  LANGUAGE is also a
-   pass-through  argument  denoting  the  language  attributed  to the
-   Symbol.  In the case of SYM being  NULL, this  will be  set to  the
-   current  language.  Returns  EXT_LANG_BT_ERROR  on  error  with the
-   appropriate Python exception set, and EXT_LANG_BT_OK on success.  */
+   symbol will be written.  In the case of the API returning a string,
+   this will be set to NULL.  LANGUAGE is also a pass-through argument
+   denoting the language attributed to the Symbol.  In the case of SYM
+   being NULL, this will be set to the current language.  Returns
+   EXT_LANG_BT_ERROR on error with the appropriate Python exception
+   set, and EXT_LANG_BT_OK on success.  */
 
 static enum ext_lang_bt_status
 extract_sym (PyObject *obj, gdb::unique_xmalloc_ptr<char> *name,
-	     struct symbol **sym, const struct block **sym_block,
-	     const struct language_defn **language)
+	     block_symbol *sym, const struct language_defn **language)
 {
   gdbpy_ref<> result (PyObject_CallMethod (obj, "symbol", NULL));
 
@@ -79,21 +77,19 @@ extract_sym (PyObject *obj, gdb::unique_xmalloc_ptr<char> *name,
 	 entirely synthetic symbol/value pairing.  In that case, use
 	 the current language.  */
       *language = current_language;
-      *sym = NULL;
-      *sym_block = NULL;
+      *sym = {};
     }
   else
     {
       /* This type checks 'result' during the conversion so we
 	 just call it unconditionally and check the return.  */
-      *sym = symbol_object_to_symbol (result.get ());
       /* TODO: currently, we have no way to recover the block in which SYMBOL
 	 was found, so we have no block to return.  Trying to evaluate SYMBOL
 	 will yield an incorrect value when it's located in a FRAME and
 	 evaluated from another frame (as permitted in nested functions).  */
-      *sym_block = NULL;
+      *sym = { symbol_object_to_symbol (result.get ()), nullptr };
 
-      if (*sym == NULL)
+      if (sym->symbol == NULL)
 	{
 	  PyErr_SetString (PyExc_RuntimeError,
 			   _("Unexpected value.  Expecting a "
@@ -103,13 +99,13 @@ extract_sym (PyObject *obj, gdb::unique_xmalloc_ptr<char> *name,
 
       /* Duplicate the symbol name, so the caller has consistency
 	 in garbage collection.  */
-      name->reset (xstrdup ((*sym)->print_name ()));
+      name->reset (xstrdup (sym->symbol->print_name ()));
 
       /* If a symbol is specified attempt to determine the language
 	 from the symbol.  If mode is not "auto", then the language
 	 has been explicitly set, use that.  */
       if (language_mode == language_mode_auto)
-	*language = language_def ((*sym)->language ());
+	*language = language_def (sym->symbol->language ());
       else
 	*language = current_language;
     }
@@ -443,21 +439,20 @@ enumerate_args (PyObject *iter,
     {
       const struct language_defn *language;
       gdb::unique_xmalloc_ptr<char> sym_name;
-      struct symbol *sym;
-      const struct block *sym_block;
+      block_symbol bsym;
       struct value *val;
       enum ext_lang_bt_status success = EXT_LANG_BT_ERROR;
 
-      success = extract_sym (item.get (), &sym_name, &sym, &sym_block,
-			     &language);
+      success = extract_sym (item.get (), &sym_name, &bsym, &language);
       if (success == EXT_LANG_BT_ERROR)
 	return EXT_LANG_BT_ERROR;
+      symbol *sym = bsym.symbol;
 
       success = extract_value (item.get (), &val);
       if (success == EXT_LANG_BT_ERROR)
 	return EXT_LANG_BT_ERROR;
 
-      if (sym && out->is_mi_like_p ()
+      if (sym != nullptr && out->is_mi_like_p ()
 	  && ! mi_should_print (sym, MI_PRINT_ARGS))
 	continue;
 
@@ -559,8 +554,6 @@ enumerate_locals (PyObject *iter,
       gdb::unique_xmalloc_ptr<char> sym_name;
       struct value *val;
       enum ext_lang_bt_status success = EXT_LANG_BT_ERROR;
-      struct symbol *sym;
-      const struct block *sym_block;
       int local_indent = 8 + (8 * indent);
       gdb::optional<ui_out_emit_tuple> tuple;
 
@@ -568,10 +561,11 @@ enumerate_locals (PyObject *iter,
       if (item == NULL)
 	break;
 
-      success = extract_sym (item.get (), &sym_name, &sym, &sym_block,
-			     &language);
+      block_symbol bsym;
+      success = extract_sym (item.get (), &sym_name, &bsym, &language);
       if (success == EXT_LANG_BT_ERROR)
 	return EXT_LANG_BT_ERROR;
+      symbol *sym = bsym.symbol;
 
       success = extract_value (item.get (), &val);
       if (success == EXT_LANG_BT_ERROR)
@@ -583,7 +577,7 @@ enumerate_locals (PyObject *iter,
 
       /* If the object did not provide a value, read it.  */
       if (val == NULL)
-	val = read_var_value (sym, sym_block, frame);
+	val = read_var_value (bsym, frame);
 
       /* With PRINT_NO_VALUES, MI does not emit a tuple normally as
 	 each output contains only one field.  The exception is

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 24/31] Use read_var_value overload in Guile
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (22 preceding siblings ...)
  2023-11-05 18:12 ` [PATCH v2 23/31] Use read_var_value overload in py-framefilter.c Tom Tromey
@ 2023-11-05 18:12 ` Tom Tromey
  2023-11-05 18:12 ` [PATCH v2 25/31] Use read_var_value in read_frame_arg and read_frame_local Tom Tromey
                   ` (7 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:12 UTC (permalink / raw)
  To: gdb-patches

This changes the Guile layer to store a block_symbol in its symbol
wrapper, and then to use the new read_var_value overload.
---
 gdb/guile/guile-internal.h |  2 +-
 gdb/guile/scm-block.c      |  6 ++--
 gdb/guile/scm-frame.c      |  9 +++---
 gdb/guile/scm-symbol.c     | 78 ++++++++++++++++++++++------------------------
 4 files changed, 46 insertions(+), 49 deletions(-)

diff --git a/gdb/guile/guile-internal.h b/gdb/guile/guile-internal.h
index c0f1410ed7c..e8b59c160cc 100644
--- a/gdb/guile/guile-internal.h
+++ b/gdb/guile/guile-internal.h
@@ -538,7 +538,7 @@ extern SCM gdbscm_scm_from_host_string (const char *string, size_t len);
 
 extern int syscm_is_symbol (SCM scm);
 
-extern SCM syscm_scm_from_symbol (struct symbol *symbol);
+extern SCM syscm_scm_from_symbol (block_symbol symbol);
 
 extern struct symbol *syscm_get_valid_symbol_arg_unsafe
   (SCM self, int arg_pos, const char *func_name);
diff --git a/gdb/guile/scm-block.c b/gdb/guile/scm-block.c
index 02b7a48be37..4293a13b81b 100644
--- a/gdb/guile/scm-block.c
+++ b/gdb/guile/scm-block.c
@@ -406,7 +406,7 @@ gdbscm_block_function (SCM self)
   sym = block->function ();
 
   if (sym != NULL)
-    return syscm_scm_from_symbol (sym);
+    return syscm_scm_from_symbol ({ sym, block });
   return SCM_BOOL_F;
 }
 
@@ -507,7 +507,7 @@ gdbscm_block_symbols (SCM self)
 
   for (struct symbol *sym : block_iterator_range (block))
     {
-      SCM s_scm = syscm_scm_from_symbol (sym);
+      SCM s_scm = syscm_scm_from_symbol ({ sym, block });
 
       result = scm_cons (s_scm, result);
     }
@@ -658,7 +658,7 @@ gdbscm_block_next_symbol_x (SCM self)
   if (sym == NULL)
     return gdbscm_end_of_iteration ();
 
-  return syscm_scm_from_symbol (sym);
+  return syscm_scm_from_symbol ({ sym, block });
 }
 \f
 /* (lookup-block address) -> <gdb:block>
diff --git a/gdb/guile/scm-frame.c b/gdb/guile/scm-frame.c
index 74012ffea4f..62a28a39bcf 100644
--- a/gdb/guile/scm-frame.c
+++ b/gdb/guile/scm-frame.c
@@ -654,7 +654,7 @@ static SCM
 gdbscm_frame_function (SCM self)
 {
   frame_smob *f_smob;
-  struct symbol *sym = NULL;
+  block_symbol sym = {};
   bool found = false;
 
   f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
@@ -666,7 +666,7 @@ gdbscm_frame_function (SCM self)
       if (frame != NULL)
 	{
 	  found = true;
-	  sym = find_pc_function (get_frame_address_in_block (frame)).symbol;
+	  sym = find_pc_function (get_frame_address_in_block (frame));
 	}
     }
   catch (const gdb_exception &except)
@@ -681,7 +681,7 @@ gdbscm_frame_function (SCM self)
 				   _("<gdb:frame>"));
     }
 
-  if (sym != NULL)
+  if (sym.symbol != nullptr)
     return syscm_scm_from_symbol (sym);
 
   return SCM_BOOL_F;
@@ -962,7 +962,8 @@ gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
 
   try
     {
-      value = read_var_value (var, block, frame_info_ptr (frame));
+      // FIXME
+      value = read_var_value ({ var, block }, frame_info_ptr (frame));
     }
   catch (const gdb_exception &except)
     {
diff --git a/gdb/guile/scm-symbol.c b/gdb/guile/scm-symbol.c
index 1619705f065..f7fc3123dcd 100644
--- a/gdb/guile/scm-symbol.c
+++ b/gdb/guile/scm-symbol.c
@@ -36,7 +36,7 @@ struct symbol_smob
   eqable_gdb_smob base;
 
   /* The GDB symbol structure this smob is wrapping.  */
-  struct symbol *symbol;
+  block_symbol symbol;
 };
 
 static const char symbol_smob_name[] = "gdb:symbol";
@@ -64,7 +64,7 @@ struct syscm_deleter
   {
     symbol_smob *s_smob = (symbol_smob *) *slot;
 
-    s_smob->symbol = NULL;
+    s_smob->symbol = {};
     return 1;
   }
 
@@ -96,7 +96,7 @@ syscm_hash_symbol_smob (const void *p)
 {
   const symbol_smob *s_smob = (const symbol_smob *) p;
 
-  return htab_hash_pointer (s_smob->symbol);
+  return htab_hash_pointer (s_smob->symbol.symbol);
 }
 
 /* Helper function to compute equality of symbol_smobs.  */
@@ -107,8 +107,8 @@ syscm_eq_symbol_smob (const void *ap, const void *bp)
   const symbol_smob *a = (const symbol_smob *) ap;
   const symbol_smob *b = (const symbol_smob *) bp;
 
-  return (a->symbol == b->symbol
-	  && a->symbol != NULL);
+  return (a->symbol.symbol == b->symbol.symbol
+	  && a->symbol.symbol != nullptr);
 }
 
 /* Return the struct symbol pointer -> SCM mapping table.
@@ -156,15 +156,15 @@ syscm_free_symbol_smob (SCM self)
 {
   symbol_smob *s_smob = (symbol_smob *) SCM_SMOB_DATA (self);
 
-  if (s_smob->symbol != NULL)
+  if (s_smob->symbol.symbol != nullptr)
     {
-      htab_t htab = syscm_get_symbol_map (s_smob->symbol);
+      htab_t htab = syscm_get_symbol_map (s_smob->symbol.symbol);
 
       gdbscm_clear_eqable_gsmob_ptr_slot (htab, &s_smob->base);
     }
 
   /* Not necessary, done to catch bugs.  */
-  s_smob->symbol = NULL;
+  s_smob->symbol = {};
 
   return 0;
 }
@@ -179,8 +179,8 @@ syscm_print_symbol_smob (SCM self, SCM port, scm_print_state *pstate)
   if (pstate->writingp)
     gdbscm_printf (port, "#<%s ", symbol_smob_name);
   gdbscm_printf (port, "%s",
-		 s_smob->symbol != NULL
-		 ? s_smob->symbol->print_name ()
+		 s_smob->symbol.symbol != nullptr
+		 ? s_smob->symbol.symbol->print_name ()
 		 : "<invalid>");
   if (pstate->writingp)
     scm_puts (">", port);
@@ -200,7 +200,7 @@ syscm_make_symbol_smob (void)
     scm_gc_malloc (sizeof (symbol_smob), symbol_smob_name);
   SCM s_scm;
 
-  s_smob->symbol = NULL;
+  s_smob->symbol.symbol = {};
   s_scm = scm_new_smob (symbol_smob_tag, (scm_t_bits) s_smob);
   gdbscm_init_eqable_gsmob (&s_smob->base, s_scm);
 
@@ -227,7 +227,7 @@ gdbscm_symbol_p (SCM scm)
    <gdb:symbol> object.  */
 
 SCM
-syscm_scm_from_symbol (struct symbol *symbol)
+syscm_scm_from_symbol (block_symbol symbol)
 {
   htab_t htab;
   eqable_gdb_smob **slot;
@@ -236,7 +236,7 @@ syscm_scm_from_symbol (struct symbol *symbol)
 
   /* If we've already created a gsmob for this symbol, return it.
      This makes symbols eq?-able.  */
-  htab = syscm_get_symbol_map (symbol);
+  htab = syscm_get_symbol_map (symbol.symbol);
   s_smob_for_lookup.symbol = symbol;
   slot = gdbscm_find_eqable_gsmob_ptr_slot (htab, &s_smob_for_lookup.base);
   if (*slot != NULL)
@@ -279,7 +279,7 @@ syscm_get_symbol_smob_arg_unsafe (SCM self, int arg_pos, const char *func_name)
 static int
 syscm_is_valid (symbol_smob *s_smob)
 {
-  return s_smob->symbol != NULL;
+  return s_smob->symbol.symbol != nullptr;
 }
 
 /* Throw a Scheme error if SELF is not a valid symbol smob.
@@ -311,7 +311,7 @@ syscm_get_valid_symbol_arg_unsafe (SCM self, int arg_pos,
   symbol_smob *s_smob = syscm_get_valid_symbol_smob_arg_unsafe (self, arg_pos,
 								func_name);
 
-  return s_smob->symbol;
+  return s_smob->symbol.symbol;
 }
 
 \f
@@ -337,7 +337,7 @@ gdbscm_symbol_type (SCM self)
 {
   symbol_smob *s_smob
     = syscm_get_valid_symbol_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
-  const struct symbol *symbol = s_smob->symbol;
+  const struct symbol *symbol = s_smob->symbol.symbol;
 
   if (symbol->type () == NULL)
     return SCM_BOOL_F;
@@ -354,7 +354,7 @@ gdbscm_symbol_symtab (SCM self)
 {
   symbol_smob *s_smob
     = syscm_get_valid_symbol_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
-  const struct symbol *symbol = s_smob->symbol;
+  const struct symbol *symbol = s_smob->symbol.symbol;
 
   if (!symbol->is_objfile_owned ())
     return SCM_BOOL_F;
@@ -368,7 +368,7 @@ gdbscm_symbol_name (SCM self)
 {
   symbol_smob *s_smob
     = syscm_get_valid_symbol_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
-  const struct symbol *symbol = s_smob->symbol;
+  const struct symbol *symbol = s_smob->symbol.symbol;
 
   return gdbscm_scm_from_c_string (symbol->natural_name ());
 }
@@ -380,7 +380,7 @@ gdbscm_symbol_linkage_name (SCM self)
 {
   symbol_smob *s_smob
     = syscm_get_valid_symbol_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
-  const struct symbol *symbol = s_smob->symbol;
+  const struct symbol *symbol = s_smob->symbol.symbol;
 
   return gdbscm_scm_from_c_string (symbol->linkage_name ());
 }
@@ -392,7 +392,7 @@ gdbscm_symbol_print_name (SCM self)
 {
   symbol_smob *s_smob
     = syscm_get_valid_symbol_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
-  const struct symbol *symbol = s_smob->symbol;
+  const struct symbol *symbol = s_smob->symbol.symbol;
 
   return gdbscm_scm_from_c_string (symbol->print_name ());
 }
@@ -404,7 +404,7 @@ gdbscm_symbol_addr_class (SCM self)
 {
   symbol_smob *s_smob
     = syscm_get_valid_symbol_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
-  const struct symbol *symbol = s_smob->symbol;
+  const struct symbol *symbol = s_smob->symbol.symbol;
 
   return scm_from_int (symbol->aclass ());
 }
@@ -416,7 +416,7 @@ gdbscm_symbol_argument_p (SCM self)
 {
   symbol_smob *s_smob
     = syscm_get_valid_symbol_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
-  const struct symbol *symbol = s_smob->symbol;
+  const struct symbol *symbol = s_smob->symbol.symbol;
 
   return scm_from_bool (symbol->is_argument ());
 }
@@ -428,7 +428,7 @@ gdbscm_symbol_constant_p (SCM self)
 {
   symbol_smob *s_smob
     = syscm_get_valid_symbol_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
-  const struct symbol *symbol = s_smob->symbol;
+  const struct symbol *symbol = s_smob->symbol.symbol;
   enum address_class theclass;
 
   theclass = symbol->aclass ();
@@ -443,7 +443,7 @@ gdbscm_symbol_function_p (SCM self)
 {
   symbol_smob *s_smob
     = syscm_get_valid_symbol_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
-  const struct symbol *symbol = s_smob->symbol;
+  const struct symbol *symbol = s_smob->symbol.symbol;
   enum address_class theclass;
 
   theclass = symbol->aclass ();
@@ -458,7 +458,7 @@ gdbscm_symbol_variable_p (SCM self)
 {
   symbol_smob *s_smob
     = syscm_get_valid_symbol_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
-  const struct symbol *symbol = s_smob->symbol;
+  const struct symbol *symbol = s_smob->symbol.symbol;
   enum address_class theclass;
 
   theclass = symbol->aclass ();
@@ -477,7 +477,7 @@ gdbscm_symbol_needs_frame_p (SCM self)
 {
   symbol_smob *s_smob
     = syscm_get_valid_symbol_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
-  struct symbol *symbol = s_smob->symbol;
+  struct symbol *symbol = s_smob->symbol.symbol;
   int result = 0;
 
   gdbscm_gdb_exception exc {};
@@ -502,7 +502,7 @@ gdbscm_symbol_line (SCM self)
 {
   symbol_smob *s_smob
     = syscm_get_valid_symbol_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
-  const struct symbol *symbol = s_smob->symbol;
+  const struct symbol *symbol = s_smob->symbol.symbol;
 
   return scm_from_int (symbol->line ());
 }
@@ -515,7 +515,7 @@ gdbscm_symbol_value (SCM self, SCM rest)
 {
   symbol_smob *s_smob
     = syscm_get_valid_symbol_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
-  struct symbol *symbol = s_smob->symbol;
+  block_symbol symbol = s_smob->symbol;
   SCM keywords[] = { frame_keyword, SCM_BOOL_F };
   int frame_pos = -1;
   SCM frame_scm = SCM_BOOL_F;
@@ -527,7 +527,7 @@ gdbscm_symbol_value (SCM self, SCM rest)
   if (!gdbscm_is_false (frame_scm))
     f_smob = frscm_get_frame_smob_arg_unsafe (frame_scm, frame_pos, FUNC_NAME);
 
-  if (symbol->aclass () == LOC_TYPEDEF)
+  if (symbol.symbol->aclass () == LOC_TYPEDEF)
     {
       gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self,
 				 _("cannot get the value of a typedef"));
@@ -545,14 +545,10 @@ gdbscm_symbol_value (SCM self, SCM rest)
 	    error (_("Invalid frame"));
 	}
       
-      if (symbol_read_needs_frame (symbol) && frame_info == NULL)
+      if (symbol_read_needs_frame (symbol.symbol) && frame_info == nullptr)
 	error (_("Symbol requires a frame to compute its value"));
 
-      /* TODO: currently, we have no way to recover the block in which SYMBOL
-	 was found, so we have no block to pass to read_var_value.  This will
-	 yield an incorrect value when symbol is not local to FRAME_INFO (this
-	 can happen with nested functions).  */
-      value = read_var_value (symbol, NULL, frame_info);
+      value = read_var_value (symbol, frame_info);
     }
   catch (const gdb_exception &except)
     {
@@ -578,7 +574,7 @@ gdbscm_lookup_symbol (SCM name_scm, SCM rest)
   int domain = VAR_DOMAIN;
   int block_arg_pos = -1, domain_arg_pos = -1;
   struct field_of_this_result is_a_field_of_this;
-  struct symbol *symbol = NULL;
+  block_symbol symbol = {};
 
   gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, keywords, "s#Oi",
 			      name_scm, &name, rest,
@@ -618,7 +614,7 @@ gdbscm_lookup_symbol (SCM name_scm, SCM rest)
   try
     {
       symbol = lookup_symbol (name, block, (domain_enum) domain,
-			      &is_a_field_of_this).symbol;
+			      &is_a_field_of_this);
     }
   catch (const gdb_exception &ex)
     {
@@ -628,7 +624,7 @@ gdbscm_lookup_symbol (SCM name_scm, SCM rest)
   xfree (name);
   GDBSCM_HANDLE_GDB_EXCEPTION (except);
 
-  if (symbol == NULL)
+  if (symbol.symbol == nullptr)
     return SCM_BOOL_F;
 
   return scm_list_2 (syscm_scm_from_symbol (symbol),
@@ -645,7 +641,7 @@ gdbscm_lookup_global_symbol (SCM name_scm, SCM rest)
   SCM keywords[] = { domain_keyword, SCM_BOOL_F };
   int domain_arg_pos = -1;
   int domain = VAR_DOMAIN;
-  struct symbol *symbol = NULL;
+  block_symbol symbol = {};
   gdbscm_gdb_exception except {};
 
   gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, keywords, "s#i",
@@ -654,7 +650,7 @@ gdbscm_lookup_global_symbol (SCM name_scm, SCM rest)
 
   try
     {
-      symbol = lookup_global_symbol (name, NULL, (domain_enum) domain).symbol;
+      symbol = lookup_global_symbol (name, NULL, (domain_enum) domain);
     }
   catch (const gdb_exception &ex)
     {
@@ -664,7 +660,7 @@ gdbscm_lookup_global_symbol (SCM name_scm, SCM rest)
   xfree (name);
   GDBSCM_HANDLE_GDB_EXCEPTION (except);
 
-  if (symbol == NULL)
+  if (symbol.symbol == nullptr)
     return SCM_BOOL_F;
 
   return syscm_scm_from_symbol (symbol);

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 25/31] Use read_var_value in read_frame_arg and read_frame_local
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (23 preceding siblings ...)
  2023-11-05 18:12 ` [PATCH v2 24/31] Use read_var_value overload in Guile Tom Tromey
@ 2023-11-05 18:12 ` Tom Tromey
  2023-11-05 18:12 ` [PATCH v2 26/31] Change print_variable_and_value to take a block_symbol Tom Tromey
                   ` (6 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:12 UTC (permalink / raw)
  To: gdb-patches

This changes read_frame_arg and read_frame_local to take a
block_symbol and to use the new read_var_value overload.k
---
 gdb/frame.h                 |  6 +++---
 gdb/mi/mi-cmd-stack.c       | 20 ++++++++++----------
 gdb/python/py-framefilter.c |  8 ++++----
 gdb/stack.c                 | 27 ++++++++++++++-------------
 4 files changed, 31 insertions(+), 30 deletions(-)

diff --git a/gdb/frame.h b/gdb/frame.h
index 0f1640c4a68..7c664c7cea8 100644
--- a/gdb/frame.h
+++ b/gdb/frame.h
@@ -931,7 +931,7 @@ extern frame_print_options user_frame_print_options;
 struct frame_arg
 {
   /* Symbol for this parameter used for example for its name.  */
-  struct symbol *sym = nullptr;
+  block_symbol sym = {};
 
   /* Value of the parameter.  It is NULL if ERROR is not NULL; if both VAL and
      ERROR are NULL this parameter's value should not be printed.  */
@@ -954,10 +954,10 @@ struct frame_arg
 };
 
 extern void read_frame_arg (const frame_print_options &fp_opts,
-			    symbol *sym, frame_info_ptr frame,
+			    block_symbol sym, frame_info_ptr frame,
 			    struct frame_arg *argp,
 			    struct frame_arg *entryargp);
-extern void read_frame_local (struct symbol *sym, frame_info_ptr frame,
+extern void read_frame_local (block_symbol sym, frame_info_ptr frame,
 			      struct frame_arg *argp);
 
 extern void info_args_command (const char *, int);
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index e473be7d465..9a53bac92e7 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -521,18 +521,18 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
 
   string_file stb;
 
-  stb.puts (arg->sym->print_name ());
+  stb.puts (arg->sym.symbol->print_name ());
   if (arg->entry_kind == print_entry_values_only)
     stb.puts ("@entry");
   uiout->field_stream ("name", stb);
 
-  if (what == all && arg->sym->is_argument ())
+  if (what == all && arg->sym.symbol->is_argument ())
     uiout->field_signed ("arg", 1);
 
   if (values == PRINT_SIMPLE_VALUES)
     {
-      check_typedef (arg->sym->type ());
-      type_print (arg->sym->type (), "", &stb, -1);
+      check_typedef (arg->sym.symbol->type ());
+      type_print (arg->sym.symbol->type (), "", &stb, -1);
       uiout->field_stream ("type", stb);
     }
 
@@ -549,7 +549,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
 	      get_no_prettyformat_print_options (&opts);
 	      opts.deref_ref = true;
 	      common_val_print (arg->val, &stb, 0, &opts,
-				language_def (arg->sym->language ()));
+				language_def (arg->sym.symbol->language ()));
 	    }
 	  catch (const gdb_exception_error &except)
 	    {
@@ -632,15 +632,15 @@ list_args_or_locals (const frame_print_options &fp_opts,
 	    }
 	  if (print_me)
 	    {
-	      struct symbol *sym2;
+	      block_symbol sym2;
 	      struct frame_arg arg, entryarg;
 
 	      if (sym->is_argument ())
 		sym2 = lookup_symbol_search_name (sym->search_name (),
-						  block, VAR_DOMAIN).symbol;
+						  block, VAR_DOMAIN);
 	      else
-		sym2 = sym;
-	      gdb_assert (sym2 != NULL);
+		sym2 = { sym, block };
+	      gdb_assert (sym2.symbol != nullptr);
 
 	      arg.sym = sym2;
 	      arg.entry_kind = print_entry_values_no;
@@ -650,7 +650,7 @@ list_args_or_locals (const frame_print_options &fp_opts,
 	      switch (values)
 		{
 		case PRINT_SIMPLE_VALUES:
-		  if (!mi_simple_type_p (sym2->type ()))
+		  if (!mi_simple_type_p (sym2.symbol->type ()))
 		    break;
 		  /* FALLTHROUGH */
 
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 07b30a587b1..b214e82628f 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -312,7 +312,7 @@ py_print_single_arg (struct ui_out *out,
     {
       if (fa->val == NULL && fa->error == NULL)
 	return;
-      language = language_def (fa->sym->language ());
+      language = language_def (fa->sym.symbol->language ());
       val = fa->val;
     }
   else
@@ -340,12 +340,12 @@ py_print_single_arg (struct ui_out *out,
     {
       string_file stb;
 
-      gdb_puts (fa->sym->print_name (), &stb);
+      gdb_puts (fa->sym.symbol->print_name (), &stb);
       if (fa->entry_kind == print_entry_values_compact)
 	{
 	  stb.puts ("=");
 
-	  gdb_puts (fa->sym->print_name (), &stb);
+	  gdb_puts (fa->sym.symbol->print_name (), &stb);
 	}
       if (fa->entry_kind == print_entry_values_only
 	  || fa->entry_kind == print_entry_values_compact)
@@ -472,7 +472,7 @@ enumerate_args (PyObject *iter,
 	    }
 
 	  read_frame_arg (user_frame_print_options,
-			  sym, frame, &arg, &entryarg);
+			  bsym, frame, &arg, &entryarg);
 
 	  /* The object has not provided a value, so this is a frame
 	     argument to be read by GDB.  In this case we have to
diff --git a/gdb/stack.c b/gdb/stack.c
index f744baad61a..8d72949006c 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -428,14 +428,14 @@ print_frame_arg (const frame_print_options &fp_opts,
 
   annotate_arg_emitter arg_emitter;
   ui_out_emit_tuple tuple_emitter (uiout, NULL);
-  gdb_puts (arg->sym->print_name (), &stb);
+  gdb_puts (arg->sym.symbol->print_name (), &stb);
   if (arg->entry_kind == print_entry_values_compact)
     {
       /* It is OK to provide invalid MI-like stream as with
 	 PRINT_ENTRY_VALUE_COMPACT we never use MI.  */
       stb.puts ("=");
 
-      gdb_puts (arg->sym->print_name (), &stb);
+      gdb_puts (arg->sym.symbol->print_name (), &stb);
     }
   if (arg->entry_kind == print_entry_values_only
       || arg->entry_kind == print_entry_values_compact)
@@ -472,7 +472,7 @@ print_frame_arg (const frame_print_options &fp_opts,
 	      /* Use the appropriate language to display our symbol, unless the
 		 user forced the language to a specific language.  */
 	      if (language_mode == language_mode_auto)
-		language = language_def (arg->sym->language ());
+		language = language_def (arg->sym.symbol->language ());
 	      else
 		language = current_language;
 
@@ -503,7 +503,7 @@ print_frame_arg (const frame_print_options &fp_opts,
    exception.  */
 
 void
-read_frame_local (struct symbol *sym, frame_info_ptr frame,
+read_frame_local (block_symbol sym, frame_info_ptr frame,
 		  struct frame_arg *argp)
 {
   argp->sym = sym;
@@ -512,7 +512,7 @@ read_frame_local (struct symbol *sym, frame_info_ptr frame,
 
   try
     {
-      argp->val = read_var_value (sym, NULL, frame);
+      argp->val = read_var_value (sym, frame);
     }
   catch (const gdb_exception_error &except)
     {
@@ -525,7 +525,7 @@ read_frame_local (struct symbol *sym, frame_info_ptr frame,
 
 void
 read_frame_arg (const frame_print_options &fp_opts,
-		symbol *sym, frame_info_ptr frame,
+		block_symbol bsym, frame_info_ptr frame,
 		struct frame_arg *argp, struct frame_arg *entryargp)
 {
   struct value *val = NULL, *entryval = NULL;
@@ -537,7 +537,7 @@ read_frame_arg (const frame_print_options &fp_opts,
     {
       try
 	{
-	  val = read_var_value (sym, NULL, frame);
+	  val = read_var_value (bsym, frame);
 	}
       catch (const gdb_exception_error &except)
 	{
@@ -546,6 +546,7 @@ read_frame_arg (const frame_print_options &fp_opts,
 	}
     }
 
+  symbol *sym = bsym.symbol;
   if (SYMBOL_COMPUTED_OPS (sym) != NULL
       && SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry != NULL
       && fp_opts.print_entry_values != print_entry_values_no
@@ -661,7 +662,7 @@ read_frame_arg (const frame_print_options &fp_opts,
 
 	  try
 	    {
-	      val = read_var_value (sym, NULL, frame);
+	      val = read_var_value (bsym, frame);
 	    }
 	  catch (const gdb_exception_error &except)
 	    {
@@ -687,7 +688,7 @@ read_frame_arg (const frame_print_options &fp_opts,
       val_error = NULL;
     }
 
-  argp->sym = sym;
+  argp->sym = bsym;
   argp->val = val;
   argp->error.reset (val_error ? xstrdup (val_error) : NULL);
   if (!val && !val_error)
@@ -702,7 +703,7 @@ read_frame_arg (const frame_print_options &fp_opts,
   else
     argp->entry_kind = print_entry_values_no;
 
-  entryargp->sym = sym;
+  entryargp->sym = bsym;
   entryargp->val = entryval;
   entryargp->error.reset (entryval_error ? xstrdup (entryval_error) : NULL);
   if (!entryval && !entryval_error)
@@ -871,13 +872,13 @@ print_frame_args (const frame_print_options &fp_opts,
 
 	  if (!print_args)
 	    {
-	      arg.sym = sym;
+	      arg.sym = { sym, b };
 	      arg.entry_kind = print_entry_values_no;
-	      entryarg.sym = sym;
+	      entryarg.sym = { sym, b };
 	      entryarg.entry_kind = print_entry_values_no;
 	    }
 	  else
-	    read_frame_arg (fp_opts, sym, frame, &arg, &entryarg);
+	    read_frame_arg (fp_opts, { sym, b }, frame, &arg, &entryarg);
 
 	  if (arg.entry_kind != print_entry_values_only)
 	    print_frame_arg (fp_opts, &arg);

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 26/31] Change print_variable_and_value to take a block_symbol
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (24 preceding siblings ...)
  2023-11-05 18:12 ` [PATCH v2 25/31] Use read_var_value in read_frame_arg and read_frame_local Tom Tromey
@ 2023-11-05 18:12 ` Tom Tromey
  2023-11-05 18:12 ` [PATCH v2 27/31] Change find_frame_funname to return " Tom Tromey
                   ` (5 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:12 UTC (permalink / raw)
  To: gdb-patches

This changes print_variable_and_value to accept a block_symbol and to
use the new read_var_value overload.
---
 gdb/printcmd.c | 9 +++------
 gdb/stack.c    | 6 +++++-
 gdb/value.h    | 2 +-
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 57a7af67ffe..afbc4f0eb55 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2395,10 +2395,11 @@ clear_dangling_display_expressions (struct objfile *objfile)
    before printing the variable name.  */
 
 void
-print_variable_and_value (const char *name, struct symbol *var,
+print_variable_and_value (const char *name, block_symbol bvar,
 			  frame_info_ptr frame,
 			  struct ui_file *stream, int indent)
 {
+  symbol *var = bvar.symbol;
 
   if (!name)
     name = var->print_name ();
@@ -2411,11 +2412,7 @@ print_variable_and_value (const char *name, struct symbol *var,
       struct value *val;
       struct value_print_options opts;
 
-      /* READ_VAR_VALUE needs a block in order to deal with non-local
-	 references (i.e. to handle nested functions).  In this context, we
-	 print variables that are local to this frame, so we can avoid passing
-	 a block to it.  */
-      val = read_var_value (var, NULL, frame);
+      val = read_var_value (bvar, frame);
       get_user_print_options (&opts);
       opts.deref_ref = true;
       common_val_print_checked (val, stream, indent, &opts, current_language);
diff --git a/gdb/stack.c b/gdb/stack.c
index 8d72949006c..27a932cfcaa 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -2268,6 +2268,7 @@ struct print_variable_and_value_data
   int num_tabs;
   struct ui_file *stream;
   int values_printed;
+  const struct block *block;
 
   void operator() (const char *print_name, struct symbol *sym);
 };
@@ -2296,7 +2297,8 @@ print_variable_and_value_data::operator() (const char *print_name,
       return;
     }
 
-  print_variable_and_value (print_name, sym, frame, stream, num_tabs);
+  print_variable_and_value (print_name, { sym, block }, frame,
+			    stream, num_tabs);
 
   /* print_variable_and_value invalidates FRAME.  */
   frame = NULL;
@@ -2361,6 +2363,7 @@ print_frame_local_vars (frame_info_ptr frame,
   cb_data.num_tabs = 4 * num_tabs;
   cb_data.stream = stream;
   cb_data.values_printed = 0;
+  cb_data.block = block;
 
   /* Temporarily change the selected frame to the given FRAME.
      This allows routines that rely on the selected frame instead
@@ -2525,6 +2528,7 @@ print_frame_arg_vars (frame_info_ptr frame,
   cb_data.num_tabs = 0;
   cb_data.stream = stream;
   cb_data.values_printed = 0;
+  cb_data.block = func->value_block ();
 
   iterate_over_block_arg_vars (func->value_block (), cb_data);
 
diff --git a/gdb/value.h b/gdb/value.h
index 7cb830110fc..81c53536416 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1534,7 +1534,7 @@ extern int val_print_string (struct type *elttype, const char *encoding,
 			     const struct value_print_options *options);
 
 extern void print_variable_and_value (const char *name,
-				      struct symbol *var,
+				      block_symbol var,
 				      frame_info_ptr frame,
 				      struct ui_file *stream,
 				      int indent);

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 27/31] Change find_frame_funname to return a block_symbol
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (25 preceding siblings ...)
  2023-11-05 18:12 ` [PATCH v2 26/31] Change print_variable_and_value to take a block_symbol Tom Tromey
@ 2023-11-05 18:12 ` Tom Tromey
  2023-11-05 18:12 ` [PATCH v2 28/31] Change btrace_function::sym to " Tom Tromey
                   ` (4 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:12 UTC (permalink / raw)
  To: gdb-patches

This changes the out parameter of find_frame_funname to be a
block_symbol.  This helps a later patch.
---
 gdb/python/py-frame.c  |  4 +++-
 gdb/python/py-unwind.c |  4 +++-
 gdb/stack.c            | 19 ++++++++++---------
 gdb/stack.h            |  2 +-
 4 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 1a55e514e39..555354df920 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -316,6 +316,7 @@ frapy_block (PyObject *self, PyObject *args)
 static PyObject *
 frapy_function (PyObject *self, PyObject *args)
 {
+  block_symbol bsym = {};
   struct symbol *sym = NULL;
   frame_info_ptr frame;
 
@@ -326,7 +327,8 @@ frapy_function (PyObject *self, PyObject *args)
       FRAPY_REQUIRE_VALID (self, frame);
 
       gdb::unique_xmalloc_ptr<char> funname
-	= find_frame_funname (frame, &funlang, &sym);
+	= find_frame_funname (frame, &funlang, &bsym);
+      sym = bsym.symbol;
     }
   catch (const gdb_exception &except)
     {
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index ee50c51b531..97035c5a140 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -658,6 +658,7 @@ pending_framepy_function (PyObject *self, PyObject *args)
   PENDING_FRAMEPY_REQUIRE_VALID (pending_frame);
 
   struct symbol *sym = nullptr;
+  block_symbol bsym = {};
 
   try
     {
@@ -665,7 +666,8 @@ pending_framepy_function (PyObject *self, PyObject *args)
       frame_info_ptr frame = pending_frame->frame_info;
 
       gdb::unique_xmalloc_ptr<char> funname
-	= find_frame_funname (frame, &funlang, &sym);
+	= find_frame_funname (frame, &funlang, &bsym);
+      sym = bsym.symbol;
     }
   catch (const gdb_exception &except)
     {
diff --git a/gdb/stack.c b/gdb/stack.c
index 27a932cfcaa..5d7267b7b51 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -1258,21 +1258,21 @@ get_last_displayed_sal ()
 
 gdb::unique_xmalloc_ptr<char>
 find_frame_funname (frame_info_ptr frame, enum language *funlang,
-		    struct symbol **funcp)
+		    block_symbol *funcp)
 {
-  struct symbol *func;
+  block_symbol func;
   gdb::unique_xmalloc_ptr<char> funname;
 
   *funlang = language_unknown;
   if (funcp)
-    *funcp = NULL;
+    *funcp = {};
 
-  func = get_frame_function (frame).symbol;
-  if (func)
+  func = get_frame_function (frame);
+  if (func.symbol != nullptr)
     {
-      const char *print_name = func->print_name ();
+      const char *print_name = func.symbol->print_name ();
 
-      *funlang = func->language ();
+      *funlang = func.symbol->language ();
       if (funcp)
 	*funcp = func;
       if (*funlang == language_cplus)
@@ -1319,14 +1319,15 @@ print_frame (const frame_print_options &fp_opts,
   struct ui_out *uiout = current_uiout;
   enum language funlang = language_unknown;
   struct value_print_options opts;
-  struct symbol *func;
   CORE_ADDR pc = 0;
   int pc_p;
 
   pc_p = get_frame_pc_if_available (frame, &pc);
 
+  block_symbol bfunc;
   gdb::unique_xmalloc_ptr<char> funname
-    = find_frame_funname (frame, &funlang, &func);
+    = find_frame_funname (frame, &funlang, &bfunc);
+  struct symbol *func = bfunc.symbol;
 
   annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
 			gdbarch, pc);
diff --git a/gdb/stack.h b/gdb/stack.h
index 1b0c2b342a4..616eb9a93d4 100644
--- a/gdb/stack.h
+++ b/gdb/stack.h
@@ -22,7 +22,7 @@
 
 gdb::unique_xmalloc_ptr<char> find_frame_funname (frame_info_ptr frame,
 						  enum language *funlang,
-						  struct symbol **funcp);
+						  block_symbol *funcp);
 
 typedef gdb::function_view<void (const char *print_name, struct symbol *sym)>
      iterate_over_block_arg_local_vars_cb;

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 28/31] Change btrace_function::sym to a block_symbol
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (26 preceding siblings ...)
  2023-11-05 18:12 ` [PATCH v2 27/31] Change find_frame_funname to return " Tom Tromey
@ 2023-11-05 18:12 ` Tom Tromey
  2023-11-05 18:12 ` [PATCH v2 29/31] Use read_var_value overload in Python Tom Tromey
                   ` (3 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:12 UTC (permalink / raw)
  To: gdb-patches

This changes btrace_function::sym to be a block_symbol, enabling a
later patch.
---
 gdb/btrace.c                  | 38 +++++++++++++++++++-------------------
 gdb/btrace.h                  |  5 +++--
 gdb/python/py-record-btrace.c |  2 +-
 gdb/record-btrace.c           |  8 ++++----
 4 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/gdb/btrace.c b/gdb/btrace.c
index ea18daa23e0..66b08dabb64 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -78,7 +78,7 @@ ftrace_print_function_name (const struct btrace_function *bfun)
   struct symbol *sym;
 
   msym = bfun->msym;
-  sym = bfun->sym;
+  sym = bfun->sym.symbol;
 
   if (sym != NULL)
     return sym->print_name ();
@@ -98,7 +98,7 @@ ftrace_print_filename (const struct btrace_function *bfun)
   struct symbol *sym;
   const char *filename;
 
-  sym = bfun->sym;
+  sym = bfun->sym.symbol;
 
   if (sym != NULL)
     filename = symtab_to_filename_for_display (sym->symtab ());
@@ -192,7 +192,7 @@ ftrace_function_switched (const struct btrace_function *bfun,
   struct symbol *sym;
 
   msym = bfun->msym;
-  sym = bfun->sym;
+  sym = bfun->sym.symbol;
 
   /* If the minimal symbol changed, we certainly switched functions.  */
   if (mfun != NULL && msym != NULL
@@ -235,7 +235,7 @@ ftrace_function_switched (const struct btrace_function *bfun,
 static struct btrace_function *
 ftrace_new_function (struct btrace_thread_info *btinfo,
 		     struct minimal_symbol *mfun,
-		     struct symbol *fun)
+		     block_symbol fun)
 {
   int level;
   unsigned int number, insn_offset;
@@ -311,7 +311,7 @@ ftrace_fixup_caller (struct btrace_thread_info *btinfo,
 static struct btrace_function *
 ftrace_new_call (struct btrace_thread_info *btinfo,
 		 struct minimal_symbol *mfun,
-		 struct symbol *fun)
+		 block_symbol fun)
 {
   const unsigned int length = btinfo->functions.size ();
   struct btrace_function *bfun = ftrace_new_function (btinfo, mfun, fun);
@@ -331,7 +331,7 @@ ftrace_new_call (struct btrace_thread_info *btinfo,
 static struct btrace_function *
 ftrace_new_tailcall (struct btrace_thread_info *btinfo,
 		     struct minimal_symbol *mfun,
-		     struct symbol *fun)
+		     block_symbol fun)
 {
   const unsigned int length = btinfo->functions.size ();
   struct btrace_function *bfun = ftrace_new_function (btinfo, mfun, fun);
@@ -414,7 +414,7 @@ ftrace_find_call (struct btrace_thread_info *btinfo,
 static struct btrace_function *
 ftrace_new_return (struct btrace_thread_info *btinfo,
 		   struct minimal_symbol *mfun,
-		   struct symbol *fun)
+		   block_symbol fun)
 {
   struct btrace_function *prev, *bfun, *caller;
 
@@ -424,7 +424,7 @@ ftrace_new_return (struct btrace_thread_info *btinfo,
   /* It is important to start at PREV's caller.  Otherwise, we might find
      PREV itself, if PREV is a recursive function.  */
   caller = ftrace_find_call_by_number (btinfo, prev->up);
-  caller = ftrace_find_caller (btinfo, caller, mfun, fun);
+  caller = ftrace_find_caller (btinfo, caller, mfun, fun.symbol);
   if (caller != NULL)
     {
       /* The caller of PREV is the preceding btrace function segment in this
@@ -496,7 +496,7 @@ ftrace_new_return (struct btrace_thread_info *btinfo,
 static struct btrace_function *
 ftrace_new_switch (struct btrace_thread_info *btinfo,
 		   struct minimal_symbol *mfun,
-		   struct symbol *fun)
+		   block_symbol fun)
 {
   struct btrace_function *prev, *bfun;
 
@@ -524,13 +524,13 @@ ftrace_new_gap (struct btrace_thread_info *btinfo, int errcode,
   struct btrace_function *bfun;
 
   if (btinfo->functions.empty ())
-    bfun = ftrace_new_function (btinfo, NULL, NULL);
+    bfun = ftrace_new_function (btinfo, NULL, {});
   else
     {
       /* We hijack the previous function segment if it was empty.  */
       bfun = &btinfo->functions.back ();
       if (bfun->errcode != 0 || !bfun->insn.empty ())
-	bfun = ftrace_new_function (btinfo, NULL, NULL);
+	bfun = ftrace_new_function (btinfo, NULL, {});
     }
 
   bfun->errcode = errcode;
@@ -550,17 +550,16 @@ ftrace_update_function (struct btrace_thread_info *btinfo, CORE_ADDR pc)
 {
   struct bound_minimal_symbol bmfun;
   struct minimal_symbol *mfun;
-  struct symbol *fun;
   struct btrace_function *bfun;
 
   /* Try to determine the function we're in.  We use both types of symbols
      to avoid surprises when we sometimes get a full symbol and sometimes
      only a minimal symbol.  */
-  fun = find_pc_function (pc).symbol;
+  block_symbol fun = find_pc_function (pc);
   bmfun = lookup_minimal_symbol_by_pc (pc);
   mfun = bmfun.minsym;
 
-  if (fun == NULL && mfun == NULL)
+  if (fun.symbol == NULL && mfun == NULL)
     DEBUG_FTRACE ("no symbol at %s", core_addr_to_string_nz (pc));
 
   /* If we didn't have a function, we create one.  */
@@ -629,7 +628,7 @@ ftrace_update_function (struct btrace_thread_info *btinfo, CORE_ADDR pc)
 	      {
 		struct btrace_function *caller
 		  = ftrace_find_call_by_number (btinfo, bfun->up);
-		caller = ftrace_find_caller (btinfo, caller, mfun, fun);
+		caller = ftrace_find_caller (btinfo, caller, mfun, fun.symbol);
 		if (caller != NULL)
 		  return ftrace_new_return (btinfo, mfun, fun);
 	      }
@@ -637,7 +636,8 @@ ftrace_update_function (struct btrace_thread_info *btinfo, CORE_ADDR pc)
 	    /* If we can't determine the function for PC, we treat a jump at
 	       the end of the block as tail call if we're switching functions
 	       and as an intra-function branch if we don't.  */
-	    if (start == 0 && ftrace_function_switched (bfun, mfun, fun))
+	    if (start == 0 && ftrace_function_switched (bfun, mfun,
+							fun.symbol))
 	      return ftrace_new_tailcall (btinfo, mfun, fun);
 
 	    break;
@@ -646,7 +646,7 @@ ftrace_update_function (struct btrace_thread_info *btinfo, CORE_ADDR pc)
     }
 
   /* Check if we're switching functions for some other reason.  */
-  if (ftrace_function_switched (bfun, mfun, fun))
+  if (ftrace_function_switched (bfun, mfun, fun.symbol))
     {
       DEBUG_FTRACE ("switching from %s in %s at %s",
 		    ftrace_print_insn_addr (last),
@@ -707,7 +707,7 @@ ftrace_match_backtrace (struct btrace_thread_info *btinfo,
 
   for (matches = 0; lhs != NULL && rhs != NULL; ++matches)
     {
-      if (ftrace_function_switched (lhs, rhs->msym, rhs->sym))
+      if (ftrace_function_switched (lhs, rhs->msym, rhs->sym.symbol))
 	return 0;
 
       lhs = ftrace_get_caller (btinfo, lhs);
@@ -890,7 +890,7 @@ ftrace_connect_backtrace (struct btrace_thread_info *btinfo,
     {
       struct btrace_function *prev, *next;
 
-      gdb_assert (!ftrace_function_switched (lhs, rhs->msym, rhs->sym));
+      gdb_assert (!ftrace_function_switched (lhs, rhs->msym, rhs->sym.symbol));
 
       /* Connecting LHS and RHS may change the up link.  */
       prev = lhs;
diff --git a/gdb/btrace.h b/gdb/btrace.h
index 994af4c459b..9e32ce4da17 100644
--- a/gdb/btrace.h
+++ b/gdb/btrace.h
@@ -29,6 +29,7 @@
 #include "gdbsupport/btrace-common.h"
 #include "target/waitstatus.h"
 #include "gdbsupport/enum-flags.h"
+#include "block-symbol.h"
 
 #if defined (HAVE_LIBIPT)
 #  include <intel-pt.h>
@@ -131,7 +132,7 @@ enum btrace_pt_error
    We do not allow function segments without instructions otherwise.  */
 struct btrace_function
 {
-  btrace_function (struct minimal_symbol *msym_, struct symbol *sym_,
+  btrace_function (struct minimal_symbol *msym_, block_symbol sym_,
 		   unsigned int number_, unsigned int insn_offset_, int level_)
     : msym (msym_), sym (sym_), insn_offset (insn_offset_), number (number_),
       level (level_)
@@ -140,7 +141,7 @@ struct btrace_function
 
   /* The full and minimal symbol for the function.  Both may be NULL.  */
   struct minimal_symbol *msym;
-  struct symbol *sym;
+  block_symbol sym;
 
   /* The function segment numbers of the previous and next segment belonging to
      the same function.  If a function calls another function, the former will
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index 822ae18e25e..7a51b1f0786 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -341,7 +341,7 @@ recpy_bt_func_symbol (PyObject *self, void *closure)
   if (func == NULL)
     return NULL;
 
-  if (func->sym == NULL)
+  if (func->sym.symbol == nullptr)
     Py_RETURN_NONE;
 
   return symbol_to_symbol_object (func->sym);
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index abab79f3132..58017822923 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -1069,7 +1069,7 @@ btrace_compute_src_line_range (const struct btrace_function *bfun,
   begin = INT_MAX;
   end = INT_MIN;
 
-  sym = bfun->sym;
+  sym = bfun->sym.symbol;
   if (sym == NULL)
     goto out;
 
@@ -1101,7 +1101,7 @@ btrace_call_history_src_line (struct ui_out *uiout,
   struct symbol *sym;
   int begin, end;
 
-  sym = bfun->sym;
+  sym = bfun->sym.symbol;
   if (sym == NULL)
     return;
 
@@ -1135,7 +1135,7 @@ btrace_get_bfun_name (const struct btrace_function *bfun)
     return "??";
 
   msym = bfun->msym;
-  sym = bfun->sym;
+  sym = bfun->sym.symbol;
 
   if (sym != NULL)
     return sym->print_name ();
@@ -1167,7 +1167,7 @@ btrace_call_history (struct ui_out *uiout,
       struct symbol *sym;
 
       bfun = btrace_call_get (&it);
-      sym = bfun->sym;
+      sym = bfun->sym.symbol;
       msym = bfun->msym;
 
       /* Print the function index.  */

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 29/31] Use read_var_value overload in Python
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (27 preceding siblings ...)
  2023-11-05 18:12 ` [PATCH v2 28/31] Change btrace_function::sym to " Tom Tromey
@ 2023-11-05 18:12 ` Tom Tromey
  2023-11-05 18:12 ` [PATCH v2 30/31] Remove the old read_var_value Tom Tromey
                   ` (2 subsequent siblings)
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:12 UTC (permalink / raw)
  To: gdb-patches

This changes the Python layer to store a block_symbol in its symbol
wrapper, and to use the new read_var_value overload.
---
 gdb/python/py-block.c            |   6 +-
 gdb/python/py-finishbreakpoint.c |   6 +-
 gdb/python/py-frame.c            |  19 +++---
 gdb/python/py-framefilter.c      |   6 +-
 gdb/python/py-objfile.c          |  16 +++--
 gdb/python/py-symbol.c           | 143 +++++++++++++++++++--------------------
 gdb/python/py-unwind.c           |   8 +--
 gdb/python/python-internal.h     |   4 +-
 8 files changed, 100 insertions(+), 108 deletions(-)

diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index dd6d6d278a0..48921c38af2 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -156,7 +156,7 @@ blpy_get_function (PyObject *self, void *closure)
 
   sym = block->function ();
   if (sym)
-    return symbol_to_symbol_object (sym);
+    return symbol_to_symbol_object ({ sym, block });
 
   Py_RETURN_NONE;
 }
@@ -272,7 +272,7 @@ blpy_getitem (PyObject *self, PyObject *key)
   for (struct symbol *sym : block_iterator_range (block, &lookup_name))
     {
       /* Just stop at the first match */
-      return symbol_to_symbol_object (sym);
+      return symbol_to_symbol_object ({ sym, block });
     }
 
   PyErr_SetObject (PyExc_KeyError, key);
@@ -376,7 +376,7 @@ blpy_block_syms_iternext (PyObject *self)
       return NULL;
     }
 
-  return symbol_to_symbol_object (sym);
+  return symbol_to_symbol_object ({ sym, iter_obj->block });
 }
 
 static void
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index 53ba41bd157..673283ce2c6 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -115,12 +115,12 @@ bpfinishpy_pre_stop_hook (struct gdbpy_breakpoint_object *bp_obj)
     {
       scoped_value_mark free_values;
 
-      struct symbol *func_symbol =
+      block_symbol func_symbol =
 	symbol_object_to_symbol (self_finishbp->func_symbol);
       struct value *function =
 	value_object_to_value (self_finishbp->function_value);
       struct value *ret =
-	get_return_value (func_symbol, function);
+	get_return_value (func_symbol.symbol, function);
 
       if (ret)
 	{
@@ -271,7 +271,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 		  PyErr_Clear ();
 
 		  self_bpfinish->func_symbol
-		    = symbol_to_symbol_object (function);
+		    = symbol_to_symbol_object (b_fun);
 		  PyErr_Clear ();
 		}
 	    }
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 555354df920..d4e3f263d5f 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -316,8 +316,7 @@ frapy_block (PyObject *self, PyObject *args)
 static PyObject *
 frapy_function (PyObject *self, PyObject *args)
 {
-  block_symbol bsym = {};
-  struct symbol *sym = NULL;
+  block_symbol sym = {};
   frame_info_ptr frame;
 
   try
@@ -327,15 +326,14 @@ frapy_function (PyObject *self, PyObject *args)
       FRAPY_REQUIRE_VALID (self, frame);
 
       gdb::unique_xmalloc_ptr<char> funname
-	= find_frame_funname (frame, &funlang, &bsym);
-      sym = bsym.symbol;
+	= find_frame_funname (frame, &funlang, &sym);
     }
   catch (const gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
 
-  if (sym)
+  if (sym.symbol != nullptr)
     return symbol_to_symbol_object (sym);
 
   Py_RETURN_NONE;
@@ -481,8 +479,7 @@ frapy_read_var (PyObject *self, PyObject *args, PyObject *kw)
 {
   frame_info_ptr frame;
   PyObject *sym_obj, *block_obj = NULL;
-  struct symbol *var = NULL;	/* gcc-4.3.2 false warning.  */
-  const struct block *block = NULL;
+  block_symbol var;
 
   static const char *keywords[] = { "variable", "block", nullptr };
   if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "O|O!", keywords,
@@ -500,6 +497,7 @@ frapy_read_var (PyObject *self, PyObject *args, PyObject *kw)
       if (!var_name)
 	return NULL;
 
+      const struct block *block = NULL;
       if (block_obj != nullptr)
 	{
 	  /* This call should only fail if the type of BLOCK_OBJ is wrong,
@@ -517,8 +515,7 @@ frapy_read_var (PyObject *self, PyObject *args, PyObject *kw)
 	  if (!block)
 	    block = get_frame_block (frame, NULL);
 	  lookup_sym = lookup_symbol (var_name.get (), block, VAR_DOMAIN, NULL);
-	  var = lookup_sym.symbol;
-	  block = lookup_sym.block;
+	  var = lookup_sym;
 	}
       catch (const gdb_exception &except)
 	{
@@ -526,7 +523,7 @@ frapy_read_var (PyObject *self, PyObject *args, PyObject *kw)
 	  return NULL;
 	}
 
-      if (!var)
+      if (var.symbol == nullptr)
 	{
 	  PyErr_Format (PyExc_ValueError,
 			_("Variable '%s' not found."), var_name.get ());
@@ -548,7 +545,7 @@ frapy_read_var (PyObject *self, PyObject *args, PyObject *kw)
       FRAPY_REQUIRE_VALID (self, frame);
 
       scoped_value_mark free_values;
-      struct value *val = read_var_value (var, block, frame);
+      struct value *val = read_var_value (var, frame);
       result = value_to_value_object (val);
     }
   catch (const gdb_exception &except)
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index b214e82628f..b2f2d81d4de 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -83,11 +83,7 @@ extract_sym (PyObject *obj, gdb::unique_xmalloc_ptr<char> *name,
     {
       /* This type checks 'result' during the conversion so we
 	 just call it unconditionally and check the return.  */
-      /* TODO: currently, we have no way to recover the block in which SYMBOL
-	 was found, so we have no block to return.  Trying to evaluate SYMBOL
-	 will yield an incorrect value when it's located in a FRAME and
-	 evaluated from another frame (as permitted in nested functions).  */
-      *sym = { symbol_object_to_symbol (result.get ()), nullptr };
+      *sym = symbol_object_to_symbol (result.get ());
 
       if (sym->symbol == NULL)
 	{
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index bb5d0d92aba..ee0a262e0fb 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -479,9 +479,11 @@ objfpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
 
   try
     {
-      struct symbol *sym = lookup_global_symbol_from_objfile
-	(obj->objfile, GLOBAL_BLOCK, symbol_name, (domain_enum) domain).symbol;
-      if (sym == nullptr)
+      block_symbol sym
+	= lookup_global_symbol_from_objfile (obj->objfile, GLOBAL_BLOCK,
+					     symbol_name,
+					     (domain_enum) domain);
+      if (sym.symbol == nullptr)
 	Py_RETURN_NONE;
 
       return symbol_to_symbol_object (sym);
@@ -513,9 +515,11 @@ objfpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw)
 
   try
     {
-      struct symbol *sym = lookup_global_symbol_from_objfile
-	(obj->objfile, STATIC_BLOCK, symbol_name, (domain_enum) domain).symbol;
-      if (sym == nullptr)
+      block_symbol sym
+	= lookup_global_symbol_from_objfile (obj->objfile, STATIC_BLOCK,
+					     symbol_name,
+					     (domain_enum) domain);
+      if (sym.symbol == nullptr)
 	Py_RETURN_NONE;
 
       return symbol_to_symbol_object (sym);
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 99724cfc95b..b802a7fdb45 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -29,7 +29,7 @@
 struct symbol_object {
   PyObject_HEAD
   /* The GDB symbol structure this object is wrapping.  */
-  struct symbol *symbol;
+  block_symbol symbol;
   /* A symbol object is associated with an objfile, so keep track with
      doubly-linked list, rooted in the objfile.  This lets us
      invalidate the underlying struct symbol when the objfile is
@@ -40,10 +40,10 @@ struct symbol_object {
 
 /* Require a valid symbol.  All access to symbol_object->symbol should be
    gated by this call.  */
-#define SYMPY_REQUIRE_VALID(symbol_obj, symbol)		\
+#define SYMPY_REQUIRE_VALID(symbol_obj, val)		\
   do {							\
-    symbol = symbol_object_to_symbol (symbol_obj);	\
-    if (symbol == NULL)					\
+    val = symbol_object_to_symbol (symbol_obj);		\
+    if (val.symbol == NULL)				\
       {							\
 	PyErr_SetString (PyExc_RuntimeError,		\
 			 _("Symbol is invalid."));	\
@@ -60,7 +60,7 @@ struct symbol_object_deleter
       {
 	symbol_object *next = obj->next;
 
-	obj->symbol = NULL;
+	obj->symbol = {};
 	obj->next = NULL;
 	obj->prev = NULL;
 
@@ -76,11 +76,11 @@ static PyObject *
 sympy_str (PyObject *self)
 {
   PyObject *result;
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  result = PyUnicode_FromString (symbol->print_name ());
+  result = PyUnicode_FromString (symbol.symbol->print_name ());
 
   return result;
 }
@@ -88,56 +88,56 @@ sympy_str (PyObject *self)
 static PyObject *
 sympy_get_type (PyObject *self, void *closure)
 {
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  if (symbol->type () == NULL)
+  if (symbol.symbol->type () == NULL)
     {
       Py_INCREF (Py_None);
       return Py_None;
     }
 
-  return type_to_type_object (symbol->type ());
+  return type_to_type_object (symbol.symbol->type ());
 }
 
 static PyObject *
 sympy_get_symtab (PyObject *self, void *closure)
 {
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  if (!symbol->is_objfile_owned ())
+  if (!symbol.symbol->is_objfile_owned ())
     Py_RETURN_NONE;
 
-  return symtab_to_symtab_object (symbol->symtab ());
+  return symtab_to_symtab_object (symbol.symbol->symtab ());
 }
 
 static PyObject *
 sympy_get_name (PyObject *self, void *closure)
 {
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  return PyUnicode_FromString (symbol->natural_name ());
+  return PyUnicode_FromString (symbol.symbol->natural_name ());
 }
 
 static PyObject *
 sympy_get_linkage_name (PyObject *self, void *closure)
 {
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  return PyUnicode_FromString (symbol->linkage_name ());
+  return PyUnicode_FromString (symbol.symbol->linkage_name ());
 }
 
 static PyObject *
 sympy_get_print_name (PyObject *self, void *closure)
 {
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
@@ -147,32 +147,32 @@ sympy_get_print_name (PyObject *self, void *closure)
 static PyObject *
 sympy_get_addr_class (PyObject *self, void *closure)
 {
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  return gdb_py_object_from_longest (symbol->aclass ()).release ();
+  return gdb_py_object_from_longest (symbol.symbol->aclass ()).release ();
 }
 
 static PyObject *
 sympy_is_argument (PyObject *self, void *closure)
 {
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  return PyBool_FromLong (symbol->is_argument ());
+  return PyBool_FromLong (symbol.symbol->is_argument ());
 }
 
 static PyObject *
 sympy_is_constant (PyObject *self, void *closure)
 {
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
   enum address_class theclass;
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  theclass = symbol->aclass ();
+  theclass = symbol.symbol->aclass ();
 
   return PyBool_FromLong (theclass == LOC_CONST || theclass == LOC_CONST_BYTES);
 }
@@ -180,12 +180,12 @@ sympy_is_constant (PyObject *self, void *closure)
 static PyObject *
 sympy_is_function (PyObject *self, void *closure)
 {
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
   enum address_class theclass;
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  theclass = symbol->aclass ();
+  theclass = symbol.symbol->aclass ();
 
   return PyBool_FromLong (theclass == LOC_BLOCK);
 }
@@ -193,14 +193,14 @@ sympy_is_function (PyObject *self, void *closure)
 static PyObject *
 sympy_is_variable (PyObject *self, void *closure)
 {
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
   enum address_class theclass;
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  theclass = symbol->aclass ();
+  theclass = symbol.symbol->aclass ();
 
-  return PyBool_FromLong (!symbol->is_argument ()
+  return PyBool_FromLong (!symbol.symbol->is_argument ()
 			  && (theclass == LOC_LOCAL || theclass == LOC_REGISTER
 			      || theclass == LOC_STATIC || theclass == LOC_COMPUTED
 			      || theclass == LOC_OPTIMIZED_OUT));
@@ -212,14 +212,14 @@ sympy_is_variable (PyObject *self, void *closure)
 static PyObject *
 sympy_needs_frame (PyObject *self, void *closure)
 {
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
   int result = 0;
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
   try
     {
-      result = symbol_read_needs_frame (symbol);
+      result = symbol_read_needs_frame (symbol.symbol);
     }
   catch (const gdb_exception &except)
     {
@@ -237,11 +237,11 @@ sympy_needs_frame (PyObject *self, void *closure)
 static PyObject *
 sympy_line (PyObject *self, void *closure)
 {
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  return gdb_py_object_from_longest (symbol->line ()).release ();
+  return gdb_py_object_from_longest (symbol.symbol->line ()).release ();
 }
 
 /* Implementation of gdb.Symbol.is_valid (self) -> Boolean.
@@ -250,10 +250,10 @@ sympy_line (PyObject *self, void *closure)
 static PyObject *
 sympy_is_valid (PyObject *self, PyObject *args)
 {
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
 
   symbol = symbol_object_to_symbol (self);
-  if (symbol == NULL)
+  if (symbol.symbol == NULL)
     Py_RETURN_FALSE;
 
   Py_RETURN_TRUE;
@@ -265,7 +265,7 @@ sympy_is_valid (PyObject *self, PyObject *args)
 static PyObject *
 sympy_value (PyObject *self, PyObject *args)
 {
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
   frame_info_ptr frame_info = NULL;
   PyObject *frame_obj = NULL;
 
@@ -279,7 +279,7 @@ sympy_value (PyObject *self, PyObject *args)
     }
 
   SYMPY_REQUIRE_VALID (self, symbol);
-  if (symbol->aclass () == LOC_TYPEDEF)
+  if (symbol.symbol->aclass () == LOC_TYPEDEF)
     {
       PyErr_SetString (PyExc_TypeError, "cannot get the value of a typedef");
       return NULL;
@@ -295,15 +295,11 @@ sympy_value (PyObject *self, PyObject *args)
 	    error (_("invalid frame"));
 	}
 
-      if (symbol_read_needs_frame (symbol) && frame_info == NULL)
+      if (symbol_read_needs_frame (symbol.symbol) && frame_info == NULL)
 	error (_("symbol requires a frame to compute its value"));
 
-      /* TODO: currently, we have no way to recover the block in which SYMBOL
-	 was found, so we have no block to pass to read_var_value.  This will
-	 yield an incorrect value when symbol is not local to FRAME_INFO (this
-	 can happen with nested functions).  */
       scoped_value_mark free_values;
-      struct value *value = read_var_value (symbol, NULL, frame_info);
+      struct value *value = read_var_value (symbol, frame_info);
       result = value_to_value_object (value);
     }
   catch (const gdb_exception &except)
@@ -320,14 +316,14 @@ sympy_value (PyObject *self, PyObject *args)
    with the life-cycle of the object file associated with this
    symbol, if needed.  */
 static void
-set_symbol (symbol_object *obj, struct symbol *symbol)
+set_symbol (symbol_object *obj, block_symbol symbol)
 {
   obj->symbol = symbol;
   obj->prev = NULL;
-  if (symbol->is_objfile_owned ()
-      && symbol->symtab () != NULL)
+  if (symbol.symbol->is_objfile_owned ()
+      && symbol.symbol->symtab () != NULL)
     {
-      struct objfile *objfile = symbol->objfile ();
+      struct objfile *objfile = symbol.symbol->objfile ();
 
       obj->next = sympy_objfile_data_key.get (objfile);
       if (obj->next)
@@ -341,7 +337,7 @@ set_symbol (symbol_object *obj, struct symbol *symbol)
 /* Create a new symbol object (gdb.Symbol) that encapsulates the struct
    symbol object from GDB.  */
 PyObject *
-symbol_to_symbol_object (struct symbol *sym)
+symbol_to_symbol_object (block_symbol sym)
 {
   symbol_object *sym_obj;
 
@@ -353,11 +349,11 @@ symbol_to_symbol_object (struct symbol *sym)
 }
 
 /* Return the symbol that is wrapped by this symbol object.  */
-struct symbol *
+block_symbol
 symbol_object_to_symbol (PyObject *obj)
 {
   if (! PyObject_TypeCheck (obj, &symbol_object_type))
-    return NULL;
+    return {};
   return ((symbol_object *) obj)->symbol;
 }
 
@@ -368,13 +364,14 @@ sympy_dealloc (PyObject *obj)
 
   if (sym_obj->prev)
     sym_obj->prev->next = sym_obj->next;
-  else if (sym_obj->symbol != NULL
-	   && sym_obj->symbol->is_objfile_owned ()
-	   && sym_obj->symbol->symtab () != NULL)
-    sympy_objfile_data_key.set (sym_obj->symbol->objfile (), sym_obj->next);
+  else if (sym_obj->symbol.symbol != NULL
+	   && sym_obj->symbol.symbol->is_objfile_owned ()
+	   && sym_obj->symbol.symbol->symtab () != NULL)
+    sympy_objfile_data_key.set (sym_obj->symbol.symbol->objfile (),
+				sym_obj->next);
   if (sym_obj->next)
     sym_obj->next->prev = sym_obj->prev;
-  sym_obj->symbol = NULL;
+  sym_obj->symbol = {};
   Py_TYPE (obj)->tp_free (obj);
 }
 
@@ -384,11 +381,11 @@ static PyObject *
 sympy_repr (PyObject *self)
 {
   const auto symbol = symbol_object_to_symbol (self);
-  if (symbol == nullptr)
+  if (symbol.symbol == nullptr)
     return PyUnicode_FromFormat ("<%s (invalid)>", Py_TYPE (self)->tp_name);
 
   return PyUnicode_FromFormat ("<%s print_name=%s>", Py_TYPE (self)->tp_name,
-			       symbol->print_name ());
+			       symbol.symbol->print_name ());
 }
 
 /* Implementation of
@@ -404,7 +401,7 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
   struct field_of_this_result is_a_field_of_this;
   const char *name;
   static const char *keywords[] = { "name", "block", "domain", NULL };
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
   PyObject *block_obj = NULL, *sym_obj, *bool_obj;
   const struct block *block = NULL;
 
@@ -433,7 +430,7 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
   try
     {
       symbol = lookup_symbol (name, block, (domain_enum) domain,
-			      &is_a_field_of_this).symbol;
+			      &is_a_field_of_this);
     }
   catch (const gdb_exception &except)
     {
@@ -444,7 +441,7 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
   if (ret_tuple == NULL)
     return NULL;
 
-  if (symbol)
+  if (symbol.symbol != nullptr)
     {
       sym_obj = symbol_to_symbol_object (symbol);
       if (!sym_obj)
@@ -472,7 +469,7 @@ gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
   int domain = VAR_DOMAIN;
   const char *name;
   static const char *keywords[] = { "name", "domain", NULL };
-  struct symbol *symbol = NULL;
+  block_symbol symbol;
   PyObject *sym_obj;
 
   if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name,
@@ -481,14 +478,14 @@ gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
 
   try
     {
-      symbol = lookup_global_symbol (name, NULL, (domain_enum) domain).symbol;
+      symbol = lookup_global_symbol (name, NULL, (domain_enum) domain);
     }
   catch (const gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
 
-  if (symbol)
+  if (symbol.symbol != nullptr)
     {
       sym_obj = symbol_to_symbol_object (symbol);
       if (!sym_obj)
@@ -512,7 +509,7 @@ gdbpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw)
   const char *name;
   int domain = VAR_DOMAIN;
   static const char *keywords[] = { "name", "domain", NULL };
-  struct symbol *symbol = NULL;
+  block_symbol symbol = {};
   PyObject *sym_obj;
 
   if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name,
@@ -543,19 +540,18 @@ gdbpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw)
   try
     {
       if (block != nullptr)
-	symbol
-	  = lookup_symbol_in_static_block (name, block,
-					   (domain_enum) domain).symbol;
+	symbol = lookup_symbol_in_static_block (name, block,
+						(domain_enum) domain);
 
-      if (symbol == nullptr)
-	symbol = lookup_static_symbol (name, (domain_enum) domain).symbol;
+      if (symbol.symbol == nullptr)
+	symbol = lookup_static_symbol (name, (domain_enum) domain);
     }
   catch (const gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
 
-  if (symbol)
+  if (symbol.symbol != nullptr)
     {
       sym_obj = symbol_to_symbol_object (symbol);
       if (!sym_obj)
@@ -612,10 +608,11 @@ gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw)
 
 	      if (block != nullptr)
 		{
-		  symbol *symbol = lookup_symbol_in_static_block
-		    (name, block, (domain_enum) domain).symbol;
+		  block_symbol symbol
+		    = lookup_symbol_in_static_block (name, block,
+						     (domain_enum) domain);
 
-		  if (symbol != nullptr)
+		  if (symbol.symbol != nullptr)
 		    {
 		      PyObject *sym_obj
 			= symbol_to_symbol_object (symbol);
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index 97035c5a140..7229ac86889 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -657,8 +657,7 @@ pending_framepy_function (PyObject *self, PyObject *args)
 
   PENDING_FRAMEPY_REQUIRE_VALID (pending_frame);
 
-  struct symbol *sym = nullptr;
-  block_symbol bsym = {};
+  block_symbol sym = {};
 
   try
     {
@@ -666,15 +665,14 @@ pending_framepy_function (PyObject *self, PyObject *args)
       frame_info_ptr frame = pending_frame->frame_info;
 
       gdb::unique_xmalloc_ptr<char> funname
-	= find_frame_funname (frame, &funlang, &bsym);
-      sym = bsym.symbol;
+	= find_frame_funname (frame, &funlang, &sym);
     }
   catch (const gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
 
-  if (sym != nullptr)
+  if (sym.symbol != nullptr)
     return symbol_to_symbol_object (sym);
 
   Py_RETURN_NONE;
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 847bed84dfe..a4c392085a6 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -435,7 +435,7 @@ PyObject *gdbpy_register_tui_window (PyObject *self, PyObject *args,
 
 PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal);
 PyObject *symtab_to_symtab_object (struct symtab *symtab);
-PyObject *symbol_to_symbol_object (struct symbol *sym);
+PyObject *symbol_to_symbol_object (block_symbol sym);
 PyObject *block_to_block_object (const struct block *block,
 				 struct objfile *objfile);
 PyObject *value_to_value_object (struct value *v);
@@ -474,7 +474,7 @@ gdbpy_ref<> target_to_connection_object (process_stratum_target *target);
 PyObject *gdbpy_connections (PyObject *self, PyObject *args);
 
 const struct block *block_object_to_block (PyObject *obj);
-struct symbol *symbol_object_to_symbol (PyObject *obj);
+block_symbol symbol_object_to_symbol (PyObject *obj);
 struct value *value_object_to_value (PyObject *self);
 struct value *convert_value_from_python (PyObject *obj);
 struct type *type_object_to_type (PyObject *obj);

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 30/31] Remove the old read_var_value
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (28 preceding siblings ...)
  2023-11-05 18:12 ` [PATCH v2 29/31] Use read_var_value overload in Python Tom Tromey
@ 2023-11-05 18:12 ` Tom Tromey
  2023-11-05 18:12 ` [PATCH v2 31/31] Change language_defn::read_var_value to accept block_symbol Tom Tromey
  2023-11-06 15:16 ` [PATCH v2 00/31] Baby step for objfile splitting Andrew Burgess
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:12 UTC (permalink / raw)
  To: gdb-patches

This removes the old, original read_var_value.  It is no longer
called.
---
 gdb/findvar.c | 13 -------------
 gdb/value.h   |  4 ----
 2 files changed, 17 deletions(-)

diff --git a/gdb/findvar.c b/gdb/findvar.c
index f3be783ec24..4282d85425a 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -783,19 +783,6 @@ language_defn::read_var_value (struct symbol *var,
 
 /* Calls VAR's language read_var_value hook with the given arguments.  */
 
-struct value *
-read_var_value (struct symbol *var, const struct block *var_block,
-		frame_info_ptr frame)
-{
-  const struct language_defn *lang = language_def (var->language ());
-
-  gdb_assert (lang != NULL);
-
-  return lang->read_var_value (var, var_block, frame);
-}
-
-/* Calls VAR's language read_var_value hook with the given arguments.  */
-
 struct value *
 read_var_value (block_symbol var, frame_info_ptr frame)
 {
diff --git a/gdb/value.h b/gdb/value.h
index 81c53536416..7072dce9782 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1134,10 +1134,6 @@ extern enum symbol_needs_kind symbol_read_needs (struct symbol *);
 
 extern int symbol_read_needs_frame (struct symbol *);
 
-extern struct value *read_var_value (struct symbol *var,
-				     const struct block *var_block,
-				     frame_info_ptr frame);
-
 extern struct value *read_var_value (block_symbol var,
 				     frame_info_ptr frame);
 

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v2 31/31] Change language_defn::read_var_value to accept block_symbol
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (29 preceding siblings ...)
  2023-11-05 18:12 ` [PATCH v2 30/31] Remove the old read_var_value Tom Tromey
@ 2023-11-05 18:12 ` Tom Tromey
  2023-11-06 15:16 ` [PATCH v2 00/31] Baby step for objfile splitting Andrew Burgess
  31 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2023-11-05 18:12 UTC (permalink / raw)
  To: gdb-patches

This changes language_defn::read_var_value to accept a block_symbol,
and to call block_symbol::address.
---
 gdb/ada-lang.c |  9 ++++-----
 gdb/findvar.c  | 17 ++++++++---------
 gdb/language.h | 14 ++++----------
 3 files changed, 16 insertions(+), 24 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 6beadad568a..ad39f5d496c 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13391,8 +13391,7 @@ class ada_language : public language_defn
 
   /* Implement the "read_var_value" language_defn method for Ada.  */
 
-  struct value *read_var_value (struct symbol *var,
-				const struct block *var_block,
+  struct value *read_var_value (block_symbol var,
 				frame_info_ptr frame) const override
   {
     /* The only case where default_read_var_value is not sufficient
@@ -13400,13 +13399,13 @@ class ada_language : public language_defn
     if (frame != nullptr)
       {
 	const struct block *frame_block = get_frame_block (frame, NULL);
-	if (frame_block != nullptr && ada_is_renaming_symbol (var))
-	  return ada_read_renaming_var_value (var, frame_block);
+	if (frame_block != nullptr && ada_is_renaming_symbol (var.symbol))
+	  return ada_read_renaming_var_value (var.symbol, frame_block);
       }
 
     /* This is a typical case where we expect the default_read_var_value
        function to work.  */
-    return language_defn::read_var_value (var, var_block, frame);
+    return language_defn::read_var_value (var, frame);
   }
 
   /* See language.h.  */
diff --git a/gdb/findvar.c b/gdb/findvar.c
index 4282d85425a..359024e931b 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -549,11 +549,10 @@ get_hosting_frame (struct symbol *var, const struct block *var_block,
 /* See language.h.  */
 
 struct value *
-language_defn::read_var_value (struct symbol *var,
-			       const struct block *var_block,
-			       frame_info_ptr frame) const
+language_defn::read_var_value (block_symbol bvar, frame_info_ptr frame) const
 {
   struct value *v;
+  symbol *var = bvar.symbol;
   struct type *type = var->type ();
   CORE_ADDR addr;
   enum symbol_needs_kind sym_need;
@@ -572,7 +571,7 @@ language_defn::read_var_value (struct symbol *var,
     error (_("Cannot read `%s' without registers"), var->print_name ());
 
   if (frame != NULL)
-    frame = get_hosting_frame (var, var_block, frame);
+    frame = get_hosting_frame (var, bvar.block, frame);
 
   if (SYMBOL_COMPUTED_OPS (var) != NULL)
     return SYMBOL_COMPUTED_OPS (var)->read_variable (var, frame);
@@ -598,11 +597,11 @@ language_defn::read_var_value (struct symbol *var,
 	if (overlay_debugging)
 	  {
 	    struct objfile *var_objfile = var->objfile ();
-	    addr = symbol_overlayed_address (var->value_address (),
+	    addr = symbol_overlayed_address (bvar.address (),
 					     var->obj_section (var_objfile));
 	  }
 	else
-	  addr = var->value_address ();
+	  addr = bvar.address ();
 
 	/* First convert the CORE_ADDR to a function pointer type, this
 	   ensures the gdbarch knows what type of pointer we are
@@ -635,10 +634,10 @@ language_defn::read_var_value (struct symbol *var,
     case LOC_STATIC:
       if (overlay_debugging)
 	addr
-	  = symbol_overlayed_address (var->value_address (),
+	  = symbol_overlayed_address (bvar.address (),
 				      var->obj_section (var->objfile ()));
       else
-	addr = var->value_address ();
+	addr = bvar.address ();
       break;
 
     case LOC_ARG:
@@ -790,7 +789,7 @@ read_var_value (block_symbol var, frame_info_ptr frame)
 
   gdb_assert (lang != NULL);
 
-  return lang->read_var_value (var.symbol, var.block, frame);
+  return lang->read_var_value (var, frame);
 }
 
 /* Install default attributes for register values.  */
diff --git a/gdb/language.h b/gdb/language.h
index 6ee8f6160e1..ede720ef7c8 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -308,19 +308,13 @@ struct language_defn
 				  struct ui_file *stream,
 				  const value_print_options *options) const;
 
-  /* Given a symbol VAR, the corresponding block VAR_BLOCK (if any) and a
-     stack frame id FRAME, read the value of the variable and return (pointer
-     to a) struct value containing the value.
-
-     VAR_BLOCK is needed if there's a possibility for VAR to be outside
-     FRAME.  This is what happens if FRAME correspond to a nested function
-     and VAR is defined in the outer function.  If callers know that VAR is
-     located in FRAME or is global/static, NULL can be passed as VAR_BLOCK.
+  /* Given a block_symbol VAR and a stack frame id FRAME, read the
+     value of the variable and return (pointer to a) struct value
+     containing the value.
 
      Throw an error if the variable cannot be found.  */
 
-  virtual struct value *read_var_value (struct symbol *var,
-					const struct block *var_block,
+  virtual struct value *read_var_value (block_symbol var,
 					frame_info_ptr frame) const;
 
   /* Return information about whether TYPE should be passed

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v2 00/31] Baby step for objfile splitting
  2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
                   ` (30 preceding siblings ...)
  2023-11-05 18:12 ` [PATCH v2 31/31] Change language_defn::read_var_value to accept block_symbol Tom Tromey
@ 2023-11-06 15:16 ` Andrew Burgess
  2023-11-07  3:36   ` Tom Tromey
  31 siblings, 1 reply; 35+ messages in thread
From: Andrew Burgess @ 2023-11-06 15:16 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

Tom Tromey <tom@tromey.com> writes:

> Every year or so, I take a stab at the objfile splitting work.  This
> always fails and I end up not sending anything.

For those of us who aren't familiar with the background here.  Do you
have a link to a previous description of, or could you give a
description of, what the "objfile splitting work" is about.  What's the
longer term goal, of which this series is a step towards.

Thanks,
Andrew


>
> This year, I decided to take a baby step instead, thinking maybe it
> would be possible to slowly grind away at the problem.
>
> This series is the first such step.  It spreads the use of
> block_symbol through a bunch of code, trying to eliminate calls to
> symbol::value_address.
>
> The longer term idea here is to then add an objfile member to
> block_symbol.  After this, it would be relatively simple to change
> symbols to be relocated at point of use.  (This would be a significant
> step toward objfile splitting, but there's even more to do after
> that...)
>
> Regression tested on x86-64 Fedora 38.
>
> ---
> Changes in v2:
> - Updated per review
> - Added bound_symbol patch, converted some patches to use it
> - More comprehensive change in ada-lang.c
> - Link to v1: https://inbox.sourceware.org/gdb-patches/20231029-split-objfile-2023-bound-sym-october-v1-0-612531df2734@tromey.com
>
> ---
> Tom Tromey (31):
>       Introduce block-symbol.h
>       Add block_symbol::address
>       Add bound_symbol
>       Easy conversions to use block_symbol::address
>       Use block_symbol::address in ada-tasks.c
>       Use block_symbol::address in printcmd.c
>       Use bound_symbol::address in tracepoint.c
>       Use block_symbol::address in tracepoint.c
>       Use block_symbol::address in ax-gdb.c
>       Use block_symbol::address in linespec.c
>       Use block_symbol::address in ada-lang.c
>       Use bound_symbol::address in symmisc.c
>       Introduce read_var_value overload
>       Use read_var_value in gdb/compile
>       Return a block_symbol from find_pc_sect_function
>       Use read_var_value overload in finish_command_fsm
>       Use block_symbol in overload-handling code
>       Change evaluate_var_value to accept a block_symbol
>       Change value_of_variable to take a block_symbol
>       Return a block_symbol from get_frame_function
>       Use read_var_value overload in return_command
>       Use read_var_value overload in py-finishbreakpoint.c
>       Use read_var_value overload in py-framefilter.c
>       Use read_var_value overload in Guile
>       Use read_var_value in read_frame_arg and read_frame_local
>       Change print_variable_and_value to take a block_symbol
>       Change find_frame_funname to return a block_symbol
>       Change btrace_function::sym to a block_symbol
>       Use read_var_value overload in Python
>       Remove the old read_var_value
>       Change language_defn::read_var_value to accept block_symbol
>
>  gdb/ada-lang.c                      | 116 +++++++++++++----------------
>  gdb/ada-tasks.c                     |  19 ++---
>  gdb/ax-gdb.c                        |  28 +++----
>  gdb/ax-gdb.h                        |   2 +-
>  gdb/block-symbol.h                  |  42 +++++++++++
>  gdb/blockframe.c                    |  18 ++---
>  gdb/breakpoint.c                    |   4 +-
>  gdb/btrace.c                        |  38 +++++-----
>  gdb/btrace.h                        |   5 +-
>  gdb/cli/cli-cmds.c                  |   4 +-
>  gdb/compile/compile-c-symbols.c     |  18 +++--
>  gdb/compile/compile-cplus-symbols.c |   6 +-
>  gdb/compile/compile-cplus-types.c   |   2 +-
>  gdb/compile/compile-loc2c.c         |  14 ++--
>  gdb/compile/compile.h               |   6 +-
>  gdb/cp-support.c                    |  46 +++++++-----
>  gdb/cp-support.h                    |   6 +-
>  gdb/dwarf2/ada-imported.c           |   2 +-
>  gdb/dwarf2/loc.c                    |  16 ++--
>  gdb/dwarf2/loc.h                    |   3 +-
>  gdb/eval.c                          |  62 +++++++---------
>  gdb/expop.h                         |   5 ++
>  gdb/f-valprint.c                    |   4 +-
>  gdb/findvar.c                       |  24 +++---
>  gdb/frame.c                         |   2 +-
>  gdb/frame.h                         |   9 ++-
>  gdb/guile/guile-internal.h          |   2 +-
>  gdb/guile/scm-block.c               |   6 +-
>  gdb/guile/scm-frame.c               |   7 +-
>  gdb/guile/scm-symbol.c              |  78 ++++++++++----------
>  gdb/infcall.c                       |   4 +-
>  gdb/infcmd.c                        |  29 ++++----
>  gdb/infrun.c                        |  10 +--
>  gdb/inline-frame.c                  |   2 +-
>  gdb/language.h                      |  14 +---
>  gdb/linespec.c                      |  15 ++--
>  gdb/mi/mi-cmd-stack.c               |  20 ++---
>  gdb/printcmd.c                      |  22 +++---
>  gdb/python/py-block.c               |   6 +-
>  gdb/python/py-finishbreakpoint.c    |  11 +--
>  gdb/python/py-frame.c               |  15 ++--
>  gdb/python/py-framefilter.c         |  64 +++++++---------
>  gdb/python/py-objfile.c             |  16 ++--
>  gdb/python/py-record-btrace.c       |   2 +-
>  gdb/python/py-symbol.c              | 143 ++++++++++++++++++------------------
>  gdb/python/py-type.c                |   2 +-
>  gdb/python/py-unwind.c              |   4 +-
>  gdb/python/python-internal.h        |   4 +-
>  gdb/record-btrace.c                 |   8 +-
>  gdb/rust-lang.c                     |   2 +-
>  gdb/skip.c                          |   2 +-
>  gdb/solib-frv.c                     |   2 +-
>  gdb/sparc-tdep.c                    |   4 +-
>  gdb/stack.c                         |  59 ++++++++-------
>  gdb/stack.h                         |   2 +-
>  gdb/symmisc.c                       |  15 ++--
>  gdb/symtab.c                        |   4 +-
>  gdb/symtab.h                        |  38 +++++++---
>  gdb/tracepoint.c                    |  26 ++++---
>  gdb/tracepoint.h                    |   2 +-
>  gdb/valarith.c                      |   9 +--
>  gdb/valops.c                        |  75 ++++++++++---------
>  gdb/value.c                         |   2 +-
>  gdb/value.h                         |  18 ++---
>  64 files changed, 647 insertions(+), 598 deletions(-)
> ---
> base-commit: 0a845aef62b8813275616bd399e8fca679161cfc
> change-id: 20231029-split-objfile-2023-bound-sym-october-8da7ff1061cc
>
> Best regards,
> -- 
> Tom Tromey <tom@tromey.com>


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v2 00/31] Baby step for objfile splitting
  2023-11-06 15:16 ` [PATCH v2 00/31] Baby step for objfile splitting Andrew Burgess
@ 2023-11-07  3:36   ` Tom Tromey
  2023-11-07 11:06     ` Andrew Burgess
  0 siblings, 1 reply; 35+ messages in thread
From: Tom Tromey @ 2023-11-07  3:36 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: Tom Tromey, gdb-patches

>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:

Andrew> Tom Tromey <tom@tromey.com> writes:
>> Every year or so, I take a stab at the objfile splitting work.  This
>> always fails and I end up not sending anything.

Andrew> For those of us who aren't familiar with the background here.  Do you
Andrew> have a link to a previous description of, or could you give a
Andrew> description of, what the "objfile splitting work" is about.  What's the
Andrew> longer term goal, of which this series is a step towards.

The basic idea is that debug info should be independent of the program
space.  That way, symbol tables can be shared across inferiors.

The project is somewhat documented here:

https://sourceware.org/gdb/wiki/ObjfileSplitting

It's been vaguely ongoing for a very long time.  I managed to implement
it for minsyms, psyms, and line tables; but symbols and blocks have
proven to be more difficult, with a trail of failed branches behind
them.

Tom

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v2 00/31] Baby step for objfile splitting
  2023-11-07  3:36   ` Tom Tromey
@ 2023-11-07 11:06     ` Andrew Burgess
  0 siblings, 0 replies; 35+ messages in thread
From: Andrew Burgess @ 2023-11-07 11:06 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Tom Tromey, gdb-patches

Tom Tromey <tom@tromey.com> writes:

>>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
>
> Andrew> Tom Tromey <tom@tromey.com> writes:
>>> Every year or so, I take a stab at the objfile splitting work.  This
>>> always fails and I end up not sending anything.
>
> Andrew> For those of us who aren't familiar with the background here.  Do you
> Andrew> have a link to a previous description of, or could you give a
> Andrew> description of, what the "objfile splitting work" is about.  What's the
> Andrew> longer term goal, of which this series is a step towards.
>
> The basic idea is that debug info should be independent of the program
> space.  That way, symbol tables can be shared across inferiors.
>
> The project is somewhat documented here:
>
> https://sourceware.org/gdb/wiki/ObjfileSplitting
>
> It's been vaguely ongoing for a very long time.  I managed to implement
> it for minsyms, psyms, and line tables; but symbols and blocks have
> proven to be more difficult, with a trail of failed branches behind
> them.

Thanks.  I have heard this discussed before, I'd just not associated
with that name.

Thanks,
Andrew


^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2023-11-07 11:06 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
2023-11-05 18:11 ` [PATCH v2 01/31] Introduce block-symbol.h Tom Tromey
2023-11-05 18:11 ` [PATCH v2 02/31] Add block_symbol::address Tom Tromey
2023-11-05 18:11 ` [PATCH v2 03/31] Add bound_symbol Tom Tromey
2023-11-05 18:11 ` [PATCH v2 04/31] Easy conversions to use block_symbol::address Tom Tromey
2023-11-05 18:11 ` [PATCH v2 05/31] Use block_symbol::address in ada-tasks.c Tom Tromey
2023-11-05 18:11 ` [PATCH v2 06/31] Use block_symbol::address in printcmd.c Tom Tromey
2023-11-05 18:11 ` [PATCH v2 07/31] Use bound_symbol::address in tracepoint.c Tom Tromey
2023-11-05 18:11 ` [PATCH v2 08/31] Use block_symbol::address " Tom Tromey
2023-11-05 18:11 ` [PATCH v2 09/31] Use block_symbol::address in ax-gdb.c Tom Tromey
2023-11-05 18:11 ` [PATCH v2 10/31] Use block_symbol::address in linespec.c Tom Tromey
2023-11-05 18:11 ` [PATCH v2 11/31] Use block_symbol::address in ada-lang.c Tom Tromey
2023-11-05 18:11 ` [PATCH v2 12/31] Use bound_symbol::address in symmisc.c Tom Tromey
2023-11-05 18:11 ` [PATCH v2 13/31] Introduce read_var_value overload Tom Tromey
2023-11-05 18:11 ` [PATCH v2 14/31] Use read_var_value in gdb/compile Tom Tromey
2023-11-05 18:11 ` [PATCH v2 15/31] Return a block_symbol from find_pc_sect_function Tom Tromey
2023-11-05 18:11 ` [PATCH v2 16/31] Use read_var_value overload in finish_command_fsm Tom Tromey
2023-11-05 18:11 ` [PATCH v2 17/31] Use block_symbol in overload-handling code Tom Tromey
2023-11-05 18:11 ` [PATCH v2 18/31] Change evaluate_var_value to accept a block_symbol Tom Tromey
2023-11-05 18:11 ` [PATCH v2 19/31] Change value_of_variable to take " Tom Tromey
2023-11-05 18:11 ` [PATCH v2 20/31] Return a block_symbol from get_frame_function Tom Tromey
2023-11-05 18:11 ` [PATCH v2 21/31] Use read_var_value overload in return_command Tom Tromey
2023-11-05 18:12 ` [PATCH v2 22/31] Use read_var_value overload in py-finishbreakpoint.c Tom Tromey
2023-11-05 18:12 ` [PATCH v2 23/31] Use read_var_value overload in py-framefilter.c Tom Tromey
2023-11-05 18:12 ` [PATCH v2 24/31] Use read_var_value overload in Guile Tom Tromey
2023-11-05 18:12 ` [PATCH v2 25/31] Use read_var_value in read_frame_arg and read_frame_local Tom Tromey
2023-11-05 18:12 ` [PATCH v2 26/31] Change print_variable_and_value to take a block_symbol Tom Tromey
2023-11-05 18:12 ` [PATCH v2 27/31] Change find_frame_funname to return " Tom Tromey
2023-11-05 18:12 ` [PATCH v2 28/31] Change btrace_function::sym to " Tom Tromey
2023-11-05 18:12 ` [PATCH v2 29/31] Use read_var_value overload in Python Tom Tromey
2023-11-05 18:12 ` [PATCH v2 30/31] Remove the old read_var_value Tom Tromey
2023-11-05 18:12 ` [PATCH v2 31/31] Change language_defn::read_var_value to accept block_symbol Tom Tromey
2023-11-06 15:16 ` [PATCH v2 00/31] Baby step for objfile splitting Andrew Burgess
2023-11-07  3:36   ` Tom Tromey
2023-11-07 11:06     ` Andrew Burgess

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