public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [patch 3/3 optional] Template Lookup
@ 2010-07-19 15:29 sami wagiaalla
  2010-08-18 22:15 ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: sami wagiaalla @ 2010-07-19 15:29 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1027 bytes --]

This patch improves the output provided by patch 2 in the series. It 
makes the meta symbol created for templates aware of its instanced 
within scope. So if the symbol table contained:

foo<int>(int)
foo<char>(char)
Bar<int>
Bar<char>

and the user did:

(gdb) print foo
or
(gdb) ptype Bar

Symbol represents a template and cannot be evaluated.
Did you mean:
    foo<int>(int)
    foo<char>(char)
Address of symbol "foo" is unknown.

and

Symbol represents a template and cannot be evaluated.
Did you mean:
    Bar<int>
    Bar<char>
type = Template Symbol

respectively. The output needs a bit of cleanup. This is achieved 
through a bit of coordination between symbol evaluation and type 
printing. Also the instance suggested will come only from the current 
scope. If this template had instance in other blocks or files they will 
not be presented here.

I don't think completing the work on this patch would provide 
significant improvement on user experience but I posted it as a 
demonstration, to get other opinions.


[-- Attachment #2: template_lookup_3.patch --]
[-- Type: text/plain, Size: 6603 bytes --]

Template meta var now knows about its instances.

2010-07-16  Sami Wagiaalla  <swagiaal@redhat.com>

	* symtab.h (symbol_add_template_instance): New function prototype.
	(symbol_get_template_instances): New function prototype.
	Created struct symbol_list_element.
	(instances): Add an instance of symbol_list_element to
	general_symbol_info
	* symtab.c (symbol_add_template_instance): New function.
	(symbol_get_template_instances): New function.
	* findvar.c (read_var_value): Print list of candidates when
	attempting to
	evaluate a LOC_TEMPLATE.
	* dwarf2read.c (add_template_variable): Find template variable and
	add instance reference to it.

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 6659968..2c074ef 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -8641,7 +8641,7 @@ add_template_variable (struct symbol *symbol, struct pending **listhead,
                        struct objfile *objfile)
 {
   const struct pending *iterator = *listhead;
-  struct symbol *template_sym;
+  struct symbol *template_sym = NULL;
   struct symbol *iterator_sym;
   struct type *type;
   char *name = SYMBOL_NATURAL_NAME (symbol);
@@ -8672,7 +8672,7 @@ add_template_variable (struct symbol *symbol, struct pending **listhead,
 
   /* Has a template symbol for this symbol been added already ?  */
   for (iterator = *(listhead);
-       iterator != NULL;
+       iterator != NULL && template_sym == NULL;
        iterator = iterator->next)
     {
       for (i = iterator->nsyms - 1; i >= 0; --i)
@@ -8682,28 +8682,32 @@ add_template_variable (struct symbol *symbol, struct pending **listhead,
 	  if (TYPE_CODE (SYMBOL_TYPE (iterator_sym)) == TYPE_CODE_TEMPLATE
 	      && strcmp (SYMBOL_SEARCH_NAME(iterator_sym), search_name) == 0)
 	    {
-	      do_cleanups (all_cleanups);
-	      return;
+	      template_sym = iterator_sym;
+	      break;
 	    }
         }
     }
 
-  /* Add a new template symbol.  */
-  template_sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
-                                         sizeof (struct symbol));
-  OBJSTAT (objfile, n_syms++);
-  memset (template_sym, 0, sizeof (struct symbol));
+  if (template_sym == NULL)
+    {
+      /* Add a new template symbol.  */
+      template_sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
+					     sizeof (struct symbol));
+      OBJSTAT (objfile, n_syms++);
+      memset (template_sym, 0, sizeof (struct symbol));
 
-  SYMBOL_SET_NAMES (template_sym, search_name, strlen (search_name), 0, objfile);
-  type = alloc_type (objfile);
-  TYPE_CODE (type) = TYPE_CODE_TEMPLATE;
-  SYMBOL_TYPE (template_sym) = type;
+      SYMBOL_SET_NAMES (template_sym, search_name, strlen (search_name), 0, objfile);
+      type = alloc_type (objfile);
+      TYPE_CODE (type) = TYPE_CODE_TEMPLATE;
+      SYMBOL_TYPE (template_sym) = type;
 
-  SYMBOL_DOMAIN (template_sym) = VAR_DOMAIN;
-  SYMBOL_CLASS (template_sym) = LOC_TEMPLATE;
+      SYMBOL_DOMAIN (template_sym) = VAR_DOMAIN;
+      SYMBOL_CLASS (template_sym) = LOC_TEMPLATE;
 
-  add_symbol_to_list (template_sym, listhead);
+      add_symbol_to_list (template_sym, listhead);
+    }
 
+  symbol_add_template_instance (template_sym, symbol, objfile);
   do_cleanups (all_cleanups);
 
 }
