How to get parameters passed to function

Moderator: Rathinagiri

Post Reply
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

How to get parameters passed to function

Post 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.
Last edited by mol on Fri Oct 06, 2017 7:53 am, edited 1 time in total.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: How to get parameters passed to fiunction

Post by Rathinagiri »

Have you gone through the debugger coding by Claudio distributed along with HMG?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: How to get parameters passed to fiunction

Post 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
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: How to get parameters passed to function

Post by mol »

I can't find solution for retrieving local variables :-( Maybe Claudio will help
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: How to get parameters passed to function

Post 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)
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: How to get parameters passed to function

Post 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
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: How to get parameters passed to function

Post 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?
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: How to get parameters passed to function

Post by srvet_claudio »

the debugger functions of hb only link when compiled with /b
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
Post Reply