http://d.puremagic.com/issues/show_bug.cgi?id=3987



--- Comment #4 from Robert Clipsham <rob...@octarineparrot.com> 2010-03-29 
14:28:51 PDT ---
I've found the issue. In backend/dwarf.c:dward_typidx(), there is a switch
statement which switches on the basic type for the current type. For a function
pointer, this is a pointer, so the debug info for a pointer is generated. dmd
tries to select the type the pointer is pointing to, (for int* it would be int
for example) and seems to select the wrong value for function pointers.
Comparing the debug output with that of clang, it seems that the DW_AT_type is
not needed for function pointers. Commenting out lines 1210, 1328, 1329 and
1386 (in dmd 2.042, may be different for other versions) fixes the debug info
and all is well. Of course this breaks debug info for normal pointer types, so
a special case needs to be made.
----
void function() foobar;
extern(C)void _Dmodule_ref(){}
extern(C)int main(int argc, char** argv)
{
        return 0;
}
----
When compiled with dmd -gc test.d, the debug info is as follows (irrelevant
parts removed):
.debug_info:
 <1><4b>: Abbrev Number: 4 (DW_TAG_pointer_type)
    <4c>   DW_AT_byte_size   : 4            
    <4d>   DW_AT_type        : <0x45>   
.debug_abbrev:
   4      DW_TAG_pointer_type    [no children]
    DW_AT_byte_size    DW_FORM_data1
    DW_AT_type         DW_FORM_ref4

When removing the above lines:
.debug_info:
 <1><4b>: Abbrev Number: 4 (DW_TAG_pointer_type)
    <4c>   DW_AT_byte_size   : 4  
.debug_abbrev:
   4      DW_TAG_pointer_type    [no children]
    DW_AT_byte_size    DW_FORM_data1
Removing the DW_AT_type fixes the issue. I don't know enough about the dmd
backend to create a patch to check if the type is a function pointer or not, so
I can't create a patch, but the patch should be simple if you're familiar with
the DM backend.

Looking at it again, the above isn't the right way to fix it (although it
does)... The DW_TAG_pointer_type should have a DW_AT_type (void for the above
code sample), and the DW_tag_subroutine_type shouldn't have a DW_AT_type (it is
currently set to 0x0). Sorry if this comment doesn't make complete sense, I
kept coming back to it and amending it :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to