Thinking about stack traces in D

kris foo at bar.com
Sun Sep 16 12:25:24 PDT 2007


Myron Alexander wrote:
> I have been thinking about exception design as a whole and for D 
> specifically. The lack of stack traces make certain types of bug tracing 
> very difficult so I went a googling looking for the answer and came 
> across this article in Dr. Dobbs:
> 
> http://www.ddj.com/184405270
> 
> This paragraph, in particular, has me interested:
> 
>> Hooking Entry and Exit
>>
>> This version uses an explicit code to report the function name (as a 
>> string). An alternative, used by code profilers (such as Numega 
>> TrueTime), is to parse the binary code, and inject hooks to it. The 
>> best alternative is to use compiler supplied hooks. In this 
>> hook—_penter() and _pexit()—the function address is written to the 
>> registrar. A symbol engine can then convert the address to a 
>> well-formed function name. This requires compilation with debug 
>> symbols. The technique is thoroughly described by John Robbins in his 
>> article on creating the Smooth Working Set tool (MSDN Magazine, 
>> October and December 2000; http://msdn.microsoft.com/msdnmag/ 
>> issues/1000/bugslayer/bugslayer1000.asp). This technique seems to be 
>> the ideal solution, but since I use VC 6, the compiler supplies only 
>> the _penter(). I tried injecting my own _pexit() from it but failed. A 
>> full explanation is beyond the scope of this article.
>>
> 
> Does D have entry and exit hooks already and, if not, would Walter add 
> them?
> 
> Regards,
> 
> Myron.


All Tango exceptions (apart from OutOfMemoryException) are derived from 
one which can be hooked by an external backtrace facility. This means 
that, for example, when you link Tango with the Flectioned library you 
will get a backtrace for the standard Tango exceptions also



More information about the Digitalmars-d mailing list