Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [rfa] language hooks for lookup_symbol
@ 2003-05-18 22:47 David Carlton
  2003-05-19 15:14 ` Elena Zannoni
  0 siblings, 1 reply; 5+ messages in thread
From: David Carlton @ 2003-05-18 22:47 UTC (permalink / raw)
  To: gdb-patches; +Cc: Elena Zannoni

Here's a patch to add language hooks to lookup_symbol.  I settled on
two hooks: one of them is a boolean saying whether or not to do the
field of this check, and the other is a function that replaces the
static/global lookup part of lookup_symbol_aux.  The reason why I
broke these up into two separate parts is that the field of this part
doesn't return a symbol, so it's a little hard to do it gracefully and
without duplicating code.  It also provides some functions that other
languages can use to build nonlocal hook functions if necessary.

The only potential behavior change (I hope) is that I turned off the
field of this check for the C, asm, and minimal languages.  Doubtless
it should be turned off for other languages, too, but I didn't want to
tamper with them.  This patch tells all languages to use a function
basic_lookup_symbol_nonlocal that implements the standard C behavior
that lookup_symbol_aux had been doing.  (I'll submit the C++ namespace
stuff in my next patch.)

It also deletes the strange #if 0 hunk from lookup_symbol_aux; if you
want, I can commit that change as a separate patch.

This is my first time playing around with struct language_defn, so
please let me know if I did anything wrong.  I like this idea; I
really should spend time thinking about where else we should use it.
For example, should lookup_symbol call language_demangle instead of
cplus_demangle?  Hmm.

Tested on GCC 3.2, DWARF 2, i686-pc-linux-gnu; OK to commit?

David Carlton
carlton@bactrian.org

2003-05-18  David Carlton  <carlton@bactrian.org>

	* language.h (struct language_defn): Add 'la_lookup_symbol_this'
	and 'la_lookup_symbol_nonlocal' members.
	* symtab.h: Declare basic_lookup_symbol_nonlocal,
	lookup_symbol_static, lookup_symbol_global,
	lookup_symbol_aux_block.
	* symtab.c (lookup_symbol_aux): Call language hooks to determine
	if we should search fields of this and how to do static/global
	lookup.  Remove 'static_block' argument to
	lookup_symbol_aux_local.
	(lookup_symbol_aux_local): Delete 'static_block' argument.
	(lookup_symbol_aux_block): Make extern.
	(basic_lookup_symbol_nonlocal): New.
	(lookup_symbol_static, lookup_symbol_global): Ditto.
	* block.h: Declare block_static_block.
	* block.c (block_static_block): New.
	* ada-lang.c (ada_language_defn): Set 'la_lookup_symbol_this' and
	'la_lookup_symbol_nonlocal' members.
	* c-lang.c (c_language_defn, cplus_language_defn)
	(asm_language_defn, minimal_language_defn): Ditto.
	* f-lang.c (f_language_defn): Ditto.
	* jv-lang.c (java_language_defn): Ditto.
	* language.c (unknown_language_defn, auto_language_defn)
	(local_language_defn): Ditto.
	* m2-lang.c (m2_language_defn): Ditto.
	* objc-lang.c (objc_language_defn): Ditto.
	* p-lang.c (pascal_language_defn): Ditto.
	* scm-lang.c (scm_language_defn): Ditto.

Index: language.h
===================================================================
RCS file: /cvs/src/src/gdb/language.h,v
retrieving revision 1.19
diff -u -p -r1.19 language.h
--- language.h	12 Apr 2003 17:41:25 -0000	1.19
+++ language.h	18 May 2003 16:05:37 -0000
@@ -211,6 +211,23 @@ struct language_defn
        if it isn't a language tramp for this language.  */
     CORE_ADDR (*skip_trampoline) (CORE_ADDR pc);
 
+    /* Now come some hooks for lookup_symbol.  */
+
+    /* If this is non-zero, lookup_symbol will do the 'field_of_this'
+       check.  */
+
+    int la_lookup_symbol_this;
+
+    /* This is a function that lookup_symbol will call when it gets to
+       the part of symbol lookup where C looks up static and global
+       variables.  */
+
+    struct symbol *(*la_lookup_symbol_nonlocal) (const char *,
+						 const char *,
+						 const struct block *,
+						 const domain_enum,
+						 struct symtab **);
+
     /* Return demangled language symbol, or NULL.  */
     char *(*la_demangle) (const char *mangled, int options);
 
Index: symtab.h
===================================================================
RCS file: /cvs/src/src/gdb/symtab.h,v
retrieving revision 1.71
diff -u -p -r1.71 symtab.h
--- symtab.h	15 May 2003 22:23:24 -0000	1.71
+++ symtab.h	18 May 2003 16:05:46 -0000
@@ -988,6 +988,45 @@ extern struct symbol *lookup_symbol (con
 				     const domain_enum, int *,
 				     struct symtab **);
 
+/* A default version of lookup_symbol_nonlocal for use by languages
+   that can't think of anything better to do.  */
+
+extern struct symbol *basic_lookup_symbol_nonlocal (const char *,
+						    const char *,
+						    const struct block *,
+						    const domain_enum,
+						    struct symtab **);
+
+/* Some helper functions for languages that need to write their own
+   lookup_symbol_nonlocal functions.  */
+
+/* Lookup a symbol in the static block associated to BLOCK, if there
+   is one; do nothing if BLOCK is NULL or a global block.  */
+
+extern struct symbol *lookup_symbol_static (const char *name,
+					    const char *linkage_name,
+					    const struct block *block,
+					    const domain_enum domain,
+					    struct symtab **symtab);
+
+/* Lookup a symbol in all files' global blocks (searching psymtabs if
+   necessary).  */
+
+extern struct symbol *lookup_symbol_global (const char *name,
+					    const char *linkage_name,
+					    const domain_enum domain,
+					    struct symtab **symtab);
+
+/* Lookup a symbol within the block BLOCK.  This, unlike
+   lookup_symbol_block, will set SYMTAB and BLOCK_FOUND correctly, and
+   will fix up the symbol if necessary.  */
+
+extern struct symbol *lookup_symbol_aux_block (const char *name,
+					       const char *linkage_name,
+					       const struct block *block,
+					       const domain_enum domain,
+					       struct symtab **symtab);
+
 /* lookup a symbol by name, within a specified block */
 
 extern struct symbol *lookup_block_symbol (const struct block *, const char *,
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.105
diff -u -p -r1.105 symtab.c
--- symtab.c	18 May 2003 15:29:31 -0000	1.105
+++ symtab.c	18 May 2003 16:05:44 -0000
@@ -93,14 +93,6 @@ struct symbol *lookup_symbol_aux_local (
 					const char *linkage_name,
 					const struct block *block,
 					const domain_enum domain,
-					struct symtab **symtab,
-					const struct block **static_block);
-
-static
-struct symbol *lookup_symbol_aux_block (const char *name,
-					const char *linkage_name,
-					const struct block *block,
-					const domain_enum domain,
 					struct symtab **symtab);
 
 static
@@ -958,65 +950,19 @@ lookup_symbol_aux (const char *name, con
 		   int *is_a_field_of_this, struct symtab **symtab)
 {
   struct symbol *sym;
-  const struct block *static_block;
 
   /* Search specified block and its superiors.  Don't search
      STATIC_BLOCK or GLOBAL_BLOCK.  */
 
   sym = lookup_symbol_aux_local (name, linkage_name, block, domain,
-				 symtab, &static_block);
+				 symtab);
   if (sym != NULL)
     return sym;
 
-#if 0
-  /* NOTE: carlton/2002-11-05: At the time that this code was
-     #ifdeffed out, the value of 'block' was always NULL at this
-     point, hence the bemused comments below.  */
-
-  /* FIXME: this code is never executed--block is always NULL at this
-     point.  What is it trying to do, anyway?  We already should have
-     checked the STATIC_BLOCK above (it is the superblock of top-level
-     blocks).  Why is VAR_DOMAIN special-cased?  */
-  /* Don't need to mess with the psymtabs; if we have a block,
-     that file is read in.  If we don't, then we deal later with
-     all the psymtab stuff that needs checking.  */
-  /* Note (RT): The following never-executed code looks unnecessary to me also.
-   * If we change the code to use the original (passed-in)
-   * value of 'block', we could cause it to execute, but then what
-   * would it do? The STATIC_BLOCK of the symtab containing the passed-in
-   * 'block' was already searched by the above code. And the STATIC_BLOCK's
-   * of *other* symtabs (those files not containing 'block' lexically)
-   * should not contain 'block' address-wise. So we wouldn't expect this
-   * code to find any 'sym''s that were not found above. I vote for 
-   * deleting the following paragraph of code.
-   */
-  if (domain == VAR_DOMAIN && block != NULL)
-    {
-      struct block *b;
-      /* Find the right symtab.  */
-      ALL_SYMTABS (objfile, s)
-      {
-	bv = BLOCKVECTOR (s);
-	b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
-	if (BLOCK_START (b) <= BLOCK_START (block)
-	    && BLOCK_END (b) > BLOCK_START (block))
-	  {
-	    sym = lookup_block_symbol (b, name, linkage_name, VAR_DOMAIN);
-	    if (sym)
-	      {
-		block_found = b;
-		if (symtab != NULL)
-		  *symtab = s;
-		return fixup_symbol_section (sym, objfile);
-	      }
-	  }
-      }
-    }
-#endif /* 0 */
+  /* If requested to do so by the caller and if appropriate for the
+     current language, check to see if NAME is a field of `this'. */
 
