annotate libinterp/parse-tree/bp-table.cc @ 24738:3695c2cd69b8

don't use singleton pattern for bp_table * bp-table.h, bp-table.cc (class bp_table): Don't use singleton pattern. Move inside octave namespace. Change all uses. * interpreter-private.h, interpreter-private.cc (__get_bp_table__): New function. * interpreter.h, interpreter.cc (interpreter::m_bp_table): New data member. (interpreter::interpreter): Initialize it. (interpreter::get_bp_table): New function.
author John W. Eaton <jwe@octave.org>
date Mon, 12 Feb 2018 00:58:31 -0500
parents 194eb4bd202b
children 6652d3823428
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
23221
debe0c7dcefc maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23170
diff changeset
3 Copyright (C) 2001-2017 Ben Sapp
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 Copyright (C) 2007-2009 John Swensen
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 This file is part of Octave.
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24286
diff changeset
8 Octave is free software: you can redistribute it and/or modify it
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24286
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 (at your option) any later version.
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 WITHOUT ANY WARRANTY; without even the implied warranty of
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 GNU General Public License for more details.
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24286
diff changeset
20 <https://www.gnu.org/licenses/>.
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 */
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 #if defined (HAVE_CONFIG_H)
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 # include "config.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #endif
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27
23824
061a343089be Miscellaneous cleanups of C++11 std::string code.
Rik <rik@octave.org>
parents: 23807
diff changeset
28 #include <algorithm>
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include <fstream>
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include <limits>
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include <list>
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include <map>
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include <set>
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #include <string>
23170
b3f2645803fe Add headers needed on MacOS to avoid "implicit instantiation of undefined
Mike Miller <mtmiller@octave.org>
parents: 23158
diff changeset
35 #include <sstream>
b3f2645803fe Add headers needed on MacOS to avoid "implicit instantiation of undefined
Mike Miller <mtmiller@octave.org>
parents: 23158
diff changeset
36 #include <iostream>
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 #include "file-ops.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #include "bp-table.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 #include "defun-int.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 #include "call-stack.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 #include "error.h"
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
44 #include "interpreter-private.h"
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 #include "oct-map.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 #include "octave-link.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 #include "ov-usr-fcn.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 #include "ov.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 #include "ovl.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 #include "pager.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 #include "parse.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 #include "pt-eval.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 #include "pt-exp.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 #include "pt-stmt.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 #include "sighandlers.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 #include "symtab.h"
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
58 namespace octave
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 {
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
60 // Clear all reasons to stop, other than breakpoints.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
61
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
62 void bp_table::dbclear_all_signals (void)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
63 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
64 Vdebug_on_error = false;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
65 bp_table::m_errors_that_stop.clear ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
66
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
67 Vdebug_on_caught = false;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
68 bp_table::m_caught_that_stop.clear ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
69
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
70 Vdebug_on_warning = false;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
71 bp_table::m_warnings_that_stop.clear ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
72
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
73 octave::Vdebug_on_interrupt = false;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
74 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
75
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
76 // Process the "warn", "errs", "caught" and "intr" fields for a call of
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
77 // "dbstop (p)".
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
79 void bp_table::dbstop_process_map_args (const octave_map& mv)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
80 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
81 // process errs
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
82 // why so many levels of indirection needed?
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
83 bool fail = false;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
84 Cell U = mv.contents ("errs");
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
85 if (U.numel () != 1)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
86 fail = (U.numel () > 1);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
87 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
88 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
89 Array<octave_value> W = U.index (static_cast<octave_idx_type> (0));
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
90 if (W.isempty () || W(0).isempty ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
91 Vdebug_on_error = 1; // like "dbstop if error" with no identifier
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
92 else if (! W(0).iscell ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
93 fail = true;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
94 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
95 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
96 Cell V = W(0).cell_value ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
97 for (int i = 0; i < V.numel (); i++)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
98 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
99 m_errors_that_stop.insert (V(i).string_value ());
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
100 Vdebug_on_error = 1;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
101 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
102 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
103 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
104 if (fail)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
105 error ("dbstop: invalid 'errs' field");
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
106
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
107 // process caught
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
108 // why so many levels of indirection needed?
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
109 fail = false;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
110 U = mv.contents ("caught");
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
111 if (U.numel () != 1)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
112 fail = (U.numel () > 1);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
113 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
114 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
115 Array<octave_value> W = U.index (static_cast<octave_idx_type> (0));
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
116 if (W.isempty () || W(0).isempty ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
117 Vdebug_on_caught = 1; // like "dbstop if caught error" with no ID
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
118 else if (! W(0).iscell ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
119 fail = true;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
120 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
121 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
122 Cell V = W(0).cell_value ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
123 for (int i = 0; i < V.numel (); i++)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
124 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
125 m_caught_that_stop.insert (V(i).string_value ());
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
126 Vdebug_on_caught = 1;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
127 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
128 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
129 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
130 if (fail)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
131 error ("dbstop: invalid 'caught' field");
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
133 // process warn
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
134 // why so many levels of indirection needed?
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
135 fail = false;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
136 U = mv.contents ("warn");
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
137 if (U.numel () != 1)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
138 fail = (U.numel () > 1);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
139 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
140 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
141 Array<octave_value> W = U.index (static_cast<octave_idx_type> (0));
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
142 if (W.isempty () || W(0).isempty ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
143 Vdebug_on_warning = 1; // like "dbstop if warning" with no identifier
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
144 else if (! W(0).iscell ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
145 fail = true;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
146 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
147 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
148 Cell V = W(0).cell_value ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
149 for (int i = 0; i < V.numel (); i++)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
150 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
151 m_warnings_that_stop.insert (V(i).string_value ());
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
152 Vdebug_on_warning = 1;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
153 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
154 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
155 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
156 if (fail)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
157 error ("dbstop: invalid 'warn' field");
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
159 // process interrupt
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
160 if (mv.isfield ("intr"))
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
161 octave::Vdebug_on_interrupt = 1;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
162 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
163
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
164 // Insert a breakpoint in function fcn at line within file fname,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
165 // to stop only when condition is true.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
166 // Record in m_bp_set that fname contains a breakpoint.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
167
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
168 bool bp_table::add_breakpoint_1 (octave_user_code *fcn,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
169 const std::string& fname,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
170 const bp_table::intmap& line,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
171 const std::string& condition,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
172 bp_table::intmap& retval)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
173 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
174 bool found = false;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
175
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
176 octave::tree_statement_list *cmds = fcn->body ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
177
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
178 std::string file = fcn->fcn_file_name ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
179
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
180 if (cmds)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
181 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
182 retval = cmds->add_breakpoint (file, line, condition);
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
184 for (auto& idx_line_p : retval)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
185 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
186 if (idx_line_p.second != 0)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
187 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
188 // Normalize to store only the file name.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
189 // Otherwise, there can be an entry for both
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
190 // file>subfunction and file, which causes a crash on
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
191 // dbclear all
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
192 const char *s = strchr (fname.c_str (), '>');
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
193 if (s)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
194 m_bp_set.insert (fname.substr (0, s - fname.c_str ()));
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
195 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
196 m_bp_set.insert (fname);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
197 found = true;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
198 break;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
199 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
200 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
201 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
203 return found;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
204 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
206 // Cursory check that cond is a valid condition to use for a breakpoint.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
207 // Currently allows conditions with side-effects, like 'y+=10' and 'y++';
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
208 // it is odd that the former is not flagged by "is_assignment_expression".
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
209 // Throws an exception if not valid.
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
210
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
211 bool bp_table::condition_valid (const std::string& cond)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
212 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
213 if (cond.length () > 0)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
214 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
215 octave::parser parser (cond + " ;"); // ; to reject partial expr like "y=="
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
216 parser.reset ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
217 int parse_status = parser.run ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
218 if (parse_status)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
219 error ("dbstop: Cannot parse condition '%s'", cond.c_str ());
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
220 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
221 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
222 octave::tree_statement *stmt = nullptr;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
223 if (! parser.m_stmt_list)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
224 error ("dbstop: "
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
225 "condition is not empty, but has nothing to evaluate");
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
226 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
227 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
228 if (parser.m_stmt_list->length () == 1
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
229 && (stmt = parser.m_stmt_list->front ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
230 && stmt->is_expression ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
231 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
232 octave::tree_expression *expr = stmt->expression ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
233 if (expr->is_assignment_expression ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
234 error ("dbstop: condition cannot be an assignment. "
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
235 "Did you mean '=='?");
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
236 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
237 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
238 error ("dbstop: condition must be an expression");
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
239 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
240 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
241 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
242 return true;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
243 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
244
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
245 enum dbstop_args
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
246 {
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
247 dbstop_in,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
248 dbstop_at,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
249 dbstop_if,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
250 dbstop_none
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
251 };
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
252
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
253 // Parse parameters (args) of dbstop and dbclear commands.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
254 // For dbstop, who=="dbstop"; for dbclear, who=="dbclear".
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
255 // The syntax is: dbstop [[in] symbol] [[at] line [line [...]]] [if condition]
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
256 // where the form of condition depends on whether or not a file or line has
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
257 // been seen.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
258 // Also execute "if [error|warning|interrupt|naninf]" clauses.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
259
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
260 void bp_table::parse_dbfunction_params (const char *who,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
261 const octave_value_list& args,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
262 std::string& symbol_name,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
263 bp_table::intmap& lines,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
264 std::string& cond)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
265 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
266 int nargin = args.length ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
267 int list_idx = 0;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
268 symbol_name = "";
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
269 lines = bp_table::intmap ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
270
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
271 if (nargin == 0 || ! args(0).is_string ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
272 print_usage (who);
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
273
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
274 // elements already processed
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
275 bool seen_in = false, seen_at = false, seen_if = false;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
276 int pos = 0;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
277 dbstop_args tok = dbstop_none;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
278 while (pos < nargin)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
279 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
280 // allow "in" and "at" to be implicit
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
281 if (args(pos).is_string ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
282 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
283 std::string arg = args(pos).string_value ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
284 if (arg == "in")
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
285 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
286 tok = dbstop_in;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
287 pos++;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
288 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
289 else if (arg == "at")
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
290 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
291 tok = dbstop_at;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
292 pos++;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
293 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
294 else if (arg == "if")
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
295 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
296 tok = dbstop_if;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
297 pos++;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
298 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
299 else if (atoi (args(pos).string_value ().c_str ()) > 0)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
300 tok = dbstop_at;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
301 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
302 tok = dbstop_in;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
303 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
304 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
305 tok = dbstop_at;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
306
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
307 if (pos >= nargin)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
308 error ("%s: '%s' missing argument", who,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
309 (tok == dbstop_in
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
310 ? "in" : (tok == dbstop_at ? "at" : "if")));
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
311
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
312 // process the actual arguments
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
313 switch (tok)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
314 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
315 case dbstop_in:
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
316 symbol_name = args(pos).string_value ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
317 if (seen_in)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
318 error ("%s: Too many function names specified -- %s",
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
319 who, symbol_name.c_str ());
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
320 else if (seen_at || seen_if)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
321 error ("%s: function name must come before line number and 'if'",
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
322 who);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
323 seen_in = true;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
324 pos++;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
325 break;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
326
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
327 case dbstop_at:
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
328 if (seen_at)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
329 error ("%s: Only one 'at' clause is allowed -- %s",
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
330 who, args(pos).string_value ().c_str ());
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
331 else if (seen_if)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
332 error ("%s: line number must come before 'if' clause\n");
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
333 seen_at = true;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
334
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
335 if (! seen_in)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
336 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
337 // It was a line number. Get function name from debugger.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
338 if (Vdebugging)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
339 symbol_name = get_user_code ()->profiler_name ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
340 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
341 error ("%s: function name must come before line number "
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
342 "and 'if'", who);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
343 seen_in = true;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
344 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
345 else if (seen_if)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
346 error ("%s: line number must come before 'if' clause\n");
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
347
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
348 // Read a list of line numbers (or arrays thereof)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
349 for ( ; pos < nargin; pos++)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
350 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
351 if (args(pos).is_string ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
352 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
353 int line = atoi (args(pos).string_value ().c_str ());
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
354
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
355 if (line > 0)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
356 lines[list_idx++] = line;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
357 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
358 break; // may be "if"
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
359 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
360 else if (args(pos).isnumeric ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
361 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
362 const NDArray arg = args(pos).array_value ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
363
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
364 for (octave_idx_type j = 0; j < arg.numel (); j++)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
365 lines[list_idx++] = static_cast<int> (arg.elem (j));
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
366 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
367 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
368 error ("%s: Invalid argument type %s",
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
369 args(pos).type_name ().c_str ());
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
370 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
371 break;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
372
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
373 case dbstop_if:
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
374 if (seen_in) // conditional breakpoint
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
375 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
376 cond = ""; // remaining arguments form condition
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
377 for (; pos < nargin; pos++)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
378 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
379 if (args(pos).is_string ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
380 cond += ' ' + args(pos).string_value ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
381 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
382 error ("%s: arguments to 'if' must all be strings", who);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
383 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
384
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
385 cond = cond.substr (1); // omit initial space
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
386 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
387 else // stop on event (error, warning, interrupt, NaN/inf)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
388 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
389 std::string condition = args(pos).string_value ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
390 int on_off = ! strcmp(who, "dbstop");
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
391
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
392 // list of error/warning IDs to update
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
393 std::set<std::string> *id_list = nullptr;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
394 bool *stop_flag = nullptr; // Vdebug_on_... flag
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
395
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
396 if (condition == "error")
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
397 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
398 id_list = &m_errors_that_stop;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
399 stop_flag = &Vdebug_on_error;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
400 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
401 else if (condition == "warning")
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
402 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
403 id_list = &m_warnings_that_stop;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
404 stop_flag = &Vdebug_on_warning;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
405 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
406 else if (condition == "caught" && nargin > pos+1
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
407 && args(pos+1).string_value () == "error")
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
408 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
409 id_list = &m_caught_that_stop;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
410 stop_flag = &Vdebug_on_caught;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
411 pos++;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
412 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
413 else if (condition == "interrupt")
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
414 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
415 octave::Vdebug_on_interrupt = on_off;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
416 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
417 else if (condition == "naninf")
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
418 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
419 #if defined (DBSTOP_NANINF)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
420 Vdebug_on_naninf = on_off;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
421 enable_fpe (on_off);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
422 #else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
423 warning ("%s: condition '%s' not yet supported",
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
424 who, condition.c_str ());
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
425 #endif
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
426 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
427 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
428 error ("%s: invalid condition %s",
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
429 who, condition.c_str ());
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
430
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
431 // process ID list for "dbstop if error <error_ID>" etc
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
432 if (id_list)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
433 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
434 pos++;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
435 if (pos < nargin) // only affect a single error ID
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
436 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
437 if (! args(pos).is_string () || nargin > pos+1)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
438 error ("%s: ID must be a single string", who);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
439 else if (on_off == 1)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
440 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
441 id_list->insert (args(pos).string_value ());
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
442 *stop_flag = true;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
443 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
444 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
445 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
446 id_list->erase (args(pos).string_value ());
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
447 if (id_list->empty ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
448 *stop_flag = false;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
449 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
450 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
451 else // unqualified. Turn all on or off
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
452 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
453 id_list->clear ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
454 *stop_flag = on_off;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
455 if (stop_flag == &Vdebug_on_error)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
456 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
457 // Matlab stops on both.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
458 octave::Vdebug_on_interrupt = on_off;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
459 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
460 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
461 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
462
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
463 pos = nargin;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
464 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
465 break;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
466
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
467 default: // dbstop_none should never occur
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
468 break;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
469 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
470 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
471 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
472
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
473 /*
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
474 %!test
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
475 %! dbclear all; # Clear out breakpoints before test
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
476 %! dbstop help;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
477 %! dbstop in ls;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
478 %! dbstop help at 100;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
479 %! dbstop in ls 100;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
480 %! dbstop help 201 if a==5;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
481 %! dbstop if error Octave:undefined-function;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
482 %! s = dbstatus;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
483 %! dbclear all;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
484 %! assert ({s.bkpt(:).name}, {"help", "help", "help>do_contents", "ls", "ls"});
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
485 %! assert ([s.bkpt(:).line], [48, 100, 201, 58, 100]);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
486 %! assert (s.errs, {"Octave:undefined-function"});
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
487 */
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
488
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
489 // Return the sub/nested/main function of MAIN_FCN that contains
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
490 // line number LINENO of the source file.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
491 // If END_LINE != 0, *END_LINE is set to last line of the returned function.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
492
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
493 static octave_user_code * find_fcn_by_line (octave_user_code *main_fcn,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
494 int lineno, int *end_line = nullptr)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
495 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
496 octave_user_code *retval = nullptr;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
497 octave_user_code *next_fcn = nullptr; // 1st function starting after lineno
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
498
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
499 // Find innermost nested (or parent) function containing lineno.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
500 int earliest_end = std::numeric_limits<int>::max ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
501
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
502 std::map<std::string, octave_value> subfcns = main_fcn->subfunctions ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
503 for (const auto& str_val_p : subfcns)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
504 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
505 if (str_val_p.second.is_user_function ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
506 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
507 auto *dbg_subfcn = str_val_p.second.user_function_value ();
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
508
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
509 // Check if lineno is within dbg_subfcn.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
510 // FIXME: we could break when beginning_line() > lineno,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
511 // but that makes the code "fragile"
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
512 // if the order of walking subfcns changes,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
513 // for a minor speed improvement in non-critical code.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
514 if (dbg_subfcn->ending_line () < earliest_end
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
515 && dbg_subfcn->ending_line () >= lineno
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
516 && dbg_subfcn->beginning_line () <= lineno)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
517 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
518 earliest_end = dbg_subfcn->ending_line ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
519 retval = find_fcn_by_line (dbg_subfcn, lineno, &earliest_end);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
520 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
521
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
522 // Find the first fcn starting after lineno.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
523 // This is used if line is not inside any function.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
524 if (dbg_subfcn->beginning_line () >= lineno && ! next_fcn)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
525 next_fcn = dbg_subfcn;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
526 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
527 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
528
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
529 // The breakpoint is either in the subfunction found above,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
530 // or in the main function, which we check now.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
531 if (main_fcn->is_user_function ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
532 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
533 int e = dynamic_cast<octave_user_function *> (main_fcn)->ending_line ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
534 if (e >= lineno && e < earliest_end)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
535 retval = main_fcn;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
536
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
537 if (! retval)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
538 retval = next_fcn;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
539 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
540 else // main_fcn is a script.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
541 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
542 if (! retval)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
543 retval = main_fcn;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
544 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
545
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
546 if (end_line && earliest_end < *end_line)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
547 *end_line = earliest_end;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
548
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
549 return retval;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
550 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
551
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
552 // Given file name fname, find the subfunction at line and create
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
553 // a breakpoint there. Put the system into debug_mode.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
554 bp_table::intmap bp_table::add_breakpoint (const std::string& fname,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
555 const bp_table::intmap& line,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
556 const std::string& condition)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
557 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
558 octave_user_code *main_fcn = get_user_code (fname);
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
559
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
560 if (! main_fcn)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
561 error ("add_breakpoint: unable to find function '%s'\n", fname.c_str ());
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
562
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
563 condition_valid (condition); // Throw error if condition not valid.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
564
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
565 intmap retval;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
566
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
567 octave_idx_type len = line.size ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
568
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
569 for (int i = 0; i < len; i++)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
570 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
571 const_intmap_iterator m = line.find (i);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
572
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
573 if (m != line.end ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
574 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
575 int lineno = m->second;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
576
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
577 octave_user_code *dbg_fcn = find_fcn_by_line (main_fcn, lineno);
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
578
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
579 // We've found the right (sub)function. Now insert the breakpoint.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
580 // We insert all breakpoints.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
581 // If multiple are in the same function, we insert multiple times.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
582 intmap ret_one;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
583 if (dbg_fcn
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
584 && add_breakpoint_1 (dbg_fcn, fname, line, condition, ret_one))
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
585 retval.insert (std::pair<int,int> (i, ret_one.find (i)->second));
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
586 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
587 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
588
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
589 octave::tree_evaluator::debug_mode = bp_table::have_breakpoints ()
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
590 || Vdebugging;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
591
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
592 return retval;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
593 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
594
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
595 int bp_table::remove_breakpoint_1 (octave_user_code *fcn,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
596 const std::string& fname,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
597 const bp_table::intmap& line)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
598 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
599 int retval = 0;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
600
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
601 std::string file = fcn->fcn_file_name ();
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
602
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
603 octave::tree_statement_list *cmds = fcn->body ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
604
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
605 // FIXME: move the operation on cmds to the tree_statement_list class?
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
606
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
607 if (cmds)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
608 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
609 octave_value_list results = cmds->list_breakpoints ();
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
610
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
611 if (results.length () > 0)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
612 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
613 octave_idx_type len = line.size ();
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
614
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
615 for (int i = 0; i < len; i++)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
616 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
617 const_intmap_iterator p = line.find (i);
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
618
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
619 if (p != line.end ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
620 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
621 int lineno = p->second;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
622
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
623 cmds->delete_breakpoint (lineno);
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
624
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
625 if (! file.empty ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
626 octave_link::update_breakpoint (false, file, lineno);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
627 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
628 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
629
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
630 results = cmds->list_breakpoints ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
631
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
632 bp_set_iterator it = m_bp_set.find (fname);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
633 if (results.empty () && it != m_bp_set.end ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
634 m_bp_set.erase (it);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
635 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
636
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
637 retval = results.length ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
638 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
639
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
640 return retval;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
641 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
642
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
643 int bp_table::remove_breakpoint (const std::string& fname,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
644 const bp_table::intmap& line)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
645 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
646 int retval = 0;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
647
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
648 octave_idx_type len = line.size ();
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
649
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
650 if (len == 0)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
651 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
652 intmap results = remove_all_breakpoints_in_file (fname);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
653 retval = results.size ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
654 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
655 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
656 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
657 octave_user_code *dbg_fcn = get_user_code (fname);
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
658
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
659 if (! dbg_fcn)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
660 error ("remove_breakpoint: unable to find function %s\n",
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
661 fname.c_str ());
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
662
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
663 retval = remove_breakpoint_1 (dbg_fcn, fname, line);
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
664
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
665 // Search subfunctions in the order they appear in the file.
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
666
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
667 const std::list<std::string> subfcn_names
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
668 = dbg_fcn->subfunction_names ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
669
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
670 std::map<std::string, octave_value> subfcns
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
671 = dbg_fcn->subfunctions ();
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
672
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
673 for (const auto& subf_nm : subfcn_names)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
674 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
675 const auto q = subfcns.find (subf_nm);
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
676
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
677 if (q != subfcns.end ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
678 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
679 octave_user_code *dbg_subfcn = q->second.user_code_value ();
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
680
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
681 retval += remove_breakpoint_1 (dbg_subfcn, fname, line);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
682 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
683 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
684 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
685
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
686 octave::tree_evaluator::debug_mode = bp_table::have_breakpoints ()
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
687 || Vdebugging;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
688
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
689 return retval;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
690 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
691
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
692 // Remove all breakpoints from a file, including those in subfunctions.
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
693
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
694 bp_table::intmap
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
695 bp_table::remove_all_breakpoints_in_file (const std::string& fname,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
696 bool silent)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
697 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
698 intmap retval;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
699
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
700 octave_user_code *dbg_fcn = get_user_code (fname);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
701
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
702 if (dbg_fcn)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
703 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
704 std::string file = dbg_fcn->fcn_file_name ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
705
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
706 octave::tree_statement_list *cmds = dbg_fcn->body ();
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
707
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
708 if (cmds)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
709 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
710 retval = cmds->remove_all_breakpoints (file);
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
711
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
712 bp_set_iterator it = m_bp_set.find (fname);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
713 if (it != m_bp_set.end ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
714 m_bp_set.erase (it);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
715 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
716 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
717 else if (! silent)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
718 error ("remove_all_breakpoint_in_file: "
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
719 "unable to find function %s\n", fname.c_str ());
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
720
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
721 octave::tree_evaluator::debug_mode = bp_table::have_breakpoints ()
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
722 || Vdebugging;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
723
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
724 return retval;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
725 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
726
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
727 void bp_table::remove_all_breakpoints (void)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
728 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
729 // Odd loop structure required because delete will invalidate m_bp_set iterators
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
730 for (const_bp_set_iterator it = m_bp_set.begin (), it_next = it;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
731 it != m_bp_set.end ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
732 it = it_next)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
733 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
734 ++it_next;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
735 remove_all_breakpoints_in_file (*it);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
736 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
737
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
738 octave::tree_evaluator::debug_mode = bp_table::have_breakpoints ()
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
739 || Vdebugging;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
740 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
741
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
742 std::string find_bkpt_list (octave_value_list slist, std::string match)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
743 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
744 std::string retval;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
745
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
746 for (int i = 0; i < slist.length (); i++)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
747 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
748 if (slist(i).string_value () == match)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
749 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
750 retval = slist(i).string_value ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
751 break;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
752 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
753 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
754
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
755 return retval;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
756 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
757
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
758 bp_table::fname_bp_map
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
759 bp_table::get_breakpoint_list (const octave_value_list& fname_list)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
760 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
761 fname_bp_map retval;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
762
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
763 // make copy since changes may invalidate iters of m_bp_set.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
764 std::set<std::string> tmp_bp_set = m_bp_set;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
765
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
766 for (auto& bp_fname : tmp_bp_set)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
767 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
768 if (fname_list.empty ()
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
769 || find_bkpt_list (fname_list, bp_fname) != "")
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
770 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
771 octave_user_code *dbg_fcn = get_user_code (bp_fname);
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
772
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
773 if (dbg_fcn)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
774 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
775 octave::tree_statement_list *cmds = dbg_fcn->body ();
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
776
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
777 // FIXME: move the operation on cmds to the
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
778 // tree_statement_list class?
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
779 if (cmds)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
780 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
781 std::list<bp_type> bkpts = cmds->breakpoints_and_conds ();
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
782
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
783 if (! bkpts.empty ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
784 retval[bp_fname] = bkpts;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
785 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
786
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
787 // look for breakpoints in subfunctions
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
788 const std::list<std::string> subf_nm
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
789 = dbg_fcn->subfunction_names ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
790
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
791 std::map<std::string, octave_value> subfcns
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
792 = dbg_fcn->subfunctions ();
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
793
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
794 for (const auto& subfcn_nm : subf_nm)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
795 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
796 const auto q = subfcns.find (subfcn_nm);
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
797
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
798 if (q != subfcns.end ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
799 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
800 octave_user_code *dbg_subfcn
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
801 = q->second.user_code_value ();
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
802
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
803 cmds = dbg_subfcn->body ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
804 if (cmds)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
805 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
806 std::list<bp_type> bkpts
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
807 = cmds->breakpoints_and_conds ();
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
808
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
809 if (! bkpts.empty ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
810 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
811 std::string key
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
812 = bp_fname + '>' + dbg_subfcn->name ();
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
813
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
814 retval[key] = bkpts;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
815 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
816 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
817 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
818 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
819 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
820 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
821 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
822
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
823 return retval;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
824 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
825
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
826 // Report the status of "dbstop if error ..." and "dbstop if warning ..."
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
827 // If to_screen is true, the output goes to octave_stdout; otherwise it is
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
828 // returned.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
829 // If dbstop if error is true but no explicit IDs are specified, the return
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
830 // value will have an empty field called "errs". If IDs are specified, the
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
831 // "errs" field will have a row per ID. If dbstop if error is false, there
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
832 // is no "errs" field. The "warn" field is set similarly by dbstop if warning
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
833
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
834 octave_map bp_table::stop_on_err_warn_status (bool to_screen)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
835 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
836 octave_map retval;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
837
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
838 // print dbstop if error information
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
839 if (Vdebug_on_error)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
840 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
841 if (m_errors_that_stop.empty ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
842 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
843 if (to_screen)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
844 octave_stdout << "stop if error\n";
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
845 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
846 retval.assign ("errs", octave_value(""));
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
847 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
848 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
849 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
850 Cell errs (dim_vector (bp_table::m_errors_that_stop.size (), 1));
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
851 int i = 0;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
852
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
853 for (const auto& e : m_errors_that_stop)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
854 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
855 if (to_screen)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
856 octave_stdout << "stop if error " << e << "\n";
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
857 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
858 errs(i++) = e;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
859 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
860 if (! to_screen)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
861 retval.assign ("errs", octave_value (errs));
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
862 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
863 }
24286
6bfb96ab73cb * bp-table.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 24279
diff changeset
864
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
865 // print dbstop if caught error information
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
866 if (Vdebug_on_caught)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
867 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
868 if (m_caught_that_stop.empty ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
869 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
870 if (to_screen)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
871 octave_stdout << "stop if caught error\n";
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
872 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
873 retval.assign ("caught", octave_value(""));
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
874 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
875 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
876 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
877 Cell errs (dim_vector (m_caught_that_stop.size (), 1));
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
878 int i = 0;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
879
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
880 for (const auto& e : m_caught_that_stop)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
881 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
882 if (to_screen)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
883 octave_stdout << "stop if caught error " << e << "\n";
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
884 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
885 errs(i++) = e;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
886 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
887 if (! to_screen)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
888 retval.assign ("caught", octave_value (errs));
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
889 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
890 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
891
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
892 // print dbstop if warning information
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
893 if (Vdebug_on_warning)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
894 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
895 if (m_warnings_that_stop.empty ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
896 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
897 if (to_screen)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
898 octave_stdout << "stop if warning\n";
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
899 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
900 retval.assign ("warn", octave_value(""));
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
901 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
902 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
903 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
904 Cell warn (dim_vector (m_warnings_that_stop.size (), 1));
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
905 int i = 0;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
906
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
907 for (const auto& w : m_warnings_that_stop)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
908 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
909 if (to_screen)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
910 octave_stdout << "stop if warning " << w << "\n";
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
911 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
912 warn(i++) = w;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
913 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
914 if (! to_screen)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
915 retval.assign ("warn", octave_value (warn));
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
916 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
917 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
918
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
919 // print dbstop if interrupt information
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
920 if (octave::Vdebug_on_interrupt)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
921 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
922 if (to_screen)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
923 octave_stdout << "stop if interrupt\n";
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
924 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
925 retval.assign ("intr", octave_value ());
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
926 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
927
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
928 return retval;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
929 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
930
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
931 // Return a pointer to the user-defined function FNAME. If FNAME is empty,
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
932 // search backward for the first user-defined function in the
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
933 // current call stack.
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
934
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
935 octave_user_code *
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
936 get_user_code (const std::string& fname)
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
937 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
938 octave_user_code *dbg_fcn = nullptr;
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
939
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
940 if (fname.empty ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
941 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
942 octave::call_stack& cs = octave::__get_call_stack__ ("get_user_code");
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
943
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
944 dbg_fcn = cs.debug_user_code ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
945 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
946 else
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
947 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
948 std::string name = fname;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
949
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
950 if (octave::sys::file_ops::dir_sep_char () != '/' && name[0] == '@')
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
951 {
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
952 auto beg = name.begin () + 2; // never have @/method
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
953 auto end = name.end () - 1; // never have trailing '/'
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
954 std::replace (beg, end, '/', octave::sys::file_ops::dir_sep_char ());
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
955 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
956
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
957 size_t name_len = name.length ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
958
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
959 if (name_len > 2 && name.substr (name_len-2) == ".m")
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
960 name = name.substr (0, name_len-2);
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
961
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
962 octave::symbol_table& symtab =
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
963 octave::__get_symbol_table__ ("get_user_code");
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
964
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
965 octave_value fcn = symtab.find_function (name);
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
966
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
967 if (fcn.is_defined () && fcn.is_user_code ())
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
968 dbg_fcn = fcn.user_code_value ();
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
969 }
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
970
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
971 return dbg_fcn;
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
972 }
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
973 }