This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[3/5] RFC look up "main" symbol, not its file name


This addresses this "dwz -m" regression introduced by patch #1:

FAIL: gdb.cp/anon-struct.exp: print type of X::t2::t2

This happens because of the funny way we run "dwz -m", and the
interaction between this and the symbol tables.

In this situation, "main" appears in both the PU and the importing CU.
However, the PU does not have a file name.  So, find_main_filename
returns the empty string, making deduce_language_from_filename return
language_unknown.


This patch fixes this problem by changing gdb to use the ordinary
symbol-lookup functions to find "main"'s symbol.  Then, it examines the
symbol's language.

I thought this was cleaner than the current approach.  For one thing it
avoids trying to guess the language based on the source file name,
instead deferring to the presumably more reliable debuginfo.


Another possible fix would have been to change how the file name is
found via the "qf" methods.  However, I think the approach given is
preferable for the reason outlined above.


Built and regtested (both ways) on x86-64 Fedora 16.

Tom

	* symfile.c (set_initial_language): Look up "main" symbol
	and use its language.
	* symtab.c (find_main_filename): Remove.
	* symtab.h (find_main_filename): Remove.
---
 gdb/symfile.c |    8 ++++----
 gdb/symtab.c  |   23 -----------------------
 gdb/symtab.h  |    2 --
 3 files changed, 4 insertions(+), 29 deletions(-)

diff --git a/gdb/symfile.c b/gdb/symfile.c
index 6f968b7..94eb09b 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1711,11 +1711,11 @@ set_initial_language (void)
     lang = language_of_main;
   else
     {
-      const char *filename;
+      char *name = main_name ();
+      struct symbol *sym = lookup_symbol (name, NULL, VAR_DOMAIN, NULL);
 
-      filename = find_main_filename ();
-      if (filename != NULL)
-	lang = deduce_language_from_filename (filename);
+      if (sym != NULL)
+	lang = SYMBOL_LANGUAGE (sym);
     }
 
   if (lang == language_unknown)
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 57441c1..9ba99a5 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1942,29 +1942,6 @@ basic_lookup_transparent_type (const char *name)
   return (struct type *) 0;
 }
 
-/* Find the name of the file containing main().  */
-/* FIXME:  What about languages without main() or specially linked
-   executables that have no main() ?   */
-
-const char *
-find_main_filename (void)
-{
-  struct objfile *objfile;
-  char *name = main_name ();
-
-  ALL_OBJFILES (objfile)
-  {
-    const char *result;
-
-    if (!objfile->sf)
-      continue;
-    result = objfile->sf->qf->find_symbol_file (objfile, name);
-    if (result)
-      return result;
-  }
-  return (NULL);
-}
-
 /* Search BLOCK for symbol NAME in DOMAIN.
 
    Note that if NAME is the demangled form of a C++ symbol, we will fail
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 378e933..04c2c1f 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1195,8 +1195,6 @@ extern VEC (char_ptr) *make_source_files_completion_list (char *, char *);
 
 int matching_obj_sections (struct obj_section *, struct obj_section *);
 
-extern const char *find_main_filename (void);
-
 extern struct symtab *find_line_symtab (struct symtab *, int, int *, int *);
 
 extern struct symtab_and_line find_function_start_sal (struct symbol *sym,
-- 
1.7.7.6


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]