This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

misc java-related gdb patches


I have a bunch of Java-related gdb patches I haven't gotten around
to checking in.  They've been sitting in my tree for a while, and
I can't always remember why I did them.  Before I try to check
them in, I would appreciate any feedback on whether they make the
"gdb experience" better or worse.
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/
2002-04-10  Per Bothner  <per@bothner.com>

	* eval.c (evaluate_subexp_standard):  Do overload resolution for Java.

	* infcmd.c (run_command):  Reset innermost_block.

	* jv-exp.y (MethodInvocation)):  Add preliminary support.

	* valops.c (search_struct_field):  Make non-static.
	* jv-lang.c (java_class_from_object):  De-reference first.
	Then call search_struct_field.

	* jv-lang.c:  Comment out (using #if DYNAMICS) support for generating
	type by reading Class structures from inferior.  Needs work.

	* jv-lang.c (evaluate_subexp_java):  On UNOP_IND, just smash type.

	* jv-valprint.c (java_value_print):  Call value_copy instead of
	value_copy.  Don't remember why - it may be faster.

	* language.c (unk_lang_create_fundamental_type):  Remove.
	(unknown_language_defn, auto_language_defn, local_language_defn):
	In place of unk_lang_create_fundamental_type use
	c_create_fundamental_type.

Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.21
diff -u -p -r1.21 eval.c
--- eval.c	16 Mar 2002 20:51:44 -0000	1.21
+++ eval.c	11 Apr 2002 19:44:57 -0000
@@ -827,7 +827,9 @@ evaluate_subexp_standard (struct type *e
 	  /* Name of method from expression */
 	  strcpy (tstr, &exp->elts[pc2 + 2].string);
 
-	  if (overload_resolution && (exp->language_defn->la_language == language_cplus))
+	  if (overload_resolution
+	      && (exp->language_defn->la_language == language_cplus
+		  || exp->language_defn->la_language == language_java))
 	    {
 	      /* Language is C++, do some overload resolution before evaluation */
 	      struct value *valp = NULL;
Index: infcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/infcmd.c,v
retrieving revision 1.43
diff -u -p -r1.43 infcmd.c
--- infcmd.c	28 Mar 2002 01:35:55 -0000	1.43
+++ infcmd.c	11 Apr 2002 19:44:59 -0000
@@ -387,6 +387,8 @@ Start it from the beginning? "))
       init_wait_for_inferior ();
     }
 
+  innermost_block = NULL;
+
   clear_breakpoint_hit_counts ();
 
   /* Purge old solib objfiles. */
Index: jv-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/jv-exp.y,v
retrieving revision 1.5
diff -u -p -r1.5 jv-exp.y
--- jv-exp.y	21 Feb 2002 02:54:46 -0000	1.5
+++ jv-exp.y	11 Apr 2002 19:44:59 -0000
@@ -442,12 +442,25 @@ FieldAccess:
 ;
 
 MethodInvocation:
-	Name '(' ArgumentList_opt ')'
-		{ error ("method invocation not implemented"); }
-|	Primary '.' SimpleName '(' ArgumentList_opt ')'
-		{ error ("method invocation not implemented"); }
+	Name '('
+		{ push_expression_name ($1);
+		/* FIXME does not handle static calls, i.e. Name is a Type. */
+		  start_arglist (); }
+	ArgumentList_opt ')'
+		{ write_exp_elt_opcode (OP_FUNCALL);
+		  write_exp_elt_longcst ((LONGEST) end_arglist ());
+		  write_exp_elt_opcode (OP_FUNCALL); }
+|	Primary '.' SimpleName '('
+		{ write_exp_elt_opcode (STRUCTOP_PTR);
+		  write_exp_string ($3);
+		  write_exp_elt_opcode (STRUCTOP_PTR);
+		  start_arglist (); }
+	ArgumentList_opt ')'
+		{ write_exp_elt_opcode (OP_FUNCALL);
+		  write_exp_elt_longcst ((LONGEST) end_arglist ());
+		  write_exp_elt_opcode (OP_FUNCALL); }
 |	SUPER '.' SimpleName '(' ArgumentList_opt ')'
-		{ error ("method invocation not implemented"); }
+		{ error ("super method invocation not implemented"); }
 ;
 
 ArrayAccess:
Index: jv-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/jv-lang.c,v
retrieving revision 1.11
diff -u -p -r1.11 jv-lang.c
--- jv-lang.c	2 Dec 2001 22:43:59 -0000	1.11
+++ jv-lang.c	11 Apr 2002 19:45:00 -0000
@@ -68,6 +68,9 @@ static struct objfile *dynamics_objfile 
 
 static struct type *java_link_class_type (struct type *, struct value *);
 
+#define DYNAMICS 0
+
+#if DYNAMICS
 static struct objfile *
 get_dynamics_objfile (void)
 {
@@ -77,8 +80,9 @@ get_dynamics_objfile (void)
     }
   return dynamics_objfile;
 }
+#endif
 
-#if 1
+#if DYNAMICS
 /* symtab contains classes read from the inferior. */
 
 static struct symtab *class_symtab = NULL;
@@ -164,7 +168,7 @@ add_class_symbol (struct type *type, COR
   SYMBOL_VALUE_ADDRESS (sym) = addr;
   return sym;
 }
-#endif
+#endif /* DYNAMICS */
 
 struct type *
 java_lookup_class (char *name)
@@ -200,8 +204,9 @@ java_lookup_class (char *name)
 #endif
 }
 
