Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sample call trace procedure

Status
Not open for further replies.

PinkeyNBrain

IS-IT--Management
Dec 12, 2006
279
0
0
US
Since I drop in here now and again to ask questions - thought I'd attempt to return some effort. The following procedure is something I put together a long time ago but has come in fairly handy while debugging larger scripts. If anyone has upgrade suggestions - great. If anyone can use this - you are welcome to it:
Code:
# If you just want to look at yourself, call w/ value
#   nesting_levels_to_trace_back = 0
# You'll at least see what was passed to you.
proc call_trace {{nesting_levels_to_trace_back 999}} {
   puts "Call Trace: {call lvl} -> proc args_passed_to_proc"
   set call_trace_nesting_level [info level]
   set calling_nest_level [expr $call_trace_nesting_level - 1]
   if {! [regexp -- {^\s*\d+\s*$} $nesting_levels_to_trace_back]} {
      set nesting_levels_to_trace_back 0
   }

   set level_to_trace_to          [expr $calling_nest_level - $nesting_levels_to_trace_back]
   if {$level_to_trace_to < 1} {set level_to_trace_to 1}

   for {set i $calling_nest_level} {$i >= $level_to_trace_to} {incr i -1} {
      set outline [format "%3s --> %s" $i [info level $i]]
      puts $outline
   }
   return {}
};# END call_trace
I know some of the variable names are a little long. I'd just recently changed them to try and make the code a little more self documenting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top