From: pfieland@citron.sw.stratus.com (Peggy Fieland)
Subject: (none)
Organization: GNUs Not Usenet
Distribution: gnu
Date: Thu, 13 Aug 1992 20:15:36 GMT

On a stratus i860, using gdb-4.6 and cfront, gdb does not print
the demangled opertor name as part of the class.  This is because
the code that is printing it as part of the class does not account
for the difference in operator naming conventions between cfront
and g++.  Note that "info functions" is correct, though.

Here is a test program:

class a {
private:
    int data;
public:
    a() { data =0; }
    a(a & val) { data = val.data; }
    a(int val) { data = val; }
    int         operator=(int);
};

int a::operator=(int i)
{
 return i;
}

void foo( a temp)
{
    a b(temp);
    a c=temp;
}

main()
{
    a   one(3);

    foo(one);
    foo(2);
}

Here is a sample debugging session:

maestro-tests% /net/citron/home/citron/pfieland/gdb-4.6/gdb-4.6/gdb/gdbx class2
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.6, Copyright 1992 Free Software Foundation, Inc...
(gdb) b main
Breakpoint 1 at 0x1490: file class2.c, line 25.
(gdb) info functions a
All functions matching regular expression "a":

File class2.c:
int a::operator=(int);
int main();

Non-debugging symbols:
        00001368  _start
        000014d8  _main
(gdb) ptype a
type = class a {
  private:
    int data;

  public:
    a ();
    a (struct a &);
    a (int);
    int __as (int);
}
(gdb) q

Here is a fix:

*** /home/tools/gnu/gdb-4.6/gdb/valprint.c	Tue Jul 14 03:34:32 1992
--- gdb-4.6/gdb/valprint.c	Mon Aug 10 18:06:43 1992
***************
*** 1840,1845 ****
--- 1899,1905 ----
  	      struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
  	      int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
  	      char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
+            char *demangled_name = NULL;
  	      int is_constructor = name && strcmp(method_name, name) == 0;
  	      for (j = 0; j < len2; j++)
  		{
***************
*** 1877,1882 ****
--- 1937,1960 ----
  		    fprintf_filtered (stream, "virtual ");
  		  else if (TYPE_FN_FIELD_STATIC_P (f, j))
  		    fprintf_filtered (stream, "static ");
+ 
+             /* cfront naming conventions for operator names are rather obscure.
+                This code ensures that the function names printed are the same
+                as those that appear in "info functions". Peggy Fieland. */
+             if (current_demangling_style == cfront_demangling)
+                {
+                   char *tem;
+ 
+                   demangled_name = cplus_demangle(TYPE_FN_FIELD_PHYSNAME (f, 0), 0);
+                   tem = strchr(demangled_name, ':');
+ 
+                   if ((demangled_name != NULL)  && (tem != NULL))
+                      {
+                         tem += 2;
+                         method_name = tem;
+                      }
+                }    
+ 
  		  if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
  		    {
  		      /* Keep GDB from crashing here.  */
***************
*** 1921,1926 ****
--- 1999,2006 ----
  
  		  fprintf_filtered (stream, ";\n");
  		}
+            if (demangled_name != NULL)
+               free (demangled_name);
  	    }
  
  	  print_spaces_filtered (level, stream);

Newsgroups: gnu.gdb.bug