Jump to content

Variable Visualizer


Shafayat
 Share

Recommended Posts

Variable Visualizer is a simple runtime variable debugger. Features -

1. Dynamic Updates of Global Variables

2. Manual Updates for all kind of Variables

The UDF (Properly commented)

#include-once
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

; #INDEX# =======================================================================================================================
; Title .........: Variable Visualizer
; AutoIt Version : 3.3.6.0+
; Language ......: English
; Description ...: Functions for Runtime Debugging using a simple GUI and Adlib
; Author(s) .....: Shafayat
; ===============================================================================================================================

; #CURRENT# =====================================================================================================================
; _VV_Init()
; _VV_Show()
; _VV_Hide()
; _VV_RegisterCallBack()
; _VV_Add()
; _VV_AddRaw()
; _VV_Delete()
; _VV_Close()
;
; ===============================================================================================================================

; #NO_DOC_FUNCTION# =============================================================================================================
; __VariableVisualizerFormClose()
; __VariableVisualizerLib()
; __VariableVisualizerListClick()
;
; ===============================================================================================================================

; #GLOBALVARS# ===================================================================================================================
Global $__VariableVisualizerForm
Global $__VariableVisualizerList
Global $__VariableVisualizer_CallBack = ""
Global $__VariableVisualizer_Exit = False
Global $__VariableVisualizer_array[1]
; ===============================================================================================================================

; #FUNCTION# ====================================================================================================================
; Name...........: _VV_Init
; Description ...: Initiates the debugger window.
; Syntax.........: _VV_Init($width = 300, $height = 500, $delay = 500, $title = "Visualizer OutPut")
; Parameters ....: $width  - Width in pixels
;                  $height - Height in pixels
;                  $delay  - Update delay (greater slower, lesser less CPU usage)
;                  $title  - Prefered title
; Return values .: TRUE
; Author ........: Shafayat
; ===============================================================================================================================
Func _VV_Init($width = 300, $height = 500, $delay = 500, $title = "Visualizer OutPut")
    Opt("GUIOnEventMode", 1)
    $__VariableVisualizer_Exit = False
    Local $style = BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS)
    $__VariableVisualizerForm = GUICreate($title, $width, $height, @DesktopWidth - $width - 20, @DesktopHeight - $height - 80, $style)
    GUISetOnEvent($GUI_EVENT_CLOSE, "__VariableVisualizerFormClose", $__VariableVisualizerForm)
    $__VariableVisualizerList = GUICtrlCreateListView("", 0, 0, $width, $height)
    GUICtrlSetResizing($__VariableVisualizerList, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP)
    GUICtrlSetOnEvent($__VariableVisualizerList, "__VariableVisualizerListClick")
    _GUICtrlListView_AddColumn($__VariableVisualizerList, "Variable", $width / 2)
    _GUICtrlListView_AddColumn($__VariableVisualizerList, "Value", $width / 2)
    AdlibRegister("__VariableVisualizerLib", $delay)
    Return SetError(0, 1, True)
EndFunc   ;==>_VV_Init

; #FUNCTION# ====================================================================================================================
; Name...........: _VV_Show
; Description ...: Show the debugger info
; Syntax.........: _VV_Show()
; Parameters ....: None
; Return values .: None
; Author ........: Shafayat
; ===============================================================================================================================
Func _VV_Show()
    GUISetState(@SW_SHOW, $__VariableVisualizerForm)
EndFunc   ;==>_VV_Show

; #FUNCTION# ====================================================================================================================
; Name...........: _VV_Hide
; Description ...: Hide the debugger info
; Syntax.........: _VV_Hide()
; Parameters ....: None
; Return values .: None
; Author ........: Shafayat
; ===============================================================================================================================
Func _VV_Hide()
    GUISetState(@SW_HIDE, $__VariableVisualizerForm)
EndFunc   ;==>_VV_Hide

