2004-07-27 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / gdb / jv-lang.c
index 92c263b3cac1258885f576fc3910d6826e72eaa4..3f68ec4051ffeba1d3cf079236fec9410c0db595 100644 (file)
@@ -62,6 +62,8 @@ static struct value *java_value_string (char *ptr, int len);
 
 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. */
@@ -104,19 +106,19 @@ get_java_class_symtab (void)
       class_symtab = allocate_symtab ("<java-classes>", objfile);
       class_symtab->language = language_java;
       bv = (struct blockvector *)
-       obstack_alloc (&objfile->symbol_obstack,
+       obstack_alloc (&objfile->objfile_obstack,
                       sizeof (struct blockvector) + sizeof (struct block *));
       BLOCKVECTOR_NBLOCKS (bv) = 1;
       BLOCKVECTOR (class_symtab) = bv;
 
       /* Allocate dummy STATIC_BLOCK. */
-      bl = allocate_block (&objfile->symbol_obstack);
-      BLOCK_DICT (bl) = dict_create_linear (&objfile->symbol_obstack,
+      bl = allocate_block (&objfile->objfile_obstack);
+      BLOCK_DICT (bl) = dict_create_linear (&objfile->objfile_obstack,
                                            NULL);
       BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = bl;
 
       /* Allocate GLOBAL_BLOCK.  */
-      bl = allocate_block (&objfile->symbol_obstack);
+      bl = allocate_block (&objfile->objfile_obstack);
       BLOCK_DICT (bl) = dict_create_hashed_expandable ();
       BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl;
       class_symtab->free_func = free_class_block;
@@ -139,7 +141,7 @@ add_class_symbol (struct type *type, CORE_ADDR addr)
 {
   struct symbol *sym;
   sym = (struct symbol *)
-    obstack_alloc (&dynamics_objfile->symbol_obstack, sizeof (struct symbol));
+    obstack_alloc (&dynamics_objfile->objfile_obstack, sizeof (struct symbol));
   memset (sym, 0, sizeof (struct symbol));
   SYMBOL_LANGUAGE (sym) = language_java;
   DEPRECATED_SYMBOL_NAME (sym) = TYPE_TAG_NAME (type);
@@ -186,7 +188,7 @@ java_lookup_class (char *name)
   type = alloc_type (objfile);
   TYPE_CODE (type) = TYPE_CODE_STRUCT;
   INIT_CPLUS_SPECIFIC (type);
-  TYPE_TAG_NAME (type) = obsavestring (name, strlen (name), &objfile->type_obstack);
+  TYPE_TAG_NAME (type) = obsavestring (name, strlen (name), &objfile->objfile_obstack);
   TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
   TYPE ? = addr;
   return type;
@@ -289,7 +291,7 @@ type_from_class (struct value *clas)
   /* if clasloader non-null, prepend loader address. FIXME */
   temp = clas;
   utf8_name = value_struct_elt (&temp, NULL, "name", NULL, "structure");
-  name = get_java_utf8_name (&objfile->type_obstack, utf8_name);
+  name = get_java_utf8_name (&objfile->objfile_obstack, utf8_name);
   for (nptr = name; *nptr != 0; nptr++)
     {
       if (*nptr == '/')
@@ -309,7 +311,7 @@ type_from_class (struct value *clas)
       char *signature = name;
       int namelen = java_demangled_signature_length (signature);
       if (namelen > strlen (name))
-       name = obstack_alloc (&objfile->type_obstack, namelen + 1);
+       name = obstack_alloc (&objfile->objfile_obstack, namelen + 1);
       java_demangled_signature_copy (name, signature);
       name[namelen] = '\0';
       is_array = 1;
@@ -442,7 +444,7 @@ java_link_class_type (struct type *type, struct value *clas)
       temp = field;
       temp = value_struct_elt (&temp, NULL, "name", NULL, "structure");
       TYPE_FIELD_NAME (type, i) =
-       get_java_utf8_name (&objfile->type_obstack, temp);
+       get_java_utf8_name (&objfile->objfile_obstack, temp);
       temp = field;
       accflags = value_as_long (value_struct_elt (&temp, NULL, "accflags",
                                                  NULL, "structure"));
@@ -488,7 +490,7 @@ java_link_class_type (struct type *type, struct value *clas)
   TYPE_NFN_FIELDS_TOTAL (type) = nmethods;
   j = nmethods * sizeof (struct fn_field);
   fn_fields = (struct fn_field *)
-    obstack_alloc (&dynamics_objfile->symbol_obstack, j);
+    obstack_alloc (&dynamics_objfile->objfile_obstack, j);
   memset (fn_fields, 0, j);
   fn_fieldlists = (struct fn_fieldlist *)
     alloca (nmethods * sizeof (struct fn_fieldlist));
@@ -513,7 +515,7 @@ java_link_class_type (struct type *type, struct value *clas)
       /* Get method name. */
       temp = method;
       temp = value_struct_elt (&temp, NULL, "name", NULL, "structure");
-      mname = get_java_utf8_name (&objfile->type_obstack, temp);
+      mname = get_java_utf8_name (&objfile->objfile_obstack, temp);
       if (strcmp (mname, "<init>") == 0)
        mname = unqualified_name;
 
@@ -538,7 +540,7 @@ java_link_class_type (struct type *type, struct value *clas)
            {                   /* Found an existing method with the same name. */
              int l;
              if (mname != unqualified_name)
-               obstack_free (&objfile->type_obstack, mname);
+               obstack_free (&objfile->objfile_obstack, mname);
              mname = fn_fieldlists[j].name;
              fn_fieldlists[j].length++;
              k = i - k;        /* Index of new slot. */
@@ -559,7 +561,7 @@ java_link_class_type (struct type *type, struct value *clas)
 
   j = TYPE_NFN_FIELDS (type) * sizeof (struct fn_fieldlist);
   TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
-    obstack_alloc (&dynamics_objfile->symbol_obstack, j);
+    obstack_alloc (&dynamics_objfile->objfile_obstack, j);
   memcpy (TYPE_FN_FIELDLISTS (type), fn_fieldlists, j);
 
   return type;
@@ -975,6 +977,59 @@ static char *java_demangle (const char *mangled, int options)
   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.  */
@@ -1036,6 +1091,7 @@ const struct language_defn java_language_defn =
   &exp_descriptor_java,
   java_parse,
   java_error,
+  null_post_parser,
   c_printchar,                 /* Print a character constant */
   c_printstr,                  /* Function to print string constant */
   java_emit_char,              /* Function to print a single character */
@@ -1048,6 +1104,7 @@ const struct language_defn java_language_defn =
   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 */
@@ -1057,6 +1114,7 @@ const struct language_defn java_language_defn =
   0,                           /* String lower bound */
   &builtin_type_char,          /* Type of string elements */
   default_word_break_characters,
+  NULL, /* FIXME: la_language_arch_info.  */
   LANG_MAGIC
 };
 
This page took 0.030644 seconds and 4 git commands to generate.