public inbox for gdb-testers@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] [Ada] GDB crash during "finish" of function with out parameters
@ 2015-11-09 18:08 sergiodj+buildbot
  2015-11-09 18:12 ` Failures on RHEL-s390x-m64, branch master sergiodj+buildbot
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: sergiodj+buildbot @ 2015-11-09 18:08 UTC (permalink / raw)
  To: gdb-testers

*** TEST RESULTS FOR COMMIT dddc0e16ef5d77e4f97d02ee0e2d4234c97dae0e ***

Author: Joel Brobecker <brobecker@adacore.com>
Branch: master
Commit: dddc0e16ef5d77e4f97d02ee0e2d4234c97dae0e

[Ada] GDB crash during "finish" of function with out parameters

Consider a function with the following signature...

   function F (R : out Rec_Type) return Enum_Type;

... where Rec_Type is a simple record:

   type Rec_Type is record
      Cur : Integer;
   end record;

Trying to "finish" from that function causes GDB to SEGV:

    (gdb) fin
    Run till exit from #0  bar.f (r=...) at bar.adb:5
    0x00000000004022fe in foo () at foo.adb:5
    5          I : Enum_Type := F (R);
    [1]    18949 segmentation fault (core dumped)  /[..]/gdb

This is related to the fact that funtion F has a parameter (R)
which is an "out" parameter being passed by copy. For those,
GNAT transforms the return value to be a record with multiple
fields: The first one is called "RETVAL" and contains the return
value shown in the source, and the remaining fields have the same
name as the "out" or "in out" parameters which are passed by copy.
So, in the example above, function F returns a struct that has
one field who name is "r".

Because "RETVAL" starts with "R", GDB thinks it's a wrapper field,
because it looks like the encoding used for  variant records:

   --    member_name ::= {choice} | others_choice
   --    choice ::= simple_choice | range_choice
   --    simple_choice ::= S number
   --    range_choice  ::= R number T number   <<<<<-----  here
   --    number ::= {decimal_digit} [m]
   --    others_choice ::= O (upper case letter O)

See ada_is_wrapper_field:

  return (name != NULL
          && (startswith (name, "PARENT")
              || strcmp (name, "REP") == 0
              || startswith (name, "_parent")
              || name[0] == 'S' || name[0] == 'R' || name[0] == 'O'));

As a result of this, when trying to print the RETURN value,
we think that RETVAL is a wrapper, and thus recurse into
print_field_values...

      if (ada_is_wrapper_field (type, i))
        {
          comma_needed =
            print_field_values (TYPE_FIELD_TYPE (type, i),
                                valaddr,
                                (offset
                                 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
                                stream, recurse, val, options,
                                comma_needed, type, offset, language);

... which is a problem since print_field_values assumes that
the type it is given ("TYPE_FIELD_TYPE (type, i)" here), is also
a record type. However, that's not the case, since RETVAL is
an enum. That eventually leads GDB to a NULL type when trying to
extract fields out of the enum, which then leads to a SEGV when
trying to dereference it.

Ideally, we'd want to be a little more careful in identifying
wrapper fields, by enhancing ada_is_wrapper_field to be a little
more complete in its analysis of the field name before declaring
it a variant record wrapper. However, it's not super easy to do
so, considering that the choices can be combined together when
complex choices are used. Eg:

   -- [...] the choice 1 .. 4 | 7 | -10 would be represented by
   --    R1T4S7S10m

Given that we are working towards getting rid of GNAT encodings,
which means that the above will eventually disappear, we took
the more pragmatic approach is just treating  RETVAL as a special
case.

gdb/ChangeLog:

        * ada-lang.c (ada_is_wrapper_field): Add special handling
        for fields called "RETVAL".

gdb/testsuite/ChangeLog:

        * gdb.ada/fin_fun_out: New testcase.


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2015-11-09 20:39 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-09 18:08 [binutils-gdb] [Ada] GDB crash during "finish" of function with out parameters sergiodj+buildbot
2015-11-09 18:12 ` Failures on RHEL-s390x-m64, branch master sergiodj+buildbot
2015-11-09 18:13 ` Failures on Fedora-x86_64-m32, " sergiodj+buildbot
2015-11-09 18:20 ` Failures on Fedora-x86_64-native-extended-gdbserver-m32, " sergiodj+buildbot
2015-11-09 18:24 ` Failures on Debian-i686, " sergiodj+buildbot
2015-11-09 18:26 ` Failures on AIX-POWER7-plain, " sergiodj+buildbot
2015-11-09 18:26 ` Failures on Debian-s390x-native-extended-gdbserver-m64, " sergiodj+buildbot
2015-11-09 18:28 ` Failures on Fedora-x86_64-native-gdbserver-m64, " sergiodj+buildbot
2015-11-09 18:31 ` Failures on Fedora-x86_64-native-extended-gdbserver-m64, " sergiodj+buildbot
2015-11-09 18:32 ` Failures on Fedora-x86_64-native-gdbserver-m32, " sergiodj+buildbot
2015-11-09 19:03 ` Failures on Debian-i686-native-gdbserver, " sergiodj+buildbot
2015-11-09 19:05 ` Failures on Debian-i686-native-extended-gdbserver, " sergiodj+buildbot
2015-11-09 19:44 ` Failures on Fedora-ppc64be-native-gdbserver-m64, " sergiodj+buildbot
2015-11-09 20:06 ` Failures on Fedora-ppc64be-native-extended-gdbserver-m64, " sergiodj+buildbot
2015-11-09 20:39 ` Failures on Fedora-ppc64le-native-extended-gdbserver-m64, " sergiodj+buildbot
2015-11-10  5:19 ` Failures on Fedora-ppc64le-native-gdbserver-m64, " sergiodj+buildbot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).