2003-04-15 David Carlton <carlton@math.stanford.edu>
[deliverable/binutils-gdb.git] / gdb / jv-lang.c
index 5a22f1ce5637c2ee18d0f89e05d537db3540da63..a44452b29b5fdc547c3227e1cc503430cc22b806 100644 (file)
@@ -1,5 +1,5 @@
 /* Java language support routines for GDB, the GNU debugger.
-   Copyright 1997, 1998, 1999-2000 Free Software Foundation, Inc.
+   Copyright 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -33,6 +33,8 @@
 #include "c-lang.h"
 #include "jv-lang.h"
 #include "gdbcore.h"
+#include "block.h"
+#include "demangle.h"
 #include <ctype.h>
 
 struct type *java_int_type;
@@ -53,10 +55,10 @@ static int java_demangled_signature_length (char *);
 static void java_demangled_signature_copy (char *, char *);
 
 static struct symtab *get_java_class_symtab (void);
-static char *get_java_utf8_name (struct obstack *obstack, value_ptr name);
-static int java_class_is_primitive (value_ptr clas);
+static char *get_java_utf8_name (struct obstack *obstack, struct value *name);
+static int java_class_is_primitive (struct value *clas);
 static struct type *java_lookup_type (char *signature);
-static value_ptr java_value_string (char *ptr, int len);
+static struct value *java_value_string (char *ptr, int len);
 
 static void java_emit_char (int c, struct ui_file * stream, int quoter);
 
@@ -66,7 +68,13 @@ static void java_emit_char (int c, struct ui_file * stream, int quoter);
 
 static struct objfile *dynamics_objfile = NULL;
 
-static struct type *java_link_class_type (struct type *, value_ptr);
+static struct type *java_link_class_type (struct type *, struct value *);
+
+/* FIXME: carlton/2003-02-04: This is the main or only caller of
+   allocate_objfile with first argument NULL; as a result, this code
+   breaks every so often.  Somebody should write a test case that
+   exercises GDB in various ways (e.g. something involving loading a
+   dynamic library) after this code has been called.  */
 
 static struct objfile *
 get_dynamics_objfile (void)
@@ -106,19 +114,20 @@ get_java_class_symtab (void)
       bl = (struct block *)
        obstack_alloc (&objfile->symbol_obstack, sizeof (struct block));
       BLOCK_NSYMS (bl) = 0;
+      BLOCK_HASHTABLE (bl) = 0;
       BLOCK_START (bl) = 0;
       BLOCK_END (bl) = 0;
       BLOCK_FUNCTION (bl) = NULL;
       BLOCK_SUPERBLOCK (bl) = NULL;
+      BLOCK_NAMESPACE (bl) = NULL;
       BLOCK_GCC_COMPILED (bl) = 0;
       BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = bl;
 
       /* Allocate GLOBAL_BLOCK.  This has to be relocatable. */
       class_symtab_space = 128;
-      bl = (struct block *)
-       mmalloc (objfile->md,
-                sizeof (struct block)
-                + ((class_symtab_space - 1) * sizeof (struct symbol *)));
+      bl = xmmalloc (objfile->md,
+                    sizeof (struct block)
+                    + ((class_symtab_space - 1) * sizeof (struct symbol *)));
       *bl = *BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
       BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl;
       class_symtab->free_ptr = (char *) bl;
@@ -136,10 +145,9 @@ add_class_symtab_symbol (struct symbol *sym)
     {
       /* Need to re-allocate. */
       class_symtab_space *= 2;
-      bl = (struct block *)
-       mrealloc (symtab->objfile->md, bl,
-                 sizeof (struct block)
-                 + ((class_symtab_space - 1) * sizeof (struct symbol *)));
+      bl = xmrealloc (symtab->objfile->md, bl,
+                     sizeof (struct block)
+                     + ((class_symtab_space - 1) * sizeof (struct symbol *)));
       class_symtab->free_ptr = (char *) bl;
       BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl;
     }
