<$BlogRSDUrl$>

Wednesday, May 18, 2005

Another example why I love the JCL 

I've been using both the JCL and JVCL from the wonderful folks at JEDI for a few years now, and was recently reminded why.

I had an unreproducible bug which I had to track down with some debug logging. While there were only one or two points in the code which could cause this particular bug, there were literally hundreds of places in the code which called these routines. With a bit of help from the stack tracing routines in the JCL, I was able to quickly pin down exactly where the problem was originiating. Below is all it took to get the stack trace I required to pinpoint the culprit:

function BuildStackTrace(const ALevel: Integer = 0): string;
var
sl: TStringList;
locInfo: TJclLocationInfo;
procAddr: Pointer;
i: Integer;
begin
sl := TStringList.Create;
try
i := ALevel;
procAddr := Caller(i);
while procAddr <> nil do
begin
if GetLocationInfo(procAddr, locInfo) then
sl.Add(Format(
'[$%s] %s.%s Line %d',
[IntToHex(Integer(locInfo.Address), 8), locInfo.UnitName, locInfo.ProcedureName, locInfo.LineNumber]));
Inc(i);
procAddr := Caller(i);
end;
Result := sl.Text;
finally
sl.Free;
end;
end;


For any Delphi developers who haven't checked out what the JEDI projects have to offer, I strongly recommend you check them out now. And to any JEDI contributors who may be reading this, thanks a bunch and if you're ever in Auckland, look me up and I'll shout you a drink of your favourite poison (with full source code, of course).

Comments:
> if you're ever in Auckland, look me up and I'll shout you a drink of your favourite poison

I will remember that ;)

Never been to NZ yet.
 
You should definately look me up, Hallvard. I owe you one for some help you gave me a few years ago to assist in setting up exception logging with stack trace info, based on a The Delpi Magazine article you wrote.

I couldn't get it to work reliably with D2, and you promptly responded to my e-mail request for assistance, allowing me to successfully implement the stack tracing.
 
Post a Comment

This page is powered by Blogger. Isn't yours?