-  /* C++/Java/Objective-C: If requested to do so by the caller, 
-     check to see if NAME is a field of `this'. */
-  if (is_a_field_of_this)
+  if (current_language->la_lookup_symbol_this && is_a_field_of_this)
     {
       struct value *v = value_of_this (0);
 
@@ -1030,50 +976,12 @@ lookup_symbol_aux (const char *name, con
 	}
     }
 
-  /* If there's a static block to search, search it next.  */
-
-  /* NOTE: carlton/2002-12-05: There is a question as to whether or
-     not it would be appropriate to search the current global block
-     here as well.  (That's what this code used to do before the
-     is_a_field_of_this check was moved up.)  On the one hand, it's
-     redundant with the lookup_symbol_aux_symtabs search that happens
-     next.  On the other hand, if decode_line_1 is passed an argument
-     like filename:var, then the user presumably wants 'var' to be
-     searched for in filename.  On the third hand, there shouldn't be
-     multiple global variables all of which are named 'var', and it's
-     not like decode_line_1 has ever restricted its search to only
-     global variables in a single filename.  All in all, only
-     searching the static block here seems best: it's correct and it's
-     cleanest.  */
-
-  /* NOTE: carlton/2002-12-05: There's also a possible performance
-     issue here: if you usually search for global symbols in the
-     current file, then it would be slightly better to search the
-     current global block before searching all the symtabs.  But there
-     are other factors that have a much greater effect on performance
-     than that one, so I don't think we should worry about that for
-     now.  */
-
-  if (static_block != NULL)
-    {
-      sym = lookup_symbol_aux_block (name, linkage_name, static_block,
-				     domain, symtab);
-      if (sym != NULL)
-	return sym;
-    }
-
-  /* Now search all global blocks.  Do the symtab's first, then
-     check the psymtab's. If a psymtab indicates the existence
-     of the desired name as a global, then do psymtab-to-symtab
-     conversion on the fly and return the found symbol. */
+  /* Now do whatever is appropriate for the current language to look
+     up static and global variables.  */
 
-  sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, linkage_name,
-				   domain, symtab);
-  if (sym != NULL)
-    return sym;
-
-  sym = lookup_symbol_aux_psymtabs (GLOBAL_BLOCK, name, linkage_name,
-				    domain, symtab);
+  sym = current_language->la_lookup_symbol_nonlocal (name, linkage_name,
+						     block, domain,
+						     symtab);
   if (sym != NULL)
     return sym;
 
@@ -1099,27 +1007,23 @@ lookup_symbol_aux (const char *name, con
 }
 
 /* Check to see if the symbol is defined in BLOCK or its superiors.
-   Don't search STATIC_BLOCK or GLOBAL_BLOCK.  If we don't find a
-   match, store the address of STATIC_BLOCK in static_block.  */
+   Don't search STATIC_BLOCK or GLOBAL_BLOCK.  */
 
 static struct symbol *
 lookup_symbol_aux_local (const char *name, const char *linkage_name,
 			 const struct block *block,
 			 const domain_enum domain,
-			 struct symtab **symtab,
-			 const struct block **static_block)
+			 struct symtab **symtab)
 {
   struct symbol *sym;
-  
+  const struct block *static_block = block_static_block (block);
+
   /* Check if either no block is specified or it's a global block.  */
 
-  if (block == NULL || BLOCK_SUPERBLOCK (block) == NULL)
-    {
-      *static_block = NULL;
-      return NULL;
-    }
+  if (static_block == NULL)
+    return NULL;
 
-  while (BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) != NULL)
+  while (block != static_block)
     {
       sym = lookup_symbol_aux_block (name, linkage_name, block, domain,
 				     symtab);
@@ -1128,16 +1032,15 @@ lookup_symbol_aux_local (const char *nam
       block = BLOCK_SUPERBLOCK (block);
     }
 
-  /* We've reached the static block.  */
+  /* We've reached the static block without finding a result.  */
 
-  *static_block = block;
   return NULL;
 }
 
 /* Look up a symbol in a block; if found, locate its symtab, fixup the
    symbol, and set block_found appropriately.  */
 
