This is the mail archive of the gdb-patches@sourceware.org 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]

Re: [PATCH] Do not consider reference types as dynamic


Hello Pierre-Marie,

> I'm working on a GCC patch that fixes the type of Ada functions that
> return their result by reference: the debugging information
> currently says they return a pointer to the result and my patch
> turns these into references. The intent is that when evaluating a
> call to such functions from debuggers, the returned value is
> automatically dereferenced:
> 
>    # Currently we have:
>    (gdb) print my_function("foo")
>    $1 = (access ...) 0x...
> 
>    # We would like to have instead:
>    (gdb) print my_function("foo")
>    $1 = <referenced object>
> 
> Doing so in GDB is currently not possible when the referenced object
> type is dynamic. Indeed, the return value for such calls is not in
> memory and GDB considers reference types as dynamic iff the
> referenced type is dynamic. As a consequence, the type resolving
> process ends up trying to read memory at address 0x0, fails to do so
> and aborts printing the final value:
> 
>     # With my locally patched GCC, I have:
>     (gdb) print my_function("foo")
>     $1 = Cannot access memory at address 0x0
> 
> The attached patch fixes GDB so that the above works. It just makes
> GDB never consider reference types as dynamic (which makes sense per
> se IMHO) so this memory problem does not occurs.
> 
> I tested this patch on x86_64-linux with C, C++, Ada, Fortran and
> Java compilers: it triggers no regression. Note that the testcase it
> adds (gdb.ada/funcall_ref.exp) cannot pass without my local GCC
> patch and relies on my previous submitted patch
> (https://www.sourceware.org/ml/gdb-patches/2015-03/msg00241.html).

If it cannot pass without your GCC patch, let's add a setup_xfail.

> Ok to push?
> Thank you in advance!
> 
>     gdb/ChangeLog:
>     2015-03-10  Pierre-Marie de Rodat  <derodat@adacore.com>
> 
>         * gdbtypes.c (is_dynamic_type_internal): Remove special handling
>         of TYPE_CODE_REF types so that they are not considered as
>         dynamic depending on the referenced type.
> 
>     gdb/testsuite/ChangeLog:
>     2015-03-10  Pierre-Marie de Rodat  <derodat@adacore.com>
> 
>         * gdb.ada/funcall_ref.exp: New file.
>         * gdb.ada/funcall_ref/foo.adb: New file.

Mostly OK - a couple of minor comments below.

> +# Test printing and type-printing of a discriminated record that a function
> +# returns by reference.
> +
> +gdb_test "p get (\"Hello world!\")" \
> +         "= \\(n => 12, s => \"Hello world!\"\\)" \
> +         "p get (\"Hello world!\")"

If the test "label" (3rd argument) is the same as the command being
sent, you do not need to explicitly specify it. So, the following
is equivalent to your version:

        gdb_test "p get (\"Hello world!\")" \
                 "= \\(n => 12, s => \"Hello world!\"\\)"

> +gdb_test "ptype get (\"Hello world!\")" \
> +         [multi_line "type = <ref> record" \
> +                     "    n: natural;" \
> +                     "    s: access array \\(1 \\.\\. n\\) of character;" \
> +                     "end record"] \
> +         "ptype get (\"Hello world!\")"

Same here.

> +++ b/gdb/testsuite/gdb.ada/funcall_ref/foo.adb
> @@ -0,0 +1,19 @@
> +procedure Foo is

Missing copyright header.

Thank you,
-- 
Joel


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