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