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 |
|
82 tree_statement_list *list = cmd.body (); |
|
83 |
|
84 if (list) |
|
85 list->accept (*this); |
|
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 |
|
246 tree_statement_list *list = cmd.body (); |
|
247 |
|
248 if (list) |
|
249 list->accept (*this); |
|
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 |
|
266 tree_statement_list *list = cmd.body (); |
|
267 |
|
268 if (list) |
|
269 list->accept (*this); |
|
270 |
|
271 } |
|
272 |
|
273 void |
|
274 tree_breakpoint::visit_octave_user_function (octave_user_function& cmd) |
|
275 { |
|
276 // we should not visit octave user functions because the function we are currently |
|
277 // in is the function where the breakpoint was requested |
|
278 } |
|
279 |
|
280 void |
|
281 tree_breakpoint::visit_octave_user_function_header (octave_user_function& cmd) |
|
282 { |
|
283 // Do nothing |
|
284 } |
|
285 |
|
286 void |
|
287 tree_breakpoint::visit_octave_user_function_trailer (octave_user_function& cmd) |
|
288 { |
|
289 // Do nothing |
|
290 } |
|
291 |
|
292 void |
|
293 tree_breakpoint::visit_identifier (tree_identifier& id) |
|
294 { |
|
295 if (found) |
|
296 return; |
|
297 |
|
298 if (id.line () >= line ) |
|
299 take_action (id); |
|
300 } |
|
301 |
|
302 void |
|
303 tree_breakpoint::visit_if_clause (tree_if_clause& cmd) |
|
304 { |
|
305 if (found) |
|
306 return; |
|
307 |
|
308 tree_expression *expr = cmd.condition (); |
|
309 |
|
310 if (expr) |
|
311 expr->accept (*this); |
|
312 |
|
313 tree_statement_list *list = cmd.commands (); |
|
314 |
|
315 if (list) |
|
316 list->accept (*this); |
|
317 } |
|
318 |
|
319 void |
|
320 tree_breakpoint::visit_if_command (tree_if_command& cmd) |
|
321 { |
|
322 if (found) |
|
323 return; |
|
324 |
|
325 tree_if_command_list *list = cmd.cmd_list (); |
|
326 |
|
327 if (list) |
|
328 list->accept (*this); |
|
329 } |
|
330 |
|
331 void |
|
332 tree_breakpoint::visit_if_command_list (tree_if_command_list& lst) |
|
333 { |
|
334 if (found) |
|
335 return; |
|
336 |
4219
|
337 for (tree_if_command_list::iterator p = lst.begin (); p != lst.end (); p++) |
3771
|
338 { |
4219
|
339 tree_if_clause *elt = *p; |
3771
|
340 |
|
341 if (elt) |
|
342 elt->accept (*this); |
|
343 } |
|
344 } |
|
345 |
|
346 void |
|
347 tree_breakpoint::visit_index_expression (tree_index_expression& cmd) |
|
348 { |
|
349 if (found) |
|
350 return; |
|
351 |
3933
|
352 tree_expression *expr = cmd.expression (); |
|
353 |
|
354 if (expr && expr->line () >= line) |
|
355 take_action (*expr); |
|
356 |
4219
|
357 std::list<tree_argument_list *> lst = cmd.arg_lists (); |
|
358 |
3933
|
359 |
|
360 if (! lst.empty ()) |
3930
|
361 { |
4219
|
362 for (std::list<tree_argument_list *>::iterator p = lst.begin (); |
|
363 p != lst.end (); |
|
364 p++) |
3933
|
365 { |
4219
|
366 tree_argument_list *elt = *p; |
3771
|
367 |
3933
|
368 elt->accept (*this); |
|
369 } |
3930
|
370 } |
3771
|
371 } |
|
372 |
|
373 void |
|
374 tree_breakpoint::visit_matrix (tree_matrix& mat) |
|
375 { |
|
376 if (found) |
|
377 return; |
|
378 |
4219
|
379 tree_matrix::iterator p = mat.begin (); |
3771
|
380 |
4219
|
381 while (p != mat.end ()) |
3771
|
382 { |
4219
|
383 tree_argument_list *elt = *p++; |
3771
|
384 |
|
385 if (elt) |
|
386 elt->accept (*this); |
|
387 } |
|
388 } |
|
389 |
|
390 void |
|
391 tree_breakpoint::visit_cell (tree_cell& cell) |
|
392 { |
|
393 if (found) |
|
394 return; |
|
395 |
4219
|
396 tree_cell::iterator p = cell.begin (); |
3771
|
397 |
4219
|
398 while (p != cell.end ()) |
3771
|
399 { |
4219
|
400 tree_argument_list *elt = *p++; |
3771
|
401 |
|
402 if (elt) |
|
403 elt->accept (*this); |
|
404 } |
|
405 } |
|
406 |
|
407 void |
|
408 tree_breakpoint::visit_multi_assignment (tree_multi_assignment& expr) |
|
409 { |
|
410 if (found) |
|
411 return; |
|
412 |
|
413 tree_argument_list *list = expr.left_hand_side (); |
|
414 |
|
415 if (list) |
|
416 list->accept (*this); |
|
417 |
|
418 tree_expression *rhs = expr.right_hand_side (); |
|
419 |
|
420 if (rhs) |
|
421 rhs->accept (*this); |
|
422 } |
|
423 |
|
424 void |
|
425 tree_breakpoint::visit_no_op_command (tree_no_op_command& cmd) |
|
426 { |
|
427 if (found) |
|
428 return; |
|
429 |
|
430 if (cmd.line () >= line) |
|
431 take_action (cmd); |
|
432 } |
|
433 |
|
434 void |
|
435 tree_breakpoint::visit_constant (tree_constant& cmd) |
|
436 { |
|
437 if (found) |
|
438 return; |
|
439 |
|
440 if (cmd.line () >= line) |
|
441 take_action (cmd); |
|
442 } |
|
443 |
|
444 void |
|
445 tree_breakpoint::visit_parameter_list (tree_parameter_list& lst) |
|
446 { |
|
447 if (found) |
|
448 return; |
|
449 |
4219
|
450 tree_parameter_list::iterator p = lst.begin (); |
3771
|
451 |
4219
|
452 while (p != lst.end ()) |
3771
|
453 { |
4219
|
454 tree_identifier *elt = *p++; |
3771
|
455 |
|
456 if (elt) |
|
457 elt->accept (*this); |
|
458 } |
|
459 } |
|
460 |
|
461 void |
|
462 tree_breakpoint::visit_plot_command (tree_plot_command& cmd) |
|
463 { |
|
464 if (found) |
|
465 return; |
|
466 |
|
467 // Don't bother looking at the range plot list since they must be |
|
468 // on the same line. |
|
469 |
|
470 if (cmd.line () >= line) |
|
471 take_action (cmd); |
|
472 } |
|
473 |
|
474 void |
|
475 tree_breakpoint::visit_plot_limits (plot_limits& cmd) |
|
476 { |
|
477 // Do nothing. This case will be handled in visit_tree_plot_command. |
|
478 } |
|
479 |
|
480 void |
|
481 tree_breakpoint::visit_plot_range (plot_range& cmd) |
|
482 { |
|
483 // Do nothing. This case will be handled in visit_tree_plot_command. |
|
484 } |
|
485 |
|
486 void |
|
487 tree_breakpoint::visit_postfix_expression (tree_postfix_expression& expr) |
|
488 { |
|
489 if (found) |
|
490 return; |
|
491 |
|
492 if (expr.line () >= line) |
|
493 take_action (expr); |
|
494 |
|
495 tree_expression *e = expr.operand (); |
|
496 |
|
497 if (e) |
|
498 e->accept (*this); |
|
499 } |
|
500 |
|
501 void |
|
502 tree_breakpoint::visit_prefix_expression (tree_prefix_expression& expr) |
|
503 { |
|
504 if (found) |
|
505 return; |
|
506 |
|
507 if (expr.line () >= line) |
|
508 take_action (expr); |
|
509 |
|
510 tree_expression *e = expr.operand (); |
|
511 |
|
512 if (e) |
|
513 e->accept (*this); |
|
514 } |
|
515 |
|
516 void |
4207
|
517 tree_breakpoint::visit_return_command (tree_return_command& cmd) |
3771
|
518 { |
|
519 if (found) |
|
520 return; |
|
521 |
|
522 if (cmd.line () >= line) |
|
523 take_action (cmd); |
|
524 } |
|
525 |
|
526 void |
|
527 tree_breakpoint::visit_return_list (tree_return_list& lst) |
|
528 { |
|
529 if (found) |
|
530 return; |
|
531 |
4219
|
532 tree_return_list::iterator p = lst.begin (); |
3771
|
533 |
4219
|
534 while (p != lst.end ()) |
3771
|
535 { |
4219
|
536 tree_index_expression *elt = *p++; |
3771
|
537 |
|
538 if (elt) |
|
539 elt->accept (*this); |
|
540 } |
|
541 } |
|
542 |
|
543 void |
|
544 tree_breakpoint::visit_simple_assignment (tree_simple_assignment& expr) |
|
545 { |
|
546 if (found) |
|
547 return; |
|
548 |
|
549 if (expr.line () >= line) |
|
550 take_action (expr); |
|
551 |
|
552 } |
|
553 |
|
554 void |
|
555 tree_breakpoint::visit_statement (tree_statement& stmt) |
|
556 { |
|
557 if (found) |
|
558 return; |
|
559 |
|
560 tree_command *cmd = stmt.command (); |
|
561 |
|
562 if (cmd) |
|
563 cmd->accept (*this); |
|
564 else |
|
565 { |
|
566 tree_expression *expr = stmt.expression (); |
|
567 |
|
568 if (expr) |
|
569 expr->accept (*this); |
|
570 } |
|
571 } |
|
572 |
|
573 void |
|
574 tree_breakpoint::visit_statement_list (tree_statement_list& lst) |
|
575 { |
|
576 if (found) |
|
577 return; |
|
578 |
4219
|
579 for (tree_statement_list::iterator p = lst.begin (); p != lst.end (); p++) |
3771
|
580 { |
4219
|
581 tree_statement *elt = *p; |
3771
|
582 |
|
583 if (elt) |
|
584 elt->accept (*this); |
|
585 } |
|
586 } |
|
587 |
|
588 void |
|
589 tree_breakpoint::visit_subplot (subplot& cmd) |
|
590 { |
|
591 // Do nothing. This case will be handled in visit_tree_plot_command. |
|
592 } |
|
593 |
|
594 void |
|
595 tree_breakpoint::visit_subplot_axes (subplot_axes& cmd) |
|
596 { |
|
597 // Do nothing. This caser will be handled in visit_tree_plot_command. |
|
598 } |
|
599 |
|
600 void |
|
601 tree_breakpoint::visit_subplot_list (subplot_list& cmd) |
|
602 { |
|
603 // Do nothing. This case will be handled in visit_tree_plot_command. |
|
604 } |
|
605 |
|
606 void |
|
607 tree_breakpoint::visit_subplot_style (subplot_style& cmd) |
|
608 { |
|
609 // Do nothing. This case will be handled in visit_tree_plot_command. |
|
610 } |
|
611 |
|
612 void |
|
613 tree_breakpoint::visit_subplot_using (subplot_using& cmd) |
|
614 { |
|
615 // Do nothing. This case will be handled in visit_tree_plot_command. |
|
616 } |
|
617 |
|
618 void |
|
619 tree_breakpoint::visit_switch_case (tree_switch_case& cmd) |
|
620 { |
|
621 if (found) |
|
622 return; |
|
623 |
|
624 // Disallow breakpoints on the label. |
|
625 |
|
626 tree_statement_list *lst = cmd.commands (); |
|
627 |
|
628 if (lst) |
|
629 lst->accept (*this); |
|
630 } |
|
631 |
|
632 void |
|
633 tree_breakpoint::visit_switch_case_list (tree_switch_case_list& lst) |
|
634 { |
|
635 if (found) |
|
636 return; |
|
637 |
4219
|
638 tree_switch_case_list::iterator p = lst.begin (); |
3771
|
639 |
4219
|
640 while (p != lst.end ()) |
3771
|
641 { |
4219
|
642 tree_switch_case *elt = *p++; |
3771
|
643 |
|
644 if (elt) |
|
645 elt->accept (*this); |
|
646 } |
|
647 } |
|
648 |
|
649 |
|
650 void |
|
651 tree_breakpoint::visit_switch_command (tree_switch_command& cmd) |
|
652 { |
|
653 if (found) |
|
654 return; |
|
655 |
|
656 tree_expression *expr = cmd.switch_value (); |
|
657 |
|
658 if (expr) |
|
659 expr->accept (*this); |
|
660 |
|
661 tree_switch_case_list *lst = cmd.case_list (); |
|
662 |
|
663 if (lst) |
|
664 lst->accept (*this); |
|
665 } |
|
666 |
|
667 void |
|
668 tree_breakpoint::visit_try_catch_command (tree_try_catch_command& cmd) |
|
669 { |
|
670 if (found) |
|
671 return; |
|
672 |
|
673 if (cmd.line () >= line) |
|
674 take_action (cmd); |
|
675 |
|
676 tree_statement_list *try_code = cmd.body (); |
|
677 |
|
678 if (try_code) |
|
679 try_code->accept (*this); |
|
680 |
|
681 tree_statement_list *catch_code = cmd.cleanup (); |
|
682 |
|
683 if (catch_code) |
|
684 catch_code->accept (*this); |
|
685 } |
|
686 |
|
687 void |
|
688 tree_breakpoint::visit_unwind_protect_command (tree_unwind_protect_command& cmd) |
|
689 { |
|
690 if (found) |
|
691 return; |
|
692 |
|
693 if (cmd.line () >= line) |
|
694 take_action (cmd); |
|
695 |
4064
|
696 tree_statement_list *lstA = cmd.body (); |
3771
|
697 |
4064
|
698 if (lstA) |
|
699 lstA->accept (*this); |
3771
|
700 |
4064
|
701 tree_statement_list *lstB = cmd.cleanup (); |
3771
|
702 |
4064
|
703 if (lstB) |
|
704 lstB->accept (*this); |
3771
|
705 } |
|
706 |
|
707 /* |
|
708 ;;; Local Variables: *** |
|
709 ;;; mode: C++ *** |
|
710 ;;; End: *** |
|
711 */ |