Sign in to follow this  
Followers 0
Klaatu

Yet Another ... Debugger

29 posts in this topic

#1 ·  Posted (edited)

Here's my attempt at writing a debugger using AutoIt. While not as fancy schmancy as Stumpii's, it's alot simpler and written in pure AutoIt so it's easy to change if you want to. I actually came up with this before seeing anything of what Stumpii had been doing, so I guess it's true: (not so) great minds think alike.

When you want to know exactly what you're script is doing, run it under the control of this script. This script opens a window and displays in real time exactly what line of code your script is currently executing. It'll show you the execution order of your script's commands. No modification to your script is required.

Let me know if you come up with any good modifications, have any suggestions for improvements, find a bug, think it's a piece of crap, or whatever. It's only about 400 lines, including liberal use of comments, so it's not very complicated or anything. I just wanted something along the lines of what we used to have with V2. While not really anything like that, it does give similar feedback.

Along the same lines as DebugIt, I've also come up with DebugVer, which basically does the same thing as DebugIt (in that you use it to debug your script), but instead of opening up a GUI and outputting the results there, it creates a new .au3 file from your script with debug code in it. When you run this script it will create a log file of the script's execution. Hopefully that's not too convoluted; basically from YourScript.au3 DebugVer creates YourScriptVer.au3, which when executed creates YourScriptVer_somenumber.log. I use it instead of DebugIt when interactive debugging would be inconvenient. One note, though: if your script successfully executes (ie, no errors are generated), the log file is sent to the recycle bin so as not to build up a bunch of log files.

Enjoy,

Klaatu

DebugIt, Version 1.6, posted 1/24/11

DebugVer, Version 1.0, posted 1/24/11

DebugIt.au3

DebugVer.au3

Edited by Klaatu

My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites



This debugger is great, for what it does. You might consider setting the disable property for the edit box in your popup window. As it is, I can click on the edit box while a script is running and completely screw up the output.

That aside, it's a good utility. I'd suggest a pause button, but that would probably have to hook into AdLib or something and therefore would break the script being debugged if it uses AdLib.

-S


(Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]

Share this post


Link to post
Share on other sites

Compliments! It's a very useful code.

My suggestions:

  • Optionally show the variables contents on the output window
  • Write the temporary file in a temp dir. and remove it at the end (see the Helpfile - UDF "_TempFile")
  • pause button: maybe you could find useful the callback functions of this UDF: DirWalk
Keep up the good work.

Many thanks

Peppe

Share this post


Link to post
Share on other sites

This is a similar approach as the LUA scripts included in SciTE4AutoIt3.

However I do like the way you have done this which made me copy/paste your code into a Func in AutoIt3Wrapper and made the following changes to see how that would work:

1. Dumped it into a Func and only used the "create a tempfile" portion of your code

2. Changed it so the output goes into SciTE's output pane.

3. Added the @error and @extended to the output record.

4. Added a Preprocessor statement to trigger this debug function: #Run_Debug_Mode=Y ; y/n

Attached version of AutoIt3Wrapper has this added if people want to test.

Sorry for Hijacking your thread but just thought this was a good idea to implement it and wanted to thank you for the idea.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I've taken all the suggestions offered and came up with V1.1.

You might consider setting the disable property for the edit box in your popup window.

Considered, but don't know how.

I'd suggest a pause button, but that would probably have to hook into AdLib or something and therefore would break the script being debugged if it uses AdLib.

The method I used to implement a pause button did not use Adlib, so didn't break anything.

My suggestions:

  • Optionally show the variables contents on the output window
  • Write the temporary file in a temp dir. and remove it at the end (see the Helpfile - UDF "_TempFile")
  • pause button
Showing variable contents would be very, very involved, so I have my doubts that would ever be added. It'd be nice, but beyond my abilities.

As stated in the source code, I didn't use a temp folder because it could cause the script to not function as intended. (BTW, who was the genius that originally wrote that _TempFile function anyway? :whistle:)

