~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to tcl/scipadsources/db_debugsession.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
proc checkscilabbusy {{mb "message"}} {
 
2
    global sciprompt lang
 
3
    if [ expr [string compare $sciprompt -1] == 0 ] {
 
4
        if {$mb != "nomessage"} {
 
5
            if {$lang == "eng"} {
 
6
                set mes "Scilab is working, wait for the prompt to issue a\
 
7
                     debugger command."
 
8
                set tit "Scilab working"
 
9
            } else {
 
10
                set mes "Scilab est occup�, attendez le prompt pour\
 
11
                     effectuer des commandes de d�bug."
 
12
                set tit "Scilab occup�"
 
13
            }
 
14
            tk_messageBox -message $mes -title $tit -type ok -icon info
 
15
        }
 
16
        return "busy"
 
17
    } else {
 
18
        return "OK"
 
19
    }
 
20
}
 
21
 
 
22
proc execfile_bp {} {
 
23
    global funnameargs funsinbuffer
 
24
    if {[checkscilabbusy] == "OK"} {
 
25
        set removecomm [removescilab_bp "no_output"]
 
26
        set textareacur [gettextareacur]
 
27
        set tagranges [$textareacur tag ranges breakpoint]
 
28
        set setbpcomm ""
 
29
        set firstbp "true"
 
30
#        set nlins -1
 
31
 #       set nlins -2
 
32
        foreach {tstart tstop} $tagranges {
 
33
            set infun [whichfun [$textareacur index $tstart]]
 
34
            if {$infun !={} } {
 
35
                set funname [lindex $infun 0]
 
36
                set lineinfun [expr [lindex $infun 1] - 1]
 
37
                set setbpcomm [concat $setbpcomm "setbpt(\"$funname\",$lineinfun);"]
 
38
                if {$firstbp == "true"} {
 
39
                    set firstbp "false"
 
40
                    $textareacur tag remove activebreakpoint 1.0 end
 
41
                    $textareacur tag add activebreakpoint "$tstart linestart" "$tstart lineend"
 
42
                    $textareacur mark set insert "$tstart linestart"
 
43
                    $textareacur see "$tstart linestart"
 
44
                }
 
45
           } else {
 
46
                # <TODO> .sce case: I thought about:
 
47
                # - inserting pause before each bp, or
 
48
                # - inserting mode(6) plus mode(0) before each bp
 
49
                # but none is satisfactory. Using mode() will fail in loops,
 
50
                # and pause is very limited (no way to add a new bp during debug,
 
51
                # or to remove all bp to finish execution ignoring them)
 
52
#                incr nlins 1
 
53
 #               incr nlins 2
 
54
#                $textareacur insert "$tstart +$nlins l linestart" "pause\n"
 
55
 #               $textareacur insert "$tstart +$nlins l linestart" "mode(6)\nmode(0)\n"
 
56
            }
 
57
        }
 
58
        if {$funnameargs != ""} {
 
59
            execfile
 
60
# Leading spaces here to avoid possible loss of first characters
 
61
# However this does not work for long lines created by execfile (i.e.
 
62
# lines that take a long time to display or execute in Scilab window)
 
63
            if {$setbpcomm != ""} {
 
64
                set commnvars [createsetinscishellcomm]
 
65
                set watchsetcomm [lindex $commnvars 0]
 
66
                if {$watchsetcomm != ""} {
 
67
                    ScilabEval "     $watchsetcomm"
 
68
                }
 
69
                while {[checkscilabbusy "nomessage"] == "busy"} {}
 
70
                ScilabEval "     $setbpcomm; $funnameargs,$removecomm"
 
71
                set filename [creategetfromshellcomm]
 
72
                ScilabEval "     exec(\"$filename\");"
 
73
            } else {
 
74
                ScilabEval "     $funnameargs"
 
75
            }
 
76
        } else {
 
77
            # <TODO> .sce case
 
78
##            execfile
 
79
        }
 
80
    }
 
81
}
 
82
 
 
83
proc removescilab_bp {outp} {
 
84
    global funnames
 
85
    if {[checkscilabbusy] == "OK"} {
 
86
        set textareacur [gettextareacur]
 
87
        set tagranges [$textareacur tag ranges breakpoint]
 
88
        set setbpcomm ""
 
89
        if {$funnames != ""} {
 
90
            foreach fun $funnames {
 
91
                set setbpcomm [concat $setbpcomm "delbpt(\"$fun\");"]
 
92
            }
 
93
            if {$outp != "no_output"} {
 
94
                ScilabEval " $setbpcomm"
 
95
            }
 
96
        } else {
 
97
            # <TODO> .sce case
 
98
        }
 
99
        return $setbpcomm
 
100
    }
 
101
}
 
