How can I tell where a proc was called

33 views
Skip to first unread message

Gaz Taylor

unread,
May 30, 2001, 6:22:38 PM5/30/01
to
I am having a great deal of trouble owrking out where a proc is being
called, is there a command which I can put in the proc, to give the name of
the procedure from which it was started? i.e.

proc one {} {
two
}

proc two {} {
# Would say 'I was called from 'one'!'
}

Or something like that.

Thanks in advance, answers would be appreciated be email,
gta...@ednet.co.uk

Cheers

Garry


Bruce Hartweg

unread,
May 30, 2001, 6:42:47 PM5/30/01
to
Gaz Taylor wrote:

see the man page on info for details but
puts "I was called from '[lindex [info level -1] 0]' - but first call was to '[lindex [info level 1] 0]'"
should do the trick (negative work up the stack, positive down)

# quick tester:

proc who_called {} {
puts "I was called from '[lindex [info level -1] 0]' - but first call was to '[lindex [info level 1] 0]'"
}

proc a {} {who_called}
proc b {} {who_called}
proc c {} {who_called}
proc d {} {a}
proc e {n} {$n}

# end


Output:

% a
I was called from 'a' - but first call was to 'a'
% b
I was called from 'b' - but first call was to 'b'
% c
I was called from 'c' - but first call was to 'c'
% d
I was called from 'a' - but first call was to 'd'
% e a
I was called from 'a' - but first call was to 'e'
% e b
I was called from 'b' - but first call was to 'e'
% e c
I was called from 'c' - but first call was to 'e'
% e d
I was called from 'a' - but first call was to 'e'


Bruce


Will Taylor

unread,
May 30, 2001, 9:28:44 PM5/30/01
to
I find a backtrace useful -- putting these two stmts in the
proc in question:
set backtrace ""; getBackTrace backtrace
puts stderr "<the-proc-in-question>: `$backtrace'"

Here is the backtrace proc:
proc getBackTrace { backTraceRef } {
upvar $backTraceRef backTrace

set startLevel [expr {[info level] - 2}]
for {set level 1} {$level <= $startLevel} {incr level} {
append backTrace "[lindex [info level $level] 0] => "
}
}

==> Will Taylor

Gaz Taylor wrote:

--

Will Taylor > Computational Sciences Division, Code IC
NASA Ames Research Center - voice:(650)604-3364, fax:(650)604-3594
Bldg 269, room 276, MS 269-2, Moffett Field, CA 94035-1000
tay...@ptolemy.arc.nasa.gov
http://ic-www.arc.nasa.gov/ic/people/taylor/taylor-home.html


Reply all
Reply to author
Forward
0 new messages