PDA

View Full Version : using EL to get call stack info


MerijnB
09-Mar-2006, 11:26 AM
in jcl there are some function to get call stack info (jclDebug.pas).

these functions allow you to get procedure name, filename, module name and line nr when giving a 'callstack depth'.

from jclDebug.pas:
function FileByLevel(const Level: Integer = 0): string;
function ModuleByLevel(const Level: Integer = 0): string;
function ProcByLevel(const Level: Integer = 0): string;
function LineByLevel(const Level: Integer = 0): Integer;

Getting this from EL would allow me to get rid of JCL.

procedure SomeProc;
begin
ProcByLevel(0); // gives back SomeProc
end;

procecure SomeProcA;
begin
ProcByLevel(1); // gives back SomeProcB
end;

procedure SomeProcB;
begin
SomeProcA();
end;

this should work the same for filename, module name, line nr and optinally line offset number (offset from procedure beginning). Maybe even another string where line nr and line nr offset are together (as in EL log files)

regards,

Merijn

Emily
16-Mar-2006, 08:37 PM
Take a look at GetCurrentCallStack to get the info that you need.

"MerijnB" <merijn.bosma@aviavox.com> wrote in message
news:MerijnB.24eguy@no-mx.news.eurekalog.com...
>
> in jcl there are some function to get call stack info (jclDebug.pas).
>
> these functions allow you to get procedure name, filename, module name
> and line nr when giving a 'callstack depth'.
>
> from jclDebug.pas:
>
> Code:
> --------------------
> function FileByLevel(const Level: Integer = 0): string;
> function ModuleByLevel(const Level: Integer = 0): string;
> function ProcByLevel(const Level: Integer = 0): string;
> function LineByLevel(const Level: Integer = 0): Integer;
> --------------------
>
>
> Getting this from EL would allow me to get rid of JCL.
>
>
> Code:
> --------------------
> procedure SomeProc;
> begin
> ProcByLevel(0); // gives back SomeProc
> end;
> --------------------
>
>
>
> Code:
> --------------------
> procecure SomeProcA;
> begin
> ProcByLevel(1); // gives back SomeProcB
> end;
>
> procedure SomeProcB;
> begin
> SomeProcA();
> end;
> --------------------
>
>
> this should work the same for filename, module name, line nr and
> optinally line offset number (offset from procedure beginning). Maybe
> even another string where line nr and line nr offset are together (as
> in EL log files)
>
> regards,
>
> Merijn
>
>
> --
> MerijnB
> ------------------------------------------------------------------------
> MerijnB's Profile: http://news.eurekalog.com/member.php?userid=128
> View this thread: http://news.eurekalog.com/showthread.php?t=275
>

admin
05-Apr-2006, 04:20 PM
Hi,

MerijnB wrote:
> in jcl there are some function to get call stack info (jclDebug.pas).
>
> these functions allow you to get procedure name, filename, module name
> and line nr when giving a 'callstack depth'.
>
> from jclDebug.pas:
>
> Code:
> --------------------
> function FileByLevel(const Level: Integer = 0): string;
> function ModuleByLevel(const Level: Integer = 0): string;
> function ProcByLevel(const Level: Integer = 0): string;
> function LineByLevel(const Level: Integer = 0): Integer;
> --------------------
>
> [...]

You can use the following code:



function GetCallingUnit: string;
var
Stack: TEurekaStackList;
begin
Result := '';
Stack := GetCurrentCallStack;
try
if (Stack.Count >= 2) Then Result := Stack[2].UnitName;
finally
Stack.Free;
end;
end;

function GetCallingProcedure: string;
var
Stack: TEurekaStackList;
begin
Result := '';
Stack := GetCurrentCallStack;
try
if (Stack.Count >= 2) Then
begin
if (Stack[2].ClassName <> '') then
Result := (Stack[2].ClassName + '.');
Result := (Result + Stack[2].ProcedureName);
end;
finally
Stack.Free;
end;
end;

function GetCallingLineNo: Integer;
var
Stack: TEurekaStackList;
begin
Result := 0;
Stack := GetCurrentCallStack;
try
if (Stack.Count >= 2) Then Result := Stack[2].Line;
finally
Stack.Free;
end;
end;




--
Best regards...

Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!

admin
11-Apr-2006, 12:28 PM
Hi,

MerijnB wrote:
> in jcl there are some function to get call stack info (jclDebug.pas).
>
> these functions allow you to get procedure name, filename, module name
> and line nr when giving a 'callstack depth'.
>
> from jclDebug.pas:
>
> Code:
> --------------------
> function FileByLevel(const Level: Integer = 0): string;
> function ModuleByLevel(const Level: Integer = 0): string;
> function ProcByLevel(const Level: Integer = 0): string;
> function LineByLevel(const Level: Integer = 0): Integer;
> --------------------
>
> [...]


I have just released the last EurekaLog 5.1.4 RC 4 with the following
new routines:

1)...New "CallStackToStrings" procedure added (to convert any EurekaLog
call-stack into a simple text representation);
2)...New "GetLastExceptionCallStack" function added (to obtain the last
handled/unhandled exception call-stack);
3)...New "GetCallStackByLevels" function added (to obtain a call-stack
subset working on the calls levels);

Try them and came back to me with your opinion, OK? :)

Download it at: http://www.eurekalog.com/login.php

--
Best regards...

Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!