[09/14] gdb: pass program space to get_current_source_symtab_and_line

Message ID 20240711195307.1544451-10-simon.marchi@polymtl.ca
State New
Headers
Series Some random program space cleanups |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed

Commit Message

Simon Marchi July 11, 2024, 7:52 p.m. UTC
  Make the current program space reference bubble up one level.

Change-Id: I6ba6dc4a2cb188720cbb61b84ab5c954aac105c6
---
 gdb/breakpoint.c        |  5 ++---
 gdb/cli/cli-cmds.c      | 14 +++++++++-----
 gdb/compile/compile.c   |  4 +++-
 gdb/infcmd.c            |  3 ++-
 gdb/linespec.c          |  9 +++++----
 gdb/macroscope.c        |  6 +++---
 gdb/mi/mi-cmd-file.c    |  4 ++--
 gdb/objfiles.c          |  3 ++-
 gdb/parse.c             |  4 ++--
 gdb/python/python.c     |  2 +-
 gdb/source.c            | 11 +++++------
 gdb/source.h            |  4 +++-
 gdb/tui/tui-disasm.c    |  3 ++-
 gdb/tui/tui-hooks.c     |  3 ++-
 gdb/tui/tui-source.c    |  5 +++--
 gdb/tui/tui-winsource.c | 10 +++++-----
 16 files changed, 51 insertions(+), 39 deletions(-)
  

Comments

Thiago Jung Bauermann July 13, 2024, 5:26 a.m. UTC | #1
Simon Marchi <simon.marchi@polymtl.ca> writes:

