Page 1 of 1
How to get parameters passed to function
Posted: Fri Oct 06, 2017 6:54 am
by mol
Hi guys!
I want to log parameters passed to function in situation when program crashes.
We can retrive path to error using this code
Code: Select all
cLog := ""
i := 2
while ( !Empty(ProcName(i)) )
cLog += ProcName(i) + "(" + alltrim(str(ProcLine(i)) + ")"+CRLF
i++
end
but, how to retrieve variables in
ProcName(i) ?
It's realized in debugger, but I don't know how to find it.
Re: How to get parameters passed to fiunction
Posted: Fri Oct 06, 2017 7:20 am
by Rathinagiri
Have you gone through the debugger coding by Claudio distributed along with HMG?
Re: How to get parameters passed to fiunction
Posted: Fri Oct 06, 2017 7:53 am
by mol
I've extracted some code from Claudio debugger and it works super! This code generates only PRIVATE, I'll modify it later for optionally show LOCAL and GLOBAL
Code: Select all
#include "hbmemvar.ch"
function ShowVariables
local aBVars := {}
local cName := ""
local i
local hSkip
local m
local nCount
local xValue
local cLog := ""
i := 2
while ( !Empty(ProcName(i)) )
aBVars := {}
nCount := __mvDbgInfo( HB_MV_PRIVATE )
IF nCount > 0
m := __mvDbgInfo( HB_MV_PRIVATE_LOCAL, i )
hSkip := { => }
hb_HAllocate( hSkip, nCount )
FOR n := nCount TO 1 STEP -1
xValue := __mvDbgInfo( HB_MV_PRIVATE, n, @cName )
IF ! cName $ hSkip
AAdd( aBVars, { cName, xValue, Iif( m > 0, "Private LOCAL", "Private GLOBAL" ), Iif( m > 0, i, 0 ) } )
hSkip[ cName ] := NIL
ENDIF
--m
NEXT
ENDIF
cLog += ProcName(i)+CRLF
for m := 1 to len(aBVars)
cLog += chr(9)+hb_valtoexp(aBVars[m])+CRLF
next m
i++
end
return cLog
Re: How to get parameters passed to function
Posted: Fri Oct 06, 2017 10:17 am
by mol
I can't find solution for retrieving local variables
![Sad :-(](./images/smilies/icon_e_sad.gif)
Maybe Claudio will help
Re: How to get parameters passed to function
Posted: Sat Oct 07, 2017 3:28 am
by srvet_claudio
Hi Marek,
compile with /b and call in your app:
aVars := HMG_Debugger():GetVars( nil, nil, lShowPublics, lShowPrivates, lShowStatics, lShowLocals )
MsgDebug (aVars)
Re: How to get parameters passed to function
Posted: Sat Oct 07, 2017 6:00 am
by mol
Is it possible to get it without debugger?
Re: How to get parameters passed to function
Posted: Sat Oct 07, 2017 2:02 pm
by srvet_claudio
mol wrote: ↑Sat Oct 07, 2017 6:00 am
Is it possible to get it without debugger?
I do not know, is need to investigate the structure of the stack of local variables
Re: How to get parameters passed to function
Posted: Sat Oct 07, 2017 2:48 pm
by mol
There is __DbgEntry in debugger, which builds stack.
Array of Local variables is third parameter of this function.
But,I didn't found any call of this function. Is it wrong direction?
Re: How to get parameters passed to function
Posted: Sun Oct 08, 2017 8:18 pm
by srvet_claudio
the debugger functions of hb only link when compiled with /b