Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

debugging using A_LIneNumber


  • Please log in to reply
5 replies to this topic
daorc
  • Members
  • 177 posts
  • Last active:
  • Joined: 18 Oct 2006
Hello all. I would like to be able to debug my script in a way that the user would not be able to see the code. One way to do this would be to assign a hotkey to do the following:

msgbox line %A_linenumber%

However, this of course tells me that the script has reeched the 'debugging msgbox' line, which isn't much use! Any way of checking what line was executed just before the currently executing line (i.e. the problem line, just before someone presses the 'debug' hotkey)?

Alternatively, any other ideas are welcome.

Thanks

Daorc :)

Klaus
  • Members
  • 333 posts
  • Last active: Feb 17 2015 09:31 AM
  • Joined: 12 May 2005
Hi, daorc,
here's a way to provide a little debugging help, not the most elegant way, but form an opinion about it on your own.

1) define a hotkey at the beginning of your script:
HotKey, !a, debug
2) code the "gosub"-label for that hotkey
debug:
MsgBox, %myLineNumber%`n%myLine%
myLine =
myLineNumber = 
return
3) After each line of your script (or after each line or block you regard as important!) code the following:
StringReplace, data, data, `r, , ReplaceAll  ; this is a sample line of your script
myLine =  StringReplace, data, data, `r, , ReplaceAll  ; store the current line of your script
myLineNumber = 221 ; store the line number of "StringReplace, ..."
This inserting job could be done by a special script. I had one, but can't find it now, but that's not that miracle. It blows your script up to its triple size. These debugging lines should be removed (when everythins's fine) by another script.
Now start your script and when you hit Alt-A , the last values of myLine and myLineNumber will be shown.

Hope I could help,
Klaus

daorc
  • Members
  • 177 posts
  • Last active:
  • Joined: 18 Oct 2006
Thanks, Klaus. You're right, it isn't elegant, but I'll give it a go. It would be very simple to create a script that created this debugging script so it could prove very useful. Thanks,

Daorc

haichen
  • Members
  • 200 posts
  • Last active: Oct 20 2013 01:14 PM
  • Joined: 05 Feb 2007
Have a look at OutputDebug (its described in the helpfile).

As an example write somewhere in your code:
programName = testprogramm
OutputDebug, Line=%A_LineNumber% ProgramName= %programName%

Start dbgview.exe (you can get it from sysinternals.com = now Microsoft; under Sysinternals Utilities: Miscellaneous).

Start your script and you get:
Line=4 ProgramName=testprogramm
in the debugview.exe window.

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
also, ListLines

haichen
  • Members
  • 200 posts
  • Last active: Oct 20 2013 01:14 PM
  • Joined: 05 Feb 2007
Because I`m a bit lazy I made the following function and put it in the standardlib directory (autohotkey/lib) as RunDebugView.ahk:

RunDebugView(){
debuggerpath .= "c:\programme\autohotkey\DebugView\Dbgview.exe"
debuggerTitel := "DebugView on \\" . A_ComputerName . " (local)"
IfExist, %debuggerpath%
 ifwinNotexist, %debuggerTitel%
    Run, %debuggerpath%
sleep, 1000
FileGetTime, Created, %A_ScriptFullPath%, C 
FormatTime, Created, Created, dd.MM.yyyy HH:mm
outputdebug, Script= ---- %A_ScriptName% ----
outputdebug, Created= --- %Created% ---`n`n
}

Now put this Example at the beginning of your testscript :
RunDebugView()
programName = testprogramm
OutputDebug, Line=%A_LineNumber% ProgramName= %programName%
Then debgview.exe is started together with your script.

Posted Image