diff --git a/gdb/findvar.c b/gdb/findvar.c
index f4749b7..2e6de94 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -568,9 +568,19 @@ read_var_value (struct symbol *var, struct frame_info *frame)
       return v;
 
     case LOC_TEMPLATE:
-      error (_("Symbol represents a template and cannot be evaluated."));
-      break;
+      {
+	struct symbol_list_element* instance = symbol_get_template_instances (var);
+
+	printf_filtered ("Symbol represents a template and cannot be evaluated.\n");
+	printf_filtered ("Did you mean:\n");
 
+	while (instance != NULL)
+	  {
+	    printf_filtered ("  %s\n", SYMBOL_NATURAL_NAME (instance->sym));
+	    instance = instance->next;
+	  }
+	return NULL;
+      }
     default:
       error (_("Cannot look up value of a botched symbol."));
       break;
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 70feb62..1240b09 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -343,6 +343,28 @@ gdb_mangle_name (struct type *type, int method_id, int signature_id)
 /* Initialize the cplus_specific structure.  'cplus_specific' should
    only be allocated for use with C++ symbols.  */
 
+void
+symbol_add_template_instance (struct symbol* sym,
+                              const struct symbol* instance,
+                              struct objfile *objfile)
+{
+  struct symbol_list_element* new_instance =
+      OBSTACK_ZALLOC (&objfile->objfile_obstack,
+		      struct symbol_list_element);
+
+  new_instance->sym = instance;
+  new_instance->next = sym->ginfo.value.instances;
+  sym->ginfo.value.instances = new_instance;
+}
+
+/* Return the list of known instances of this template symbol.  */
+
+struct symbol_list_element *
+symbol_get_template_instances (struct symbol* sym)
+{
+  return sym->ginfo.value.instances;
+}
+
 static void
 symbol_init_cplus_specific (struct general_symbol_info *gsymbol,
                             struct objfile *objfile)
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 67dddeb..3f98916 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -75,6 +75,15 @@ struct program_space;
 
    --chastain 2003-08-21  */
 
+/* A likend list of symbols used to keep references to
+   instances of a template.  */
+
+struct symbol_list_element
+{
+  struct symbol_list_element *next;
+  const struct symbol *sym;
+};
+
 /* Struct for storing C++ specific information.  Allocated when needed.  */
 
 struct cplus_specific
@@ -126,6 +135,10 @@ struct general_symbol_info
     /* for opaque typedef struct chain */
 
     struct symbol *chain;
+
+    /* If this is a value of a template symbol this is a pointer to the
+       list of instances of that variable.  */
+    struct symbol_list_element *instances;
   }
   value;
 
@@ -197,6 +210,14 @@ extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
 #define SYMBOL_SECTION(symbol)		(symbol)->ginfo.section
 #define SYMBOL_OBJ_SECTION(symbol)	(symbol)->ginfo.obj_section
 
