AutoIt DebugPrint() function and trace output
Modifications for use with a debugger

Hi,

Just want to propose some changes for AutoIt to allow easier script
debugging. There has been a lot of talk in other topics about the need
for debugging features. 

The changes detailed below are a trace output and a DebugPrint() function. 
Both of these use the win32 OutputDebugString() to spit messages to a
debugger - either Visual Studio, or DebugView from www.sysinternals.com.
DebugView can log the debug output to a file and perform remote debugging.

Debug output is generated with DebugPrint($my_var)
Trace output is enabled with AutoItSetOption('DebugOutputEnabled',1)
Trace output with variable values is enabled with AutoItSetOption('DebugOutputEnabled',2)

Output looks something like: [FONT=Courier]
[7396] test.au3: Line 029: TestFunc2(20)
[7396] test.au3: Line 044: MsgBox(0, "AutoIt Example", "Inside TestFunc2() - $var is: " & $var)
[7396] test.au3: Line 044: TRACE $var=20
[7396] test.au3: Line 045: DebugPrint($var)
[7396] test.au3: Line 045: TRACE $var=20
[7396] 20
[7396] test.au3: Line 046: EndFunc [\FONT]

Files attached to the post have the test executable, source, test script and output.
Based on sources autoit-v3.1.0-src.exe

Feedback appreciated. 
Cheers, Matt_J

[CODE]
Trace Output:
D:\Projects\AutoIt\Source\src\globaldata.h(104):
    extern int g_nDebugOutputEnabled;

D:\Projects\AutoIt\Source\src\globaldata.cpp(108):
    int g_nDebugOutputEnabled; // True when debugger output is allowed

D:\Projects\AutoIt\Source\src\application.cpp(95):
    g_nDebugOutputEnabled = 0;

D:\Projects\AutoIt\Source\src\script_misc.cpp(1770): (AutoIt_Script::F_AutoItSetOption)
    else if ( !stricmp(szOption, "DebugOutputEnabled") )			// DebugOutputEnabled
	{
		vResult = (int)g_nDebugOutputEnabled;	// Store current value
		if (nValue >= 0)
			g_nDebugOutputEnabled = nValue;
	}

D:\Projects\AutoIt\Source\src\script.cpp(866): (AutoIt_Script::Execute)
	Lexer(nScriptLine-1, szScriptLine, LineTokens);				// No need to check for errors, already lexed in InitScript()

	if (g_nDebugOutputEnabled > 0)
	{
		// code from AutoIt_App::SetTrayIconToolTip
		char			szTip[63+1];
		AString			str(_MAX_PATH);
		int nCurLine;

		nCurLine = nScriptLine-1;
		str = g_oScriptFile.GetIncludeFileName(g_oScriptFile.GetIncludeID(nCurLine));
		sprintf(szTip, ": Line %03d: ", g_oScriptFile.GetAutLineNumber(nCurLine));
		str += szTip;
		str += g_oScriptFile.GetLine(nCurLine);
		str += "\n";
		OutputDebugString(str.c_str());
	
		if(g_nDebugOutputEnabled > 1)
		{
			unsigned int i;
			for(i=0;i<LineTokens.size();i++)
			{
				if(LineTokens[i].m_nType == TOK_VARIABLE)
				{
					Variant *pvVariant;
					bool bConst = false;
					if(g_oVarTable.GetRef(LineTokens[i].szValue,&pvVariant,bConst))
					{
						str = g_oScriptFile.GetIncludeFileName(g_oScriptFile.GetIncludeID(nCurLine));
						sprintf(szTip, ": Line %03d: ", g_oScriptFile.GetAutLineNumber(nCurLine));
						str += szTip;
						str += "TRACE $";
						str += LineTokens[i].szValue;
						str += "=";
						str += pvVariant->szValue();
						str += "\n";
						OutputDebugString(str.c_str());
					}
				}
			}
		}
	}

DebugPrint():
D:\Projects\AutoIt\Source\src\script.cpp(219):
    {"DEBUGPRINT", &AutoIt_Script::F_DebugPrint, 1, 1},

D:\Projects\AutoIt\Source\src\script.h(850):
    AUT_RESULT  F_DebugPrint(VectorVariant &vParams, Variant &vResult);

D:\Projects\AutoIt\Source\src\script_misc.cpp(321):
    AUT_RESULT AutoIt_Script::F_DebugPrint(VectorVariant &vParams, Variant &vResult)
    {
        vResult = 1;
        OutputDebugString(vParams[0].szValue());

        return AUT_OK;
    } // F_DebugPrint()

[/FONT]
