Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Re: [RFA]: Make class_name_from_physname part of language vector
@ 2004-07-05 20:21 Jeff Johnston
  2004-07-05 21:50 ` Daniel Jacobowitz
  0 siblings, 1 reply; 8+ messages in thread
From: Jeff Johnston @ 2004-07-05 20:21 UTC (permalink / raw)
  To: gdb-patches, drow

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

> On Fri, May 14, 2004 at 07:37:31PM -0400, Jeff Johnston wrote:
>> Index: jv-lang.c
> 
>> +  /* P now points at the `)' at the end of the argument list.  Walk
>> +     back to the beginning.  */
>> +  p--;
>> +  depth = 1;
>> +  while (p > name && depth > 0)
>> +    {
>> +      if (*p == '<' || *p == '(')
>> +	depth--;
>> +      else if (*p == '>' || *p == ')')
>> +	depth++;
>> +      p--;
>> +    }
>> +
>> +  if (p == name)
>> +    return NULL;
>> +
>> +  while (p > name && *p != '.')
>> +    p--;
> 
> You've left in a lot of hokery from the C++ support which I'm
> reasonably confident Java does not need.  I don't believe that Java
> mangled names will ever have templates, or classes nested inside of
> functions, or multiple argument lists - no depth at all.  Also, I'd
> appreciate it if you called it something other than
> find_last_component; the C++ version shouldn't have such a generic name
> either, IMO.
> 
> Otherwise this looks fine.
> 
> -- 
> Daniel Jacobowitz
> 
> 

I have made the changes you recommended.  The function now only looks for the 
opening parenthesis.  I renamed it to "find_member_function_name" as well.