-static struct symbol *
+struct symbol *
 lookup_symbol_aux_block (const char *name, const char *linkage_name,
 			 const struct block *block,
 			 const domain_enum domain,
@@ -1394,6 +1297,64 @@ lookup_symbol_aux_minsyms (const char *n
   return NULL;
 }
 #endif /* 0 */
+
+/* A default version of lookup_symbol_nonlocal for use by languages
+   that can't think of anything better to do.  This implements the C
+   lookup rules.  */
+
+struct symbol *
+basic_lookup_symbol_nonlocal (const char *name,
+			      const char *linkage_name,
+			      const struct block *block,
+			      const domain_enum domain,
+			      struct symtab **symtab)
+{
+  struct symbol *sym;
+
+  sym = lookup_symbol_static (name, linkage_name, block, domain, symtab);
+  if (sym != NULL)
+    return sym;
+
+  return lookup_symbol_global (name, linkage_name, domain, symtab);
+}
+
+/* Lookup a symbol in the static block associated to BLOCK, if there
+   is one; do nothing if BLOCK is NULL or a global block.  */
+
+struct symbol *
+lookup_symbol_static (const char *name,
+		      const char *linkage_name,
+		      const struct block *block,
+		      const domain_enum domain,
+		      struct symtab **symtab)
+{
+  const struct block *static_block = block_static_block (block);
+
+  if (static_block != NULL)
+    return lookup_symbol_aux_block (name, linkage_name, static_block,
+				    domain, symtab);
+  else
+    return NULL;
+}
+
+/* Lookup a symbol in all files' global blocks (searching psymtabs if
+   necessary).  */
+
+struct symbol *lookup_symbol_global (const char *name,
+				     const char *linkage_name,
+				     const domain_enum domain,
+				     struct symtab **symtab)
+{
+  struct symbol *sym;
+
+  sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, linkage_name,
+				   domain, symtab);
+  if (sym != NULL)
+    return sym;
+
+  return lookup_symbol_aux_psymtabs (GLOBAL_BLOCK, name, linkage_name,
+				     domain, symtab);
+}
 
 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
    If LINKAGE_NAME is non-NULL, check in addition that the symbol's
Index: block.h
===================================================================
RCS file: /cvs/src/src/gdb/block.h,v
retrieving revision 1.3
diff -u -p -r1.3 block.h
--- block.h	15 Apr 2003 23:07:11 -0000	1.3
+++ block.h	18 May 2003 16:05:33 -0000
@@ -207,4 +207,6 @@ extern void block_set_using (struct bloc
 			     struct using_direct *using,
 			     struct obstack *obstack);
 
+extern const struct block *block_static_block (const struct block *block);
+
 #endif /* BLOCK_H */
Index: block.c
===================================================================
RCS file: /cvs/src/src/gdb/block.c,v
retrieving revision 1.3
diff -u -p -r1.3 block.c
--- block.c	15 Apr 2003 23:07:11 -0000	1.3
+++ block.c	18 May 2003 16:05:33 -0000
@@ -199,3 +199,18 @@ block_initialize_namespace (struct block
       BLOCK_NAMESPACE (block)->using = NULL;
     }
 }
+
+/* Return the static block associated to BLOCK.  Return NULL if block
+   is NULL or if block is a global block.  */
+
+const struct block *
+block_static_block (const struct block *block)
+{
+  if (block == NULL || BLOCK_SUPERBLOCK (block) == NULL)
+    return NULL;
+
+  while (BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) != NULL)
+    block = BLOCK_SUPERBLOCK (block);
+
+  return block;
+}
Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.25
diff -u -p -r1.25 ada-lang.c
--- ada-lang.c	14 May 2003 17:43:15 -0000	1.25
+++ ada-lang.c	18 May 2003 16:05:33 -0000
@@ -8082,6 +8082,8 @@ const struct language_defn ada_language_
   ada_val_print,		/* Print a value using appropriate syntax */
   ada_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  1,				/* lookup_symbol_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal  */
   NULL,				/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
 #if 0
Index: c-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/c-lang.c,v
retrieving revision 1.20
diff -u -p -r1.20 c-lang.c
--- c-lang.c	15 May 2003 22:18:42 -0000	1.20
+++ c-lang.c	18 May 2003 16:05:33 -0000
@@ -553,6 +553,8 @@ const struct language_defn c_language_de
   c_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  0,				/* lookup_symbol_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
@@ -607,6 +609,8 @@ const struct language_defn cplus_languag
   c_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  1,				/* lookup_symbol_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   cplus_demangle,		/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
@@ -638,6 +642,8 @@ const struct language_defn asm_language_
   c_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  0,				/* lookup_symbol_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
@@ -674,6 +680,8 @@ const struct language_defn minimal_langu
   c_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  0,				/* lookup_symbol_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
Index: f-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/f-lang.c,v
retrieving revision 1.14
diff -u -p -r1.14 f-lang.c
--- f-lang.c	15 May 2003 22:18:42 -0000	1.14
+++ f-lang.c	18 May 2003 16:05:33 -0000
@@ -472,6 +472,8 @@ const struct language_defn f_language_de
   f_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* FIXME */
   NULL,				/* Language specific skip_trampoline */
+  1,				/* lookup_symbol_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%o", "0", "o", ""},	/* Octal format info */
Index: jv-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/jv-lang.c,v
retrieving revision 1.19
diff -u -p -r1.19 jv-lang.c
--- jv-lang.c	14 May 2003 17:43:18 -0000	1.19
+++ jv-lang.c	18 May 2003 16:05:34 -0000
@@ -1063,6 +1063,8 @@ const struct language_defn java_language
   java_val_print,		/* Print a value using appropriate syntax */
   java_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  1,				/* lookup_symbol_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   java_demangle,		/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
Index: language.c
===================================================================
RCS file: /cvs/src/src/gdb/language.c,v
retrieving revision 1.34
diff -u -p -r1.34 language.c
--- language.c	14 May 2003 17:43:18 -0000	1.34
+++ language.c	18 May 2003 16:05:36 -0000
@@ -1479,6 +1479,8 @@ const struct language_defn unknown_langu
   unk_lang_val_print,		/* Print a value using appropriate syntax */
   unk_lang_value_print,		/* Print a top-level value */
   unk_lang_trampoline,		/* Language specific skip_trampoline */
