Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the location of TCL procedure?

Tags:

procedure

tcl

How can be find the location of procedure (function) in TCL. Under location I mean the source file in which it is declared.

I'm trying to read foreign source-code and can not find the declaration of a single procedure, example:

set MSISDNElement [regexp -all -inline {ISDN +[0-9]+} $Command]

if { $MSISDNElement != "" } {
    foreach elm $MSISDNElement {
        set MSISDNValue [list ISDN [getInternationalFormat [lindex $elm 1]]]
    }
}

set EptData [list [lindex $Command 1]]

InitEptData 3
foreach Element $EptData {
    SetEptData [lindex $Element 0] [lindex $Element 1]
}

For the functions InitEptData & SetEptData I can't find any declaration. Could someone familiar much more in deep with TCL, to explain how to solve that issue which I'm facing? Thanks in advance!

like image 224
nenito Avatar asked Sep 29 '12 09:09

nenito


1 Answers

There is no generic answer to this, as Tcl allows you to declare procedures on the fly, so they could have no actual file reference.

There are some attempts to improve the situation for procs that have a defining file, for example TIP280, which is actually available as info framein recent 8.5 versions, and TIP 86, which is only in discussion.

But if a simple grepdoes not work, you could track the moment a procedure or command gets created.

This happens in various places (Tcl OO might add a few more, not sure):

  • During a load command when a binary extension registers its command handler functions with Tcl_CreateCommand or the more modern Tcl_CreateObjCommand.
  • During a source command when a file with proc definitions is loaded
  • While running the proc command itself to define a new procedure

Using the commands info commands and namespace children you can walk the whole namespace tree to get a list of defined commands before and after the executed command. So you can create a wrapper that tracks any new commands. See http://wiki.tcl.tk/1489 for some hints how to do it.

Or, simply use a debugger like RamDebugger http://www.compassis.com/ramdebugger/Intro, or ActiveStates commercial debugger.

like image 79
schlenk Avatar answered Oct 18 '22 16:10

schlenk