Jump to content

Retreive Last executed func name


Recommended Posts

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 by ivan
Link to comment
Share on other sites

  • Moderators

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 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

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

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

Link to comment
Share on other sites

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. :D

-brendan

Edited by bhoar
Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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

:D

Edit Hmm... the full semicolon and open brace turn into a emoticon within the AutoIt code tags.

Edited by MHz
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...