Jump to content

Which Debugger do you use?


Recommended Posts

So far, I've stuck to MsgBox and ConsoleWrite to debug scripts (+some SciTE Syntax Checks), but looking for something a little better.

It seems both Heron's Debugger: http://www.autoitscript.com/forum/index.php?showtopic=103142

and "Another Debugger for Autoit"


have been abandoned. I'm curious what tools forum members are using to debug scripts?

Link to comment
Share on other sites

+ _ArrayDisplay
+ FileWriteLine to write some info to a log file

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

noellarkin,

ConsoleWrite, MsgBox (or ExtMsgBox ;) ) and (Debug)ArrayDisplay have always been sufficient to date.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

The full version of SciTE also has a very useful trace feature with ConsoleLog, I've used it several times to track tricky bugs.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

9 hours ago, noellarkin said:

I'm curious what tools forum members are using to debug scripts?

There are some beneficial keyboard shortcuts for debugging.

Example : 

Local $iCount = 0
For $i = 1 To 5
     $iCount += $i * 2
Next

Place the mouse cursor on the $iCount variable in the loop.

Now use ALT-D (without the - character, of course ;)). This will automatically insert a ConsoleWrite statement.

With CTRL-SHIFT-D a MsgBox is inserted analogously.

With CTRL-ALT-Z all lines inserted in this way can be removed.

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

I sprinkle my code with calls to this func. Disable/enable with a Ctrl-Q as needed. Shows me the Function , step, and multiple variable names and values on one line.  (All of my Func have a "Local Const $ThisFunc = "Func Name" line right after the Func definition).
 

#include-once

; =====================================================================
;
;   #include "HotRod\hr_Debug_Print.au3"
;
;   Example Calls:
;
;   hr_Debug_Print( $ThisFunc, "StepName", "MsgText", "$P1Name", $P1Value, ... )
;   hr_Debug_Print( $ThisFunc, "StepName", Default, "$P1Name", $P1Value, ... )
;   hr_Debug_Print( $ThisFunc, Default, Default, "$P1Name", $P1Value, ... )
;
;   hr_Debug_Print( $ThisFunc, "StepName", _
;       "MsgText", _
;       "$P1Name", $P1Value, ... )
;
; =====================================================================

Func hr_Debug_Print( _
    Const $FuncName = Default, _
    $StepName = Default, _
    $MsgText = Default, _
    $P1Name = Default, $P1Value = Default, _
    $P2Name = Default, $P2Value = Default, _
    $P3Name = Default, $P3Value = Default, _
    $P4Name = Default, $P4Value = Default, _
    $P5Name = Default, $P5Value = Default, _
    $P6Name = Default, $P6Value = Default, _
    $P7Name = Default, $P7Value = Default, _
    $P8Name = Default, $P8Value = Default, _
    $P9Name = Default, $P9Value = Default _
    )

    Local $MsgStrg = "DEBUG_PRINT"

    If NOT ( ( $FuncName = Default ) OR ( $FuncName = "")  ) Then
        $MsgStrg = $MsgStrg & " | " & $FuncName
    EndIf

    If NOT ( ( $StepName = Default ) OR ( $StepName = "")  ) Then
        $MsgStrg = $MsgStrg & " | " & $StepName
    EndIf

    If NOT ( ( $MsgText = Default ) OR ( $MsgText = "")  ) Then
        $MsgStrg = $MsgStrg & " | " & $MsgText
    EndIf

    If $P1Name <> Default Then $MsgStrg = $MsgStrg & " | " & $P1Name & ": '" & $P1Value & "'"
    If $P2Name <> Default Then $MsgStrg = $MsgStrg & " | " & $P2Name & ": '" & $P2Value & "'"
    If $P3Name <> Default Then $MsgStrg = $MsgStrg & " | " & $P3Name & ": '" & $P3Value & "'"
    If $P4Name <> Default Then $MsgStrg = $MsgStrg & " | " & $P4Name & ": '" & $P4Value & "'"
    If $P5Name <> Default Then $MsgStrg = $MsgStrg & " | " & $P5Name & ": '" & $P5Value & "'"
    If $P6Name <> Default Then $MsgStrg = $MsgStrg & " | " & $P6Name & ": '" & $P6Value & "'"
    If $P7Name <> Default Then $MsgStrg = $MsgStrg & " | " & $P7Name & ": '" & $P7Value & "'"
    If $P8Name <> Default Then $MsgStrg = $MsgStrg & " | " & $P8Name & ": '" & $P8Value & "'"
    If $P9Name <> Default Then $MsgStrg = $MsgStrg & " | " & $P9Name & ": '" & $P9Value & "'"

    ConsoleWrite( $MsgStrg & @CRLF )

EndFunc

 

Link to comment
Share on other sites

I've written a couple of functions that I use everywhere, saved them as "CustomDebugging.au3" in my includes folder, and included them in every script. The basic idea was:

; Calls Debug with a custom message. Uses '!' as a prefix to make the text red in the debugger.
; I set mine up to let SciTE jump to the right line... like you see with a compile error
Func ErrMsg($sMsg = "", $iError = @error, $iExtended = @extended, $iScriptLineNum = @ScriptLineNumber)
    ; If there is an error, then write the error message
    If $iError Then
        ; I also added this later to simplify the function call
        If IsFunc($sMsg) Then $sMsg = FuncName($sMsg)
        Local $sText = '"' & @ScriptFullPath & '" (' & $iScriptLineNum & ',5) : (See below for message)' & @CRLF
        $sText &= "! Error: " & $iError & " - "
        If $iExtended <> 0 Then $sText &= "Extended: " & $iExtended & " - "
        Debug($sText & $sMsg, "")
    EndIf
    ; Preserve the error
    Return SetError($iError, $iExtended, $iError)
    
EndFunc

; a wrapper around ConsoleWrite... mostly because I always forget to add a newline
Func Debug($sMsg, $sPrefix = "+")
    If $sPrefix <> "" Then $sPrefix &= " "
    ConsoleWrite($sPrefix & $sMsg & @CRLF)
EndFunc

Func Examples()
    Local $aFiles = _FileListToArray(@UserProfileDir)
    If ErrMsg(_FileListToArray) Then Exit
    
    Debug("Found " & $aFiles[0]  & " files")
    
EndFunc

I (even) later added options to write messages to a log file (the name of the log and if it should write).

I did a few things right and more than a couple wrong and it's a bit of a mess now because of my refusal to fix all my old scripts. I'd suggest writing your own and making it work for you.

One thing I wish I'd done differently would be to use best practices in naming my functions: _<name of include>_<function name>  I'd be much easier for me to fix some of my mistakes if I'd done that. So I would've named the include Debug.au3 and renamed the functions _Debug_Debug and _Debug_ErrMsg, but with the time I saved from not writing _Debug_ so many times, I wrote this post :P

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...