+  1,				/* lookup_symbol_this */
+  basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
   unk_lang_demangle,		/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
@@ -1511,6 +1513,8 @@ const struct language_defn auto_language
   unk_lang_val_print,		/* Print a value using appropriate syntax */
   unk_lang_value_print,		/* Print a top-level value */
   unk_lang_trampoline,		/* Language specific skip_trampoline */
+  1,				/* lookup_symbol_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   unk_lang_demangle,		/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
@@ -1542,6 +1546,8 @@ const struct language_defn local_languag
   unk_lang_val_print,		/* Print a value using appropriate syntax */
   unk_lang_value_print,		/* Print a top-level value */
   unk_lang_trampoline,		/* Language specific skip_trampoline */
+  1,				/* lookup_symbol_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   unk_lang_demangle,		/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
Index: m2-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/m2-lang.c,v
retrieving revision 1.10
diff -u -p -r1.10 m2-lang.c
--- m2-lang.c	15 May 2003 22:18:42 -0000	1.10
+++ m2-lang.c	18 May 2003 16:05:37 -0000
@@ -426,6 +426,8 @@ const struct language_defn m2_language_d
   m2_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  1,				/* lookup_symbol_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"%loB", "", "o", "B"},	/* Octal format info */
Index: objc-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/objc-lang.c,v
retrieving revision 1.22
diff -u -p -r1.22 objc-lang.c
--- objc-lang.c	15 May 2003 22:18:42 -0000	1.22
+++ objc-lang.c	18 May 2003 16:05:39 -0000
@@ -701,6 +701,8 @@ const struct language_defn objc_language
   c_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
   objc_skip_trampoline, 	/* Language specific skip_trampoline */
+  1,				/* lookup_symbol_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   objc_demangle,		/* Language specific symbol demangler */
   {"",     "",    "",  ""},	/* Binary format info */
   {"0%lo",  "0",   "o", ""},	/* Octal format info */
Index: p-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/p-lang.c,v
retrieving revision 1.12
diff -u -p -r1.12 p-lang.c
--- p-lang.c	15 May 2003 22:18:43 -0000	1.12
+++ p-lang.c	18 May 2003 16:05:40 -0000
@@ -461,6 +461,8 @@ const struct language_defn pascal_langua
   pascal_val_print,		/* Print a value using appropriate syntax */
   pascal_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  1,				/* lookup_symbol_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
   {"", "%", "b", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
Index: scm-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/scm-lang.c,v
retrieving revision 1.17
diff -u -p -r1.17 scm-lang.c
--- scm-lang.c	14 May 2003 17:43:18 -0000	1.17
+++ scm-lang.c	18 May 2003 16:05:40 -0000
@@ -252,6 +252,8 @@ const struct language_defn scm_language_
   scm_val_print,		/* Print a value using appropriate syntax */
   scm_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  1,				/* lookup_symbol_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"#o%lo", "#o", "o", ""},	/* Octal format info */


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

* Re: [rfa] language hooks for lookup_symbol
  2003-05-18 22:47 [rfa] language hooks for lookup_symbol David Carlton
@ 2003-05-19 15:14 ` Elena Zannoni
  2003-05-19 19:23   ` David Carlton
  2003-05-20  2:01   ` David Carlton
  0 siblings, 2 replies; 5+ messages in thread
From: Elena Zannoni @ 2003-05-19 15:14 UTC (permalink / raw)
  To: David Carlton; +Cc: gdb-patches, Elena Zannoni

David Carlton writes:
 > Here's a patch to add language hooks to lookup_symbol.  I settled on
 > two hooks: one of them is a boolean saying whether or not to do the
 > field of this check, and the other is a function that replaces the
 > static/global lookup part of lookup_symbol_aux.  The reason why I
 > broke these up into two separate parts is that the field of this part
 > doesn't return a symbol, so it's a little hard to do it gracefully and
 > without duplicating code.  It also provides some functions that other
 > languages can use to build nonlocal hook functions if necessary.
 > 
 > The only potential behavior change (I hope) is that I turned off the
 > field of this check for the C, asm, and minimal languages.  Doubtless
 > it should be turned off for other languages, too, but I didn't want to
 > tamper with them.  This patch tells all languages to use a function
 > basic_lookup_symbol_nonlocal that implements the standard C behavior
 > that lookup_symbol_aux had been doing.  (I'll submit the C++ namespace
 > stuff in my next patch.)
 > 
 > It also deletes the strange #if 0 hunk from lookup_symbol_aux; if you
 > want, I can commit that change as a separate patch.
 > 
 > This is my first time playing around with struct language_defn, so
 > please let me know if I did anything wrong.  I like this idea; I
 > really should spend time thinking about where else we should use it.
 > For example, should lookup_symbol call language_demangle instead of
 > cplus_demangle?  Hmm.


Yes. I like it.
A couple of comments.

1. check in the if0 elimination by itself, then the deletion of
   static_block parameter and teh addition of the block_static_bloc
   function. After that check in the rest (which is really the big change).

2. I think that instead of: int la_lookup_symbol_this; We can just
     have the new field be a function pointer to NULL or to the
     value_of_this function itself. This function itself can be split
     in 2, one for objc and one for c++.

3. move the comments as well, instead of deleting them.

demangle? probably so, it will be much cleaner if that gets moved too
(eventually).  Other thought, Adam added a few if language == objc
checks in other parts of generic code. Those are also candidate for
hooks, if you feel lucky! At the very least, they should not conflict
with your changes, and should be included in the 'grand plan'. At a
first look I don't think they will create any problems.


 > +/* Lookup a symbol in all files' global blocks (searching psymtabs if
 > +   necessary).  */
 > +
 > +struct symbol *lookup_symbol_global (const char *name,
 > +				     const char *linkage_name,
 > +				     const domain_enum domain,
 > +				     struct symtab **symtab)

watch out for grep ^func.....



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

* Re: [rfa] language hooks for lookup_symbol
  2003-05-19 15:14 ` Elena Zannoni