@@ -158,7 +166,7 @@ add_class_symbol (struct type *type, CORE_ADDR addr)
     obstack_alloc (&dynamics_objfile->symbol_obstack, sizeof (struct symbol));
   memset (sym, 0, sizeof (struct symbol));
   SYMBOL_LANGUAGE (sym) = language_java;
-  SYMBOL_NAME (sym) = TYPE_TAG_NAME (type);
+  DEPRECATED_SYMBOL_NAME (sym) = TYPE_TAG_NAME (type);
   SYMBOL_CLASS (sym) = LOC_TYPEDEF;
   /*  SYMBOL_VALUE (sym) = valu; */
   SYMBOL_TYPE (sym) = type;
@@ -206,10 +214,10 @@ java_lookup_class (char *name)
    a name given by NAME (which has type Utf8Const*). */
 
 char *
-get_java_utf8_name (struct obstack *obstack, value_ptr name)
+get_java_utf8_name (struct obstack *obstack, struct value *name)
 {
   char *chrs;
-  value_ptr temp = name;
+  struct value *temp = name;
   int name_length;
   CORE_ADDR data_addr;
   temp = value_struct_elt (&temp, NULL, "length", NULL, "structure");
@@ -222,17 +230,17 @@ get_java_utf8_name (struct obstack *obstack, value_ptr name)
   return chrs;
 }
 
-value_ptr
-java_class_from_object (value_ptr obj_val)
+struct value *
+java_class_from_object (struct value *obj_val)
 {
   /* This is all rather inefficient, since the offsets of vtable and
      class are fixed.  FIXME */
-  value_ptr vtable_val;
+  struct value *vtable_val;
 
   if (TYPE_CODE (VALUE_TYPE (obj_val)) == TYPE_CODE_PTR
       && TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (obj_val))) == 0)
     obj_val = value_at (get_java_object_type (),
-                       value_as_pointer (obj_val), NULL);
+                       value_as_address (obj_val), NULL);
 
   vtable_val = value_struct_elt (&obj_val, NULL, "vtable", NULL, "structure");
   return value_struct_elt (&vtable_val, NULL, "class", NULL, "structure");
@@ -240,23 +248,23 @@ java_class_from_object (value_ptr obj_val)
 
 /* Check if CLASS_IS_PRIMITIVE(value of clas): */
 static int
-java_class_is_primitive (value_ptr clas)
+java_class_is_primitive (struct value *clas)
 {
-  value_ptr vtable = value_struct_elt (&clas, NULL, "vtable", NULL, "struct");
-  CORE_ADDR i = value_as_pointer (vtable);
+  struct value *vtable = value_struct_elt (&clas, NULL, "vtable", NULL, "struct");
+  CORE_ADDR i = value_as_address (vtable);
   return (int) (i & 0x7fffffff) == (int) 0x7fffffff;
 }
 
 /* Read a GCJ Class object, and generated a gdb (TYPE_CODE_STRUCT) type. */
 
 struct type *
