3771
|
1 /* |
|
2 |
|
3 Copyright (C) 2001 Ben Sapp |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
3771
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "ov-usr-fcn.h" |
|
32 #include "ov-list.h" |
|
33 #include "pager.h" |
|
34 #include "pt-all.h" |
|
35 |
4185
|
36 // TRUE means SIGINT should put us in the debugger at the next |
|
37 // available breakpoint. |
|
38 bool octave_debug_on_interrupt_state = false; |
|
39 |
3771
|
40 void |
|
41 tree_breakpoint::take_action (tree &tr) |
|
42 { |
|
43 if (act == set) |
|
44 { |
|
45 tr.set_breakpoint (); |
|
46 line = tr.line (); |
|
47 found = true; |
|
48 } |
|
49 else if (act == clear) |
|
50 { |
|
51 tr.delete_breakpoint (); |
|
52 found = true; |
|
53 } |
|
54 else if (act == list) |
|
55 { |
|
56 if (tr.is_breakpoint ()) |
|
57 { |
4233
|
58 bp_list.append (octave_value (tr.line ())); |
3771
|
59 line = tr.line () + 1; |
|
60 } |
|
61 } |
|
62 else |
|
63 panic_impossible (); |
|
64 |
|
65 return; |
|
66 } |
|
67 |
|
68 void |
|
69 tree_breakpoint::visit_while_command (tree_while_command& cmd) |
|
70 { |
|
71 if (found) |
|
72 return; |
|
73 |
|
74 if (cmd.line () >= line) |
|
75 take_action (cmd); |
|
76 |
|
77 tree_expression *expr = cmd.condition (); |
|
78 |
|
79 if (expr) |
|
80 expr->accept (*this); |
|
81 |
4274
|
82 tree_statement_list *lst = cmd.body (); |
3771
|
83 |
4274
|
84 if (lst) |
|
85 lst->accept (*this); |
3771
|
86 } |
|
87 |
|
88 void |
|
89 tree_breakpoint::visit_do_until_command (tree_do_until_command& cmd) |
|
90 { |
3805
|
91 if (found) |
|
92 return; |
3771
|
93 |
|
94 if (cmd.line () >= line) |
|
95 take_action (cmd); |
|
96 |
3805
|
97 tree_statement_list *lst = cmd.body (); |
|
98 |
3771
|
99 if (lst) |
|
100 lst->accept (*this); |
|
101 |
|
102 if (found) |
|
103 return; |
|
104 |
|
105 tree_expression *expr = cmd.condition (); |
|
106 |
|
107 if (expr) |
|
108 expr->accept (*this); |
|
109 } |
|
110 |
|
111 void |
|
112 tree_breakpoint::visit_argument_list (tree_argument_list& lst) |
|
113 { |
|
114 if (found) |
|
115 return; |
|
116 |
4219
|
117 for (tree_argument_list::iterator p = lst.begin (); p != lst.end (); p++) |
3771
|
118 { |
4219
|
119 tree_expression *elt = *p; |
3771
|
120 |
|
121 if (elt) |
|
122 elt->accept (*this); |
|
123 } |
|
124 } |
|
125 |
|
126 void |
|
127 tree_breakpoint::visit_binary_expression (tree_binary_expression& expr) |
|
128 { |
|
129 if (found) |
|
130 return; |
|
131 |
|
132 tree_expression *lhs = expr.lhs (); |
|
133 tree_expression *rhs = expr.rhs (); |
|
134 |
|
135 if (lhs && lhs->line () >= line) |
3805
|
136 lhs->accept (*this); |
3771
|
137 |
|
138 if (rhs && rhs->line () >= line) |
3805
|
139 rhs->accept (*this); |
3771
|
140 } |
|
141 |
|
142 void |
4207
|
143 tree_breakpoint::visit_break_command (tree_break_command& cmd) |
3771
|
144 { |
|
145 if (found) |
|
146 return; |
|
147 |
|
148 if (cmd.line () >= line) |
|
149 take_action (cmd); |
|
150 } |
|
151 |
|
152 void |
|
153 tree_breakpoint::visit_colon_expression (tree_colon_expression& expr) |
|
154 { |
|
155 if (found) |
|
156 return; |
|
157 |
3805
|
158 if (expr.line () >= line) |
|
159 take_action (expr); |
|
160 |
3771
|
161 tree_expression *base = expr.base (); |
|
162 |
|
163 if (base) |
|
164 base->accept (*this); |
|
165 |
|
166 tree_expression *increment = expr.increment (); |
|
167 |
|
168 if (increment) |
|
169 increment->accept (*this); |
|
170 |
|
171 tree_expression *limit = expr.limit (); |
|
172 |
|
173 if (limit) |
|
174 limit->accept (*this); |
|
175 } |
|
176 |
|
177 void |
4207
|
178 tree_breakpoint::visit_continue_command (tree_continue_command& cmd) |
3771
|
179 { |
|
180 if (found) |
|
181 return; |
|
182 |
|
183 if (cmd.line () >= line) |
|
184 take_action (cmd); |
|
185 } |
|
186 |
|
187 void |
|
188 tree_breakpoint::visit_decl_command (tree_decl_command& cmd) |
|
189 { |
|
190 if (found) |
|
191 return; |
|
192 |
|
193 tree_decl_init_list *init_list = cmd.initializer_list (); |
|
194 |
|
195 if (init_list) |
|
196 init_list->accept (*this); |
|
197 } |
|
198 |
|
199 void |
|
200 tree_breakpoint::visit_decl_elt (tree_decl_elt& cmd) |
|
201 { |
|
202 if (found) |
|
203 return; |
|
204 |
|
205 tree_identifier *ident = cmd.ident (); |
|
206 |
|
207 if (ident) |
|
208 ident->accept (*this); |
|
209 |
|
210 tree_expression *expr = cmd.expression (); |
|
211 |
|
212 if (expr) |
|
213 expr->accept (*this); |
|
214 |
|
215 } |
|
216 |
|
217 void |
|
218 tree_breakpoint::visit_decl_init_list (tree_decl_init_list& lst) |
|
219 { |
|
220 if (found) |
|
221 return; |
|
222 |
4219
|
223 for (tree_decl_init_list::iterator p = lst.begin (); p != lst.end (); p++) |
3771
|
224 { |
4219
|
225 tree_decl_elt *elt = *p; |
3771
|
226 |
|
227 if (elt) |
|
228 elt->accept (*this); |
|
229 } |
|
230 } |
|
231 |
|
232 void |
|
233 tree_breakpoint::visit_simple_for_command (tree_simple_for_command& cmd) |
|
234 { |
|
235 if (found) |
|
236 return; |
|
237 |
|
238 if (cmd.line () >= line) |
|
239 take_action (cmd); |
|
240 |
|
241 tree_expression *expr = cmd.control_expr (); |
|
242 |
|
243 if (expr) |
|
244 expr->accept (*this); |
|
245 |
4274
|
246 tree_statement_list *lst = cmd.body (); |
3771
|
247 |
4274
|
248 if (lst) |
|
249 lst->accept (*this); |
3771
|
250 } |
|
251 |
|
252 void |
|
253 tree_breakpoint::visit_complex_for_command (tree_complex_for_command& cmd) |
|
254 { |
|
255 if (found) |
|
256 return; |
|
257 |
|
258 if (cmd.line () >= line) |
|
259 take_action (cmd); |
|
260 |
|
261 tree_expression *expr = cmd.control_expr (); |
|
262 |
|
263 if (expr) |
|
264 expr->accept (*this); |
|
265 |
4274
|
266 tree_statement_list *lst = cmd.body (); |
3771
|
267 |
4274
|
268 if (lst) |
|
269 lst->accept (*this); |
3771
|
270 |
|
271 } |
|
272 |
|
273 void |
4661
|
274 tree_breakpoint::visit_octave_user_function (octave_user_function&) |
3771
|
275 { |
4661
|
276 // We should not visit octave user functions because the function we |
|
277 // are currently in is the function where the breakpoint was |
|
278 // requested. |
3771
|
279 } |
|
280 |
|
281 void |
4661
|
282 tree_breakpoint::visit_octave_user_function_header (octave_user_function&) |
3771
|
283 { |
4661
|
284 // Do nothing. |
3771
|
285 } |
|
286 |
|
287 void |
4661
|
288 tree_breakpoint::visit_octave_user_function_trailer (octave_user_function&) |
3771
|
289 { |
4661
|
290 // Do nothing. |
3771
|
291 } |
|
292 |
|
293 void |
|
294 tree_breakpoint::visit_identifier (tree_identifier& id) |
|
295 { |
|
296 if (found) |
|
297 return; |
|
298 |
|
299 if (id.line () >= line ) |
|
300 take_action (id); |
|
301 } |
|
302 |
|
303 void |
|
304 tree_breakpoint::visit_if_clause (tree_if_clause& cmd) |
|
305 { |
|
306 if (found) |
|
307 return; |
|
308 |
|
309 tree_expression *expr = cmd.condition (); |
|
310 |
|
311 if (expr) |
|
312 expr->accept (*this); |
|
313 |
4274
|
314 tree_statement_list *lst = cmd.commands (); |
3771
|
315 |
4274
|
316 if (lst) |
|
317 lst->accept (*this); |
3771
|
318 } |
|
319 |
|
320 void |
|
321 tree_breakpoint::visit_if_command (tree_if_command& cmd) |
|
322 { |
|
323 if (found) |
|
324 return; |
|
325 |
4274
|
326 tree_if_command_list *lst = cmd.cmd_list (); |
3771
|
327 |
4274
|
328 if (lst) |
|
329 lst->accept (*this); |
3771
|
330 } |
|
331 |
|
332 void |
|
333 tree_breakpoint::visit_if_command_list (tree_if_command_list& lst) |
|
334 { |
|
335 if (found) |
|
336 return; |
|
337 |
4219
|
338 for (tree_if_command_list::iterator p = lst.begin (); p != lst.end (); p++) |
3771
|
339 { |
4219
|
340 tree_if_clause *elt = *p; |
3771
|
341 |
|
342 if (elt) |
|
343 elt->accept (*this); |
|
344 } |
|
345 } |
|
346 |
|
347 void |
|
348 tree_breakpoint::visit_index_expression (tree_index_expression& cmd) |
|
349 { |
|
350 if (found) |
|
351 return; |
|
352 |
3933
|
353 tree_expression *expr = cmd.expression (); |
|
354 |
|
355 if (expr && expr->line () >= line) |
|
356 take_action (*expr); |
|
357 |
4219
|
358 std::list<tree_argument_list *> lst = cmd.arg_lists (); |
|
359 |
3933
|
360 |
|
361 if (! lst.empty ()) |
3930
|
362 { |
4219
|
363 for (std::list<tree_argument_list *>::iterator p = lst.begin (); |
|
364 p != lst.end (); |
|
365 p++) |
3933
|
366 { |
4219
|
367 tree_argument_list *elt = *p; |
3771
|
368 |
3933
|
369 elt->accept (*this); |
|
370 } |
3930
|
371 } |
3771
|
372 } |
|
373 |
|
374 void |
|
375 tree_breakpoint::visit_matrix (tree_matrix& mat) |
|
376 { |
|
377 if (found) |
|
378 return; |
|
379 |
4219
|
380 tree_matrix::iterator p = mat.begin (); |
3771
|
381 |
4219
|
382 while (p != mat.end ()) |
3771
|
383 { |
4219
|
384 tree_argument_list *elt = *p++; |
3771
|
385 |
|
386 if (elt) |
|
387 elt->accept (*this); |
|
388 } |
|
389 } |
|
390 |
|
391 void |
|
392 tree_breakpoint::visit_cell (tree_cell& cell) |
|
393 { |
|
394 if (found) |
|
395 return; |
|
396 |
4219
|
397 tree_cell::iterator p = cell.begin (); |
3771
|
398 |
4219
|
399 while (p != cell.end ()) |
3771
|
400 { |
4219
|
401 tree_argument_list *elt = *p++; |
3771
|
402 |
|
403 if (elt) |
|
404 elt->accept (*this); |
|
405 } |
|
406 } |
|
407 |
|
408 void |
|
409 tree_breakpoint::visit_multi_assignment (tree_multi_assignment& expr) |
|
410 { |
|
411 if (found) |
|
412 return; |
|
413 |
4274
|
414 tree_argument_list *lst = expr.left_hand_side (); |
3771
|
415 |
4274
|
416 if (lst) |
|
417 lst->accept (*this); |
3771
|
418 |
|
419 tree_expression *rhs = expr.right_hand_side (); |
|
420 |
|
421 if (rhs) |
|
422 rhs->accept (*this); |
|
423 } |
|
424 |
|
425 void |
|
426 tree_breakpoint::visit_no_op_command (tree_no_op_command& cmd) |
|
427 { |
|
428 if (found) |
|
429 return; |
|
430 |
|
431 if (cmd.line () >= line) |
|
432 take_action (cmd); |
|
433 } |
|
434 |
|
435 void |
|
436 tree_breakpoint::visit_constant (tree_constant& cmd) |
|
437 { |
|
438 if (found) |
|
439 return; |
|
440 |
|
441 if (cmd.line () >= line) |
|
442 take_action (cmd); |
|
443 } |
|
444 |
|
445 void |
4342
|
446 tree_breakpoint::visit_fcn_handle (tree_fcn_handle& fh) |
|
447 { |
|
448 if (found) |
|
449 return; |
|
450 |
|
451 if (fh.line () >= line) |
|
452 take_action (fh); |
|
453 } |
|
454 |
|
455 void |
3771
|
456 tree_breakpoint::visit_parameter_list (tree_parameter_list& lst) |
|
457 { |
|
458 if (found) |
|
459 return; |
|
460 |
4219
|
461 tree_parameter_list::iterator p = lst.begin (); |
3771
|
462 |
4219
|
463 while (p != lst.end ()) |
3771
|
464 { |
4219
|
465 tree_identifier *elt = *p++; |
3771
|
466 |
|
467 if (elt) |
|
468 elt->accept (*this); |
|
469 } |
|
470 } |
|
471 |
|
472 void |
|
473 tree_breakpoint::visit_postfix_expression (tree_postfix_expression& expr) |
|
474 { |
|
475 if (found) |
|
476 return; |
|
477 |
|
478 if (expr.line () >= line) |
|
479 take_action (expr); |
|
480 |
|
481 tree_expression *e = expr.operand (); |
|
482 |
|
483 if (e) |
|
484 e->accept (*this); |
|
485 } |
|
486 |
|
487 void |
|
488 tree_breakpoint::visit_prefix_expression (tree_prefix_expression& expr) |
|
489 { |
|
490 if (found) |
|
491 return; |
|
492 |
|
493 if (expr.line () >= line) |
|
494 take_action (expr); |
|
495 |
|
496 tree_expression *e = expr.operand (); |
|
497 |
|
498 if (e) |
|
499 e->accept (*this); |
|
500 } |
|
501 |
|
502 void |
4207
|
503 tree_breakpoint::visit_return_command (tree_return_command& cmd) |
3771
|
504 { |
|
505 if (found) |
|
506 return; |
|
507 |
|
508 if (cmd.line () >= line) |
|
509 take_action (cmd); |
|
510 } |
|
511 |
|
512 void |
|
513 tree_breakpoint::visit_return_list (tree_return_list& lst) |
|
514 { |
|
515 if (found) |
|
516 return; |
|
517 |
4219
|
518 tree_return_list::iterator p = lst.begin (); |
3771
|
519 |
4219
|
520 while (p != lst.end ()) |
3771
|
521 { |
4219
|
522 tree_index_expression *elt = *p++; |
3771
|
523 |
|
524 if (elt) |
|
525 elt->accept (*this); |
|
526 } |
|
527 } |
|
528 |
|
529 void |
|
530 tree_breakpoint::visit_simple_assignment (tree_simple_assignment& expr) |
|
531 { |
|
532 if (found) |
|
533 return; |
|
534 |
|
535 if (expr.line () >= line) |
|
536 take_action (expr); |
|
537 |
|
538 } |
|
539 |
|
540 void |
|
541 tree_breakpoint::visit_statement (tree_statement& stmt) |
|
542 { |
|
543 if (found) |
|
544 return; |
|
545 |
|
546 tree_command *cmd = stmt.command (); |
|
547 |
|
548 if (cmd) |
|
549 cmd->accept (*this); |
|
550 else |
|
551 { |
|
552 tree_expression *expr = stmt.expression (); |
|
553 |
|
554 if (expr) |
|
555 expr->accept (*this); |
|
556 } |
|
557 } |
|
558 |
|
559 void |
|
560 tree_breakpoint::visit_statement_list (tree_statement_list& lst) |
|
561 { |
|
562 if (found) |
|
563 return; |
|
564 |
4219
|
565 for (tree_statement_list::iterator p = lst.begin (); p != lst.end (); p++) |
3771
|
566 { |
4219
|
567 tree_statement *elt = *p; |
3771
|
568 |
|
569 if (elt) |
|
570 elt->accept (*this); |
|
571 } |
|
572 } |
|
573 |
|
574 void |
|
575 tree_breakpoint::visit_switch_case (tree_switch_case& cmd) |
|
576 { |
|
577 if (found) |
|
578 return; |
|
579 |
|
580 // Disallow breakpoints on the label. |
|
581 |
|
582 tree_statement_list *lst = cmd.commands (); |
|
583 |
|
584 if (lst) |
|
585 lst->accept (*this); |
|
586 } |
|
587 |
|
588 void |
|
589 tree_breakpoint::visit_switch_case_list (tree_switch_case_list& lst) |
|
590 { |
|
591 if (found) |
|
592 return; |
|
593 |
4219
|
594 tree_switch_case_list::iterator p = lst.begin (); |
3771
|
595 |
4219
|
596 while (p != lst.end ()) |
3771
|
597 { |
4219
|
598 tree_switch_case *elt = *p++; |
3771
|
599 |
|
600 if (elt) |
|
601 elt->accept (*this); |
|
602 } |
|
603 } |
|
604 |
|
605 |
|
606 void |
|
607 tree_breakpoint::visit_switch_command (tree_switch_command& cmd) |
|
608 { |
|
609 if (found) |
|
610 return; |
|
611 |
|
612 tree_expression *expr = cmd.switch_value (); |
|
613 |
|
614 if (expr) |
|
615 expr->accept (*this); |
|
616 |
|
617 tree_switch_case_list *lst = cmd.case_list (); |
|
618 |
|
619 if (lst) |
|
620 lst->accept (*this); |
|
621 } |
|
622 |
|
623 void |
|
624 tree_breakpoint::visit_try_catch_command (tree_try_catch_command& cmd) |
|
625 { |
|
626 if (found) |
|
627 return; |
|
628 |
|
629 if (cmd.line () >= line) |
|
630 take_action (cmd); |
|
631 |
|
632 tree_statement_list *try_code = cmd.body (); |
|
633 |
|
634 if (try_code) |
|
635 try_code->accept (*this); |
|
636 |
|
637 tree_statement_list *catch_code = cmd.cleanup (); |
|
638 |
|
639 if (catch_code) |
|
640 catch_code->accept (*this); |
|
641 } |
|
642 |
|
643 void |
|
644 tree_breakpoint::visit_unwind_protect_command (tree_unwind_protect_command& cmd) |
|
645 { |
|
646 if (found) |
|
647 return; |
|
648 |
|
649 if (cmd.line () >= line) |
|
650 take_action (cmd); |
|
651 |
4064
|
652 tree_statement_list *lstA = cmd.body (); |
3771
|
653 |
4064
|
654 if (lstA) |
|
655 lstA->accept (*this); |
3771
|
656 |
4064
|
657 tree_statement_list *lstB = cmd.cleanup (); |
3771
|
658 |
4064
|
659 if (lstB) |
|
660 lstB->accept (*this); |
3771
|
661 } |
|
662 |
|
663 /* |
|
664 ;;; Local Variables: *** |
|
665 ;;; mode: C++ *** |
|
666 ;;; End: *** |
|
667 */ |