본문으로 바로가기

아래의 코드를 이용하면 매 커맨드마다 프롬프트가 뜨므로, tcl 커맨드로 변수의 값이나 기타 정보를 확인 할 수 있습니다.

debugger.tcl

# debugger.tcl

# break point - pause execution
proc bp {} {
        interp alias {} tracecmd {} tracecmd1
}

# continue execution
proc cont {} {
        interp alias {} tracecmd {} tracecmd2
}

# used after a bp command
proc tracecmd1 {cmd op} {
        puts $cmd
        puts -nonewline "[lindex [info level -1] 0]> "
        gets stdin a
        while {$a ne ""} {
                if {[catch {uplevel 1 puts \[$a\]} err]} {puts $err}
                gets stdin a
        }
}

# used before a bp command or after a cont command
proc tracecmd2 {cmd op} {
        if {$cmd eq "bp"} {
                interp alias {} tracecmd {} tracecmd1
        }
}
interp alias {} tracecmd {} tracecmd2

test.tcl

# test.tcl
source debugger.tcl

proc func1 {v} {
        func2 10
        foreach x {1 2 3 4 5} { }
        for {set i 0} {$i < $v} {incr i} {
                puts i=$i
        }
}

proc func2 {a} {
        puts {This is func2}
        puts var=$a
}

trace add execution func1 enterstep tracecmd

bp
func1 10

startup

tclsh test.tcl