[v2,3/8] Don't call decode_line_with_current_source from select_source_symtab

Message ID 20190920192017.15293-4-tromey@adacore.com
State New
Headers show
Series
  • Handle copy relocations and add $_ada_exception
Related show

Commit Message

Tom Tromey Sept. 20, 2019, 7:20 p.m.
select_source_symtab currently calls decode_line_with_current_source.
However, this function iterates over all program spaces, and so it is
possible that it will return a "main" from some other program space.

This patch changes select_source_symtab to simply use the symbol it
already found in the current program space.

2019-08-21  Tom Tromey  <tromey@adacore.com>

	* source.c (select_source_symtab): Don't call
	decode_line_with_current_source.
---
 gdb/ChangeLog |  5 +++++
 gdb/source.c  | 11 ++++-------
 2 files changed, 9 insertions(+), 7 deletions(-)

-- 
2.20.1

Patch

diff --git a/gdb/source.c b/gdb/source.c
index 0171f2748b4..77eced31628 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -251,17 +251,14 @@  select_source_symtab (struct symtab *s)
 
   /* Make the default place to list be the function `main'
      if one exists.  */
-  if (lookup_symbol (main_name (), 0, VAR_DOMAIN, 0).symbol)
+  block_symbol bsym = lookup_symbol (main_name (), 0, VAR_DOMAIN, 0);
+  if (bsym.symbol != nullptr && SYMBOL_CLASS (bsym.symbol) == LOC_BLOCK)
     {
-      std::vector<symtab_and_line> sals
-	= decode_line_with_current_source (main_name (),
-					   DECODE_LINE_FUNFIRSTLINE);
-      const symtab_and_line &sal = sals[0];
+      symtab_and_line sal = find_function_start_sal (bsym.symbol, true);
       current_source_pspace = sal.pspace;
       current_source_symtab = sal.symtab;
       current_source_line = std::max (sal.line - (lines_to_list - 1), 1);
-      if (current_source_symtab)
-	return;
+      return;
     }
 
   /* Alright; find the last file in the symtab list (ignoring .h's