Jump to content

Debugging: A way to monitor a variable?


Recommended Posts

I'm trying to debug a large, complex, Event Mode two-GUI app wherein a specific variable appears to get clobbered (set to 0) in some very non-obvious way (the variable is deliberately altered only once, and the simple monitor debug code I put in there (i.e., "If $var = 0 Then MsgBox") doesn't show any problem).

And the well-known graphical debugger doesn't show all the GUI controls I need, so that's out.  And the Dbug graphical debugger built into ISN Studio is too fragile.  So what I was considering using _Timer_SetTimer() on say a 10 millisecond delay to intermittently call an event function that would check to see if the monitored variable has been set to 0. That would work to a degree, but unless I had a reasonably good idea where in the code the variable got reset, it wouldn't do me much good.

Can anyone think of some better way to do this?

Thanks!

Link to comment
Share on other sites

I use a lot of ConsoleWrites when I'm trying to debug something, that way the script continues without having to hit OK every time.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks, BrewManNH!  I'm already using the StatusMsgs UDF by Kobashi to do the equivalent.  Unforunately, unless I make a StatusMsg call before executing every line of code (roughly 2000 of them), it won't help. You see, for all the world it looks like the variable is being clobbered quite inadvertently, as if from a asynchrous event similar to a buffer overwrite or the like (but there's no way I'm gonna blame anything but a bug in my own code).

Back in my Systems Programming days, clobbered variables were a dreaded but somewhat common problem.  Most of the time I used something similar to the timer idea in my OP; every few milliseconds, examine the contents of the clobbered variable to see when it was over-written. But unlike in this case, it was possible to determine with good precision where the clobberin' happened.  Not so using AutoIt (which is hardly a complaint, mind you!  AutoIt's advantages far outweigh it's minor downsides).

 

 

 

Link to comment
Share on other sites

You should look at every instance of where that variable is altered and put a consolewrite that shows the line number and the value of the variable, which is easy to do by clicking on the variable and hitting ALT+D in Scite (if you have the full Scite4AutoIt3). Unless you're actually accessing the variable, it can't change on it's own, it has to be something in your script doing it and this is probably the best way of figuring out where it's happening. Unless you're sending it as a parameter to a function using ByRef the only places it can be "clobbered" is where you're altering it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I completely admite that what you say seems perfectly logical, but please believe me when I say that's not appears to be happening. I stand by the parenthetical statement in the first sentence of my OP: "the variable is deliberately altered only once".

There's exactly ONE line of code which changes that variable, and it's returned by trancexx's _GUICtrlCreateGIF() function in her GifAnimation UDF.  Now, I check the error codes upon return from that call, but perhaps there's some undocumented code in that UDF that returns an invalid value.  I'll check it out...

 

Link to comment
Share on other sites

I saw that you stated that, but there's no way for a variable to get reset to zero (or set to any other value) without code doing it. You're either not getting the return you think you're getting from that function, or you're altering it somewhere else in your script, maybe by using ByRef.

But there's no magic involved, there's only code, and it's the code that's at fault somewhere and you have to go through it line-by-line until you can see where it happens. Whether by reading each line yourself, or by putting more error checking in and consolewrites.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I found the problem, and it had nothing to do with my code changing the variable at all, as I argued and expected.  Instead, in certain circumstances the UDF messes up the return codes so that what should have been reported as an error was not.

Problem solved.

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

  • Recently Browsing   0 members

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