[amibroker] Re: Is it good practice to break a huge afl script to many include files?

 

For debugging, here's some code I've shared before and which is probably lost in old posts. I have over 10,000 lines of AFL code now with probably more than 100 functions, and a good debug point practice is essential. It's a simple system for naming debug points and turning them on and off. There are four functions. "name" is the name of the debug point.


GetDebug("name");
SetDebug("name");
ClearDebug("name");
ClearDebugAll("name");

To use, put break points in your code like so,
if (GetDebug("name")) {....debug statements...}

Turn them on or off like so,
SetDebug("name"); // Turn on debug point
ClearDebug("name"); // Turn off debug point
==============code below==========================

function GetDebug(funcName) { //Begin GetDebug
//
//Boolean function which returns whether or not a function is on the debugger stack
//
funcName = StrToUpper(funcName);
if (StaticVarGet("DebugALL")==True) result=True;
else if (StaticVarGet("DebugNONE")==True) result = False;
else result=StaticVarGet("DebugRecord"+funcName);
return result;
} //End GetDebug

procedure SetDebug(funcList) { //Begin SetDebug
// This function accepts a comma separated list of breakpoint names, and turns on the breakpoints  
// whose names correspond to the names in its argument list.
//
// Puts each function in funclist into the debug stack and onto the debug list
// so that debug calls within that function execute
//
//Reset All and None flags to default states
if (GetDebug("None")) StaticVarSet("DebugNONE", False); 
if (GetDebug("All")) StaticVarSet("DebugALL", False);
// Set each function in the list to true
for(length=0; (funcName = StrExtract( funcList, length )) != ""; length++) { //Begin for
funcName = StrToUpper(funcName); 
//_TRACE("Func is "+funcName);
inStack = GetDebug(funcName);
//_TRACE("Instack is "+NumToStr(inStack));
if(IsEmpty(inStack) OR NOT inStack) { // Begin add this function to the debug list
list = StaticVarGetText("DebugList");
//_TRACE("DebugList before addition is "+list);
if (list=="")
listSet = StaticVarSetText("DebugList", funcName);
else
listSet = StaticVarSetText("DebugList", list+","+funcName);
recordSet = StaticVarSet("DebugRecord"+funcName,True);
if(!listSet) _TRACE("Function SetDebug: Attempt to extend the Debug list failed: "+funcName);
if(!recordSet) _TRACE("Function SetDebug: Attempt to add the Debug record failed: "+funcName);
} // End add this function to the debug list
} //End For

//_TRACE("DebugList after addition: "+StaticVarGetText("DebugList"));
} //End SetDebug

procedure ClearDebug(funcList) { //Begin ClearDebug
//
// This procedure accepts a list of breakpoint names and turns off the breakpoints associated
// with those names.
//
for(length=0; (func = StrExtract( funcList, length )) != ""; length++) { //Begin for
func = StrToUpper(func);
success = StaticVarSet("DebugRecord"+func, False);
list = StaticVarGetText("DebugList");
if (StrFind(list, func)) { //begin remove func from debug list
list = StrReplace(list, func+",", "");
StaticVarSetText("DebugList", list);
} //end remove func from debug list
if (!success) _TRACE("Function ClearDebug: Attempt to set the Debug variable failed: "+value);
} //End For
} //End ClearDebug

procedure ClearDebugAll() { //Begin ClearDebugAll
//
// This procedure turns off all breakpoints
//
funcList = StaticVarGetText("DebugList");
StaticVarSetText("DebugList","");
for(length=0; (func = StrExtract( funcList, length )) != ""; length++) { //Begin for
success = StaticVarSet("DebugRecord"+func, False);
if (!success) _TRACE("Function SetDebug: Attempt to set the DebugRecord failed: "+func);
} // End for

} //End ClearDebugAll


__._,_.___

Posted by: rosenberggregg@yahoo.com
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (10)
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/


.

__,_._,___


EmoticonEmoticon