How to get parameters passed to function

Moderator: Rathinagiri

Post Reply
User avatar
mol
Posts: 2834
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 118 times
Been thanked: 63 times
Contact:

How to get parameters passed to function

Post by mol » Fri Oct 06, 2017 6:54 am

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: 5161
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 127 times
Been thanked: 129 times
Contact:

Post by Rathinagiri » Fri Oct 06, 2017 7:20 am

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: 2834
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 118 times
Been thanked: 63 times
Contact:

Post by mol » Fri Oct 06, 2017 7:53 am

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: 2834
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 118 times
Been thanked: 63 times
Contact:

Post by mol » Fri Oct 06, 2017 10:17 am

I can't find solution for retrieving local variables :-( Maybe Claudio will help

User avatar
srvet_claudio
Posts: 1944
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 30 times
Been thanked: 117 times
Contact:

Post by srvet_claudio » Sat Oct 07, 2017 3:28 am

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
mol
Posts: 2834
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 118 times
Been thanked: 63 times
Contact:

Post by mol » Sat Oct 07, 2017 6:00 am

Is it possible to get it without debugger?

User avatar
srvet_claudio
Posts: 1944
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 30 times
Been thanked: 117 times
Contact:

Post by srvet_claudio » Sat Oct 07, 2017 2:02 pm

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: 2834
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 118 times
Been thanked: 63 times
Contact:

Post by mol » Sat Oct 07, 2017 2:48 pm

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: 1944
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 30 times
Been thanked: 117 times
Contact:

Post by srvet_claudio » Sun Oct 08, 2017 8:18 pm

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

Post Reply