Re: [RFA]: Java Inferior Call Take 3

Jim Blandy
2004-09-01T04:51:07Z

Jeff Johnston <jjohnstn@redhat.com> writes:
> Here is the revised patch.
>
> 2004-08-24 Jeff Johnston <jjohnstn@redhat.com>
>
> * dwarf2read.c (typename_concat): Change prototype to accept dwarf2_cu
> struct pointer as argument. Change function to use new argument to
> determine language. If language is Java, use "." as separator,
> otherwise, use "::".
> (partial_die_parent_scope): Change comment to include java. Check
> language to determine if Java "." or C++ "::" separator should be used.
> (add_partial_symbol): Enhance tests for C++ to also test for Java.
> (guess_structure_name): Ditto.
> (read_subroutine_type): Ditto.
> (new_symbol): Ditto.
> (read_structure_type): Add Java vtable support.
> (read_namespace): Add Java support.
> * jv-exp.y (FuncStart): New pattern.
> (MethodInvocation): Add support for simple function calls. Change
> warning message for other forms of inferior call currently not
> supported.
> * valarith.c (value_subscript): Treat an array with upper-bound
> of -1 as unknown size.

For the dwarf2read.c part of this patch:

There are a lot of places where we're selecting the name component
separator based on the language; I'd like compound name construction
abstracted out into its own function. Two possible approaches:

- typename_concat could take, in addition to the cu, a pointer to an
obstack. When the obstack pointer is null, typename_concat would
use xmalloc as it does now; otherwise it'd use obconcat.

- If you don't like overloading the behavior of typename_concat that
way, you could define a new function altogether that takes a prefix,
a name, a cu, and an obstack, and returns the name with the prefix
properly attached, allocated in the obstack.

But once there's a function that does this, I think all the 'if java
then "." else "::"' can be neatened up quite a bit.

In this change:

- /* The semantics of C++ state that "struct foo { ... }" also
+ /* The semantics of C++ and Java state that "struct foo { ... }" also

'struct foo { ... }' isn't valid Java; go ahead and say what you mean:

/* The semantics of C++ state that "struct foo { ... }" also
defines a typedef for "foo". A Java class declaration also
defines a typedef for the class. Synthesize a typedef symbol
so that "ptype foo" works as expected. */

The new comment for typename_concat should explain what its 'cu'
argument is used for.

The vtable pointer recognition code is kind of weird. The use of
'strlen (vptr_name) - 1' looks like a bug: don't we want to include
that last character in the comparison? I've committed the patch
below; could you adapt your patch to apply on top of that?

2004-08-31 Jim Blandy <jimb@redhat.com>

* dwarf2read.c (is_vtable_name): New function, based on logic from
read_structure_type, but passing the correct length to strncmp,
and using 'sizeof' instead of 'strlen'.
(read_structure_type): Call it.

Index: gdb/dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.159
diff -c -p -r1.159 dwarf2read.c
*** gdb/dwarf2read.c 29 Aug 2004 10:12:14 -0000 1.159
--- gdb/dwarf2read.c 31 Aug 2004 22:25:05 -0000
*************** dwarf2_attach_fn_fields_to_type (struct
*** 3265,3270 ****
--- 3265,3287 ----
TYPE_NFN_FIELDS_TOTAL (type) = total_length;
}

+
+ /* Returns non-zero if NAME is the name of a vtable member in CU's
+ language, zero otherwise. */
+ static int
+ is_vtable_name (const char *name, struct dwarf2_cu *cu)
+ {
+ static const char vptr[] = "_vptr";
+
+ /* C++ and some implementations of Java use this name. */
+ if (strncmp (name, vptr, sizeof (vptr) - 1) == 0
+ && is_cplus_marker (name[sizeof (vptr) - 1]))
+ return 1;
+
+ return 0;
+ }
+
+
/* Called when we find the DIE that starts a structure or union scope
(definition) to process all dies that define the members of the
structure or union.
*************** read_structure_type (struct die_info *di
*** 3403,3410 ****
TYPE_VPTR_BASETYPE (type) = t;
if (type == t)
{
- static const char vptr_name[] =
- {'_', 'v', 'p', 't', 'r', '\0'};
int i;

/* Our own class provides vtbl ptr. */
--- 3420,3425 ----
*************** read_structure_type (struct die_info *di
*** 3414,3423 ****
{
char *fieldname = TYPE_FIELD_NAME (t, i);

! if ((strncmp (fieldname, vptr_name,
! strlen (vptr_name) - 1)
! == 0)
! && is_cplus_marker (fieldname[strlen (vptr_name)]))
{
TYPE_VPTR_FIELDNO (type) = i;
break;
--- 3429,3435 ----
{
char *fieldname = TYPE_FIELD_NAME (t, i);

! if (is_vtable_name (fieldname, cu))
{
TYPE_VPTR_FIELDNO (type) = i;
break;