-/* Return a nul-terminated string (allocated on OBSTACK) for
-   a name given by NAME (which has type Utf8Const*). */
+/* Return a nul-terminated string for a name given by NAME (which has
+   type Utf8Const*).  The result is allocated on OBSTACK if it that is
+   non-null, otherwise xmalloc is used. */
 
 char *
 get_java_utf8_name (struct obstack *obstack, struct value *name)
@@ -214,7 +219,10 @@ get_java_utf8_name (struct obstack *obst
   name_length = (int) value_as_long (temp);
   data_addr = VALUE_ADDRESS (temp) + VALUE_OFFSET (temp)
     + TYPE_LENGTH (VALUE_TYPE (temp));
-  chrs = obstack_alloc (obstack, name_length + 1);
+  if (obstack == NULL)
+    chrs = xmalloc (name_length + 1);
+  else
+    chrs = obstack_alloc (obstack, name_length + 1);
   chrs[name_length] = '\0';
   read_memory (data_addr, chrs, name_length);
   return chrs;
@@ -226,12 +234,22 @@ java_class_from_object (struct value *ob
   /* This is all rather inefficient, since the offsets of vtable and
      class are fixed.  FIXME */
   struct value *vtable_val;
+  register struct type *t;
 
   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_address (obj_val), NULL);
 
+  t = check_typedef (VALUE_TYPE (obj_val));
+  if (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
+    {
+      obj_val = value_ind (obj_val);
+      t = check_typedef (VALUE_TYPE (obj_val));
+    }
+
+  obj_val = search_struct_field ("java.lang.Object", obj_val, 0, t, 1);
+
   vtable_val = value_struct_elt (&obj_val, NULL, "vtable", NULL, "structure");
   return value_struct_elt (&vtable_val, NULL, "class", NULL, "structure");
 }
@@ -245,7 +263,7 @@ java_class_is_primitive (struct value *c
   return (int) (i & 0x7fffffff) == (int) 0x7fffffff;
 }
 
-/* Read a GCJ Class object, and generated a gdb (TYPE_CODE_STRUCT) type. */
+/* Read a GCJ Class object, and generates a gdb (TYPE_CODE_STRUCT) type. */
 
 struct type *
 type_from_class (struct value *clas)
@@ -281,7 +299,6 @@ type_from_class (struct value *clas)
     }
 #endif
 
-  objfile = get_dynamics_objfile ();
   if (java_class_is_primitive (clas))
     {
       struct value *sig;
@@ -291,10 +308,17 @@ type_from_class (struct value *clas)
     }
 
   /* Get Class name. */
-  /* if clasloader non-null, prepend loader address. FIXME */
+  /* if clasloader non-null, prepend loader address. FIXME
+   * Check this by looking for a type, and seeing if its class$ field matches.
+   */
   temp = clas;
   utf8_name = value_struct_elt (&temp, NULL, "name", NULL, "structure");
+#if DYNAMICS
+  objfile = get_dynamics_objfile ();
   name = get_java_utf8_name (&objfile->type_obstack, utf8_name);
+#else
+  name = get_java_utf8_name (NULL, utf8_name);
+#endif
   for (nptr = name; *nptr != 0; nptr++)
     {
       if (*nptr == '/')
@@ -303,8 +327,15 @@ type_from_class (struct value *clas)
 
   type = java_lookup_class (name);
   if (type != NULL)
-    return type;
-
+    {
+#if ! DYNAMICS
+      free (name);
+#endif
+      return type;
+    }
+#if ! DYNAMICS
+  error ("unknown type '%s'", name);
+#else
   type = alloc_type (objfile);
   TYPE_CODE (type) = TYPE_CODE_STRUCT;
   INIT_CPLUS_SPECIFIC (type);
@@ -330,8 +361,10 @@ type_from_class (struct value *clas)
 
   add_class_symtab_symbol (add_class_symbol (type, addr));
   return java_link_class_type (type, clas);
+#endif
 }
 
+#if DYNAMICS
 /* Fill in class TYPE with data from the CLAS value. */
 
 struct type *
@@ -569,6 +602,7 @@ java_link_class_type (struct type *type,
 
   return type;
 }
+#endif /* DYNAMICS */
 
 static struct type *java_object_type;
 
