Re: Calling Func/Proc
- Posted by CChris <christian.cuvier at agriculture.gou?.fr> Jul 11, 2007
- 673 views
c.k.lester wrote: > > I would really like to have a function that returns the name of the > calling func/proc. To be used like as follows: > > function query_db(sequence s) > if debug then > logfile( calling_proc() ) > end if > ... > end function > > logfile() is my output function. In this case, I am using it for debugging > purposes. > > Instead of putting hundreds of lines of code (one for each function > that would call query_db()), I'd rather just have the one line in query_db(). > That seems reasonable, doesn't it? > > Is this possible, and how easy if so? I would use this sort of stuff a lot for debugging. Not straightforward if you want to avoid any impact at all on performance. In il.e, you can see that routine names are kept in the stripped down symbol table passed on to the backend. So there's a hope. The SymTab index of the callee is computed when calling a routine, but not kept (sub is a local var in the big switch routine in be_execute.c). You could get a full image of the call stack by keeping a "sequence", which doesn't exist in C, of indexes of called routines, and your routine would query the symtab image for routine names. It is relatively easy to make the mod, except for the details of dynamically growing the sequence of called symtabs when the preallocated quota is about to overflow. I'd suggest limiting such recording to sections bracketed by a with debug and without debug directives, without debug being the default. In this case, the only impact on performance with debug off would be testing a flag to decide whether to record subroutine symtab indexes or not, on every routine call. CChris