Thread overview
[dmd-internals] AAs in the dmd backend
Apr 01, 2010
Robert Clipsham
Apr 01, 2010
Walter Bright
Apr 01, 2010
Robert Clipsham
Apr 01, 2010
Robert Clipsham
Apr 01, 2010
Robert Clipsham
April 01, 2010
Hi there,

I'm working on a patch for http://d.puremagic.com/issues/show_bug.cgi?id=3987 and have figured out all the details of why debugging with function pointers isn't working, I need to make sure I implement the fix properly so it gets accepted though... I'm in need of an associative array, what is the correct way to do this in the dmd backend?

The exact issue is that the .debug_info for function pointers isn't cached, so unlike the basic types the info is generated again, and breaks by writing out the debug info in the middle of the current function pointer (if that makes sense). So with the following:

T function(U function(V)) foobar;

The debug info is generated recursively, then the debug info for V is output, then U, then the function pointer etc etc. When it gets to writing the debug info for T function() though, it tries to generate the debug info for its parameters. For basic types this is cached in the typidx_tab array, so it pulls out the reference and places that in, however for function pointers it generates it again, so you end up mixing up the debug order. To fix this I need a way to cache function pointers, the obvious way to do this seems to be with an AA (I'd also need to find a way to mangle a given function pointers type, probably by recurring through it). What would be the right way to go about this? Should I use an AA, and if so, what is the preferred way to do this in the DMDBE? If not, how would you recommend I go about this?

Thanks,

Robert

March 31, 2010
There is an AA implementation in backend/aa.c that should do the job.

But I thought the dwarf implementation already caches already used types?

Robert Clipsham wrote:
> Hi there,
>
> I'm working on a patch for http://d.puremagic.com/issues/show_bug.cgi?id=3987 and have figured out all the details of why debugging with function pointers isn't working, I need to make sure I implement the fix properly so it gets accepted though... I'm in need of an associative array, what is the correct way to do this in the dmd backend?
>
> The exact issue is that the .debug_info for function pointers isn't cached, so unlike the basic types the info is generated again, and breaks by writing out the debug info in the middle of the current function pointer (if that makes sense). So with the following:
>
> T function(U function(V)) foobar;
>
> The debug info is generated recursively, then the debug info for V is output, then U, then the function pointer etc etc. When it gets to writing the debug info for T function() though, it tries to generate the debug info for its parameters. For basic types this is cached in the typidx_tab array, so it pulls out the reference and places that in, however for function pointers it generates it again, so you end up mixing up the debug order. To fix this I need a way to cache function pointers, the obvious way to do this seems to be with an AA (I'd also need to find a way to mangle a given function pointers type, probably by recurring through it). What would be the right way to go about this? Should I use an AA, and if so, what is the preferred way to do this in the DMDBE? If not, how would you recommend I go about this?
>
> Thanks,
>
> Robert
>
> _______________________________________________
> dmd-internals mailing list
> dmd-internals at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-internals
>
>


April 01, 2010
On 01/04/10 05:11, Walter Bright wrote:
> There is an AA implementation in backend/aa.c that should do the job.
>
> But I thought the dwarf implementation already caches already used types?

If you look at the implementation it only caches the used types if they are basic types, it doesn't cache for function pointers, so will regenerate the debug info and trample on the debug info that it wasn't done writing. A quick Ctrl+F for typeidx_tab in dwarf.c will confirm this.

April 01, 2010
On 01/04/10 05:11, Walter Bright wrote:
> There is an AA implementation in backend/aa.c that should do the job.

This needs me to implement a hashing function... What would be the best way to hash a TYPE (backend/type.h)? Will using TypeInfo_Atype work well enough, setting atype.start = t; atype.end = t + sizeof(TYPE);?

April 01, 2010
On 01/04/10 11:59, Robert Clipsham wrote:
> On 01/04/10 05:11, Walter Bright wrote:
>> There is an AA implementation in backend/aa.c that should do the job.
>
> This needs me to implement a hashing function... What would be the best way to hash a TYPE (backend/type.h)? Will using TypeInfo_Atype work well enough, setting atype.start = t; atype.end = t + sizeof(TYPE);?

Sorted now, I've attached a working patch to bug #3987.