> diff --git a/gdb/objfiles.c b/gdb/objfiles.c
> index 77d759b3aa59..600d205d0645 100644
> --- a/gdb/objfiles.c
> +++ b/gdb/objfiles.c
> @@ -561,7 +561,8 @@ objfile::~objfile ()
>       and if so, call clear_current_source_symtab_and_line.  */
>  
>    {
> -    struct symtab_and_line cursal = get_current_source_symtab_and_line ();
> +    symtab_and_line cursal
> +      = get_current_source_symtab_and_line (current_program_space);

Can this->pspace be used here? Maybe not, since the comment above says
that the idea is to "Check to see if the current_source_symtab belongs
to this objfile" but I thought I'd ask.

>  
>      if (cursal.symtab && cursal.symtab->compunit ()->objfile () == this)
>        clear_current_source_symtab_and_line (current_program_space);
  
Simon Marchi July 15, 2024, 2:36 p.m. UTC | #2
On 7/13/24 1:26 AM, Thiago Jung Bauermann wrote:
> Simon Marchi <simon.marchi@polymtl.ca> writes:
> 
>> diff --git a/gdb/objfiles.c b/gdb/objfiles.c
>> index 77d759b3aa59..600d205d0645 100644
>> --- a/gdb/objfiles.c
>> +++ b/gdb/objfiles.c
>> @@ -561,7 +561,8 @@ objfile::~objfile ()
>>       and if so, call clear_current_source_symtab_and_line.  */
>>  
>>    {
>> -    struct symtab_and_line cursal = get_current_source_symtab_and_line ();
>> +    symtab_and_line cursal
>> +      = get_current_source_symtab_and_line (current_program_space);
> 
> Can this->pspace be used here? Maybe not, since the comment above says
> that the idea is to "Check to see if the current_source_symtab belongs
> to this objfile" but I thought I'd ask.

I think it makes sense.  The "current source symtab and line" property
is per-pspace (passing the pspace as a parameter makes it more obvious
than it was).  A symtab that is current (per that "current source symtab
and line" thing) will be current for the pspace of its objfile.  It
wouldn't make sense to have any other pspace involved here.

I'm confortable making that change, I'll update my patch.

Thanks,

Simon
  

Patch

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index a973518ac5f0..46ac8d655c65 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -8825,8 +8825,6 @@  static void
 parse_breakpoint_sals (location_spec *locspec,
 		       struct linespec_result *canonical)
 {
-  struct symtab_and_line cursal;
-
   if (locspec->type () == LINESPEC_LOCATION_SPEC)
     {
       const char *spec
@@ -8875,7 +8873,8 @@  parse_breakpoint_sals (location_spec *locspec,
 
      ObjC: However, don't match an Objective-C method name which
      may have a '+' or '-' succeeded by a '['.  */
-  cursal = get_current_source_symtab_and_line ();
+  symtab_and_line cursal
+    = get_current_source_symtab_and_line (current_program_space);
   if (last_displayed_sal_is_valid ())
     {
       const char *spec = NULL;
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 9d3a90b057d2..92bb8fc21420 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -984,7 +984,7 @@  edit_command (const char *arg, int from_tty)
   if (arg == 0)
     {
       set_default_source_symtab_and_line ();
-      sal = get_current_source_symtab_and_line ();
+      sal = get_current_source_symtab_and_line (current_program_space);
     }
 
   /* Bare "edit" edits file with present line.  */
@@ -1240,7 +1240,8 @@  list_command (const char *arg, int from_tty)
       if (get_first_line_listed () == 0 && (arg == nullptr || arg[0] != '.'))
 	{
 	  set_default_source_symtab_and_line ();
-	  list_around_line (arg, get_current_source_symtab_and_line ());
+	  list_around_line
+	    (arg, get_current_source_symtab_and_line (current_program_space));
 	}
 
       /* "l" and "l +" lists the next few lines, unless we're listing past
@@ -1248,7 +1249,8 @@  list_command (const char *arg, int from_tty)
       else if (arg == nullptr || arg[0] == '+')
 	{
 	  set_default_source_symtab_and_line ();
-	  const symtab_and_line cursal = get_current_source_symtab_and_line ();
+	  const symtab_and_line cursal
+	    = get_current_source_symtab_and_line (current_program_space);
 	  if (last_symtab_line (cursal.symtab) >= cursal.line)
 	    print_source_lines (cursal.symtab,
 				source_lines_range (cursal.line), 0);
@@ -1262,7 +1264,8 @@  list_command (const char *arg, int from_tty)
       else if (arg[0] == '-')
 	{
 	  set_default_source_symtab_and_line ();
-	  const symtab_and_line cursal = get_current_source_symtab_and_line ();
+	  const symtab_and_line cursal
+	    = get_current_source_symtab_and_line (current_program_space);
 
 	  if (get_first_line_listed () == 1)
 	    error (_("Already at the start of %s."),
@@ -1305,7 +1308,8 @@  list_command (const char *arg, int from_tty)
 		  error (_("Insufficient debug info for showing source "
 			   "lines at default location"));
 		}
-	      cursal = get_current_source_symtab_and_line ();
+	      cursal
+		= get_current_source_symtab_and_line (current_program_space);
 
 	      gdb_assert (cursal.symtab != nullptr);
 	    }
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 88531a217814..8896b44a8c41 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -17,6 +17,7 @@ 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+#include "progspace.h"
 #include "ui.h"
 #include "ui-out.h"
 #include "command.h"
@@ -487,7 +488,8 @@  get_expr_block_and_pc (CORE_ADDR *pc)
 
   if (block == NULL)
     {
-      struct symtab_and_line cursal = get_current_source_symtab_and_line ();
+      symtab_and_line cursal
+	= get_current_source_symtab_and_line (current_program_space);
 
       if (cursal.symtab)
 	block = cursal.symtab->compunit ()->blockvector ()->static_block ();
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index e34ce80dbf0c..d7a4674bda20 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -1078,7 +1078,8 @@  jump_command (const char *arg, int from_tty)
     {
       /* If multiple sal-objects were found, try dropping those that aren't
 	 from the current symtab.  */
-      struct symtab_and_line cursal = get_current_source_symtab_and_line ();
+      symtab_and_line cursal
+	= get_current_source_symtab_and_line (current_program_space);
       sals.erase (std::remove_if (sals.begin (), sals.end (),
 		  [&] (const symtab_and_line &sal)
 		    {
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 7a6b21e1b741..abefe3440aff 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -3205,7 +3205,8 @@  decode_line_with_current_source (const char *string, int flags)
 
   /* We use whatever is set as the current source line.  We do not try
      and get a default source symtab+line or it will recursively call us!  */
-  symtab_and_line cursal = get_current_source_symtab_and_line ();
+  symtab_and_line cursal
+    = get_current_source_symtab_and_line (current_program_space);
 
   location_spec_up locspec = string_to_location_spec (&string,
 						      current_language);
@@ -3255,9 +3256,9 @@  initialize_defaults (struct symtab **default_symtab, int *default_line)
       /* Use whatever we have for the default source line.  We don't use
 	 get_current_or_default_symtab_and_line as it can recurse and call
 	 us back!  */
-      struct symtab_and_line cursal = 
-	get_current_source_symtab_and_line ();
-      
+      symtab_and_line cursal
+	= get_current_source_symtab_and_line (current_program_space);
+
       *default_symtab = cursal.symtab;
       *default_line = cursal.line;
     }
diff --git a/gdb/macroscope.c b/gdb/macroscope.c
index 4c1304f119ad..c1b2238b173f 100644
--- a/gdb/macroscope.c
+++ b/gdb/macroscope.c
@@ -121,9 +121,9 @@  default_macro_scope (void)
 	 symbol files loaded, then get_current_or_default would raise an
 	 error.  But `set width' shouldn't raise an error just because
 	 it can't decide which scope to macro-expand its argument in.  */
-      struct symtab_and_line cursal
-	= get_current_source_symtab_and_line ();
-      
+      symtab_and_line cursal
+	= get_current_source_symtab_and_line (current_program_space);
+
       sal.symtab = cursal.symtab;
       sal.line = cursal.line;
     }
diff --git a/gdb/mi/mi-cmd-file.c b/gdb/mi/mi-cmd-file.c
index 3e2702e04ed1..f2fe4351f873 100644
--- a/gdb/mi/mi-cmd-file.c
+++ b/gdb/mi/mi-cmd-file.c
@@ -35,7 +35,6 @@  void
 mi_cmd_file_list_exec_source_file (const char *command,
 				   const char *const *argv, int argc)
 {
-  struct symtab_and_line st;
   struct ui_out *uiout = current_uiout;
   
   if (!mi_valid_noargs ("-file-list-exec-source-file", argc, argv))
@@ -43,7 +42,8 @@  mi_cmd_file_list_exec_source_file (const char *command,
 
   /* Set the default file and line, also get them.  */
   set_default_source_symtab_and_line ();
-  st = get_current_source_symtab_and_line ();
+  symtab_and_line st
+    = get_current_source_symtab_and_line (current_program_space);
 
   /* We should always get a symtab.  Apparently, filename does not
      need to be tested for NULL.  The documentation in symtab.h
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 77d759b3aa59..600d205d0645 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -561,7 +561,8 @@  objfile::~objfile ()
      and if so, call clear_current_source_symtab_and_line.  */
 
   {
-    struct symtab_and_line cursal = get_current_source_symtab_and_line ();
+    symtab_and_line cursal
+      = get_current_source_symtab_and_line (current_program_space);
 
     if (cursal.symtab && cursal.symtab->compunit ()->objfile () == this)
       clear_current_source_symtab_and_line (current_program_space);
diff --git a/gdb/parse.c b/gdb/parse.c
index c10b09af485e..2541a2eb143f 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -375,8 +375,8 @@  parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
 
       if (!expression_context_block)
 	{
-	  struct symtab_and_line cursal
-	    = get_current_source_symtab_and_line ();
+	  symtab_and_line cursal
+	    = get_current_source_symtab_and_line (current_program_space);
 
 	  if (cursal.symtab)
 	    expression_context_block
diff --git a/gdb/python/python.c b/gdb/python/python.c
index e9092b4d9943..d86a031ee95d 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -963,7 +963,7 @@  gdbpy_decode_line (PyObject *self, PyObject *args)
       else
 	{
 	  set_default_source_symtab_and_line ();
-	  def_sal = get_current_source_symtab_and_line ();
+	  def_sal = get_current_source_symtab_and_line (current_program_space);
 	  sals = def_sal;
 	}
     }
diff --git a/gdb/source.c b/gdb/source.c
index 854ba0f90f31..dbdec90881bd 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -231,16 +231,15 @@  get_source_location (program_space *pspace)
   return loc;
 }
 
-/* Return the current source file for listing and next line to list.
-   NOTE: The returned sal pc and end fields are not valid.  */
+/* See source.h.  */
    
-struct symtab_and_line
-get_current_source_symtab_and_line (void)
+symtab_and_line
+get_current_source_symtab_and_line (program_space *pspace)
 {
   symtab_and_line cursal;
-  current_source_location *loc = get_source_location (current_program_space);
+  current_source_location *loc = get_source_location (pspace);
 
-  cursal.pspace = current_program_space;
+  cursal.pspace = pspace;
   cursal.symtab = loc->symtab ();
   cursal.line = loc->line ();
   cursal.pc = 0;
diff --git a/gdb/source.h b/gdb/source.h
index 4eb179378993..541ee3b7a124 100644
--- a/gdb/source.h
+++ b/gdb/source.h
@@ -23,6 +23,7 @@ 
 
 struct program_space;
 struct symtab;
+struct symtab_and_line;
 
 /* See openp function definition for their description.  */
 
@@ -108,7 +109,8 @@  extern int get_lines_to_list (void);
 
 /* Return the current source file for listing and next line to list.
    NOTE: The returned sal pc and end fields are not valid.  */
-extern struct symtab_and_line get_current_source_symtab_and_line (void);
+extern symtab_and_line get_current_source_symtab_and_line
+  (program_space *pspace);
 
 /* If the current source file for listing is not set, try and get a default.
    Usually called before get_current_source_symtab_and_line() is called.
diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index 2f25fedbcab3..53be866187e2 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -393,7 +393,8 @@  tui_get_begin_asm_address (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
 	  || have_partial_symbols (current_program_space))
 	{
 	  set_default_source_symtab_and_line ();
-	  struct symtab_and_line sal = get_current_source_symtab_and_line ();
+	  symtab_and_line sal
+	    = get_current_source_symtab_and_line (current_program_space);
 
 	  if (sal.symtab != nullptr)
 	    find_line_pc (sal.symtab, sal.line, &addr);
diff --git a/gdb/tui/tui-hooks.c b/gdb/tui/tui-hooks.c
index e6673ab650d8..25358d08352b 100644
--- a/gdb/tui/tui-hooks.c
+++ b/gdb/tui/tui-hooks.c
@@ -127,7 +127,8 @@  tui_refresh_frame_and_register_information ()
       /* Make sure that the source window is displayed.  */
       tui_add_win_to_layout (SRC_WIN);
 
-      struct symtab_and_line sal = get_current_source_symtab_and_line ();
+      symtab_and_line sal
+	= get_current_source_symtab_and_line (current_program_space);
       tui_update_source_windows_with_line (sal);
     }
 }
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index 444c0f7a90e6..ee64e4172b51 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -136,7 +136,8 @@  tui_source_window::do_scroll_vertical (int num_to_scroll)
   if (!m_content.empty ())
     {
       struct symtab *s;
-      struct symtab_and_line cursal = get_current_source_symtab_and_line ();
+      symtab_and_line cursal
+	= get_current_source_symtab_and_line (current_program_space);
       struct gdbarch *arch = m_gdbarch;
 
       if (cursal.symtab == NULL)
@@ -220,7 +221,7 @@  void
 tui_source_window::display_start_addr (struct gdbarch **gdbarch_p,
 				       CORE_ADDR *addr_p)
 {
-  struct symtab_and_line cursal = get_current_source_symtab_and_line ();
+  symtab_and_line cursal = get_current_source_symtab_and_line (current_program_space);
 
   *gdbarch_p = m_gdbarch;
   find_line_pc (cursal.symtab, m_start_line_or_addr.u.line_no, addr_p);
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 80297e59dd60..b08fca7a7e3e 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -440,8 +440,8 @@  tui_source_window_base::rerender ()
 
   if (!m_content.empty ())
     {
-      struct symtab_and_line cursal
-	= get_current_source_symtab_and_line ();
+      symtab_and_line cursal
+	= get_current_source_symtab_and_line (current_program_space);
 
       if (m_start_line_or_addr.loa == LOA_LINE)
 	cursal.line = m_start_line_or_addr.u.line_no;
@@ -451,8 +451,8 @@  tui_source_window_base::rerender ()
     }
   else if (deprecated_safe_get_selected_frame () != NULL)
     {
-      struct symtab_and_line cursal
-	= get_current_source_symtab_and_line ();
+      symtab_and_line cursal
+	= get_current_source_symtab_and_line (current_program_space);
       frame_info_ptr frame = deprecated_safe_get_selected_frame ();
       struct gdbarch *gdbarch = get_frame_arch (frame);
 
@@ -492,7 +492,7 @@  tui_source_window_base::refill ()
 
   if (this == tui_src_win ())
     {
-      sal = get_current_source_symtab_and_line ();
+      sal = get_current_source_symtab_and_line (current_program_space);
       if (sal.symtab == NULL)
 	{
 	  frame_info_ptr fi = deprecated_safe_get_selected_frame ();