Ok to commit?

  2004-07-05  Jeff Johnston <jjohnstn@redhat.com>

     * language.h (struct_language_defn): Add new function pointer:
     la_class_name_from_physname.  Also add new prototype for
     language_class_name_from_physname.
     * language.c (language_class_name_from_physname): New function.
     (unk_lang_class_name): Ditto.
     (unknown_language_defn, auto_language_defn): Change
     to add unk_lang_class_name function pointer for
     la_class_name_from_physname.
     (local_language_defn): Ditto.
     * dwarf2read.c (guess_structure_name): Change to call
     language_class_name_from_physname.
     (determine_class_name): Ditto.
     * cp-support.c (class_name_from_physname): Renamed.
     (cp_class_name_from_physname): New name of function.
     * cp-support.h: Ditto.
     * c-lang.c (c_language_defn): Change to add NULL
     for class_name_from_physname function pointer.
     (cplus_language_defn): Change to add cp_class_name_from_physname.
     * jv-lang.c (java_class_name_physname): New function.
     (find_member_function_name): New static routine.
     (java_language_defn): Add java_class_name_from_physname pointer.
     * ada-lang.c (ada_language_defn): Change to add NULL
     for class_name_from_physname function pointer.
     * f-lang.c (f_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.


[-- Attachment #2: class_name.patch2 --]
[-- Type: text/plain, Size: 15101 bytes --]

Index: cp-support.h
===================================================================
RCS file: /cvs/src/src/gdb/cp-support.h,v
retrieving revision 1.13
diff -u -p -r1.13 cp-support.h
--- cp-support.h	2 Feb 2004 20:44:52 -0000	1.13
+++ cp-support.h	5 Jul 2004 20:19:25 -0000
@@ -52,7 +52,7 @@ struct using_direct
 
 /* Functions from cp-support.c.  */
 
-extern char *class_name_from_physname (const char *physname);
+extern char *cp_class_name_from_physname (const char *physname);
 
 extern char *method_name_from_physname (const char *physname);
 
Index: language.h
===================================================================
RCS file: /cvs/src/src/gdb/language.h,v
retrieving revision 1.26
diff -u -p -r1.26 language.h
--- language.h	10 Apr 2004 22:10:01 -0000	1.26
+++ language.h	5 Jul 2004 20:19:25 -0000
@@ -247,6 +247,9 @@ struct language_defn
     /* Return demangled language symbol, or NULL.  */
     char *(*la_demangle) (const char *mangled, int options);
 
+    /* Return class name of a mangled method name or NULL.  */
+    char *(*la_class_name_from_physname) (const char *physname);
+
     /* Base 2 (binary) formats. */
 
     struct language_format_info la_binary_format;
@@ -516,6 +519,10 @@ extern CORE_ADDR skip_language_trampolin
 extern char *language_demangle (const struct language_defn *current_language, 
 				const char *mangled, int options);
 
+/* Return class name from physname, or NULL.  */
+extern char *language_class_name_from_physname (const struct language_defn *,
+					        const char *physname);
+
 /* Splitting strings into words.  */
 extern char *default_word_break_characters (void);
 
Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.46
diff -u -p -r1.46 ada-lang.c
--- ada-lang.c	1 Jul 2004 10:30:57 -0000	1.46
+++ ada-lang.c	5 Jul 2004 20:19:25 -0000
@@ -10144,6 +10144,7 @@ const struct language_defn ada_language_
   ada_lookup_symbol_nonlocal,   /* Looking up non-local symbols.  */
   basic_lookup_transparent_type,        /* lookup_transparent_type */
   ada_la_decode,                /* Language specific symbol demangler */
+  NULL,                         /* Language specific class_name_from_physname */
   {"", "", "", ""},             /* Binary format info */
 #if 0
   {"8#%lo#", "8#", "o", "#"},   /* Octal format info */
Index: c-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/c-lang.c,v
retrieving revision 1.27
diff -u -p -r1.27 c-lang.c
--- c-lang.c	10 Apr 2004 22:10:00 -0000	1.27
+++ c-lang.c	5 Jul 2004 20:19:25 -0000
@@ -559,6 +559,7 @@ const struct language_defn c_language_de
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
@@ -618,6 +619,7 @@ const struct language_defn cplus_languag
   cp_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   cp_lookup_transparent_type,   /* lookup_transparent_type */
   cplus_demangle,		/* Language specific symbol demangler */
+  cp_class_name_from_physname,  /* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
@@ -654,6 +656,7 @@ const struct language_defn asm_language_
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
@@ -695,6 +698,7 @@ const struct language_defn minimal_langu
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
Index: cp-support.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-support.c,v
retrieving revision 1.12
diff -u -p -r1.12 cp-support.c
--- cp-support.c	2 Feb 2004 20:44:52 -0000	1.12
+++ cp-support.c	5 Jul 2004 20:19:25 -0000
@@ -148,7 +148,7 @@ find_last_component (const char *name)
 /* Return the name of the class containing method PHYSNAME.  */
 
 char *
-class_name_from_physname (const char *physname)
+cp_class_name_from_physname (const char *physname)
 {
   char *ret = NULL;
   const char *end;
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.155
diff -u -p -r1.155 dwarf2read.c
--- dwarf2read.c	24 Jun 2004 20:42:42 -0000	1.155
+++ dwarf2read.c	5 Jul 2004 20:19:25 -0000
@@ -1840,7 +1840,8 @@ guess_structure_name (struct partial_die
 	  if (child_pdi->tag == DW_TAG_subprogram)
 	    {
 	      char *actual_class_name
-		= class_name_from_physname (child_pdi->name);
+		= language_class_name_from_physname (cu->language_defn,
+						     child_pdi->name);
 	      if (actual_class_name != NULL)
 		{
 		  struct_pdi->name
@@ -3557,7 +3558,9 @@ determine_class_name (struct die_info *d
 	{
 	  if (child->tag == DW_TAG_subprogram)
 	    {
-	      new_prefix = class_name_from_physname (dwarf2_linkage_name
+	      new_prefix 
+		= language_class_name_from_physname (cu->language_defn,
+						     dwarf2_linkage_name
 						     (child, cu));
 
 	      if (new_prefix != NULL)
Index: f-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/f-lang.c,v
retrieving revision 1.23
diff -u -p -r1.23 f-lang.c
--- f-lang.c	10 Apr 2004 22:10:00 -0000	1.23
+++ f-lang.c	5 Jul 2004 20:19:25 -0000
@@ -478,6 +478,7 @@ const struct language_defn f_language_de
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%o", "0", "o", ""},	/* Octal format info */
   {"%d", "", "d", ""},		/* Decimal format info */
Index: jv-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/jv-lang.c,v
retrieving revision 1.30
diff -u -p -r1.30 jv-lang.c
--- jv-lang.c	10 Apr 2004 22:10:00 -0000	1.30
+++ jv-lang.c	5 Jul 2004 20:19:26 -0000
@@ -62,6 +62,8 @@ static struct value *java_value_string (
 
 static void java_emit_char (int c, struct ui_file * stream, int quoter);
 
+static char *java_class_name_from_physname (const char *physname);
+
 /* This objfile contains symtabs that have been dynamically created
    to record dynamically loaded Java classes and dynamically
    compiled java methods. */
@@ -975,6 +977,73 @@ static char *java_demangle (const char *
   return cplus_demangle (mangled, options | DMGL_JAVA);
 }
 
+/* Find the member function name of the demangled name NAME.  NAME
+   must be a method name including arguments, in order to correctly
+   locate the last component.
+
+   This function return a pointer to the first dot before the
+   member function name, or NULL if the name was not of the
+   expected form.  */
+
+static const char *
+find_member_function_name (const char *name)
+{
+  const char *p;
+  int depth;
+
+  /* Functions can have local classes, so we need to find the
+     beginning of the last argument list, not the end of the first
+     one.  */
+  p = name + strlen (name) - 1;
+  while (p > name && *p != ')')
+    p--;
+
+  if (p == name)
+    return NULL;
+
+  /* P now points at the `)' at the end of the argument list.  Walk
+     back to the beginning.  */
+  p--;
+  depth = 1;
+  while (p > name && *p != '(')
+    p--;
+
+  if (p == name)
+    return NULL;
+
+  while (p > name && *p != '.')
+    p--;
+
+  if (p == name)
+    return NULL;
+
+  return p;
+}
+
+/* Return the name of the class containing method PHYSNAME.  */
+
+static char *
+java_class_name_from_physname (const char *physname) 
+{
+  char *ret = NULL;
+  const char *end;
+  int depth = 0;
+  char *demangled_name = java_demangle (physname, DMGL_PARAMS | DMGL_ANSI);
+
+  if (demangled_name == NULL)
+    return NULL;
+
+  end = find_member_function_name (demangled_name);
+  if (end != NULL)
+    {
+      ret = xmalloc (end - demangled_name + 1);
+      memcpy (ret, demangled_name, end - demangled_name);
+      ret[end - demangled_name] = '\0';
+    }
+
+  xfree (demangled_name);
+  return ret;
+}
 
 /* Table mapping opcodes into strings for printing operators
    and precedences of the operators.  */
@@ -1049,6 +1118,7 @@ const struct language_defn java_language
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   java_demangle,		/* Language specific symbol demangler */
+  java_class_name_from_physname,/* Language specific class name */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
Index: language.c
===================================================================
RCS file: /cvs/src/src/gdb/language.c,v
retrieving revision 1.44
diff -u -p -r1.44 language.c
--- language.c	10 Apr 2004 22:10:00 -0000	1.44
+++ language.c	5 Jul 2004 20:19:26 -0000
@@ -1176,6 +1176,16 @@ language_demangle (const struct language
   return NULL;
 }
 
+/* Return class name from physname or NULL.  */
+char *
+language_class_name_from_physname (const struct language_defn *current_language,
+				   const char *physname)
+{
+  if (current_language != NULL && current_language->la_class_name_from_physname)
+    return current_language->la_class_name_from_physname (physname);
+  return NULL;
+}
+
 /* Return the default string containing the list of characters
    delimiting words.  This is a reasonable default value that
    most languages should be able to use.  */
@@ -1258,6 +1268,10 @@ static char *unk_lang_demangle (const ch
   return cplus_demangle (mangled, options);
 }
 
+static char *unk_lang_class_name (const char *mangled)
+{
+  return NULL;
+}
 
 static struct type **const (unknown_builtin_types[]) =
 {
@@ -1292,6 +1306,7 @@ const struct language_defn unknown_langu
   basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   unk_lang_demangle,		/* Language specific symbol demangler */
+  unk_lang_class_name,		/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
@@ -1329,6 +1344,7 @@ const struct language_defn auto_language
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   unk_lang_demangle,		/* Language specific symbol demangler */
+  unk_lang_class_name,		/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
@@ -1365,6 +1381,7 @@ const struct language_defn local_languag
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   unk_lang_demangle,		/* Language specific symbol demangler */
+  unk_lang_class_name,		/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
Index: m2-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/m2-lang.c,v
retrieving revision 1.16
diff -u -p -r1.16 m2-lang.c
--- m2-lang.c	10 Apr 2004 22:10:01 -0000	1.16
+++ m2-lang.c	5 Jul 2004 20:19:26 -0000
@@ -431,6 +431,7 @@ const struct language_defn m2_language_d
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"%loB", "", "o", "B"},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
Index: objc-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/objc-lang.c,v
retrieving revision 1.35
diff -u -p -r1.35 objc-lang.c
--- objc-lang.c	10 Apr 2004 22:10:01 -0000	1.35
+++ objc-lang.c	5 Jul 2004 20:19:26 -0000
@@ -675,6 +675,7 @@ const struct language_defn objc_language
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   objc_demangle,		/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"",     "",    "",  ""},	/* Binary format info */
   {"0%lo",  "0",   "o", ""},	/* Octal format info */
   {"%ld",   "",    "d", ""},	/* Decimal format info */
Index: p-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/p-lang.c,v
retrieving revision 1.18
diff -u -p -r1.18 p-lang.c
--- p-lang.c	10 Apr 2004 22:09:59 -0000	1.18
+++ p-lang.c	5 Jul 2004 20:19:26 -0000
@@ -467,6 +467,7 @@ const struct language_defn pascal_langua
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "%", "b", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
Index: scm-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/scm-lang.c,v
retrieving revision 1.23
diff -u -p -r1.23 scm-lang.c
--- scm-lang.c	10 Apr 2004 22:10:01 -0000	1.23
+++ scm-lang.c	5 Jul 2004 20:19:26 -0000
@@ -266,6 +266,7 @@ const struct language_defn scm_language_
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"#o%lo", "#o", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */

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

* Re: [RFA]: Make class_name_from_physname part of language vector
  2004-07-05 20:21 [RFA]: Make class_name_from_physname part of language vector Jeff Johnston
@ 2004-07-05 21:50 ` Daniel Jacobowitz
  2004-07-05 23:50   ` Jeff Johnston
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Jacobowitz @ 2004-07-05 21:50 UTC (permalink / raw)
  To: Jeff Johnston; +Cc: gdb-patches

On Mon, Jul 05, 2004 at 04:21:20PM -0400, Jeff Johnston wrote:
> >You've left in a lot of hokery from the C++ support which I'm
> >reasonably confident Java does not need.  I don't believe that Java
> >mangled names will ever have templates, or classes nested inside of
> >functions, or multiple argument lists - no depth at all.  Also, I'd
> >appreciate it if you called it something other than
> >find_last_component; the C++ version shouldn't have such a generic name
> >either, IMO.
> >
> >Otherwise this looks fine.

> I have made the changes you recommended.  The function now only looks for 
> the opening parenthesis.  I renamed it to "find_member_function_name" as 
> well.

Sorry I wasn't clear - I was hoping for something that said it was for
Java.  Maybe java_find_last_component?  Also:

> +/* Find the member function name of the demangled name NAME.  NAME
> +   must be a method name including arguments, in order to correctly
> +   locate the last component.
> +
> +   This function return a pointer to the first dot before the
> +   member function name, or NULL if the name was not of the
> +   expected form.  */
> +
> +static const char *
> +find_member_function_name (const char *name)
> +{
> +  const char *p;
> +  int depth;

DEPTH is now write-only.

> +
> +  /* Functions can have local classes, so we need to find the
> +     beginning of the last argument list, not the end of the first
> +     one.  */
> +  p = name + strlen (name) - 1;
> +  while (p > name && *p != ')')
> +    p--;

Is this true for Java?

I don't think it is.  If it isn't, you can just search forward for the
first '(' (and use strchr, even - I'm not sure why the old code doesn't
use strrchr).


-- 
Daniel Jacobowitz


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

* Re: [RFA]: Make class_name_from_physname part of language vector
  2004-07-05 21:50 ` Daniel Jacobowitz
@ 2004-07-05 23:50   ` Jeff Johnston
  2004-07-06 14:29     ` Daniel Jacobowitz
  0 siblings, 1 reply; 8+ messages in thread
From: Jeff Johnston @ 2004-07-05 23:50 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

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

Daniel Jacobowitz wrote:
> On Mon, Jul 05, 2004 at 04:21:20PM -0400, Jeff Johnston wrote:
> 
>>>You've left in a lot of hokery from the C++ support which I'm
>>>reasonably confident Java does not need.  I don't believe that Java
>>>mangled names will ever have templates, or classes nested inside of
>>>functions, or multiple argument lists - no depth at all.  Also, I'd
>>>appreciate it if you called it something other than
>>>find_last_component; the C++ version shouldn't have such a generic name
>>>either, IMO.
>>>
>>>Otherwise this looks fine.
> 
> 
>>I have made the changes you recommended.  The function now only looks for 
>>the opening parenthesis.  I renamed it to "find_member_function_name" as 
>>well.
> 
> 
> Sorry I wasn't clear - I was hoping for something that said it was for
> Java.  Maybe java_find_last_component?  Also:
>

Oops.  I thought you meant the functional description was too generic.  Anyway, 
changed to java_find_last_component.

> 
>>+/* Find the member function name of the demangled name NAME.  NAME
>>+   must be a method name including arguments, in order to correctly
>>+   locate the last component.
>>+
>>+   This function return a pointer to the first dot before the
>>+   member function name, or NULL if the name was not of the
>>+   expected form.  */
>>+
>>+static const char *
>>+find_member_function_name (const char *name)
>>+{
>>+  const char *p;
>>+  int depth;
> 
> 
> DEPTH is now write-only.
> 

Deleted.

> 
>>+
>>+  /* Functions can have local classes, so we need to find the
>>+     beginning of the last argument list, not the end of the first
>>+     one.  */
>>+  p = name + strlen (name) - 1;
>>+  while (p > name && *p != ')')
>>+    p--;
> 
> 
> Is this true for Java?
> 
> I don't think it is.  If it isn't, you can just search forward for the
> first '(' (and use strchr, even - I'm not sure why the old code doesn't
> use strrchr).
>

No, you're correct.  I have simplified the code.

New ChangeLog with name change:

2004-07-05  Jeff Johnston <jjohnstn@redhat.com>

         * language.h (struct_language_defn): Add new function pointer:
         la_class_name_from_physname.  Also add new prototype for
         language_class_name_from_physname.
         * language.c (language_class_name_from_physname): New function.
         (unk_lang_class_name): Ditto.
         (unknown_language_defn, auto_language_defn): Change
         to add unk_lang_class_name function pointer for
         la_class_name_from_physname.
         (local_language_defn): Ditto.
         * dwarf2read.c (guess_structure_name): Change to call
         language_class_name_from_physname.
         (determine_class_name): Ditto.
         * cp-support.c (class_name_from_physname): Renamed.
         (cp_class_name_from_physname): New name of function.
         * cp-support.h: Ditto.
         * c-lang.c (c_language_defn): Change to add NULL
         for class_name_from_physname function pointer.
         (cplus_language_defn): Change to add cp_class_name_from_physname.
         * jv-lang.c (java_class_name_physname): New function.
         (java_find_last_component): New static routine.
         (java_language_defn): Add java_class_name_from_physname pointer.
         * ada-lang.c (ada_language_defn): Change to add NULL
         for class_name_from_physname function pointer.
         * f-lang.c (f_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.

-- Jeff J.

> 

[-- Attachment #2: class_name.patch2 --]
[-- Type: text/plain, Size: 14774 bytes --]

Index: cp-support.h
===================================================================
RCS file: /cvs/src/src/gdb/cp-support.h,v
retrieving revision 1.13
diff -u -p -r1.13 cp-support.h
--- cp-support.h	2 Feb 2004 20:44:52 -0000	1.13
+++ cp-support.h	5 Jul 2004 23:44:36 -0000
@@ -52,7 +52,7 @@ struct using_direct
 
 /* Functions from cp-support.c.  */
 
-extern char *class_name_from_physname (const char *physname);
+extern char *cp_class_name_from_physname (const char *physname);
 
 extern char *method_name_from_physname (const char *physname);
 
Index: language.h
===================================================================
RCS file: /cvs/src/src/gdb/language.h,v
retrieving revision 1.26
diff -u -p -r1.26 language.h
--- language.h	10 Apr 2004 22:10:01 -0000	1.26
+++ language.h	5 Jul 2004 23:44:36 -0000
@@ -247,6 +247,9 @@ struct language_defn
     /* Return demangled language symbol, or NULL.  */
     char *(*la_demangle) (const char *mangled, int options);
 
+    /* Return class name of a mangled method name or NULL.  */
+    char *(*la_class_name_from_physname) (const char *physname);
+
     /* Base 2 (binary) formats. */
 
     struct language_format_info la_binary_format;
@@ -516,6 +519,10 @@ extern CORE_ADDR skip_language_trampolin
 extern char *language_demangle (const struct language_defn *current_language, 
 				const char *mangled, int options);
 
+/* Return class name from physname, or NULL.  */
+extern char *language_class_name_from_physname (const struct language_defn *,
+					        const char *physname);
+
 /* Splitting strings into words.  */
 extern char *default_word_break_characters (void);
 
Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.46
diff -u -p -r1.46 ada-lang.c
--- ada-lang.c	1 Jul 2004 10:30:57 -0000	1.46
+++ ada-lang.c	5 Jul 2004 23:44:36 -0000
@@ -10144,6 +10144,7 @@ const struct language_defn ada_language_
   ada_lookup_symbol_nonlocal,   /* Looking up non-local symbols.  */
   basic_lookup_transparent_type,        /* lookup_transparent_type */
   ada_la_decode,                /* Language specific symbol demangler */
+  NULL,                         /* Language specific class_name_from_physname */
   {"", "", "", ""},             /* Binary format info */
 #if 0
   {"8#%lo#", "8#", "o", "#"},   /* Octal format info */
Index: c-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/c-lang.c,v
retrieving revision 1.27
diff -u -p -r1.27 c-lang.c
--- c-lang.c	10 Apr 2004 22:10:00 -0000	1.27
+++ c-lang.c	5 Jul 2004 23:44:36 -0000
@@ -559,6 +559,7 @@ const struct language_defn c_language_de
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
@@ -618,6 +619,7 @@ const struct language_defn cplus_languag
   cp_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   cp_lookup_transparent_type,   /* lookup_transparent_type */
   cplus_demangle,		/* Language specific symbol demangler */
+  cp_class_name_from_physname,  /* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
@@ -654,6 +656,7 @@ const struct language_defn asm_language_
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
@@ -695,6 +698,7 @@ const struct language_defn minimal_langu
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
Index: cp-support.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-support.c,v
retrieving revision 1.12
diff -u -p -r1.12 cp-support.c
--- cp-support.c	2 Feb 2004 20:44:52 -0000	1.12
+++ cp-support.c	5 Jul 2004 23:44:36 -0000
@@ -148,7 +148,7 @@ find_last_component (const char *name)
 /* Return the name of the class containing method PHYSNAME.  */
 
 char *
-class_name_from_physname (const char *physname)
+cp_class_name_from_physname (const char *physname)
 {
   char *ret = NULL;
   const char *end;
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.155
diff -u -p -r1.155 dwarf2read.c
--- dwarf2read.c	24 Jun 2004 20:42:42 -0000	1.155
+++ dwarf2read.c	5 Jul 2004 23:44:37 -0000
@@ -1840,7 +1840,8 @@ guess_structure_name (struct partial_die
 	  if (child_pdi->tag == DW_TAG_subprogram)
 	    {
 	      char *actual_class_name
-		= class_name_from_physname (child_pdi->name);
+		= language_class_name_from_physname (cu->language_defn,
+						     child_pdi->name);
 	      if (actual_class_name != NULL)
 		{
 		  struct_pdi->name
@@ -3557,7 +3558,9 @@ determine_class_name (struct die_info *d
 	{
 	  if (child->tag == DW_TAG_subprogram)
 	    {
-	      new_prefix = class_name_from_physname (dwarf2_linkage_name
+	      new_prefix 
+		= language_class_name_from_physname (cu->language_defn,
+						     dwarf2_linkage_name
 						     (child, cu));
 
 	      if (new_prefix != NULL)
Index: f-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/f-lang.c,v
retrieving revision 1.23
diff -u -p -r1.23 f-lang.c
--- f-lang.c	10 Apr 2004 22:10:00 -0000	1.23
+++ f-lang.c	5 Jul 2004 23:44:37 -0000
@@ -478,6 +478,7 @@ const struct language_defn f_language_de
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%o", "0", "o", ""},	/* Octal format info */
   {"%d", "", "d", ""},		/* Decimal format info */
Index: jv-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/jv-lang.c,v
retrieving revision 1.30
diff -u -p -r1.30 jv-lang.c
--- jv-lang.c	10 Apr 2004 22:10:00 -0000	1.30
+++ jv-lang.c	5 Jul 2004 23:44:37 -0000
@@ -62,6 +62,8 @@ static struct value *java_value_string (
 
 static void java_emit_char (int c, struct ui_file * stream, int quoter);
 
+static char *java_class_name_from_physname (const char *physname);
+
 /* This objfile contains symtabs that have been dynamically created
    to record dynamically loaded Java classes and dynamically
    compiled java methods. */
@@ -975,6 +977,59 @@ static char *java_demangle (const char *
   return cplus_demangle (mangled, options | DMGL_JAVA);
 }
 
+/* Find the member function name of the demangled name NAME.  NAME
+   must be a method name including arguments, in order to correctly
+   locate the last component.
+
+   This function return a pointer to the first dot before the
+   member function name, or NULL if the name was not of the
+   expected form.  */
+
+static const char *
+java_find_last_component (const char *name)
+{
+  const char *p;
+
+  /* Find argument list.  */
+  p = strchr (name, '(');
+
+  if (p == NULL)
+    return NULL;
+
+  /* Back up and find first dot prior to argument list.  */
+  while (p > name && *p != '.')
+    p--;
+
+  if (p == name)
+    return NULL;
+
+  return p;
+}
+
+/* Return the name of the class containing method PHYSNAME.  */
+
+static char *
+java_class_name_from_physname (const char *physname) 
+{
+  char *ret = NULL;
+  const char *end;
+  int depth = 0;
+  char *demangled_name = java_demangle (physname, DMGL_PARAMS | DMGL_ANSI);
+
+  if (demangled_name == NULL)
+    return NULL;
+
+  end = java_find_last_component (demangled_name);
+  if (end != NULL)
+    {
+      ret = xmalloc (end - demangled_name + 1);
+      memcpy (ret, demangled_name, end - demangled_name);
+      ret[end - demangled_name] = '\0';
+    }
+
+  xfree (demangled_name);
+  return ret;
+}
 
 /* Table mapping opcodes into strings for printing operators
    and precedences of the operators.  */
@@ -1049,6 +1104,7 @@ const struct language_defn java_language
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   java_demangle,		/* Language specific symbol demangler */
+  java_class_name_from_physname,/* Language specific class name */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
Index: language.c
===================================================================
RCS file: /cvs/src/src/gdb/language.c,v
retrieving revision 1.44
diff -u -p -r1.44 language.c
--- language.c	10 Apr 2004 22:10:00 -0000	1.44
+++ language.c	5 Jul 2004 23:44:37 -0000
@@ -1176,6 +1176,16 @@ language_demangle (const struct language
   return NULL;
 }
 
+/* Return class name from physname or NULL.  */
+char *
+language_class_name_from_physname (const struct language_defn *current_language,
+				   const char *physname)
+{
+  if (current_language != NULL && current_language->la_class_name_from_physname)
+    return current_language->la_class_name_from_physname (physname);
+  return NULL;
+}
+
 /* Return the default string containing the list of characters
    delimiting words.  This is a reasonable default value that
    most languages should be able to use.  */
@@ -1258,6 +1268,10 @@ static char *unk_lang_demangle (const ch
   return cplus_demangle (mangled, options);
 }
 
+static char *unk_lang_class_name (const char *mangled)
+{
+  return NULL;
+}
 
 static struct type **const (unknown_builtin_types[]) =
 {
@@ -1292,6 +1306,7 @@ const struct language_defn unknown_langu
   basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   unk_lang_demangle,		/* Language specific symbol demangler */
+  unk_lang_class_name,		/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
@@ -1329,6 +1344,7 @@ const struct language_defn auto_language
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   unk_lang_demangle,		/* Language specific symbol demangler */
+  unk_lang_class_name,		/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
@@ -1365,6 +1381,7 @@ const struct language_defn local_languag
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   unk_lang_demangle,		/* Language specific symbol demangler */
+  unk_lang_class_name,		/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
Index: m2-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/m2-lang.c,v
retrieving revision 1.16
diff -u -p -r1.16 m2-lang.c
--- m2-lang.c	10 Apr 2004 22:10:01 -0000	1.16
+++ m2-lang.c	5 Jul 2004 23:44:37 -0000
@@ -431,6 +431,7 @@ const struct language_defn m2_language_d
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"%loB", "", "o", "B"},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
Index: objc-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/objc-lang.c,v
retrieving revision 1.35
diff -u -p -r1.35 objc-lang.c
--- objc-lang.c	10 Apr 2004 22:10:01 -0000	1.35
+++ objc-lang.c	5 Jul 2004 23:44:37 -0000
@@ -675,6 +675,7 @@ const struct language_defn objc_language
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   objc_demangle,		/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"",     "",    "",  ""},	/* Binary format info */
   {"0%lo",  "0",   "o", ""},	/* Octal format info */
   {"%ld",   "",    "d", ""},	/* Decimal format info */
Index: p-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/p-lang.c,v
retrieving revision 1.18
diff -u -p -r1.18 p-lang.c
--- p-lang.c	10 Apr 2004 22:09:59 -0000	1.18
+++ p-lang.c	5 Jul 2004 23:44:37 -0000
@@ -467,6 +467,7 @@ const struct language_defn pascal_langua
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "%", "b", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
Index: scm-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/scm-lang.c,v
retrieving revision 1.23
diff -u -p -r1.23 scm-lang.c
--- scm-lang.c	10 Apr 2004 22:10:01 -0000	1.23
+++ scm-lang.c	5 Jul 2004 23:44:37 -0000
@@ -266,6 +266,7 @@ const struct language_defn scm_language_
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"#o%lo", "#o", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */

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

* Re: [RFA]: Make class_name_from_physname part of language vector
  2004-07-05 23:50   ` Jeff Johnston
@ 2004-07-06 14:29     ` Daniel Jacobowitz
  2004-07-06 19:29       ` Jeff Johnston
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Jacobowitz @ 2004-07-06 14:29 UTC (permalink / raw)
  To: Jeff Johnston; +Cc: gdb-patches

On Mon, Jul 05, 2004 at 07:50:38PM -0400, Jeff Johnston wrote:
> New ChangeLog with name change:
> 
> 2004-07-05  Jeff Johnston <jjohnstn@redhat.com>
> 
>         * language.h (struct_language_defn): Add new function pointer:
>         la_class_name_from_physname.  Also add new prototype for
>         language_class_name_from_physname.
>         * language.c (language_class_name_from_physname): New function.
>         (unk_lang_class_name): Ditto.
>         (unknown_language_defn, auto_language_defn): Change
>         to add unk_lang_class_name function pointer for
>         la_class_name_from_physname.
>         (local_language_defn): Ditto.
>         * dwarf2read.c (guess_structure_name): Change to call
>         language_class_name_from_physname.
>         (determine_class_name): Ditto.
>         * cp-support.c (class_name_from_physname): Renamed.
>         (cp_class_name_from_physname): New name of function.
>         * cp-support.h: Ditto.
>         * c-lang.c (c_language_defn): Change to add NULL
>         for class_name_from_physname function pointer.
>         (cplus_language_defn): Change to add cp_class_name_from_physname.
>         * jv-lang.c (java_class_name_physname): New function.
>         (java_find_last_component): New static routine.
>         (java_language_defn): Add java_class_name_from_physname pointer.
>         * ada-lang.c (ada_language_defn): Change to add NULL
>         for class_name_from_physname function pointer.
>         * f-lang.c (f_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.

Thanks, this version is OK.

-- 
Daniel Jacobowitz


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

* Re: [RFA]: Make class_name_from_physname part of language vector
  2004-07-06 14:29     ` Daniel Jacobowitz
@ 2004-07-06 19:29       ` Jeff Johnston
  0 siblings, 0 replies; 8+ messages in thread
From: Jeff Johnston @ 2004-07-06 19:29 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

Patch checked in.  Thanks.

-- Jeff J.

Daniel Jacobowitz wrote:
> On Mon, Jul 05, 2004 at 07:50:38PM -0400, Jeff Johnston wrote:
> 
>>New ChangeLog with name change:
>>
>>2004-07-05  Jeff Johnston <jjohnstn@redhat.com>
>>
>>        * language.h (struct_language_defn): Add new function pointer:
>>        la_class_name_from_physname.  Also add new prototype for
>>        language_class_name_from_physname.
>>        * language.c (language_class_name_from_physname): New function.
>>        (unk_lang_class_name): Ditto.
>>        (unknown_language_defn, auto_language_defn): Change
>>        to add unk_lang_class_name function pointer for
>>        la_class_name_from_physname.
>>        (local_language_defn): Ditto.
>>        * dwarf2read.c (guess_structure_name): Change to call
>>        language_class_name_from_physname.
>>        (determine_class_name): Ditto.
>>        * cp-support.c (class_name_from_physname): Renamed.
>>        (cp_class_name_from_physname): New name of function.
>>        * cp-support.h: Ditto.
>>        * c-lang.c (c_language_defn): Change to add NULL
>>        for class_name_from_physname function pointer.
>>        (cplus_language_defn): Change to add cp_class_name_from_physname.
>>        * jv-lang.c (java_class_name_physname): New function.
>>        (java_find_last_component): New static routine.
>>        (java_language_defn): Add java_class_name_from_physname pointer.
>>        * ada-lang.c (ada_language_defn): Change to add NULL
>>        for class_name_from_physname function pointer.
>>        * f-lang.c (f_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.
> 
> 
> Thanks, this version is OK.
> 


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

* Re: [RFA]: Make class_name_from_physname part of language vector
  2004-05-14 23:37 Jeff Johnston
  2004-06-11 17:49 ` Jeff Johnston
@ 2004-06-17  2:18 ` Daniel Jacobowitz
  1 sibling, 0 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2004-06-17  2:18 UTC (permalink / raw)
  To: gdb-patches

On Fri, May 14, 2004 at 07:37:31PM -0400, Jeff Johnston wrote:
> Index: jv-lang.c

> +  /* P now points at the `)' at the end of the argument list.  Walk
> +     back to the beginning.  */
> +  p--;
> +  depth = 1;
> +  while (p > name && depth > 0)
> +    {
> +      if (*p == '<' || *p == '(')
> +	depth--;
> +      else if (*p == '>' || *p == ')')
> +	depth++;
> +      p--;
> +    }
> +
> +  if (p == name)
> +    return NULL;
> +
> +  while (p > name && *p != '.')
> +    p--;

You've left in a lot of hokery from the C++ support which I'm
reasonably confident Java does not need.  I don't believe that Java
mangled names will ever have templates, or classes nested inside of
functions, or multiple argument lists - no depth at all.  Also, I'd
appreciate it if you called it something other than
find_last_component; the C++ version shouldn't have such a generic name
either, IMO.

Otherwise this looks fine.

-- 
Daniel Jacobowitz


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

* Re: [RFA]: Make class_name_from_physname part of language vector
  2004-05-14 23:37 Jeff Johnston
@ 2004-06-11 17:49 ` Jeff Johnston
  2004-06-17  2:18 ` Daniel Jacobowitz
  1 sibling, 0 replies; 8+ messages in thread
From: Jeff Johnston @ 2004-06-11 17:49 UTC (permalink / raw)
  To: Jeff Johnston; +Cc: gdb-patches

Ping.

Jeff Johnston wrote:
> The attached patch is a fix for Java support.  Currently, dwarf2read.c 
> calls class_name_from_physname to get a class name.  This code currently 
> resides in the cp-support.c file and is C++ specific as it parses 
> looking for "::".
> 
> This patch changes it so the class_name_from_physname becomes a function 
> in the language definition.  The current class_name_from_physname 
> routine is the C++ version and is renamed.
> 
> Ok to commit?
> 
> 2004-05-14  Jeff Johnston  <jjohnstn@redhat.com>
> 
>     * language.h (struct_language_defn): Add new function pointer:
>     la_class_name_from_physname.  Also add new prototype for
>     language_class_name_from_physname.
>     * language.c (language_class_name_from_physname): New function.
>     (unk_lang_class_name): Ditto.
>     (unknown_language_defn, auto_language_defn): Change
>     to add unk_lang_class_name function pointer for
>     la_class_name_from_physname.
>     (local_language_defn): Ditto.
>     * dwarf2read.c (guess_structure_name): Change to call
>     language_class_name_from_physname.
>     (determine_class_name): Ditto.
>     * cp-support.c (class_name_from_physname): Renamed.
>     (cp_class_name_from_physname): New name of function.
>     * cp-support.h: Ditto.
>     * c-lang.c (c_language_defn): Change to add NULL
>     for class_name_from_physname function pointer.
>     (cplus_language_defn): Change to add cp_class_name_from_physname.
>     * jv-lang.c (java_class_name_physname): New function.
>     (find_last_component): New static routine.
>     (java_language_defn): Add java_class_name_from_physname pointer.
>     * ada-lang.c (ada_language_defn): Change to add NULL
>     for class_name_from_physname function pointer.
>     * f-lang.c (f_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.
> 
>     
>     


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

* [RFA]: Make class_name_from_physname part of language vector
@ 2004-05-14 23:37 Jeff Johnston
  2004-06-11 17:49 ` Jeff Johnston
  2004-06-17  2:18 ` Daniel Jacobowitz
  0 siblings, 2 replies; 8+ messages in thread
From: Jeff Johnston @ 2004-05-14 23:37 UTC (permalink / raw)
  To: gdb-patches

The attached patch is a fix for Java support.  Currently, dwarf2read.c calls 
class_name_from_physname to get a class name.  This code currently resides in 
the cp-support.c file and is C++ specific as it parses looking for "::".

This patch changes it so the class_name_from_physname becomes a function in the 
language definition.  The current class_name_from_physname routine is the C++ 
version and is renamed.

Ok to commit?

2004-05-14  Jeff Johnston  <jjohnstn@redhat.com>

	* language.h (struct_language_defn): Add new function pointer:
	la_class_name_from_physname.  Also add new prototype for
	language_class_name_from_physname.
	* language.c (language_class_name_from_physname): New function.
	(unk_lang_class_name): Ditto.
	(unknown_language_defn, auto_language_defn): Change
	to add unk_lang_class_name function pointer for
	la_class_name_from_physname.
	(local_language_defn): Ditto.
	* dwarf2read.c (guess_structure_name): Change to call
	language_class_name_from_physname.
	(determine_class_name): Ditto.
	* cp-support.c (class_name_from_physname): Renamed.
	(cp_class_name_from_physname): New name of function.
	* cp-support.h: Ditto.
	* c-lang.c (c_language_defn): Change to add NULL
	for class_name_from_physname function pointer.
	(cplus_language_defn): Change to add cp_class_name_from_physname.
	* jv-lang.c (java_class_name_physname): New function.
	(find_last_component): New static routine.
	(java_language_defn): Add java_class_name_from_physname pointer.
	* ada-lang.c (ada_language_defn): Change to add NULL
	for class_name_from_physname function pointer.
	* f-lang.c (f_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: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.35
diff -u -p -r1.35 ada-lang.c
--- ada-lang.c	23 Jan 2004 23:03:28 -0000	1.35
+++ ada-lang.c	14 May 2004 23:03:34 -0000
@@ -8021,6 +8021,7 @@ const struct language_defn ada_language_
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal  */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
 #if 0
   {"8#%lo#", "8#", "o", "#"},	/* Octal format info */
Index: c-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/c-lang.c,v
retrieving revision 1.27
diff -u -p -r1.27 c-lang.c
--- c-lang.c	10 Apr 2004 22:10:00 -0000	1.27
+++ c-lang.c	14 May 2004 23:03:34 -0000
@@ -559,6 +559,7 @@ const struct language_defn c_language_de
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
@@ -618,6 +619,7 @@ const struct language_defn cplus_languag
   cp_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   cp_lookup_transparent_type,   /* lookup_transparent_type */
   cplus_demangle,		/* Language specific symbol demangler */
+  cp_class_name_from_physname,  /* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
@@ -654,6 +656,7 @@ const struct language_defn asm_language_
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
@@ -695,6 +698,7 @@ const struct language_defn minimal_langu
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
Index: cp-support.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-support.c,v
retrieving revision 1.12
diff -u -p -r1.12 cp-support.c
--- cp-support.c	2 Feb 2004 20:44:52 -0000	1.12
+++ cp-support.c	14 May 2004 23:03:34 -0000
@@ -148,7 +148,7 @@ find_last_component (const char *name)
 /* Return the name of the class containing method PHYSNAME.  */
 
 char *
-class_name_from_physname (const char *physname)
+cp_class_name_from_physname (const char *physname)
 {
   char *ret = NULL;
   const char *end;
Index: cp-support.h
===================================================================
RCS file: /cvs/src/src/gdb/cp-support.h,v
retrieving revision 1.13
diff -u -p -r1.13 cp-support.h
--- cp-support.h	2 Feb 2004 20:44:52 -0000	1.13
+++ cp-support.h	14 May 2004 23:03:34 -0000
@@ -52,7 +52,7 @@ struct using_direct
 
 /* Functions from cp-support.c.  */
 
-extern char *class_name_from_physname (const char *physname);
+extern char *cp_class_name_from_physname (const char *physname);
 
 extern char *method_name_from_physname (const char *physname);
 
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.151
diff -u -p -r1.151 dwarf2read.c
--- dwarf2read.c	7 May 2004 14:29:33 -0000	1.151
+++ dwarf2read.c	14 May 2004 23:03:34 -0000
@@ -1836,7 +1836,8 @@ guess_structure_name (struct partial_die
 	  if (child_pdi->tag == DW_TAG_subprogram)
 	    {
 	      char *actual_class_name
-		= class_name_from_physname (child_pdi->name);
+		= language_class_name_from_physname (cu->language_defn,
+						     child_pdi->name);
 	      if (actual_class_name != NULL)
 		{
 		  struct_pdi->name
@@ -3560,7 +3561,9 @@ determine_class_name (struct die_info *d
 	{
 	  if (child->tag == DW_TAG_subprogram)
 	    {
-	      new_prefix = class_name_from_physname (dwarf2_linkage_name
+	      new_prefix 
+		= language_class_name_from_physname (cu->language_defn,
+						     dwarf2_linkage_name
 						     (child, cu));
 
 	      if (new_prefix != NULL)
Index: f-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/f-lang.c,v
retrieving revision 1.23
diff -u -p -r1.23 f-lang.c
--- f-lang.c	10 Apr 2004 22:10:00 -0000	1.23
+++ f-lang.c	14 May 2004 23:03:35 -0000
@@ -478,6 +478,7 @@ const struct language_defn f_language_de
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%o", "0", "o", ""},	/* Octal format info */
   {"%d", "", "d", ""},		/* Decimal format info */
Index: jv-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/jv-lang.c,v
retrieving revision 1.30
diff -u -p -r1.30 jv-lang.c
--- jv-lang.c	10 Apr 2004 22:10:00 -0000	1.30
+++ jv-lang.c	14 May 2004 23:03:35 -0000
@@ -62,6 +62,8 @@ static struct value *java_value_string (
 
 static void java_emit_char (int c, struct ui_file * stream, int quoter);
 
+static char *java_class_name_from_physname (const char *physname);
+
 /* This objfile contains symtabs that have been dynamically created
    to record dynamically loaded Java classes and dynamically
    compiled java methods. */
@@ -975,6 +977,78 @@ static char *java_demangle (const char *
   return cplus_demangle (mangled, options | DMGL_JAVA);
 }
 
+/* Find the last component of the demangled name NAME.  NAME
+   must be a method name including arguments, in order to correctly
+   locate the last component.
+
+   This function return a pointer to the first dot before the
+   last component, or NULL if the name had only one component.  */
+
+static const char *
+find_last_component (const char *name)
+{
+  const char *p;
+  int depth;
+
+  /* Functions can have local classes, so we need to find the
+     beginning of the last argument list, not the end of the first
+     one.  */
+  p = name + strlen (name) - 1;
+  while (p > name && *p != ')')
+    p--;
+
+  if (p == name)
+    return NULL;
+
+  /* P now points at the `)' at the end of the argument list.  Walk
+     back to the beginning.  */
+  p--;
+  depth = 1;
+  while (p > name && depth > 0)
+    {
+      if (*p == '<' || *p == '(')
+	depth--;
+      else if (*p == '>' || *p == ')')
+	depth++;
+      p--;
+    }
+
+  if (p == name)
+    return NULL;
+
+  while (p > name && *p != '.')
+    p--;
+
+  if (p == name)
+    return NULL;
+
+  return p;
+}
+
+/* Return the name of the class containing method PHYSNAME.  */
+
+static char *
+java_class_name_from_physname (const char *physname) 
+{
+  char *ret = NULL;
+  const char *end;
+  int depth = 0;
+  char *demangled_name = java_demangle (physname, DMGL_PARAMS | DMGL_ANSI);
+
+  if (demangled_name == NULL)
+    return NULL;
+
+  end = find_last_component (demangled_name);
+  if (end != NULL)
+    {
+      ret = xmalloc (end - demangled_name + 1);
+      memcpy (ret, demangled_name, end - demangled_name);
+      ret[end - demangled_name] = '\0';
+    }
+
+  xfree (demangled_name);
+  return ret;
+}
 
 /* Table mapping opcodes into strings for printing operators
    and precedences of the operators.  */
@@ -1049,6 +1123,7 @@ const struct language_defn java_language
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   java_demangle,		/* Language specific symbol demangler */
+  java_class_name_from_physname,/* Language specific class name */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
Index: language.c
===================================================================
RCS file: /cvs/src/src/gdb/language.c,v
retrieving revision 1.44
diff -u -p -r1.44 language.c
--- language.c	10 Apr 2004 22:10:00 -0000	1.44
+++ language.c	14 May 2004 23:03:35 -0000
@@ -1176,6 +1176,16 @@ language_demangle (const struct language
   return NULL;
 }
 
+/* Return class name from physname or NULL.  */
+char *
+language_class_name_from_physname (const struct language_defn *current_language,
+				   const char *physname)
+{
+  if (current_language != NULL && current_language->la_class_name_from_physname)
+    return current_language->la_class_name_from_physname (physname);
+  return NULL;
+}
+
 /* Return the default string containing the list of characters
    delimiting words.  This is a reasonable default value that
    most languages should be able to use.  */
@@ -1258,6 +1268,10 @@ static char *unk_lang_demangle (const ch
   return cplus_demangle (mangled, options);
 }
 
+static char *unk_lang_class_name (const char *mangled)
+{
+  return NULL;
+}
 
 static struct type **const (unknown_builtin_types[]) =
 {
@@ -1292,6 +1306,7 @@ const struct language_defn unknown_langu
   basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   unk_lang_demangle,		/* Language specific symbol demangler */
+  unk_lang_class_name,		/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
@@ -1329,6 +1344,7 @@ const struct language_defn auto_language
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   unk_lang_demangle,		/* Language specific symbol demangler */
+  unk_lang_class_name,		/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
@@ -1365,6 +1381,7 @@ const struct language_defn local_languag
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   unk_lang_demangle,		/* Language specific symbol demangler */
+  unk_lang_class_name,		/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
Index: language.h
===================================================================
RCS file: /cvs/src/src/gdb/language.h,v
retrieving revision 1.26
diff -u -p -r1.26 language.h
--- language.h	10 Apr 2004 22:10:01 -0000	1.26
+++ language.h	14 May 2004 23:03:35 -0000
@@ -247,6 +247,9 @@ struct language_defn
     /* Return demangled language symbol, or NULL.  */
     char *(*la_demangle) (const char *mangled, int options);
 
+    /* Return class name of a mangled method name or NULL.  */
+    char *(*la_class_name_from_physname) (const char *physname);
+
     /* Base 2 (binary) formats. */
 
     struct language_format_info la_binary_format;
@@ -515,6 +518,10 @@ extern CORE_ADDR skip_language_trampolin
 /* Return demangled language symbol, or NULL.  */
 extern char *language_demangle (const struct language_defn *current_language, 
 				const char *mangled, int options);
+
+/* Return class name from physname, or NULL.  */
+extern char *language_class_name_from_physname (const struct language_defn *,
+					        const char *physname);
 
 /* Splitting strings into words.  */
 extern char *default_word_break_characters (void);
Index: m2-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/m2-lang.c,v
retrieving revision 1.16
diff -u -p -r1.16 m2-lang.c
--- m2-lang.c	10 Apr 2004 22:10:01 -0000	1.16
+++ m2-lang.c	14 May 2004 23:03:35 -0000
@@ -431,6 +431,7 @@ const struct language_defn m2_language_d
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"%loB", "", "o", "B"},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
Index: objc-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/objc-lang.c,v
retrieving revision 1.35
diff -u -p -r1.35 objc-lang.c
--- objc-lang.c	10 Apr 2004 22:10:01 -0000	1.35
+++ objc-lang.c	14 May 2004 23:03:35 -0000
@@ -675,6 +675,7 @@ const struct language_defn objc_language
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   objc_demangle,		/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"",     "",    "",  ""},	/* Binary format info */
   {"0%lo",  "0",   "o", ""},	/* Octal format info */
   {"%ld",   "",    "d", ""},	/* Decimal format info */
Index: p-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/p-lang.c,v
retrieving revision 1.18
diff -u -p -r1.18 p-lang.c
--- p-lang.c	10 Apr 2004 22:09:59 -0000	1.18
+++ p-lang.c	14 May 2004 23:03:35 -0000
@@ -467,6 +467,7 @@ const struct language_defn pascal_langua
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "%", "b", ""},		/* Binary format info */
   {"0%lo", "0", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
Index: scm-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/scm-lang.c,v
retrieving revision 1.23
diff -u -p -r1.23 scm-lang.c
--- scm-lang.c	10 Apr 2004 22:10:01 -0000	1.23
+++ scm-lang.c	14 May 2004 23:03:35 -0000
@@ -266,6 +266,7 @@ const struct language_defn scm_language_
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
+  NULL,				/* Language specific class_name_from_physname */
   {"", "", "", ""},		/* Binary format info */
   {"#o%lo", "#o", "o", ""},	/* Octal format info */
   {"%ld", "", "d", ""},		/* Decimal format info */
From kevinb@redhat.com Sat May 15 00:05:00 2004
From: Kevin Buettner <kevinb@redhat.com>
To: Joel Brobecker <brobecker@gnat.com>
Cc: Jim Blandy <jimb@redhat.com>, gdb-patches@sources.redhat.com
Subject: Re: [RFA] Fix small problems in rs6000-tdep.c:skip_prologue()
Date: Sat, 15 May 2004 00:05:00 -0000
Message-id: <20040514170539.4727eec9@saguaro>
References: <20040402183637.GC871@gnat.com> <vt2u1026q1j.fsf@zenia.home> <20040417051545.GO22414@gnat.com> <20040508001600.GH16083@gnat.com> <vt2r7tmlkjs.fsf@zenia.home>
X-SW-Source: 2004-05/msg00438.html
Content-length: 1149

On 14 May 2004 17:18:31 -0500
Jim Blandy <jimb@redhat.com> wrote:

> > > Attached is a revised version incorporating your changes. Could you
> > > give it a shot against your function, and let me know if it works for
> > > you? It works for me, and doesn't introduce any regression on our
> > > powerpc-aix-5.1 machine.
> > > 
> > > 2004-04-16  Joel Brobecker  <brobecker@gnat.com>
> > > 
> > >         * rs6000-tdep.c (store_param_on_stack_p): New function,
> > >         an improved version of some code extracted from skip_prologue().
> > >         (skip_prologue): Use store_param_on_stack_p() to detect
> > >         instructions saving a parameter on the stack. Detect when r0
> > >         is used to save a parameter.
> > >         Do not mark "li rx, SIMM" instructions as part of the prologue,
> > >         unless the following instruction is also part of the prologue.
> > >         
> > > I'll followup with a testcase soon.
> 
> I've finally been able to give this a shot, and it works fine on my
> prologue, too.  So I have no objections to the patch.  Thanks for your
> patience, Joel!

Joel, your revised patch is approved.

Kevin


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

end of thread, other threads:[~2004-07-06 19:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-05 20:21 [RFA]: Make class_name_from_physname part of language vector Jeff Johnston
2004-07-05 21:50 ` Daniel Jacobowitz
2004-07-05 23:50   ` Jeff Johnston
2004-07-06 14:29     ` Daniel Jacobowitz
2004-07-06 19:29       ` Jeff Johnston
  -- strict thread matches above, loose matches on Subject: below --
2004-05-14 23:37 Jeff Johnston
2004-06-11 17:49 ` Jeff Johnston
2004-06-17  2:18 ` Daniel Jacobowitz

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