@ 2003-05-19 19:23   ` David Carlton
  2003-05-19 19:52     ` Elena Zannoni
  2003-05-20  2:01   ` David Carlton
  1 sibling, 1 reply; 5+ messages in thread
From: David Carlton @ 2003-05-19 19:23 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: gdb-patches

On Mon, 19 May 2003 11:19:50 -0400, Elena Zannoni <ezannoni@redhat.com> said:

> 1. check in the if0 elimination by itself, then the deletion of
>    static_block parameter and teh addition of the block_static_bloc
>    function. After that check in the rest (which is really the big change).

Will do.

> 2. I think that instead of: int la_lookup_symbol_this; We can just
>      have the new field be a function pointer to NULL or to the
>      value_of_this function itself. This function itself can be split
>      in 2, one for objc and one for c++.

That makes sense.  I'll also add a FIXME comment saying that we should
audit all existing languages to make sure that the field is set
properly.

> 3. move the comments as well, instead of deleting them.

I assume you're referring to these comments?

-  /* NOTE: carlton/2002-12-05: There is a question as to whether or
-     not it would be appropriate to search the current global block
-     here as well.  (That's what this code used to do before the
-     is_a_field_of_this check was moved up.)  On the one hand, it's
-     redundant with the lookup_symbol_aux_symtabs search that happens
-     next.  On the other hand, if decode_line_1 is passed an argument
-     like filename:var, then the user presumably wants 'var' to be
-     searched for in filename.  On the third hand, there shouldn't be
-     multiple global variables all of which are named 'var', and it's
-     not like decode_line_1 has ever restricted its search to only
-     global variables in a single filename.  All in all, only
-     searching the static block here seems best: it's correct and it's
-     cleanest.  */
-
-  /* NOTE: carlton/2002-12-05: There's also a possible performance
-     issue here: if you usually search for global symbols in the
-     current file, then it would be slightly better to search the
-     current global block before searching all the symtabs.  But there
-     are other factors that have a much greater effect on performance
-     than that one, so I don't think we should worry about that for
-     now.  */
-

The reason why I was planning to delete them is because they don't
make a lot of sense after this latest reorganization (since the "this
code" and the "is_a_field_of_this" mention wouldn't refer to the
function in question) and because I'm no longer bothered by the qualms
that led me to write the comments in the first place.  But if you want
me to keep them, I will (adding another note that they've been moved).

David Carlton
carlton@math.stanford.edu


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

* Re: [rfa] language hooks for lookup_symbol
  2003-05-19 19:23   ` David Carlton
@ 2003-05-19 19:52     ` Elena Zannoni
  0 siblings, 0 replies; 5+ messages in thread
From: Elena Zannoni @ 2003-05-19 19:52 UTC (permalink / raw)
  To: David Carlton; +Cc: Elena Zannoni, gdb-patches

David Carlton writes:
 > On Mon, 19 May 2003 11:19:50 -0400, Elena Zannoni <ezannoni@redhat.com> said:
 > 
 > > 1. check in the if0 elimination by itself, then the deletion of
 > >    static_block parameter and teh addition of the block_static_bloc
 > >    function. After that check in the rest (which is really the big change).
 > 
 > Will do.
 > 
 > > 2. I think that instead of: int la_lookup_symbol_this; We can just
 > >      have the new field be a function pointer to NULL or to the
 > >      value_of_this function itself. This function itself can be split
 > >      in 2, one for objc and one for c++.
 > 
 > That makes sense.  I'll also add a FIXME comment saying that we should
 > audit all existing languages to make sure that the field is set
 > properly.
 > 
 > > 3. move the comments as well, instead of deleting them.
 > 
 > I assume you're referring to these comments?
 > 
 > -  /* NOTE: carlton/2002-12-05: There is a question as to whether or
 > -     not it would be appropriate to search the current global block
 > -     here as well.  (That's what this code used to do before the
 > -     is_a_field_of_this check was moved up.)  On the one hand, it's
 > -     redundant with the lookup_symbol_aux_symtabs search that happens
 > -     next.  On the other hand, if decode_line_1 is passed an argument
 > -     like filename:var, then the user presumably wants 'var' to be
 > -     searched for in filename.  On the third hand, there shouldn't be
 > -     multiple global variables all of which are named 'var', and it's
 > -     not like decode_line_1 has ever restricted its search to only
 > -     global variables in a single filename.  All in all, only
 > -     searching the static block here seems best: it's correct and it's
 > -     cleanest.  */
 > -
 > -  /* NOTE: carlton/2002-12-05: There's also a possible performance
 > -     issue here: if you usually search for global symbols in the
 > -     current file, then it would be slightly better to search the
 > -     current global block before searching all the symtabs.  But there
 > -     are other factors that have a much greater effect on performance
 > -     than that one, so I don't think we should worry about that for
 > -     now.  */
 > -
 > 
 > The reason why I was planning to delete them is because they don't
 > make a lot of sense after this latest reorganization (since the "this
 > code" and the "is_a_field_of_this" mention wouldn't refer to the
 > function in question) and because I'm no longer bothered by the qualms
 > that led me to write the comments in the first place.  But if you want
 > me to keep them, I will (adding another note that they've been moved).

If it makes more sense, just rephrase them as you see appropriate.

elena


 > 
 > David Carlton
 > carlton@math.stanford.edu


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

* Re: [rfa] language hooks for lookup_symbol
  2003-05-19 15:14 ` Elena Zannoni
  2003-05-19 19:23   ` David Carlton
@ 2003-05-20  2:01   ` David Carlton
  1 sibling, 0 replies; 5+ messages in thread
From: David Carlton @ 2003-05-20  2:01 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: gdb-patches

On Mon, 19 May 2003 11:19:50 -0400, Elena Zannoni <ezannoni@redhat.com> said:

> Yes. I like it.

Great; it's in, in 3 parts, as you suggested.  I'm including the patch
for the third part below.

Thanks a bunch for working with me on this lookup_symbol rewrite.
It's amazing how much we've changed it over the last half-year.

David Carlton
carlton@math.stanford.edu

2003-05-19  David Carlton  <carlton@bactrian.org>

	* language.h (struct language_defn): Add 'la_value_of_this'
	and 'la_lookup_symbol_nonlocal' members.
	* symtab.h: Declare basic_lookup_symbol_nonlocal,
	lookup_symbol_static, lookup_symbol_global,
	lookup_symbol_aux_block.
	* symtab.c (lookup_symbol_aux): Call language hooks to determine
	if we should search fields of this and how to do static/global
	lookup.
	(lookup_symbol_aux_block): Make extern.
	(basic_lookup_symbol_nonlocal): New.
	(lookup_symbol_static, lookup_symbol_global): Ditto.
	* ada-lang.c (ada_language_defn): Set 'la_value_of_this' and
	'la_lookup_symbol_nonlocal' members.
	* c-lang.c (c_language_defn, cplus_language_defn)
	(asm_language_defn, minimal_language_defn): Ditto.
	* jv-lang.c (java_language_defn): Ditto.
	* language.c (unknown_language_defn, auto_language_defn)
	(local_language_defn): Ditto.
	* m2-lang.c (m2_language_defn): Ditto.
	* objc-lang.c (objc_language_defn): Ditto.
	* scm-lang.c (scm_language_defn): Ditto.
	* f-lang.c (f_language_defn): Ditto, and include value.h as well.
	* p-lang.c (pascal_language_defn): Ditto for both.
	* Makefile.in (f-lang.o): Depend on value_h.
	(p-lang.o): Ditto.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.378