+extern void
+symbol_add_template_instance (struct symbol* sym,
+                              const struct symbol* instance,
+                              struct objfile *objfile);
+
+extern struct symbol_list_element*
+symbol_get_template_instances (struct symbol* sym);
+
 /* Initializes the language dependent portion of a symbol
    depending upon the language for the symbol. */
 #define SYMBOL_INIT_LANGUAGE_SPECIFIC(symbol,language) \


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

* Re: [patch 3/3 optional] Template Lookup
  2010-07-19 15:29 [patch 3/3 optional] Template Lookup sami wagiaalla
@ 2010-08-18 22:15 ` Tom Tromey
  2010-08-30 14:59   ` sami wagiaalla
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2010-08-18 22:15 UTC (permalink / raw)
  To: sami wagiaalla; +Cc: gdb-patches

>>>>> "Sami" == sami wagiaalla <swagiaal@redhat.com> writes:

Sami> This patch improves the output provided by patch 2 in the series. It
Sami> makes the meta symbol created for templates aware of its instanced
Sami> within scope.

Sami> +	struct symbol_list_element* instance = symbol_get_template_instances (var);

Space before "*", not after.  There are a few of these.

Sami> +  new_instance->sym = instance;
Sami> +  new_instance->next = sym->ginfo.value.instances;
Sami> +  sym->ginfo.value.instances = new_instance;

You could save a little memory by making a "subclass" of symbol for just
these instances, and have the subclass include the link.

Sami> +extern struct symbol_list_element*
Sami> +symbol_get_template_instances (struct symbol* sym);

It seems like this could return a 'const struct symbol_list_element *'.
And perhaps accept a 'const struct symbol *'.  I didn't really examine
the other patches for const opportunities, but I think it would be
worthwhile to look at.

Tom

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

