[PATCH] Do not consider reference types as dynamic

Pierre-Marie de Rodat derodat@adacore.com
Tue Mar 10 11:57:00 GMT 2015


Hello,

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).

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.

-- 
Pierre-Marie de Rodat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Do-not-consider-reference-types-as-dynamic.patch
Type: text/x-diff
Size: 4156 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20150310/b1862682/attachment.bin>


More information about the Gdb-patches mailing list