; #FUNCTION# ====================================================================================================================
; Name...........: _VV_RegisterCallBack
; Description ...: Set the function to call when the debugger window starts to close
; Syntax.........: _VV_RegisterCallBack($function)
; Parameters ....: $function - function to call
; Return values .: None
; Author ........: Shafayat
; ===============================================================================================================================
Func _VV_RegisterCallBack($function)
    $__VariableVisualizer_CallBack = $function
EndFunc   ;==>_VV_RegisterCallBack

; #FUNCTION# ====================================================================================================================
; Name...........: _VV_Add
; Description ...: Add a variable (preferably a global variable)
; Syntax.........: _VV_Add($varname, $dynamic = False)
; Parameters ....: $varname - variable name (as string)
;                  $dynamic -
;                           - True = Automatically update values
;                           - False = Do NOT automatically update values
; Return values .: None
; Author ........: Shafayat
; ===============================================================================================================================
Func _VV_Add($varname, $dynamic = False)
    If IsDeclared($varname) = False Then Return False
    Local $index, $found = False
    If $dynamic = False Then
        $index = _GUICtrlListView_FindText($__VariableVisualizerList, $varname & " = ", -1, False, False)
        If $index = -1 Then
            $index = _GUICtrlListView_AddItem($__VariableVisualizerList, $varname & " = ")
            _GUICtrlListView_AddSubItem($__VariableVisualizerList, $index, Eval($varname), 1)
        Else
            _GUICtrlListView_AddSubItem($__VariableVisualizerList, $index, Eval($varname), 1)
        EndIf
    Else
        _ArrayAdd($__VariableVisualizer_array, $varname)
        $__VariableVisualizer_array[0] = $__VariableVisualizer_array[0] + 1
    EndIf
EndFunc   ;==>_VV_Add

; #FUNCTION# ====================================================================================================================
; Name...........: _VV_AddRaw
; Description ...: Add a variable in RAW mode (preferably a local variable)
; Syntax.........: _VV_AddRaw($varname, $value)
; Parameters ....: $varname - variable name (as string)
;                  $value   - value of variables
; Return values .: None
; Author ........: Shafayat
; ===============================================================================================================================
Func _VV_AddRaw($varname, $value)
    Local $index, $found = False
    $index = _GUICtrlListView_FindText($__VariableVisualizerList, $varname & " = ", -1, False, False)
    If $index = -1 Then
        $index = _GUICtrlListView_AddItem($__VariableVisualizerList, $varname & " = ")
        _GUICtrlListView_AddSubItem($__VariableVisualizerList, $index, $value, 1)
    Else
        _GUICtrlListView_AddSubItem($__VariableVisualizerList, $index, $value, 1)
    EndIf
EndFunc   ;==>_VV_AddRaw

; #FUNCTION# ====================================================================================================================
; Name...........: _VV_Delete
; Description ...: Delere a previouslt entried variable
; Syntax.........: _VV_Delete($varname)
; Parameters ....: $varname - variable name (as string)
; Return values .: None
; Author ........: Shafayat
; ===============================================================================================================================
Func _VV_Delete($varname)
    Local $index
    For $i = 1 To $__VariableVisualizer_array[0]
        If $varname = $__VariableVisualizer_array[$i] Then
            $__VariableVisualizer_array[0] = $__VariableVisualizer_array[0] - 1
            Local $confirm = _ArrayDelete($__VariableVisualizer_array, $i)
        EndIf
    Next
    $index = _GUICtrlListView_FindText($__VariableVisualizerList, $varname & " = ", -1, False, False)
    If $index = -1 Then
    Else
        Local $ret = _GUICtrlListView_DeleteItem(GUICtrlGetHandle($__VariableVisualizerList), $index)
        Return $ret
    EndIf
    Return 0
EndFunc   ;==>_VV_Delete

