]> gitweb.factorcode.org Git - factor.git/blob - basis/debugger/debugger.factor
factor: Make source files/resources 644 instead of 755.
[factor.git] / basis / debugger / debugger.factor
1 ! Copyright (C) 2004, 2011 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.strings arrays assocs classes
4 classes.builtin classes.mixin classes.tuple classes.tuple.parser
5 combinators combinators.short-circuit compiler.errors compiler.units
6 continuations definitions destructors effects.parser fry generic
7 generic.math generic.parser generic.single grouping io io.encodings
8 io.styles kernel kernel.private lexer libc make math math.order
9 math.parser math.ratios namespaces parser prettyprint sequences
10 sequences.private slots source-files.errors strings strings.parser
11 summary system vocabs vocabs.loader vocabs.parser words ;
12 IN: debugger
13
14 GENERIC: error-help ( error -- topic )
15
16 M: object error-help drop f ;
17
18 M: tuple error-help class-of ;
19
20 M: source-file-error error-help error>> error-help ;
21
22 GENERIC: error. ( error -- )
23
24 M: object error. short. ;
25
26 M: string error. print ;
27
28 : traceback-link. ( continuation -- )
29     "[" write [ "Traceback" ] dip write-object "]" print ;
30
31 : :s ( -- )
32     error-continuation get data>> stack. ;
33
34 : :r ( -- )
35     error-continuation get retain>> stack. ;
36
37 : :c ( -- )
38     error-continuation get call>> callstack. ;
39
40 : :get ( variable -- value )
41     error-continuation get name>> assoc-stack ;
42
43 : :res ( n -- * )
44     1 - restarts [ nth f ] change-global continue-restart ;
45
46 : :1 ( -- * ) 1 :res ;
47 : :2 ( -- * ) 2 :res ;
48 : :3 ( -- * ) 3 :res ;
49
50 : restart. ( restart n -- )
51     [
52         1 + dup 3 <= [ ":" % # "      " % ] [ # " :res  " % ] if
53         name>> %
54     ] "" make print ;
55
56 : restarts. ( -- )
57     restarts get [
58         nl
59         "The following restarts are available:" print
60         nl
61         [ restart. ] each-index
62     ] unless-empty ;
63
64 : print-error ( error -- )
65     [ error. flush ] curry
66     [ [ "Error in print-error!" print drop ] with-global ]
67     recover ;
68
69 : :error ( -- )
70     error get print-error ;
71
72 : print-error-and-restarts ( error -- )
73     print-error
74     restarts.
75     nl
76     "Type :help for debugging help." print flush ;
77
78 : try ( quot -- )
79     [ print-error-and-restarts ] recover ; inline
80
81 : expired-error. ( obj -- )
82     "Object did not survive image save/load: " write third . ;
83
84 : io-error. ( error -- )
85     "I/O error #" write third [ . ] [ strerror print ] bi ;
86
87 : type-check-error. ( obj -- )
88     "Type check error" print
89     "Object: " write dup fourth short.
90     "Object type: " write dup fourth class-of .
91     "Expected type: " write third type>class . ;
92
93 : divide-by-zero-error. ( obj -- )
94     "Division by zero" print drop ;
95
96 HOOK: signal-error. os ( obj -- )
97
98 : array-size-error. ( obj -- )
99     "Invalid array size: " write dup third .
100     "Maximum: " write fourth 1 - . ;
101
102 : fixnum-range-error. ( obj -- )
103     "Cannot convert to fixnum: " write third . ;
104
105 : ffi-error. ( obj -- )
106     "FFI error" print drop ;
107
108 : find-ffi-error ( string -- error )
109     [ linkage-errors get ] dip
110     '[ nip asset>> name>> _ = ] assoc-find drop nip
111     [ error>> message>> ] [ "none" ] if* ;
112
113 : undefined-symbol-error. ( obj -- )
114     "Cannot resolve C library function" print
115     "Library: " write dup fourth .
116     third symbol>string
117     [ "Symbol: " write print ]
118     [ "DlError: " write find-ffi-error print ] bi
119     "See http://concatenative.org/wiki/view/Factor/Requirements" print ;
120
121 : stack-underflow. ( obj name -- )
122     write " stack underflow" print drop ;
123
124 : stack-overflow. ( obj name -- )
125     write " stack overflow" print drop ;
126
127 : datastack-underflow. ( obj -- ) "Data" stack-underflow. ;
128 : datastack-overflow. ( obj -- ) "Data" stack-overflow. ;
129 : retainstack-underflow. ( obj -- ) "Retain" stack-underflow. ;
130 : retainstack-overflow. ( obj -- ) "Retain" stack-overflow. ;
131 : callstack-underflow. ( obj -- ) "Call" stack-underflow. ;
132 : callstack-overflow. ( obj -- ) "Call" stack-overflow. ;
133
134 : memory-error. ( error -- )
135     "Memory protection fault at address " write third .h ;
136
137 : fp-trap-error. ( error -- )
138     "Floating point trap" print drop ;
139
140 : interrupt-error. ( error -- )
141     "Interrupt" print drop ;
142
143 : callback-space-overflow. ( error -- )
144     "Callback space overflow" print drop ;
145
146 PREDICATE: vm-error < array
147     dup length 2 < [ drop f ] [
148         {
149             [ first-unsafe KERNEL-ERROR = ]
150             [ second-unsafe 0 kernel-error-count 1 - between? ]
151         } 1&&
152     ] if ;
153
154 : vm-errors ( error -- n errors )
155     second {
156         [ expired-error.           ]
157         [ io-error.                ]
158         [ drop                     ]
159         [ type-check-error.        ]
160         [ divide-by-zero-error.    ]
161         [ signal-error.            ]
162         [ array-size-error.        ]
163         [ fixnum-range-error.      ]
164         [ ffi-error.               ]
165         [ undefined-symbol-error.  ]
166         [ datastack-underflow.     ]
167         [ datastack-overflow.      ]
168         [ retainstack-underflow.   ]
169         [ retainstack-overflow.    ]
170         [ callstack-underflow.     ]
171         [ callstack-overflow.      ]
172         [ memory-error.            ]
173         [ fp-trap-error.           ]
174         [ interrupt-error.         ]
175         [ callback-space-overflow. ]
176     } ; inline
177
178 M: vm-error summary drop "VM error" ;
179
180 M: vm-error error. dup vm-errors dispatch ;
181
182 M: vm-error error-help vm-errors nth first ;
183
184 M: division-by-zero summary
185     drop "Division by zero" ;
186
187 M: no-method summary
188     drop "No suitable method" ;
189
190 M: no-method error.
191     "Generic word " write
192     dup generic>> pprint
193     " does not define a method for the " write
194     dup object>> class-of pprint
195     " class." print
196     "Dispatching on object: " write object>> short. ;
197
198 M: bad-slot-value summary drop "Bad store to specialized slot" ;
199
200 M: bad-slot-name summary drop "Bad slot name in object literal" ;
201
202 M: bad-vocab-name summary drop "Vocab name cannot contain \":/\\ \"" ;
203
204 M: no-math-method summary
205     drop "No suitable arithmetic method" ;
206
207 M: no-next-method summary
208     drop "Executing call-next-method from least-specific method" ;
209
210 M: inconsistent-next-method summary
211     drop "Executing call-next-method with inconsistent parameters" ;
212
213 M: check-method-error summary
214     drop "Invalid parameters for create-method" ;
215
216 M: not-a-tuple summary
217     drop "Not a tuple" ;
218
219 M: bad-superclass summary
220     drop "Tuple classes can only inherit from non-final tuple classes" ;
221
222 M: bad-initial-value summary
223     drop "Incompatible initial value" ;
224
225 M: no-cond summary
226     drop "Fall-through in cond" ;
227
228 M: no-case summary
229     drop "Fall-through in case" ;
230
231 M: slice-error summary
232     "Cannot create slice" swap {
233         { [ dup from>> 0 < ] [ ": from < 0" ] }
234         { [ dup [ to>> ] [ seq>> length ] bi > ] [ ": to > length" ] }
235         { [ dup [ from>> ] [ to>> ] bi > ] [ ": from > to" ] }
236         [ f ]
237     } cond nip append ;
238
239 M: bounds-error summary drop "Sequence index out of bounds" ;
240
241 M: groups-error summary drop "Non positive group size" ;
242
243 M: condition error. error>> error. ;
244
245 M: condition summary error>> summary ;
246
247 M: condition error-help error>> error-help ;
248
249 M: assert summary drop "Assertion failed" ;
250
251 M: assert-sequence summary drop "Assertion failed" ;
252
253 M: assert-sequence error.
254     standard-table-style [
255         [ "=== Expected:" print expected>> stack. ]
256         [ "=== Got:" print got>> stack. ] bi
257     ] tabular-output ;
258
259 M: immutable summary drop "Sequence is immutable" ;
260
261 M: redefine-error error.
262     "Re-definition of " write
263     def>> . ;
264
265 M: undefined-word summary
266     word>> undefined-word?
267     "Cannot execute a deferred word before it has been defined"
268     "Cannot execute a word before it has been compiled"
269     ? ;
270
271 M: no-compilation-unit error.
272     "Attempting to define " write
273     definition>> pprint
274     " outside of a compilation unit" print ;
275
276 M: no-vocab summary
277     drop "Vocabulary does not exist" ;
278
279 M: encode-error summary drop "Character encoding error" ;
280
281 M: decode-error summary drop "Character decoding error" ;
282
283 M: bad-create summary drop "Bad parameters to create" ;
284
285 M: cannot-be-inline summary drop "This type of word cannot be inlined" ;
286
287 M: attempt-all-error summary drop "Nothing to attempt" ;
288
289 M: already-disposed summary drop "Attempting to operate on disposed object" ;
290
291 M: no-current-vocab-error summary
292     drop "Not in a vocabulary; IN: form required" ;
293
294 M: no-word-error summary
295     name>>
296     "No word named “"
297     "” found in current vocabulary search path" surround ;
298
299 M: no-word-error error. summary print ;
300
301 M: no-word-in-vocab summary
302     [ vocab>> ] [ word>> ] bi
303     [ "No word named “" % % "” found in “" % % "” vocabulary" % ] "" make ;
304
305 M: no-word-in-vocab error. summary print ;
306
307 M: ambiguous-use-error summary
308     name>>
309     "The name “" "” resolves to more than one word." surround ;
310
311 M: ambiguous-use-error error. summary print ;
312
313 M: staging-violation summary
314     drop
315     "A parsing word cannot be used in the same file it is defined in." ;
316
317 M: bad-number summary
318     drop "Bad number literal" ;
319
320 M: duplicate-slot-names summary
321     drop "Duplicate slot names" ;
322
323 M: invalid-slot-name summary
324     drop "Invalid slot name" ;
325
326 M: bad-inheritance summary
327     drop "Circularity in inheritance chain" ;
328
329 M: not-in-a-method-error summary
330     drop "call-next-method can only be called in a method definition" ;
331
332 M: version-control-merge-conflict summary
333     drop "Version control merge conflict in source code" ;
334
335 GENERIC: expected>string ( obj -- str )
336
337 M: f expected>string drop "end of input" ;
338 M: word expected>string name>> ;
339 M: string expected>string ;
340
341 M: unexpected error.
342     "Expected " write
343     dup want>> expected>string write
344     " but got " write
345     got>> expected>string print ;
346
347 M: lexer-error error.
348     [ lexer-dump ] [ error>> error. ] bi ;
349
350 M: lexer-error summary
351     error>> summary ;
352
353 M: lexer-error compute-restarts
354     error>> compute-restarts ;
355
356 M: lexer-error error-help
357     error>> error-help ;
358
359 M: bad-effect summary
360     drop "Bad stack effect declaration" ;
361
362 M: invalid-row-variable summary
363     drop "Stack effect row variables can only occur as the first input or output" ;
364
365 M: row-variable-can't-have-type summary
366     drop "Stack effect row variables cannot have a declared type" ;
367
368 M: bad-escape error.
369     "Bad escape code: \\" write char>> write nl ;
370
371 M: bad-literal-tuple summary drop "Bad literal tuple" ;
372
373 M: not-a-mixin-class summary drop "Not a mixin class" ;
374
375 M: not-found-in-roots summary
376     path>> "Cannot resolve vocab: " prepend ;
377
378 M: wrong-values summary drop "Quotation's stack effect does not match call site" ;
379
380 M: stack-effect-omits-dashes summary drop "Stack effect must contain “--”" ;
381
382 M: callsite-not-compiled summary
383     drop "Caller not compiled with the optimizing compiler" ;
384
385 { "threads" "debugger" } "debugger.threads" require-when