Jump to content

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

AHK debugging: How to know current line number being execute


  • Please log in to reply
8 replies to this topic
jsingh125
  • Members
  • 14 posts
  • Last active: Dec 15 2011 05:10 AM
  • Joined: 14 Dec 2011
I have a AHK script which I need to debug. I basically want to see which line number is being currently executed in the script (which piece of code).

Is there a way to do that? Or anything close to that for debugging? I am using this AHK script to automate some windows explorer related task. But sometimes it gets stuck in between and I have no idea where the script gets stuck. If I knew the current line number being executed, it would be great. Using Msgbox after each line is not possible and very inefficient.

Could someone please help me with this?

Also, I am new to AHK scripting so I would be grateful if you could explain with a short example if possible.

Thanks
Sunny

Odlanir
  • Members
  • 775 posts
  • Last active: Mar 06 2014 11:02 AM
  • Joined: 07 Aug 2011

A_LineNumber
The number of the currently executing line within the script (or one of its #Include files). This line number will match the one shown by ListLines; it can be useful for error reporting such as this example: MsgBox Could not write to log file (line number %A_LineNumber%).Since a compiled script has merged all its #Include files into one big script, its line numbering may be different than when it is run in non-compiled mode.

#SingleInstance, force
a=10
b=20
c=30
msgbox %A_LineNumber%
a=11
b=22
c=33
msgbox %A_LineNumber%
ExitApp

Win7 - Firefox 10.0.2 - AHK_L 1.1.07.00
Please bear with me and my English which is so bad at times that even I don't understand myself

jsingh125
  • Members
  • 14 posts
  • Last active: Dec 15 2011 05:10 AM
  • Joined: 14 Dec 2011
thanks for the reply. could you please give a short example?

Odlanir
  • Members
  • 775 posts
  • Last active: Mar 06 2014 11:02 AM
  • Joined: 07 Aug 2011
I've edited my previous post
Win7 - Firefox 10.0.2 - AHK_L 1.1.07.00
Please bear with me and my English which is so bad at times that even I don't understand myself

jsingh125
  • Members
  • 14 posts
  • Last active: Dec 15 2011 05:10 AM
  • Joined: 14 Dec 2011
thanks for the help.

The problem is that if I knew where all to put Msgbox, then it would be fine to use this function.

But is there any where to see, while execution of the script, which line number is being executed. Since, i don't know where it would hang, i cannot predict putting Msgbox and so is there anything that tells me on run-time, which line number of being executed?

I was looking at the 'Pause' command. When the tool I am automating using AHK, hangs, I could Pause the script. But then after that, is there a way to figure out which line number has the script been paused at?
This, i suppose would be the nearest possible solution to getting line numbers at run-time (i.e. if that is not possible)

Thanks

girlgamer
  • Moderators
  • 3263 posts
  • Last active: Feb 01 2015 09:49 AM
  • Joined: 04 Jun 2010
There is also a ListLines command
http://www.autohotke...s/ListLines.htm
although what i suspect you're asking for is a trace facility. Generally those are built into IDE's when a program is run from there. What happens in a trace facility is that each line is essentially captured before it's run and displayed on a debugging monitor screen. Facilities for tracing generally also have breakpointing as well so when a program hits a specific line number or subroutine it stops. May i recommend a debugger called DbgView for checking program flow. you can find it here
http://technet.micro...ernals/bb896647
it has trace facilities and the ability to show variables as well as other useful debugging tools. It's free and it's safe.

one other thing. you will need to run the debugger before the script starts and somewhere, generally at the beginning of the area you want to check, you can add the AutoHotkey command OutputDebug
http://www.autohotke...OutputDebug.htm
to capture specific script events as they occur

The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter   KeyLooperDemo   Key Spammer   TinyClickRecorder  GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Rock-on%20kitten.gif


  • Guests
  • Last active:
  • Joined: --
You can try the debugging feature of AutoHotkey_L
<!-- m -->http://l.autohotkey....ipts.htm#idebug<!-- m -->

or you could try this debug log function by Rapte_Of_Suzaku
<!-- m -->http://www.autohotke... ... =debug log<!-- m -->

Grendahl
  • Members
  • 416 posts
  • Last active: Jul 07 2014 08:01 PM
  • Joined: 10 Aug 2009
You could use ToolTip to show you the <!-- m -->http://www.autohotke...s/ListLines.htm<!-- m --> contents.
Always have your scripts when you need them with Dropbox.
Sign up for free! http://db.tt/9Hrieqj

Odlanir
  • Members
  • 775 posts
  • Last active: Mar 06 2014 11:02 AM
  • Joined: 07 Aug 2011
You can use Try/Catch with those lines of code that you think could potentially generate errors
try { 
	inst := ComObjCreate(a_surely_non_existent_COM_object) ; <---- Put here 
} catch e { 
	 MsgBox, 16,, % "Exception thrown!`n`nwhat: " e.what "`nfile: " e.file 
		. "`nline: " e.line "`nmessage: " e.message "`nextra: " e.extra 
}

Win7 - Firefox 10.0.2 - AHK_L 1.1.07.00
Please bear with me and my English which is so bad at times that even I don't understand myself