diff -u -p -r1.378 Makefile.in
--- Makefile.in	18 May 2003 21:10:10 -0000	1.378
+++ Makefile.in	20 May 2003 01:51:56 -0000
@@ -1703,7 +1703,7 @@ expprint.o: expprint.c $(defs_h) $(symta
 	$(block_h)
 f-lang.o: f-lang.c $(defs_h) $(gdb_string_h) $(symtab_h) $(gdbtypes_h) \
 	$(expression_h) $(parser_defs_h) $(language_h) $(f_lang_h) \
-	$(valprint_h)
+	$(valprint_h) $(value_h)
 f-typeprint.o: f-typeprint.c $(defs_h) $(gdb_obstack_h) $(bfd_h) $(symtab_h) \
 	$(gdbtypes_h) $(expression_h) $(value_h) $(gdbcore_h) $(target_h) \
 	$(f_lang_h) $(gdb_string_h)
@@ -2022,7 +2022,7 @@ osabi.o: osabi.c $(defs_h) $(gdb_string_
 	$(gdbcmd_h) $(command_h) $(arch_utils_h)
 p-lang.o: p-lang.c $(defs_h) $(gdb_string_h) $(symtab_h) $(gdbtypes_h) \
 	$(expression_h) $(parser_defs_h) $(language_h) $(p_lang_h) \
-	$(valprint_h)
+	$(valprint_h) $(value_h)
 p-typeprint.o: p-typeprint.c $(defs_h) $(gdb_obstack_h) $(bfd_h) $(symtab_h) \
 	$(gdbtypes_h) $(expression_h) $(value_h) $(gdbcore_h) $(target_h) \
 	$(language_h) $(p_lang_h) $(typeprint_h) $(gdb_string_h)
Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.25
diff -u -p -r1.25 ada-lang.c
--- ada-lang.c	14 May 2003 17:43:15 -0000	1.25
+++ ada-lang.c	20 May 2003 01:52:04 -0000
@@ -8082,6 +8082,8 @@ const struct language_defn ada_language_
   ada_val_print,		/* Print a value using appropriate syntax */
   ada_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  value_of_this,		/* value_of_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal  */
   NULL,				/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
 #if 0
Index: c-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/c-lang.c,v
retrieving revision 1.20
diff -u -p -r1.20 c-lang.c
--- c-lang.c	15 May 2003 22:18:42 -0000	1.20
+++ c-lang.c	20 May 2003 01:52:05 -0000
@@ -553,6 +553,8 @@ const struct language_defn c_language_de
   c_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  NULL,				/* value_of_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
@@ -607,6 +609,8 @@ const struct language_defn cplus_languag
   c_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  value_of_this,		/* value_of_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   cplus_demangle,		/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
@@ -638,6 +642,8 @@ const struct language_defn asm_language_
   c_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  NULL,				/* value_of_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
@@ -674,6 +680,8 @@ const struct language_defn minimal_langu
   c_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  NULL,				/* value_of_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
Index: f-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/f-lang.c,v
retrieving revision 1.14
diff -u -p -r1.14 f-lang.c
--- f-lang.c	15 May 2003 22:18:42 -0000	1.14
+++ f-lang.c	20 May 2003 01:52:06 -0000
@@ -30,6 +30,7 @@
 #include "language.h"
 #include "f-lang.h"
 #include "valprint.h"
+#include "value.h"
 
 /* The built-in types of F77.  FIXME: integer*4 is missing, plain
    logical is missing (builtin_type_logical is logical*4).  */
@@ -472,6 +473,8 @@ const struct language_defn f_language_de
   f_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* FIXME */
   NULL,				/* Language specific skip_trampoline */
+  value_of_this,		/* value_of_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%o", "0", "o", ""},	/* Octal format info */
Index: jv-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/jv-lang.c,v
retrieving revision 1.19
diff -u -p -r1.19 jv-lang.c
--- jv-lang.c	14 May 2003 17:43:18 -0000	1.19
+++ jv-lang.c	20 May 2003 01:52:08 -0000
@@ -1063,6 +1063,8 @@ const struct language_defn java_language
   java_val_print,		/* Print a value using appropriate syntax */
   java_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  value_of_this,		/* value_of_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   java_demangle,		/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
Index: language.c
===================================================================
RCS file: /cvs/src/src/gdb/language.c,v
retrieving revision 1.34
diff -u -p -r1.34 language.c
--- language.c	14 May 2003 17:43:18 -0000	1.34
+++ language.c	20 May 2003 01:52:08 -0000
@@ -1479,6 +1479,8 @@ const struct language_defn unknown_langu
   unk_lang_val_print,		/* Print a value using appropriate syntax */
   unk_lang_value_print,		/* Print a top-level value */
   unk_lang_trampoline,		/* Language specific skip_trampoline */
+  value_of_this,		/* value_of_this */
+  basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
   unk_lang_demangle,		/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
@@ -1511,6 +1513,8 @@ const struct language_defn auto_language
   unk_lang_val_print,		/* Print a value using appropriate syntax */
   unk_lang_value_print,		/* Print a top-level value */
   unk_lang_trampoline,		/* Language specific skip_trampoline */
+  value_of_this,		/* value_of_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   unk_lang_demangle,		/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
@@ -1542,6 +1546,8 @@ const struct language_defn local_languag
   unk_lang_val_print,		/* Print a value using appropriate syntax */
   unk_lang_value_print,		/* Print a top-level value */
   unk_lang_trampoline,		/* Language specific skip_trampoline */
+  value_of_this,		/* value_of_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   unk_lang_demangle,		/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
Index: language.h
===================================================================
RCS file: /cvs/src/src/gdb/language.h,v
retrieving revision 1.19
diff -u -p -r1.19 language.h
--- language.h	12 Apr 2003 17:41:25 -0000	1.19
+++ language.h	20 May 2003 01:52:09 -0000
@@ -211,6 +211,27 @@ struct language_defn
        if it isn't a language tramp for this language.  */
     CORE_ADDR (*skip_trampoline) (CORE_ADDR pc);
 
+    /* Now come some hooks for lookup_symbol.  */
+
+    /* If this is non-NULL, lookup_symbol will do the 'field_of_this'
+       check, using this function to find the value of this.  */
+
+    /* FIXME: carlton/2003-05-19: Audit all the language_defn structs
+       to make sure we're setting this appropriately: I'm sure it
+       could be NULL in more languages.  */
+
+    struct value *(*la_value_of_this) (int complain);
+
+    /* This is a function that lookup_symbol will call when it gets to
+       the part of symbol lookup where C looks up static and global
+       variables.  */
+
+    struct symbol *(*la_lookup_symbol_nonlocal) (const char *,
+						 const char *,
+						 const struct block *,
+						 const domain_enum,
+						 struct symtab **);
+
     /* Return demangled language symbol, or NULL.  */
     char *(*la_demangle) (const char *mangled, int options);
 
Index: m2-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/m2-lang.c,v
retrieving revision 1.10
diff -u -p -r1.10 m2-lang.c
--- m2-lang.c	15 May 2003 22:18:42 -0000	1.10
+++ m2-lang.c	20 May 2003 01:52:09 -0000
@@ -426,6 +426,8 @@ const struct language_defn m2_language_d
   m2_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  value_of_this,		/* value_of_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"%loB", "", "o", "B"},	/* Octal format info */
Index: objc-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/objc-lang.c,v
retrieving revision 1.22
diff -u -p -r1.22 objc-lang.c
--- objc-lang.c	15 May 2003 22:18:42 -0000	1.22
+++ objc-lang.c	20 May 2003 01:52:11 -0000
@@ -701,6 +701,8 @@ const struct language_defn objc_language
   c_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
   objc_skip_trampoline, 	/* Language specific skip_trampoline */
+  value_of_this,		/* value_of_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   objc_demangle,		/* Language specific symbol demangler */
   {"",     "",    "",  ""},	/* Binary format info */
   {"0%lo",  "0",   "o", ""},	/* Octal format info */
Index: p-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/p-lang.c,v
retrieving revision 1.12
diff -u -p -r1.12 p-lang.c
--- p-lang.c	15 May 2003 22:18:43 -0000	1.12
+++ p-lang.c	20 May 2003 01:52:12 -0000
@@ -28,6 +28,7 @@
 #include "language.h"
 #include "p-lang.h"
 #include "valprint.h"
+#include "value.h"
 #include <ctype.h>
  
 extern void _initialize_pascal_language (void);
@@ -461,6 +462,8 @@ const struct language_defn pascal_langua
   pascal_val_print,		/* Print a value using appropriate syntax */
   pascal_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  value_of_this,		/* value_of_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
   {"", "%", "b", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
Index: scm-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/scm-lang.c,v
retrieving revision 1.17
diff -u -p -r1.17 scm-lang.c
--- scm-lang.c	14 May 2003 17:43:18 -0000	1.17
+++ scm-lang.c	20 May 2003 01:52:12 -0000
@@ -252,6 +252,8 @@ const struct language_defn scm_language_
   scm_val_print,		/* Print a value using appropriate syntax */
   scm_value_print,		/* Print a top-level value */
   NULL,				/* Language specific skip_trampoline */
+  value_of_this,		/* value_of_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
   {"", "", "", ""},		/* Binary format info */
   {"#o%lo", "#o", "o", ""},	/* Octal format info */
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.108
diff -u -p -r1.108 symtab.c
--- symtab.c	20 May 2003 01:26:58 -0000	1.108
+++ symtab.c	20 May 2003 01:52:16 -0000
@@ -96,13 +96,6 @@ struct symbol *lookup_symbol_aux_local (
 					struct symtab **symtab);
 
 static
-struct symbol *lookup_symbol_aux_block (const char *name,
-					const char *linkage_name,
-					const struct block *block,
-					const domain_enum domain,
-					struct symtab **symtab);
-
-static
 struct symbol *lookup_symbol_aux_symtabs (int block_index,
 					  const char *name,
 					  const char *linkage_name,
@@ -957,7 +950,6 @@ lookup_symbol_aux (const char *name, con
 		   int *is_a_field_of_this, struct symtab **symtab)
 {
   struct symbol *sym;
-  const struct block *static_block;
 
   /* Search specified block and its superiors.  Don't search
      STATIC_BLOCK or GLOBAL_BLOCK.  */
@@ -967,11 +959,13 @@ lookup_symbol_aux (const char *name, con
   if (sym != NULL)
     return sym;
 
-  /* C++/Java/Objective-C: If requested to do so by the caller, 
-     check to see if NAME is a field of `this'. */
-  if (is_a_field_of_this)
+  /* If requested to do so by the caller and if appropriate for the
+     current language, check to see if NAME is a field of `this'. */
+
+  if (current_language->la_value_of_this != NULL
+      && is_a_field_of_this != NULL)
     {
-      struct value *v = value_of_this (0);
+      struct value *v = current_language->la_value_of_this (0);
 
       *is_a_field_of_this = 0;
       if (v && check_field (v, name))
@@ -983,51 +977,12 @@ lookup_symbol_aux (const char *name, con
 	}
     }
 
-  /* If there's a static block to search, search it next.  */
-
-  /* NOTE: carlton/2002-12-05: There is a question as to whether or
-     not it would be appropriate to search the current global block
-     here as well.  (That's what this code used to do before the
-     is_a_field_of_this check was moved up.)  On the one hand, it's
-     redundant with the lookup_symbol_aux_symtabs search that happens
-     next.  On the other hand, if decode_line_1 is passed an argument
-     like filename:var, then the user presumably wants 'var' to be
-     searched for in filename.  On the third hand, there shouldn't be
-     multiple global variables all of which are named 'var', and it's
-     not like decode_line_1 has ever restricted its search to only
-     global variables in a single filename.  All in all, only
-     searching the static block here seems best: it's correct and it's
-     cleanest.  */
-
-  /* NOTE: carlton/2002-12-05: There's also a possible performance
-     issue here: if you usually search for global symbols in the
-     current file, then it would be slightly better to search the
-     current global block before searching all the symtabs.  But there
-     are other factors that have a much greater effect on performance
-     than that one, so I don't think we should worry about that for
-     now.  */
-
-  static_block = block_static_block (block);
-  if (static_block != NULL)
-    {
-      sym = lookup_symbol_aux_block (name, linkage_name, static_block,
-				     domain, symtab);
-      if (sym != NULL)
-	return sym;
-    }
-
-  /* Now search all global blocks.  Do the symtab's first, then
-     check the psymtab's. If a psymtab indicates the existence
-     of the desired name as a global, then do psymtab-to-symtab
-     conversion on the fly and return the found symbol. */
+  /* Now do whatever is appropriate for the current language to look
+     up static and global variables.  */
 
-  sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, linkage_name,
-				   domain, symtab);
-  if (sym != NULL)
-    return sym;
-
-  sym = lookup_symbol_aux_psymtabs (GLOBAL_BLOCK, name, linkage_name,
-				    domain, symtab);
+  sym = current_language->la_lookup_symbol_nonlocal (name, linkage_name,
+						     block, domain,
+						     symtab);
   if (sym != NULL)
     return sym;
 
@@ -1086,7 +1041,7 @@ lookup_symbol_aux_local (const char *nam
 /* Look up a symbol in a block; if found, locate its symtab, fixup the
    symbol, and set block_found appropriately.  */
 
-static struct symbol *
+struct symbol *
 lookup_symbol_aux_block (const char *name, const char *linkage_name,
 			 const struct block *block,
 			 const domain_enum domain,
@@ -1343,6 +1298,93 @@ lookup_symbol_aux_minsyms (const char *n
   return NULL;
 }
 #endif /* 0 */
+
+/* A default version of lookup_symbol_nonlocal for use by languages
+   that can't think of anything better to do.  This implements the C
+   lookup rules.  */
+
+struct symbol *
+basic_lookup_symbol_nonlocal (const char *name,
+			      const char *linkage_name,
+			      const struct block *block,
+			      const domain_enum domain,
+			      struct symtab **symtab)
+{
+  struct symbol *sym;
+
+  /* NOTE: carlton/2003-05-19: The comments below were written when
+     this (or what turned into this) was part of lookup_symbol_aux;
+     I'm much less worried about these questions now, since these
+     decisions have turned out well, but I leave these comments here
+     for posterity.  */
+
+  /* NOTE: carlton/2002-12-05: There is a question as to whether or
+     not it would be appropriate to search the current global block
+     here as well.  (That's what this code used to do before the
+     is_a_field_of_this check was moved up.)  On the one hand, it's
+     redundant with the lookup_symbol_aux_symtabs search that happens
+     next.  On the other hand, if decode_line_1 is passed an argument
+     like filename:var, then the user presumably wants 'var' to be
+     searched for in filename.  On the third hand, there shouldn't be
+     multiple global variables all of which are named 'var', and it's
+     not like decode_line_1 has ever restricted its search to only
+     global variables in a single filename.  All in all, only
+     searching the static block here seems best: it's correct and it's
+     cleanest.  */
+
+  /* NOTE: carlton/2002-12-05: There's also a possible performance
+     issue here: if you usually search for global symbols in the
+     current file, then it would be slightly better to search the
+     current global block before searching all the symtabs.  But there
+     are other factors that have a much greater effect on performance
+     than that one, so I don't think we should worry about that for
+     now.  */
+
+  sym = lookup_symbol_static (name, linkage_name, block, domain, symtab);
+  if (sym != NULL)
+    return sym;
+
+  return lookup_symbol_global (name, linkage_name, domain, symtab);
+}
+
+/* Lookup a symbol in the static block associated to BLOCK, if there
+   is one; do nothing if BLOCK is NULL or a global block.  */
+
+struct symbol *
+lookup_symbol_static (const char *name,
+		      const char *linkage_name,
+		      const struct block *block,
+		      const domain_enum domain,
+		      struct symtab **symtab)
+{
+  const struct block *static_block = block_static_block (block);
+
+  if (static_block != NULL)
+    return lookup_symbol_aux_block (name, linkage_name, static_block,
+				    domain, symtab);
+  else
+    return NULL;
+}
+
+/* Lookup a symbol in all files' global blocks (searching psymtabs if
+   necessary).  */
+
+struct symbol *
+lookup_symbol_global (const char *name,
+		      const char *linkage_name,
+		      const domain_enum domain,
+		      struct symtab **symtab)
+{
+  struct symbol *sym;
+
+  sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, linkage_name,
+				   domain, symtab);
+  if (sym != NULL)
+    return sym;
+
+  return lookup_symbol_aux_psymtabs (GLOBAL_BLOCK, name, linkage_name,
+				     domain, symtab);
+}
 
 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
    If LINKAGE_NAME is non-NULL, check in addition that the symbol's
Index: symtab.h
===================================================================
RCS file: /cvs/src/src/gdb/symtab.h,v
retrieving revision 1.71
diff -u -p -r1.71 symtab.h
--- symtab.h	15 May 2003 22:23:24 -0000	1.71
+++ symtab.h	20 May 2003 01:52:18 -0000
@@ -988,6 +988,45 @@ extern struct symbol *lookup_symbol (con
 				     const domain_enum, int *,
 				     struct symtab **);
 
+/* A default version of lookup_symbol_nonlocal for use by languages
+   that can't think of anything better to do.  */
+
+extern struct symbol *basic_lookup_symbol_nonlocal (const char *,
+						    const char *,
+						    const struct block *,
+						    const domain_enum,
+						    struct symtab **);
+
+/* Some helper functions for languages that need to write their own
+   lookup_symbol_nonlocal functions.  */
+
+/* Lookup a symbol in the static block associated to BLOCK, if there
+   is one; do nothing if BLOCK is NULL or a global block.  */
+
+extern struct symbol *lookup_symbol_static (const char *name,
+					    const char *linkage_name,
+					    const struct block *block,
+					    const domain_enum domain,
+					    struct symtab **symtab);
+
+/* Lookup a symbol in all files' global blocks (searching psymtabs if
+   necessary).  */
+
+extern struct symbol *lookup_symbol_global (const char *name,
+					    const char *linkage_name,
+					    const domain_enum domain,
+					    struct symtab **symtab);
+
+/* Lookup a symbol within the block BLOCK.  This, unlike
+   lookup_symbol_block, will set SYMTAB and BLOCK_FOUND correctly, and
+   will fix up the symbol if necessary.  */
+
+extern struct symbol *lookup_symbol_aux_block (const char *name,
+					       const char *linkage_name,
+					       const struct block *block,
+					       const domain_enum domain,
+					       struct symtab **symtab);
+
 /* lookup a symbol by name, within a specified block */
 
 extern struct symbol *lookup_block_symbol (const struct block *, const char *,


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

end of thread, other threads:[~2003-05-20  2:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-18 22:47 [rfa] language hooks for lookup_symbol David Carlton
2003-05-19 15:14 ` Elena Zannoni
2003-05-19 19:23   ` David Carlton
2003-05-19 19:52     ` Elena Zannoni
2003-05-20  2:01   ` David Carlton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox