Using a Debugger with any text editor (DebugView/++)
Posted: 30 Sep 2021, 10:32
by TheArkive
I do still use a Msgobx now and then for very quick checking of code, but in the long run, to do any meaningful debugging of a complex script, one must use a debugger.
For some reason I didn't feel confident using a debugger for a very long time. It's actually not hard at all, and is well worth the time to setup.
I hope this tutorial will be a help to those who need to go past the Msgbox or the Tooltip for debugging but aren't sure how to do so.
In this tutorial I will show the default settings I use, and explain why.
DebugView++
Download your chosen distribution from here: DebugView++
(I chose the zip version.)
Below is an outline of the basic settings you need to be familiar with. If you are already familiar with DebugView, then DebugView++ is not much different, though it is better.
Open the filters window (indicated above - shown below).
DebugView++ is an independent program and doesn't require any special "connection" to your text editor/IDE. If you happen to use Notepad++ like me (as opposed to SciTE or AHKStudio) then this is one of the better ways to go.
DebugView
DebugView is an independent program and doesn't require any special "connection" to your text editor/IDE. If you happen to use Notepad++ like me (as opposed to SciTE or AHKStudio) then this is one of the better ways to go.
First acquire DebugView from the MS website. This program is portable and does not use an installer. Just unzip it anywhere. I recommend you put it somewhere reasonable, and use either a shortcut or a hotkey combo to launch it when you need it.
Once you have DebugView unzipped and your shortcuts placed, run it.
Set the check marks as indicated in the Capture menu. You won't need kernel output, so make sure Capture Kernel and Enable Verbose Kernel Output are unchecked (unless you actually need them, which is not so common).
I prefer to see the time column logged as the actual time with hh:mm:ss.xxx format so I can see milliseconds.
If you don't need "Always on top" then make sure that is unchecked.
I recommend you keep AutoScroll enabled, so you can see what is happening in real-time. But you may want to uncheck this so you can scroll when you want without stopping the script. It really depends on what you are debugging, and how you are debugging it. More on that later.
Notice the OutputDebug line starts with the same string that we set in the filter AHK: (ending in a space).
The helper function automatically prepends the desired filter to your debug messages so you can easily filter debug messages from your script(s). If you change your filter settings in DebugView, then make sure you change the helper function accordingly (or vice versa).
Without a filter, you will see a lot more debug info from other programs running (which you probably don't want).
Loop 5 {
dbg("Iteration: " A_Index)
Sleep 50
}
dbg(_in) { ; AHK v2 ; make sure this exists somewhere in your script
Loop Parse _in, "`n", "`r"
OutputDebug "AHK: " A_LoopField
}
If you have DebugView running, with the proper filters set, and run this short little script you will see the following output:
You can put any data you want in your dbg() message: ie. line numbers, function names, class name/method, etc.
The helper func will allow you to send "multi-line" data as well, but you may need to format it in a specific way so that you can tell if a batch of lines is meant to represent a single output.
The default font for both DebugView and DebugView++ is usually not a mono space font. You may wish to change the font to Consolas or Courier New which will help line up the text in the debug output. In DebugView, the font options are in the Options menu. In DebugView++ the font options are in the Options menu and in the toolbar.
Editors like VisualStudio Code, AHK Studio, and SciTE for AutoHotkey, catch the OutputputDebug-Output directly within the builtin terminal in a separate panel.
So the Debug-Output will be shown within these text editors. And some other Text Editors / IDE's will support plugins to do the same.
Re: Using a Debugger with any text editor (DebugView)
Posted: 30 Sep 2021, 11:45
by swagfag
debugview is old, debugview++ is new, these screenshots are annoying to open
Re: Using a Debugger with any text editor (DebugView)
Posted: 30 Sep 2021, 11:47
by TheArkive
@swagfag
Ok, sorry, i was trying to contribute, and I didn't see anything like this posted.
I'll look into DebugView++ and update this.
Re: Using a Debugger with any text editor (DebugView)
Posted: 30 Sep 2021, 14:23
by JoeSchmoe
This looks very helpful. Thank you!
Re: Using a Debugger with any text editor (DebugView/++)
Posted: 01 Oct 2021, 06:38
by TheArkive
@JoeSchmoe
No problem
@swagfag
Updated to include DebugView++. Any more pointers?
Re: Using a Debugger with any text editor (DebugView/++)
Posted: 01 Oct 2021, 06:44
by swagfag
Re: Using a Debugger with any text editor (DebugView/++)
Posted: 02 Oct 2021, 01:50
by hoppfrosch
Just one more hint - as you asked for:
Editors like VisualStudio Code catch the OutputputDebug-Output directly within the builtin terminal - no need to have a extra app run, just showing the Debug-Output within the IDE
Re: Using a Debugger with any text editor (DebugView/++)
Posted: 02 Oct 2021, 03:51
by TheArkive
@hoppfrosch
Thanks, I certainly did forget to mention that. OP edited.
Re: Using a Debugger with any text editor (DebugView/++)
Posted: 09 Oct 2021, 20:17
by 20170201225639
Can you outputdebug HTML to vscode's terminal and have it render as HTML?
I want to set it up so each time I enter a function, I do OutputDebug("<div>" A_ThisFunc )
And each time I exit I do OutputDebug(A_ThisFunc "</div>")
And that way I get a hierarchical representation of my callstack using nested html divs! How cool is that?
This is my current setup with debugview++, using indentation to represent the callstack (of my auto exec function). But it'd be nice to represent with html
2021_1009_2115_48 (Forsaken Icefish).png (97.99 KiB) Viewed 4893 times
Re: Using a Debugger with any text editor (DebugView/++)
Posted: 23 Dec 2021, 11:09
by doug9fo
I don't see how to actually use DebugView++ with Notepad++. What is the magic incantation, please?
Re: Using a Debugger with any text editor (DebugView/++)
Posted: 24 Dec 2021, 16:00
by TheArkive
@doug9fo
You don't actually use "DebugView++ with Nodepad++". That statement isn't entirely accurate or complete.
Your script can be edited in Notepad++. And you can design your script to use the DebugOutput command. And then you setup DebugView++ to filter only AHK messages (given the included helper function mentioned in the OP).
If you follow the directions in the OP, you should be able to use Notepad++ to edit your script, and then capture debug output in DebugView++ (with the proper settings/filters set - also described in the OP).