Pause button implemented. Thanks for the suggestion.

Sorry for Hijacking your thread but just thought this was a good idea to implement it and wanted to thank you for the idea.

No problem JdeB; you're welcome.

Change Log for V1.1:

  • calls a single function to do the work, and add said function at the bottom of the script. Similar to what Stumpii does in his debugger; after all, a good idea deserves stealing.
  • changed: event driven GUI rather than loop mode.
  • changed: font in Edit control to be fixed pitch.
  • added: pause/resume and stop/exit buttons.
I don't know that I like how it turned out. It seems to me the script being debugged runs significantly slower than before. Other than that it seems OK, but the slowness could be a big issue with some scripts I would think.

Anyway, let me know what you think either way.

(attachment removed. see first post)

Edited by Klaatu

My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites

Keep up the good work. I may steal some of your ideas if you are not watching!


“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Share this post


Link to post
Share on other sites

Good job!


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites

DebugIt.exe doesn'twork. The error messagebox says:

AutoIt Error

Error reading the file GuiConstants.au3

The error happens with every script on the first include statement. No errors usingDebugIt.au3.

Suggestion:

IMHO users are interested in debugging only some parts of their code, and so what about adding a button to switch on/off display of executed statements?

Maybe the debugging process would be faster.

All the best

Peppe

Share this post


Link to post
Share on other sites

DebugIt.exe doesn'twork. The error messagebox says:

AutoIt Error

Error reading the file GuiConstants.au3

The error happens with every script on the first include statement. No errors usingDebugIt.au3.

OK, so your using a compiled script with the /AutoIt3ExecuteScript option. The includes are not found next to the interpreter so you get messages of the includes as being not found. This is mentioned in the AutoIt help file as being normal behaviour.

A note about using the /AutoIt3ExecuteScript option. Since the standard library is searched for in the current interpreter's directory, the standard library functions will not be found; that library will only be found when run through AutoIt3.exe. It's recommended that you compile a script to the .a3x format before attempting to run it with /AutoIt3ExecuteScript.

Try moving DebugIt.exe into AutoIt's install directory and see if it works as expected there with finding the include files.

Share this post


Link to post
Share on other sites

Suggestion:

IMHO users are interested in debugging only some parts of their code, and so what about adding a button to switch on/off display of executed statements?

There is already something like this built in to the program. If you look at the documentation at the beginning of the source, you'll see that you can place ";debug" comments before and after those sections you do not want to debug and no debugging code will be added to any statements between the two ";debug" lines.

So, just place a ";debug" comment near the top of your script, another above the statement that you want to start debugging, and a third when you want to stop debugging.

While not as slick as having some method in the GUI to change that, it's a whole lot easier to implement. Feel free to modify the program to suit your needs however. If you come up with something nice, post it to the forum!


My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites

OK, so your using a compiled script with the /AutoIt3ExecuteScript option. The includes are not found next to the interpreter so you get messages of the includes as being not found. This is mentioned in the AutoIt help file as being normal behaviour.

Try moving DebugIt.exe into AutoIt's install directory and see if it works as expected there with finding the include files.

You're right. Thanks.

There is already something like this built in to the program. If you look at the documentation at the beginning of the source, you'll see that you can place ";debug" comments before and after those sections you do not want to debug and no debugging code will be added to any statements between the two ";debug" lines.

So, just place a ";debug" comment near the top of your script, another above the statement that you want to start debugging, and a third when you want to stop debugging.

While not as slick as having some method in the GUI to change that, it's a whole lot easier to implement. Feel free to modify the program to suit your needs however. If you come up with something nice, post it to the forum!

OK. Thank you.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I guess adding variable output wasn't as difficult as I though it would be, so here it is.

Version 1.2

  • added: outputs variable names and their values after the executed line.
  • changed: comment to control debugging changed from ';debug' to ';debugit'.
  • changed: font in edit control from 'Lucidia Console' to 'Courier New'.
  • other small changes, such as 'Passthru' mode described in the code.