102
 
 
103
proc stepbystep_bp {} {
 
104
# <TODO>
 
105
# I have no satisfactory solution for the time being.
 
106
# The heart of the matter with step by step execution is that
 
107
# once the execution is stopped there is no way of knowing what is the next
 
108
# line of code to execute. Of course, it is usually the next code line in the
 
109
# sci file, but this is not necessarily true in for, while, if, and case
 
110
# structures. I do not foresee any other remedy than a complete code analysis
 
111
# performed in tcl (!), but this is a huge task I'm not prepared to go into.
 
112
# Moreover, all this analysis is already (and surely better) done by the
 
113
# Scilab interpreter, therefore the best way would probably be to add a new
 
114
# Scilab function that would return the line number of the next instruction to
 
115
# be executed. This should no be such a tricky thing to do drawing inspiration
 
116
# e.g. from setbpt. Then I would have to hack a way of returning a result to
 
117
# tcl from a ScilabEval. 
 
118
# Note: There is a similar issue with active bp tag in conditional structures.
 
119
# Currently the "next active bp" is the next one in the file
 
120
# but this becomes wrong if the bp is in a for, while, if or case
 
121
    tk_messageBox -message "Sorry, step execution not yet implemented!"
 
122
}
 
123
 
 
124
proc resume_bp {} {
 
125
# <TODO> correct wrong active bp tag when bp is in conditional structure
 
126
# Solution to this is similar to what is explained in proc stepbystep_bp 
 
127
    global funnameargs
 
128
    if {[checkscilabbusy] == "OK"} {
 
129
        set textareacur [gettextareacur]
 
130
        set actbprange [$textareacur tag ranges activebreakpoint]
 
131
        if {$actbprange != {} } {
 
132
            set actstart [lindex $actbprange 0]
 
133
            set actstop [lindex $actbprange 1]
 
134
            $textareacur tag remove activebreakpoint $actstart $actstop
 
135
            set nextbprange [$textareacur tag nextrange breakpoint $actstop]
 
136
            if {$nextbprange != {} } {
 
137
                set newipos [lindex $nextbprange 0]
 
138
                $textareacur tag add activebreakpoint $newipos [lindex $nextbprange 1]
 
139
                $textareacur mark set insert $newipos
 
140
                $textareacur see $newipos
 
141
            }
 
142
        }
 
143
        if {$funnameargs != ""} {
 
144
            set commnvars [createsetinscishellcomm]
 
145
            set watchsetcomm [lindex $commnvars 0]
 
146
            if {$watchsetcomm != ""} {
 
147
                ScilabEval "     $watchsetcomm"
 
148
                set returnwithvars [lindex $commnvars 1]
 
149
                while {[checkscilabbusy "nomessage"] == "busy"} {}
 
150
    # <TODO> : [..]=resume(..) is bugged! -> replaced by a simple resume with no argument
 
151
    # but then the changes in the watch window are obviously not reflected in the calling
 
152
    # workspace in Scilab
 
153
    #            ScilabEval "     $returnwithvars"
 
154
                ScilabEval "     resume"
 
155
            } else {
 
156
                while {[checkscilabbusy "nomessage"] == "busy"} {}
 
157
                ScilabEval "     resume"
 
158
            }
 
159
            set filename [creategetfromshellcomm]
 
160
            ScilabEval "     exec(\"$filename\");"
 
161
        } else {
 
162
            # <TODO> .sce case
 
163
            # Sending \n is if mode(6) mode(0) is used. If pause, there is no
 
164
            # need to distinguish between .sci and .sce (resume is sent for both)
 
165
 #           ScilabEval " "
 
166
        }
 
167
    }
 
168
}
 
169
 
 
170
proc goonwo_bp {} {
 
171
    global funnameargs
 
172
    if {[checkscilabbusy] == "OK"} {
 
173
        if {$funnameargs != ""} {
 
174
            [gettextareacur] tag remove activebreakpoint 1.0 end
 
175
            removescilab_bp "with_output"
 
176
            ScilabEval " resume"
 
177
            set filename [creategetfromshellcomm]
 
178
            ScilabEval "     exec(\"$filename\");"
 
179
        }
 
180
    }
 
181
}
 
182
 
 
183
proc dispcallstack_bp {} {
 
184
    if {[checkscilabbusy] == "OK"} {
 
185
        ScilabEval " whereami()"
 
186
    }
 
187
}
 
188
 
 
189
proc canceldebug_bp {} {
 
190
    global funnameargs
 
191
    if {[checkscilabbusy] == "OK"} {
 
192
        if {$funnameargs != ""} {
 
193
            [gettextareacur] tag remove activebreakpoint 1.0 end
 
194
            removescilab_bp "with_output"
 
195
            ScilabEval " abort"
 
196
            set filename [creategetfromshellcomm]
 
197
            ScilabEval "     exec(\"$filename\");"
 
198
        }
 
199
    }
 
200
}