![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Getting the name of the caller function Hi, I have a function which logs a message to a log file. This function will be called from many functions within my .vbs script. In this function I want to find the name of the function which has called it (its parent function). This is so that the name of the caller gets logged. Is there a way to obtain the name of the caller or the entire call stack in .vbs? Thanks, Yash |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Getting the name of the caller function "Yash" <yashgt@xxxxxx> wrote in message news:8e6f303c-344f-483d-ba26-a04509cf1fc8@xxxxxx Quote: > Hi, > > I have a function which logs a message to a log file. This function > will be called from many functions within my .vbs script. In this > function I want to find the name of the function which has called it > (its parent function). This is so that the name of the caller gets > logged. > > Is there a way to obtain the name of the caller or the entire call > stack in .vbs? > > Thanks, > Yash Sub SetPrinter ... LogEvent (55, "SetPrinter") ... End Sub Function LogEvent (iEventID, sCaller) wscript.echo "ID=" & iEventID & " Caller=" & sCaller ... End Function |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Getting the name of the caller function The reason why I want to obtain it from call stack is so that I do not have to pass it as an argument. Quote: > You could pass the name of the calling function as an additional parameter: > > Sub SetPrinter > * ... > * LogEvent (55, "SetPrinter") > * ... > End Sub > > Function LogEvent (iEventID, sCaller) > * wscript.echo "ID=" & iEventID & " Caller=" & sCaller > * ... > End Function |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Getting the name of the caller function No, unfortunately. This is one of the awkward issues about the plain-vanilla nature of most of the script hosts - there's no way to generally determine enclosing scopes for segments of code. In theory, a custom script host could expose this kind of functionality, but that's a theoretical point that's not likely to be very helpful. In the past I've tried to do similar tracing activity within scripts, and the approach that I've used _may_ be helpful, although it's not as straightforward as what you're after. I created a generic linewriter function to make calls to the logger easier. Then within each function/routine in the code I was tracing I would insert a logger call at the beginning and end like this: function GetFoo(args) WriteLog "<Entering GetFoo" <code here> GetFoo = ... WriteLog ">Exiting GetFoo" end function This is, of course, quite cumbersome. You need to look through the log for matching enter/exit statements, and the function doesn't even know its own name automatically, making it a bit irksome to update. Out of curiosity, what's your end objective with this? I don't know if there's a palatable solution for your problem, but there may be another angle on it you haven't considered. "Yash" <yashgt@xxxxxx> wrote in message news:a24d885b-defe-4983-98ac-fd2953b06f1f@xxxxxx Quote: > The reason why I want to obtain it from call stack is so that I do not > have to pass it as an argument. > Quote: >> You could pass the name of the calling function as an additional >> parameter: >> >> Sub SetPrinter >> ... >> LogEvent (55, "SetPrinter") >> ... >> End Sub >> >> Function LogEvent (iEventID, sCaller) >> wscript.echo "ID=" & iEventID & " Caller=" & sCaller >> ... >> End Function |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Getting the name of the caller function Yash wrote: Quote: > I have a function which logs a message to a log file. This function > will be called from many functions within my .vbs script. In this > function I want to find the name of the function which has called it > (its parent function). This is so that the name of the caller gets > logged. > You might try running your script under a debugger. One debugger which might work is the "Microsoft Script Editor". The MSE comes as part of msOffice, but may also be available elsewhere. Earlier versions are named MSE.EXE, and later versions are named MSE7.EXE, (or maybe MSE8 or MSE9???. MSE does have a Call Stack Viewer. Look under: View => Debug Widows => Call Stack. I suspect there may be other debuggers which also have a call stack viewer. I have no experience with Sapien's PrimalScript, but it is the "Cadillac" of scripting tools, and has just about every feature you can think of, so you may find a call stack viewer in PrimalScript too. As far as "programatically" getting at the call stack -- that would be problematical at best. You may be able to find a 3re-party control to do it for you, but I have never seen one. You may also be able to "do-it- yourself" -- but I strongly suspect that some assembly code will have to come into play somewhere along the way. cheers, jw ____________________________________________________________ You got questions? WE GOT ANSWERS!!! ..(but, no guarantee the answers will be applicable to the questions) |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Getting the name of the caller function mr_unreliable wrote: Quote: > As far as "programatically" getting at the call stack > -- that would be problematical at best. You may be > able to find a 3re-party control to do it for you, but > I have never seen one. You may also be able to "do-it- > yourself" -- but I strongly suspect that some assembly > code will have to come into play somewhere along the > way. > reading Jochen Kalmbach's article (with code) entitled: "Walking the CallStack": http://www.codeproject.com/KB/threads/StackWalker.aspx Jochen is using microsoft's StackWalker/StackWalker64 tool, which I understand is part of the microsoft "Debugging Tools for Windows" package, which is part of the microsoft "Windows Developer Kit" (WDK). http://www.microsoft.com/whdc/DevToo...g/default.mspx If you don't have this installed, it is apparently downloadable (for free) from msdn. cheers, jw |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| bad pool caller | General Discussion | |||
| CALLER ID and Vista. | Vista General | |||
| Caller ID | Vista General | |||
| Bad Pool Caller | Vista installation & setup | |||
| Bad Pool Caller | Vista installation & setup | |||