; #FUNCTION# ====================================================================================================================
; Name...........: _VV_Close
; Description ...: Closes the debugger window
; Syntax.........: _VV_Close()
; Parameters ....: None
; Return values .: None
; Author ........: Shafayat
; ===============================================================================================================================
Func _VV_Close()
    $__VariableVisualizer_Exit = True
EndFunc   ;==>_VV_Close

; #INTERNAL_USE_ONLY# ===========================================================================================================
; These are Undocumented Functions.
; ===============================================================================================================================
Func __VariableVisualizerFormClose()
    $__VariableVisualizer_Exit = True
EndFunc   ;==>__VariableVisualizerFormClose

Func __VariableVisualizerListClick()

EndFunc   ;==>__VariableVisualizerListClick

Func __VariableVisualizerLib()
    Local $index
    If $__VariableVisualizer_Exit = True Then
        If $__VariableVisualizer_CallBack = "" Then
        Else
            Local $reallyexit = Call($__VariableVisualizer_CallBack)
            If Not $reallyexit Then Return 0
        EndIf
        Global $__VariableVisualizer_array[1]
        $__VariableVisualizer_array[0] = 0
        GUIDelete($__VariableVisualizerForm)

        AdlibUnRegister("__VariableVisualizerLib")
    Else
        For $i = 1 To $__VariableVisualizer_array[0]
            $index = _GUICtrlListView_FindText($__VariableVisualizerList, $__VariableVisualizer_array[$i] & " = ", -1, False, False)
            If $index = -1 Then
                $index = _GUICtrlListView_AddItem($__VariableVisualizerList, $__VariableVisualizer_array[$i] & " = ")
                _GUICtrlListView_AddSubItem($__VariableVisualizerList, $index, Eval($__VariableVisualizer_array[$i]), 1)
            Else
                _GUICtrlListView_AddSubItem($__VariableVisualizerList, $index, Eval($__VariableVisualizer_array[$i]), 1)
            EndIf
        Next
    EndIf
EndFunc   ;==>__VariableVisualizerLib

Full Download: (with sample) Variable Visualizer.rar

[Not using this account any more. Using "iShafayet" instead]

Link to comment
Share on other sites

Dynamic entries are automatically updated. But as local variables are limited to a function, they can not be used in the adlib that updates dynamic values.

[Not using this account any more. Using "iShafayet" instead]

Link to comment
Share on other sites

Dynamic entries are automatically updated. But as local variables are limited to a function, they can not be used in the adlib that updates dynamic values.

Fix that! Some naming scheme + on-the-fly editing of the source provides you with full access!

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Monoceres, I am neither as adept nor as experienced in autoit. Perhaps you would kindly divert my ignorance towards the proper knowledge.

[Actually, just tell me how to do that.]

[Not using this account any more. Using "iShafayet" instead]

Link to comment
Share on other sites

Monoceres, I am neither as adept nor as experienced in autoit. Perhaps you would kindly divert my ignorance towards the proper knowledge.

[Actually, just tell me how to do that.]

There's very few differences between local and global variables. For example this code:

Func test()
 Local $a = 10
 Return $a
EndFunc

Could be transformed by a debugger to:

Global $__debug__test__a
Func test()
 $__debug__test__a=10
 Return $__debug__test__a
EndFunc

Which would allow the debugger to monitor the value with an adlib approach.

A better way would be to have the debugger insert "hooks" into the code. This would make the first code look like:

Func test()
 Local $a = 10
 ; The debugger detected that $a changed, update display!
 UpdateVariable("test","a",$a)
 Return $a

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Correct me if I am mistaken, but what are you using is either-

1. Declaring a variable as global and using it in a function which essentially makes it a global variable. No matter whether you use a variable inside a function or not, i local variable is always local and a global one is always global.

2. Manually updating the value. The same effect is achieved by using the _vv_addraw() function. All the add functions work as updater as well.

I thought you were talking about some other method like reading from memory.

[Not using this account any more. Using "iShafayet" instead]

Link to comment
Share on other sites

  • 1 month later...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...