* Re: [patch 3/3 optional] Template Lookup
  2010-08-18 22:15 ` Tom Tromey
@ 2010-08-30 14:59   ` sami wagiaalla
  2010-09-23 18:43     ` [patch 3/4 " sami wagiaalla
  0 siblings, 1 reply; 4+ messages in thread
From: sami wagiaalla @ 2010-08-30 14:59 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 24 bytes --]

Revised patch attached.

[-- Attachment #2: template_lookup_3.patch --]
[-- Type: text/x-patch, Size: 7614 bytes --]

Template Lookup 3: Template meta var learns about its instances.

2010-08-30  Sami Wagiaalla  <swagiaal@redhat.com>

	* symtab.h (symbol_add_template_instance): New function prototype.
	(symbol_get_template_instances): New function prototype.
	Created struct symbol_list_element.
	Created struct template_symbol.
	(instances): Add an instance of symbol_list_element to
	general_symbol_info
	* symtab.c (symbol_add_template_instance): New function.
	(symbol_get_template_instances): New function.
	* findvar.c (read_var_value): Print list of candidates when
	attempting to evaluate a LOC_TEMPLATE.
	* dwarf2read.c (add_template_variable): Find template variable and
	add instance reference to it.

2010-08-30  Sami Wagiaalla  <swagiaal@redhat.com>

	* gdb.cp/temp-op.exp: Test printing of template instances.

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index bf57650..cbee89d 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -8647,7 +8647,7 @@ add_template_variable (struct symbol *symbol, struct pending **listhead,
                        struct objfile *objfile)
 {
   const struct pending *iterator = *listhead;
-  struct symbol *template_sym;
+  struct template_symbol *template_sym = NULL;
   struct symbol *iterator_sym;
   struct type *type;
   char *name = SYMBOL_NATURAL_NAME (symbol);
@@ -8677,7 +8677,7 @@ add_template_variable (struct symbol *symbol, struct pending **listhead,
 
   /* Has a template symbol for this symbol been added already ?  */
   for (iterator = *(listhead);
-       iterator != NULL;
+       iterator != NULL && template_sym == NULL;
        iterator = iterator->next)
     {
       for (i = iterator->nsyms - 1; i >= 0; --i)
@@ -8687,28 +8687,38 @@ add_template_variable (struct symbol *symbol, struct pending **listhead,
 	  if (TYPE_CODE (SYMBOL_TYPE (iterator_sym)) == TYPE_CODE_TEMPLATE
 	      && strcmp (SYMBOL_SEARCH_NAME (iterator_sym), search_name) == 0)
 	    {
-	      do_cleanups (all_cleanups);
-	      return;
+	      template_sym = (struct template_symbol *) iterator_sym;
+	      break;
 	    }
         }
     }
 
-  /* Add a new template symbol.  */
-  template_sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
-                                         sizeof (struct symbol));
-  OBJSTAT (objfile, n_syms++);
-  memset (template_sym, 0, sizeof (struct symbol));
+  if (template_sym == NULL)
+    {
+      /* Add a new template symbol.  */
+      template_sym = (struct template_symbol *)
+	  obstack_alloc (&objfile->objfile_obstack,
+	                 sizeof (struct template_symbol));
 
-  SYMBOL_SET_NAMES (template_sym, search_name, strlen (search_name), 0, objfile);
-  type = alloc_type (objfile);
-  TYPE_CODE (type) = TYPE_CODE_TEMPLATE;
-  SYMBOL_TYPE (template_sym) = type;
+      OBJSTAT (objfile, n_syms++);
+      memset (&template_sym->sym, 0, sizeof (struct symbol));
+
+      SYMBOL_SET_NAMES (&template_sym->sym,
+                        search_name,
+                        strlen (search_name),
+                        0, objfile);
 
-  SYMBOL_DOMAIN (template_sym) = VAR_DOMAIN;
-  SYMBOL_CLASS (template_sym) = LOC_TEMPLATE;
+      type = alloc_type (objfile);
+      TYPE_CODE (type) = TYPE_CODE_TEMPLATE;
+      SYMBOL_TYPE (&template_sym->sym) = type;
 
-  add_symbol_to_list (template_sym, listhead);
+      SYMBOL_DOMAIN (&template_sym->sym) = VAR_DOMAIN;
+      SYMBOL_CLASS (&template_sym->sym) = LOC_TEMPLATE;
+
+      add_symbol_to_list (&template_sym->sym, listhead);
+    }
 
+  symbol_add_template_instance (template_sym, symbol, objfile);
   do_cleanups (all_cleanups);
 
 }
diff --git a/gdb/findvar.c b/gdb/findvar.c
index f4749b7..1d2f2a8 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -35,6 +35,7 @@
 #include "user-regs.h"
 #include "block.h"
 #include "objfiles.h"
+#include "exceptions.h"
 
 /* Basic byte-swapping routines.  All 'extract' functions return a
    host-format integer from a target-format integer at ADDR which is
@@ -568,9 +569,20 @@ read_var_value (struct symbol *var, struct frame_info *frame)
       return v;
 
     case LOC_TEMPLATE:
-      error (_("Symbol represents a template and cannot be evaluated."));
-      break;
+      {
+	const struct symbol_list_element *instance =
+	    symbol_get_template_instances (var);
+
+	printf_filtered ("Symbol represents a template and cannot be evaluated.\n");
+	printf_filtered ("Did you mean:\n");
 
+	while (instance != NULL)
+	  {
+	    printf_filtered ("  %s\n", SYMBOL_NATURAL_NAME (instance->sym));
+	    instance = instance->next;
+	  }
+	throw_error (NOT_FOUND_ERROR, " ");
+      }
     default:
       error (_("Cannot look up value of a botched symbol."));
       break;
diff --git a/gdb/symtab.c b/gdb/symtab.c
index d0abc2d..d2dc528 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -343,6 +343,28 @@ gdb_mangle_name (struct type *type, int method_id, int signature_id)
 /* Initialize the cplus_specific structure.  'cplus_specific' should
    only be allocated for use with cplus symbols.  */
 
+void
+symbol_add_template_instance (struct template_symbol *template_sym,
+                              const struct symbol *instance,
+                              struct objfile *objfile)
+{
+  struct symbol_list_element *new_instance =
+      OBSTACK_ZALLOC (&objfile->objfile_obstack,
+		      struct symbol_list_element);
+
+  new_instance->sym = instance;
+  new_instance->next = template_sym->instances;
+  template_sym->instances = new_instance;
+}
+
+/* Return the list of known instances of this template symbol.  */
+
+const struct symbol_list_element *
+symbol_get_template_instances (const struct symbol *sym)
+{
+  return ((struct template_symbol *) sym)->instances;
+}
+
 static void
 symbol_init_cplus_specific (struct general_symbol_info *gsymbol,
                            struct objfile *objfile)
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 46d3584..c98657c 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -75,6 +75,15 @@ struct program_space;
 
    --chastain 2003-08-21  */
 
+/* A likend list of symbols used to keep references to
+   instances of a template.  */
+
+struct symbol_list_element
+{
+  struct symbol_list_element *next;
+  const struct symbol *sym;
+};
+
 /* Struct for storing C++ specific information.  Allocated when needed.  */
 
 struct cplus_specific
@@ -649,6 +658,21 @@ struct symbol
   struct symbol *hash_next;
 };
 
+/* A "subclass" of symbol object for representing templates.  */
+
+struct template_symbol
+{
+    struct symbol sym;
+    struct symbol_list_element *instances;
+};
+
+extern void
+symbol_add_template_instance (struct template_symbol *template_sym,
+                              const struct symbol *instance,
+                              struct objfile *objfile);
+
+extern const struct symbol_list_element *
+symbol_get_template_instances (const struct symbol *sym);
 
 #define SYMBOL_DOMAIN(symbol)	(symbol)->domain
 #define SYMBOL_CLASS(symbol)		(symbol)->aclass
diff --git a/gdb/testsuite/gdb.cp/temp-op.exp b/gdb/testsuite/gdb.cp/temp-op.exp
index 21e644f..7352e14 100644
--- a/gdb/testsuite/gdb.cp/temp-op.exp
+++ b/gdb/testsuite/gdb.cp/temp-op.exp
@@ -63,5 +63,5 @@ gdb_test "p bc == 'a'"       "= 19"
 # Test that printing the a template name without
 # template parameters does not return an arbitrary match
 
-gdb_test "print foo" "Symbol represents a template and cannot be evaluated."
-gdb_test "ptype B" "type = Template Symbol"
+gdb_test "print foo" "Symbol represents a template and cannot be evaluated.*foo<A>\\(A, char\\).*"
+gdb_test "ptype B" "Symbol represents a template and cannot be evaluated.*B<char>.*B<int>.*"

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

* Re: [patch 3/4 optional] Template Lookup
  2010-08-30 14:59   ` sami wagiaalla