@@ -867,10 +901,8 @@ evaluate_subexp_java (struct type *expec
 	  struct type *type;
 
 	  type = type_from_class (java_class_from_object (arg1));
-	  arg1 = value_cast (lookup_pointer_type (type), arg1);
+	  VALUE_TYPE (arg1) = lookup_pointer_type (type);
 	}
-      if (noside == EVAL_SKIP)
-	goto nosideret;
       return value_ind (arg1);
 
     case BINOP_SUBSCRIPT:
@@ -1082,6 +1114,7 @@ extern void java_rerun_cleanup (void);
 void
 java_rerun_cleanup (void)
 {
+#if DYNAMICS
   if (class_symtab != NULL)
     {
       free_symtab (class_symtab);	/* ??? */
@@ -1092,6 +1125,7 @@ java_rerun_cleanup (void)
       free_objfile (dynamics_objfile);
       dynamics_objfile = NULL;
     }
+#endif
 
   java_object_type = NULL;
 }
Index: jv-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/jv-valprint.c,v
retrieving revision 1.9
diff -u -p -r1.9 jv-valprint.c
--- jv-valprint.c	21 Oct 2001 01:57:42 -0000	1.9
+++ jv-valprint.c	11 Apr 2002 19:45:00 -0000
@@ -65,7 +65,8 @@ java_value_print (struct value *val, str
 	  type = type_from_class (java_class_from_object (val));
 	  type = lookup_pointer_type (type);
 
-	  val = value_at (type, address, NULL);
+	  val = value_copy (val);
+	  VALUE_TYPE (val) = type;
 	}
     }
 
Index: language.c
===================================================================
RCS file: /cvs/src/src/gdb/language.c,v
retrieving revision 1.23
diff -u -p -r1.23 language.c
--- language.c	28 Mar 2002 01:35:55 -0000	1.23
+++ language.c	11 Apr 2002 19:45:01 -0000
@@ -41,6 +41,7 @@
 #include "language.h"
 #include "target.h"
 #include "parser-defs.h"
+#include "c-lang.h"
 #include "jv-lang.h"
 
 extern void _initialize_language (void);
@@ -1416,12 +1417,6 @@ unk_lang_printstr (struct ui_file *strea
   error ("internal error - unimplemented function unk_lang_printstr called.");
 }
 
-static struct type *
-unk_lang_create_fundamental_type (struct objfile *objfile, int typeid)
-{
-  error ("internal error - unimplemented function unk_lang_create_fundamental_type called.");
-}
-
 static void
 unk_lang_print_type (struct type *type, char *varstring, struct ui_file *stream,
 		     int show, int level)
@@ -1467,7 +1462,7 @@ const struct language_defn unknown_langu
   unk_lang_printchar,		/* Print character constant */
   unk_lang_printstr,
   unk_lang_emit_char,
-  unk_lang_create_fundamental_type,
+  c_create_fundamental_type,
   unk_lang_print_type,		/* Print a type using appropriate syntax */
   unk_lang_val_print,		/* Print a value using appropriate syntax */
   unk_lang_value_print,		/* Print a top-level value */
@@ -1497,7 +1492,7 @@ const struct language_defn auto_language
   unk_lang_printchar,		/* Print character constant */
   unk_lang_printstr,
   unk_lang_emit_char,
-  unk_lang_create_fundamental_type,
+  c_create_fundamental_type,
   unk_lang_print_type,		/* Print a type using appropriate syntax */
   unk_lang_val_print,		/* Print a value using appropriate syntax */
   unk_lang_value_print,		/* Print a top-level value */
@@ -1526,7 +1521,7 @@ const struct language_defn local_languag
   unk_lang_printchar,		/* Print character constant */
   unk_lang_printstr,
   unk_lang_emit_char,
-  unk_lang_create_fundamental_type,
+  c_create_fundamental_type,
   unk_lang_print_type,		/* Print a type using appropriate syntax */
   unk_lang_val_print,		/* Print a value using appropriate syntax */
   unk_lang_value_print,		/* Print a top-level value */
Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.53
diff -u -p -r1.53 valops.c
--- valops.c	22 Mar 2002 18:57:08 -0000	1.53
+++ valops.c	11 Apr 2002 19:45:03 -0000
@@ -52,7 +52,7 @@ static struct value *value_arg_coerce (s
 
 static CORE_ADDR value_push (CORE_ADDR, struct value *);
 
-static struct value *search_struct_field (char *, struct value *, int,
+extern struct value *search_struct_field (char *, struct value *, int,
 				      struct type *, int);
 
 static struct value *search_struct_method (char *, struct value **,
@@ -2010,7 +2010,7 @@ typecmp (int staticp, struct type *t1[],
    If LOOKING_FOR_BASECLASS, then instead of looking for struct fields,
    look for a baseclass named NAME.  */
 
-static struct value *
+ struct value *
 search_struct_field (char *name, struct value *arg1, int offset,
 		     register struct type *type, int looking_for_baseclass)
 {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]