(attachment removed. see first post) Edited by Klaatu

My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites

I guess adding variable output wasn't as difficult as I though it would be, so here it is.

Version 1.2

  • added: outputs variable names and their values after the executed line.
  • changed: comment to control debugging changed from ';debug' to ';debugit'.
  • changed: font in edit control from 'Lucidia Console' to 'Courier New'.
  • other small changes, such as 'Passthru' mode described in the code.

I have tried DebugIt and one script I've tried sets all the control at the top left of the form. I can't see why, the script works fine without DEbugIt and all the lines appear to be copied correctly.

Any suggestions or would you need to see the script?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

That does sound very strange. You mean your script creates its own GUI and the controls it places on your form are all positioned at 0,0 of the form? That's weird.

Sure, if you want to send along feel free to send me a PM with it attached. Even better would be if you could trim it down to include only enough code to generate the problem, which also would keep private any code you wouldn't feel comfortable sharing with a stranger.

I'd be very curious myself to see if I can find out what's going on.


My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

I have tried DebugIt and one script I've tried sets all the control at the top left of the form. I can't see why, the script works fine without DEbugIt and all the lines appear to be copied correctly.

Any suggestions or would you need to see the script?

Looking at the comment strip, I don't see a fail safe for double quotes, and the same for your variable retrieve. I wonder if Martin is using double quotes, and maybe one of those 2 functions may have messed it up.

On the variable retrieve, You might look at using StringRegExp() 1 line will return all your variables into an array.

Edit:

By double quotes I mean something like:

$Var = "The ""grass"" is greener on ""the""; other side"oÝ÷ ØêÚºÚ"µÍ][ÝÒHØ[[ÜH ][ÝÉ][ÝÓÝÈÙ][ÝÉ][ÝÉÌÍÈÛÈHØ[YÜÈ   ][ÝÉ][ÝÜ^I][ÝÉ][ÝÈ^H[[[ÛI][Ý

Edit2:

I'm not deleting the above, but they very well may not be the case.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

If I'm not mistaken, double quotes within a string like you show can actually be ignored. While it's true that the second quote character on the line would technically end the string in the code, the very next quote (3rd on the line) would set the state back to being inside a string again. The same goes for every odd numbered quote on the line. Whether we're scanning the line for comments or variable names, the same logic applies.

If I'm not mistaken that is. I could be wrong though. Am I?


My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites

If I'm not mistaken, double quotes within a string like you show can actually be ignored. While it's true that the second quote character on the line would technically end the string in the code, the very next quote (3rd on the line) would set the state back to being inside a string again. The same goes for every odd numbered quote on the line. Whether we're scanning the line for comments or variable names, the same logic applies.

If I'm not mistaken that is. I could be wrong though. Am I?

No, as I looked at your code, and I was looking at what I wrote, since you weren't getting "strings" is why I made my 2nd edit. 1 stops, next comes then stops at next quote, so I would say you were fine there.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

DebutIt.au3 updated. See attachment in first post. Listed below are the changes:

Version 1.3

  • changed: activate previous window after opening our GUI, in case the script we're debugging relies or acts on the active window. Also, re-activate our debug window when and if the script we're debugging exits.

  • changed: change our debug window title slightly to reduce the possibility of our window's title interfering with window title matching in the script we're debugging.

  • added: include built-in variables (@'s) in variable output.

My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites

DebutIt.au3 updated. See attachment in first post. Listed below are the changes:

Version 1.3

  • changed: activate previous window after opening our GUI, in case the script we're debugging relies or acts on the active window. Also, re-activate our debug window when and if the script we're debugging exits.

  • changed: change our debug window title slightly to reduce the possibility of our window's title interfering with window title matching in the script we're debugging.

  • added: include built-in variables (@'s) in variable output.

Have you stopped developing this Klaatu? Just wondered since no posts since Jan 25th. Or is it lack of feedback for incentive?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
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
Sign in to follow this  
Followers 0