@ 2010-09-23 18:43     ` sami wagiaalla
  0 siblings, 0 replies; 4+ messages in thread
From: sami wagiaalla @ 2010-09-23 18:43 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 26 bytes --]

Updated patch attached.



[-- Attachment #2: template_lookup_3.patch --]
[-- Type: text/x-patch, Size: 7735 bytes --]

Template Lookup 3: Template meta var learns about its instances.

2010-09-15  Sami Wagiaalla  <swagiaal@redhat.com>

	* symtab.h (symbol_add_template_instance): New function prototype.
	(symbol_get_template_instances): New function prototype.
	Created struct symbol_list_element.
	Created struct template_symbol.
	(instances): Add an instance of symbol_list_element to
	general_symbol_info
	* symtab.c (symbol_add_template_instance): New function.
	(symbol_get_template_instances): New function.
	* findvar.c (read_var_value): Print list of candidates when
	attempting to evaluate a LOC_TEMPLATE.
	* dwarf2read.c (add_template_variable): Find template variable and
	add instance reference to it.

2010-09-15  Sami Wagiaalla  <swagiaal@redhat.com>

	* gdb.cp/temp-op.exp: Test printing of template instances.

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 848366a..0d3a34b 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -10520,7 +10520,7 @@ add_template_meta_symbol (struct symbol *symbol, struct pending **listhead,
                           struct objfile *objfile)
 {
   const struct pending *iterator = *listhead;
-  struct symbol *template_sym;
+  struct template_meta_symbol *template_sym = NULL;
   struct symbol *iterator_sym;
   struct type *type;
   char *search_name;
@@ -10534,7 +10534,7 @@ add_template_meta_symbol (struct symbol *symbol, struct pending **listhead,
 
   /* Has a template symbol for this symbol been added already ?  */
   for (iterator = *(listhead);
-       iterator != NULL;
+       iterator != NULL && template_sym == NULL;
        iterator = iterator->next)
     {
       for (i = iterator->nsyms - 1; i >= 0; --i)
@@ -10543,25 +10543,39 @@ add_template_meta_symbol (struct symbol *symbol, struct pending **listhead,
 
 	  if (TYPE_CODE (SYMBOL_TYPE (iterator_sym)) == TYPE_CODE_TEMPLATE
 	      && strcmp (SYMBOL_SEARCH_NAME (iterator_sym), search_name) == 0)
-	      return;
+	    {
+	      template_sym = (struct template_meta_symbol *) iterator_sym;
+	      break;
+	    }
         }
     }
 
-  /* This is a new template therefore add a new template symbol.  */
-  template_sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
-                                         sizeof (struct symbol));
-  OBJSTAT (objfile, n_syms++);
-  memset (template_sym, 0, sizeof (struct symbol));
+  if (template_sym == NULL)
+    {
+      /* Add a new template symbol.  */
+      template_sym = (struct template_meta_symbol *)
+	  obstack_alloc (&objfile->objfile_obstack,
+	                 sizeof (struct template_meta_symbol));
 
-  SYMBOL_SET_NAMES (template_sym, search_name, strlen (search_name), 0, objfile);
-  type = alloc_type (objfile);
-  TYPE_CODE (type) = TYPE_CODE_TEMPLATE;
-  SYMBOL_TYPE (template_sym) = type;
+      OBJSTAT (objfile, n_syms++);
+      memset (&template_sym->sym, 0, sizeof (struct symbol));
+
+      SYMBOL_SET_NAMES (&template_sym->sym,
+                        search_name,
+                        strlen (search_name),
+                        0, objfile);
+
+      type = alloc_type (objfile);
+      TYPE_CODE (type) = TYPE_CODE_TEMPLATE;
+      SYMBOL_TYPE (&template_sym->sym) = type;
 
-  SYMBOL_DOMAIN (template_sym) = VAR_DOMAIN;
-  SYMBOL_CLASS (template_sym) = LOC_TEMPLATE;
+      SYMBOL_DOMAIN (&template_sym->sym) = VAR_DOMAIN;
+      SYMBOL_CLASS (&template_sym->sym) = LOC_TEMPLATE;
+
+      add_symbol_to_list (&template_sym->sym, listhead);
+    }
 
-  add_symbol_to_list (template_sym, listhead);
+  symbol_add_template_instance (template_sym, symbol, objfile);
 }
 
 /* Given a pointer to a DWARF information entry, figure out if we need
diff --git a/gdb/findvar.c b/gdb/findvar.c
index f4749b7..1d2f2a8 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -35,6 +35,7 @@
 #include "user-regs.h"
 #include "block.h"
 #include "objfiles.h"
+#include "exceptions.h"
 
 /* Basic byte-swapping routines.  All 'extract' functions return a
    host-format integer from a target-format integer at ADDR which is
@@ -568,9 +569,20 @@ read_var_value (struct symbol *var, struct frame_info *frame)
       return v;
 
     case LOC_TEMPLATE:
-      error (_("Symbol represents a template and cannot be evaluated."));
-      break;
+      {
+	const struct symbol_list_element *instance =
+	    symbol_get_template_instances (var);
+
+	printf_filtered ("Symbol represents a template and cannot be evaluated.\n");
+	printf_filtered ("Did you mean:\n");
 
+	while (instance != NULL)
+	  {
+	    printf_filtered ("  %s\n", SYMBOL_NATURAL_NAME (instance->sym));
+	    instance = instance->next;
+	  }
+	throw_error (NOT_FOUND_ERROR, " ");
+      }
     default:
       error (_("Cannot look up value of a botched symbol."));
       break;
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 068bf87..c0b9bec 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -344,6 +344,28 @@ gdb_mangle_name (struct type *type, int method_id, int signature_id)
 /* Initialize the cplus_specific structure.  'cplus_specific' should
    only be allocated for use with cplus symbols.  */
 
+void
+symbol_add_template_instance (struct template_meta_symbol *template_sym,
+                              const struct symbol *instance,
+                              struct objfile *objfile)
+{
+  struct symbol_list_element *new_instance =
+      OBSTACK_ZALLOC (&objfile->objfile_obstack,
+		      struct symbol_list_element);
+
+  new_instance->sym = instance;
+  new_instance->next = template_sym->instances;
+  template_sym->instances = new_instance;
+}
+
+/* Return the list of known instances of this template symbol.  */
+
+const struct symbol_list_element *
+symbol_get_template_instances (const struct symbol *sym)
+{
+  return ((struct template_meta_symbol *) sym)->instances;
+}
+
 static void
 symbol_init_cplus_specific (struct general_symbol_info *gsymbol,
                            struct objfile *objfile)
diff --git a/gdb/symtab.h b/gdb/symtab.h
index a1fba1c..998545d 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -75,6 +75,15 @@ struct program_space;
 
    --chastain 2003-08-21  */
 
+/* A likend list of symbols used to keep references to
+   instances of a template.  */
+
+struct symbol_list_element
+{
+  struct symbol_list_element *next;
+  const struct symbol *sym;
+};
+
 /* Struct for storing C++ specific information.  Allocated when needed.  */
 
 struct cplus_specific
@@ -657,6 +666,22 @@ struct symbol
   struct symbol *hash_next;
 };
 
+/* A "subclass" of symbol object for representing templates.  Each
+   template knows about its INSTANCES.  */
+
+struct template_meta_symbol
+{
+    struct symbol sym;
+    struct symbol_list_element *instances;
+};
+
+extern void
+symbol_add_template_instance (struct template_meta_symbol *template_sym,
+                              const struct symbol *instance,
+                              struct objfile *objfile);
+
+extern const struct symbol_list_element *
+symbol_get_template_instances (const struct symbol *sym);
 
 #define SYMBOL_DOMAIN(symbol)	(symbol)->domain
 #define SYMBOL_CLASS(symbol)		(symbol)->aclass
diff --git a/gdb/testsuite/gdb.cp/temp-op.exp b/gdb/testsuite/gdb.cp/temp-op.exp
index 21e644f..7352e14 100644
--- a/gdb/testsuite/gdb.cp/temp-op.exp
+++ b/gdb/testsuite/gdb.cp/temp-op.exp
@@ -63,5 +63,5 @@ gdb_test "p bc == 'a'"       "= 19"
 # Test that printing the a template name without
 # template parameters does not return an arbitrary match
 
-gdb_test "print foo" "Symbol represents a template and cannot be evaluated."
-gdb_test "ptype B" "type = Template Symbol"
+gdb_test "print foo" "Symbol represents a template and cannot be evaluated.*foo<A>\\(A, char\\).*"
+gdb_test "ptype B" "Symbol represents a template and cannot be evaluated.*B<char>.*B<int>.*"


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

end of thread, other threads:[~2010-09-23 14:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-19 15:29 [patch 3/3 optional] Template Lookup sami wagiaalla
2010-08-18 22:15 ` Tom Tromey
2010-08-30 14:59   ` sami wagiaalla
2010-09-23 18:43     ` [patch 3/4 " sami wagiaalla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).