2012-04-10 83 views

回答

7

沒有,但是你可以重寫source命令本身來跟蹤source「d文件的地方,像這樣:

rename source __real_source 
proc source args { 
    global sourced 
    lappend sourced $args 
    uplevel 1 [linsert $args 0 __real_source] 
} 

更新:擴大有關source的脆弱性在多納爾的評論命令有如何設置執行軌跡:

proc register_sourced {cmd args} { 
    global sourced 
    lappend sourced [lindex $cmd end] 
} 
trace add execution source leave register_sourced 
+1

不應該在'uplevel'命令中執行'__real_source'嗎? – bmk 2012-04-10 10:33:20

+0

使用8.6,我會使用:'proc source args {lappend :: sourced [lindex $ args end]; tailcall __real_source {*} $ args}' – 2012-04-10 10:48:36

+0

謝謝,@bmk,我在輸入時忽略了這個 – kostix 2012-04-10 10:58:00