-type_from_class (value_ptr clas)
+type_from_class (struct value *clas)
 {
   struct type *type;
   char *name;
-  value_ptr temp;
+  struct value *temp;
   struct objfile *objfile;
-  value_ptr utf8_name;
+  struct value *utf8_name;
   char *nptr;
   CORE_ADDR addr;
   struct block *bl;
@@ -286,7 +294,7 @@ type_from_class (value_ptr clas)
   objfile = get_dynamics_objfile ();
   if (java_class_is_primitive (clas))
     {
-      value_ptr sig;
+      struct value *sig;
       temp = clas;
       sig = value_struct_elt (&temp, NULL, "method_count", NULL, "structure");
       return java_primitive_type (value_as_long (sig));
@@ -337,16 +345,19 @@ type_from_class (value_ptr clas)
 /* Fill in class TYPE with data from the CLAS value. */
 
 struct type *
-java_link_class_type (struct type *type, value_ptr clas)
+java_link_class_type (struct type *type, struct value *clas)
 {
-  value_ptr temp;
+  struct value *temp;
   char *unqualified_name;
   char *name = TYPE_TAG_NAME (type);
   int ninterfaces, nfields, nmethods;
   int type_is_object = 0;
   struct fn_field *fn_fields;
   struct fn_fieldlist *fn_fieldlists;
-  value_ptr fields, field, method, methods;
+  struct value *fields;
+  struct value *methods;
+  struct value *method = NULL;
+  struct value *field = NULL;
   int i, j;
   struct objfile *objfile = get_dynamics_objfile ();
   struct type *tsuper;
@@ -800,7 +811,7 @@ java_array_type (struct type *type, int dims)
 
 /* Create a Java string in the inferior from a (Utf8) literal. */
 
-static value_ptr
+static struct value *
 java_value_string (char *ptr, int len)
 {
   error ("not implemented - java_value_string");       /* FIXME */
@@ -843,7 +854,7 @@ java_emit_char (int c, struct ui_file *stream, int quoter)
     }
 }
 
-static value_ptr
+static struct value *
 evaluate_subexp_java (struct type *expect_type, register struct expression *exp,
                      register int *pos, enum noside noside)
 {
@@ -851,7 +862,8 @@ evaluate_subexp_java (struct type *expect_type, register struct expression *exp,
   int i;
   char *name;
   enum exp_opcode op = exp->elts[*pos].opcode;
-  value_ptr arg1, arg2;
+  struct value *arg1;
+  struct value *arg2;
   struct type *type;
   switch (op)
     {
@@ -897,8 +909,8 @@ evaluate_subexp_java (struct type *expect_type, register struct expression *exp,
          struct type *el_type;
          char buf4[4];
 
-         value_ptr clas = java_class_from_object (arg1);
-         value_ptr temp = clas;
+         struct value *clas = java_class_from_object (arg1);
+         struct value *temp = clas;
          /* Get CLASS_ELEMENT_TYPE of the array type. */
          temp = value_struct_elt (&temp, NULL, "methods",
                                   NULL, "structure");
@@ -909,7 +921,7 @@ evaluate_subexp_java (struct type *expect_type, register struct expression *exp,
 
          if (noside == EVAL_AVOID_SIDE_EFFECTS)
            return value_zero (el_type, VALUE_LVAL (arg1));
-         address = value_as_pointer (arg1);
+         address = value_as_address (arg1);
          address += JAVA_OBJECT_SIZE;
          read_memory (address, buf4, 4);
          length = (long) extract_signed_integer (buf4, 4);
@@ -986,6 +998,12 @@ java_create_fundamental_type (struct objfile *objfile, int typeid)
   return c_create_fundamental_type (objfile, typeid);
 }
 
+static char *java_demangle (const char *mangled, int options)
+{
+  return cplus_demangle (mangled, options | DMGL_JAVA);
+}
+
+
 /* Table mapping opcodes into strings for printing operators
    and precedences of the operators.  */
 
@@ -1033,6 +1051,7 @@ const struct language_defn java_language_defn =
   c_builtin_types,
   range_check_off,
   type_check_off,
+  case_sensitive_on,
   java_parse,
   java_error,
   evaluate_subexp_java,
@@ -1043,6 +1062,8 @@ const struct language_defn java_language_defn =
   java_print_type,             /* Print a type using appropriate syntax */
   java_val_print,              /* Print a value using appropriate syntax */
   java_value_print,            /* Print a top-level value */
+  NULL,                                /* Language specific skip_trampoline */
+  java_demangle,               /* Language specific symbol demangler */
   {"", "", "", ""},            /* Binary format info */
   {"0%lo", "0", "o", ""},      /* Octal format info */
   {"%ld", "", "d", ""},                /* Decimal format info */
This page took 0.039762 seconds and 4 git commands to generate.