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