This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [PATCH] Classify non-POD struct types more or less correctly on AMD64
- From: Daniel Jacobowitz <drow at mvista dot com>
- To: Mark Kettenis <kettenis at chello dot nl>
- Cc: jh at suse dot cz, aj at suse dot de, mark at codesourcery dot com,gdb-patches at sources dot redhat dot com
- Date: Tue, 9 Mar 2004 10:39:37 -0500
- Subject: Re: [PATCH] Classify non-POD struct types more or less correctly on AMD64
- References: <200401101800.i0AI0Zm6026623@elgar.kettenis.dyndns.org> <20040110183622.GA8108@nevyn.them.org> <200401101858.i0AIwdhk032901@elgar.kettenis.dyndns.org> <20040111041009.GA15714@nevyn.them.org> <200401111237.i0BCbVPL010349@elgar.kettenis.dyndns.org>
On Sun, Jan 11, 2004 at 01:37:31PM +0100, Mark Kettenis wrote:
> That function just implements the rules for normal C structures. Th
> rules are a bit more complex than you say above, but that bit is
> implemented correctly in GDB. At least that's the intention. The
> decision to not pass certain C++ classes in registers is made
> somewhere else, most notably in cp/class.c:finish_struct_bits(), where
> TYPE_MODE is set to BLKmode, and TREE_ADDRESSABLE is set. Both
> conditions are enough to get the type returned in memory instead of
> registers. However, there are more places where TREE_ADDRESSABLE is
> tweaked.
Hi Mark,
As it happens I just ran into the same problem on ARM and on MIPS n32.
I don't have a patch yet, but I can excerpt code I'm using at the
moment:
+ /* This is... rough. If we have a non-trivial copy constructor or
+ destructor, use reference. This should be in common code. */
+ int i, j;
+ for (i = 0; i < TYPE_NFN_FIELDS (type); i++)
+ for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (type, i); j++)
+ {
+ struct fn_field *fn = TYPE_FN_FIELDLIST1 (type, i);
+ if (TYPE_FN_FIELD_ARTIFICIAL (fn, j))
+ continue;
+ if (TYPE_FN_FIELDLIST_NAME (type, i)[0] == '~')
+ return RETURN_VALUE_STRUCT_CONVENTION;
+ if (strncmp (TYPE_NAME (type),
+ TYPE_FN_FIELDLIST_NAME (type, i),
+ strlen (TYPE_NAME (type))) == 0
+ && (TYPE_FN_FIELDLIST_NAME (type, i)[strlen (TYPE_NAME (type))] == '\0'
+ || TYPE_FN_FIELDLIST_NAME (type, i)[strlen (TYPE_NAME (type))] == '<')
+ && TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (fn, j)) == 2
+ && TYPE_CODE (TYPE_FIELD_TYPE (TYPE_FN_FIELD_TYPE (fn, j), 1)) == TYPE_CODE_REF
+ && TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (TYPE_FN_FIELD_TYPE (fn, j), 1)) == type)
+ return RETURN_VALUE_STRUCT_CONVENTION;
+ }
This doesn't address everything that GCC does to change the
pass-by-invisible-reference/return-by-invisible-reference behavior, but
it's a pretty good start and fixes one test in the GDB testsuite. Note
that we can't implement the TYPE_FN_FIELD_ARTIFICIAL test with stabs.
This also doesn't handle anything about calling constructors or
destructors, which GDB just isn't set up for yet...
I don't know if this sort of information should be in the dwarf2
information somehow. It definitely is in the C++ GNU v3 ABI:
http://www.codesourcery.com/cxx-abi/abi.html#calls
I'm guessing that this is what the x86-64 ABI was referring to, rather
than the actual term POD.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer