ivan Posted June 29, 2006 Share Posted June 29, 2006 (edited) Hello! I'm working on a tailored debugger which requies identifying executing function names so an error code can be set in order for the main function to handle possible errors and call those functions again if required. Propably trying to reinvent the weel as well! since Autoit evolved to v3, thereby replacing labels by funcs, i've never had to use label names again, but there comes a time when knowing the name of the current executing function can come in handy. Although @ScriptLineNumber can resolve this for non compiled scripts, I worked out the following trick which could be used to get the last executed function: Global $FuncName A() msgbox(0,'LastFunc', $FuncName) B() msgbox(0,'LastFunc', $FuncName) Func A() $FuncName='A' Endfunc Func B() $FuncName='B' Endfunc However, this throws the problem back if A() was called from within B(), or problems of higher order if functions are called recursively. Any help would be much appreciated. IVAN Edited June 29, 2006 by ivan Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 29, 2006 Moderators Share Posted June 29, 2006 (edited) You could always give the function a parameter specifically to track the Function it was comming from:Global $FuncName, $Count = 1 A() msgbox(0,'LastFunc', $FuncName) B() msgbox(0,'LastFunc', $FuncName) B() MsgBox(0,'LastFunc', $FuncName) Func A($FuncParam = 'A') $FuncName = $FuncParam Endfunc Func B($FuncParam = 'B') $Count += 1 $FuncName = $FuncParam If $Count = 3 Then A('A From B') Endfunc Edited June 29, 2006 by SmOke_N 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. Link to comment Share on other sites More sharing options...
ivan Posted June 29, 2006 Author Share Posted June 29, 2006 (edited) That's clever! Forgot to say thanks!! Edited June 29, 2006 by ivan Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
bhoar Posted June 29, 2006 Share Posted June 29, 2006 Some other ideas: 1. Keep track of the entire stack of function calls and append/trimm them at the start/exit of each Function call. Store this stack in a global variable (either as a string "A:B:C" or an array) and manipulate/maintain with your new _RegisterFunction("A")_ and _UnRegisterFunction("A")_ routines. Note that all possible exit points of a function must call the unregister function. You can also keep track of most recently exited functions (which it seems you want) as well with another global variable that is always set during unregister. 2. In addition, you can also keep a ring buffer of the last XX function calls which can also be useful for reporting. Note that the first item just gives you the current nesting structure, where as a ring buffer of, say 256 function calls will be useful for repeatedly called or recursively called function tracking as well. -brendan Link to comment Share on other sites More sharing options...
ivan Posted June 29, 2006 Author Share Posted June 29, 2006 bhoar: Your procedure makes sense. I've got a 2291 line script, which for obvious reasons now require a better dev environment, so got the latest scite. Also I got into documenting, debugging, and optimizing. Hope to trim redundancies by about 500 lines. Thanks IVAN Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
bhoar Posted June 29, 2006 Share Posted June 29, 2006 (edited) Thanks. You could even use the same calling convention for tracking how much time is spent in each function, etc. if there are performance issues, though if you have any functions that wait for window events or sleep, etc. that might not be so useful. And when done debugging, turn off the debug flag and make sure those function calls immeidately return instead of doing stuff. -brendan Edited June 29, 2006 by bhoar Link to comment Share on other sites More sharing options...
ivan Posted June 30, 2006 Author Share Posted June 30, 2006 @bhoar : In principle this could help as there's 8 main processes in my script which require tracking via a progress bar. However, the script will have to run on a wide range of pcs with different speeds, so time is not a constant... You gave a thought though. Cheers Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
MHz Posted June 30, 2006 Share Posted June 30, 2006 (edited) If you are using Scte4AutoIt3, then look for a tool called "Trace: Add func trace lines", which inserts a line into the start of each function. This may help to show what functions are being called and when to help with debugging. Sample line Func OnAutoItStart() ConsoleWrite('@@ (82) :(' & @MIN & ':' & @SEC & ') OnAutoItStart()' & @CR) ;### Trace Function Edit Hmm... the full semicolon and open brace turn into a emoticon within the AutoIt code tags. Edited June 30, 2006 by MHz Link to comment Share on other sites More sharing options...
ivan Posted June 30, 2006 Author Share Posted June 30, 2006 Cheers. Got it working! Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now