This is the mail archive of the gdb-patches@sources.redhat.com 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]

[PATCH]: Function to allow lookups according to language


I have committed the following change to the Ada sources, defining a 
function that we use there to allow us to re-use the C symbol-lookup 
code while the current language is Ada.  The restructuring of 
the symtab code some time ago made the symbol lookup routine context
dependent---specifically on current language.  The new function below
allows us to re-use C lookup code (e.g.) by temporarily setting the current
language in an unwind-protected fashion.  

In our own sources, we put this routine in symtab.c and use it also in
one place in the objc code (find_imps), which we found was sometimes
confused by Ada symbols.  That error is somewhat obscure, and requires
Ada in any case, so I am postponing addressing it in the public
sources until I get other Ada support turned on.

Paul Hilfinger




2004-06-08  Paul N. Hilfinger  <Hilfinger@gnat.com>

	* ada-lang.c (lookup_symbol_in_language): New function to allow
	re-use of another language's symbol lookup code.  (Placed here
	temporarily while Ada support is being integrated into the public
	tree).  
	(restore_language): New auxiliary function for 
	lookup_symbol_in_language.
	* ada-lang.h (lookup_symbol_in_language): Declare (Placed here
	temporarily while Ada support is being integrated into the public
	tree).
	
Index: gdb/ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.36
diff -u -p -r1.36 ada-lang.c
--- gdb/ada-lang.c	2 Jun 2004 09:55:36 -0000	1.36
+++ gdb/ada-lang.c	8 Jun 2004 08:33:08 -0000
@@ -4444,6 +4444,30 @@ add_symbols_from_enclosing_procs (struct
 #endif
 }
 
+/* FIXME: The next two routines belong in symtab.c */
+
+static void restore_language (void* lang)
+{
+  set_language ((enum language) lang);
+}
+
+/* As for lookup_symbol, but performed as if the current language 
+   were LANG. */
+
+struct symbol *
+lookup_symbol_in_language (const char *name, const struct block *block,
+			   domain_enum domain, enum language lang,
+			   int *is_a_field_of_this, struct symtab **symtab)
+{
+  struct cleanup *old_chain 
+    = make_cleanup (restore_language, (void*) current_language->la_language);
+  struct symbol *result;
+  set_language (lang);
+  result = lookup_symbol (name, block, domain, is_a_field_of_this, symtab);
+  do_cleanups (old_chain);
+  return result;
+}
+
 /* True if TYPE is definitely an artificial type supplied to a symbol
    for which no debugging information was given in the symbol file.  */
 
Index: gdb/ada-lang.h
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.h,v
retrieving revision 1.7
diff -u -p -r1.7 ada-lang.h
--- gdb/ada-lang.h	2 Jun 2004 09:55:36 -0000	1.7
+++ gdb/ada-lang.h	8 Jun 2004 08:33:08 -0000
@@ -393,4 +393,15 @@ extern void ada_find_printable_frame (st
 
 extern void ada_reset_thread_registers (void);
 
+/* Look up a symbol by name using the search conventions of 
+   a specific language (optional block, optional symtab). 
+   FIXME: Should be symtab.h. */
+
+extern struct symbol *lookup_symbol_in_language (const char *, 
+						 const struct block *,
+						 domain_enum, 
+						 enum language,
+						 int *,
+						 struct symtab **);
+
 #endif


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