diff libinterp/parse-tree/bp-table.h @ 29457:313b8b897733

revamp handling of breakpoint line positions Use set<int> instead of map<int,int> since we don't assign number IDs to breakpoints, we just use line numbers. Allow breakpoint functions to accept individual line number arguments. Simplify iteration over sets of breakpoint lines. * debug.cc (bp_lines_to_ov): Rename from intmap_to_ov. * bp-table.h, bp-table.cc (bp_table::bp_lines): New typedef to replace bp_table::intmap. Change all uses. (bp_table::add_breakpoint, bp_table::remove_breakpoint): New overloads that accept single lines as integers instead of requiring a set of lines.
author John W. Eaton <jwe@octave.org>
date Wed, 03 Mar 2021 23:57:31 -0500
parents 7854d5752dd2
children c0f86150aa6c
line wrap: on
line diff
--- a/libinterp/parse-tree/bp-table.h	Sun Mar 21 10:53:11 2021 +0100
+++ b/libinterp/parse-tree/bp-table.h	Wed Mar 03 23:57:31 2021 -0500
@@ -61,13 +61,13 @@
 
     ~bp_table (void) = default;
 
-    // mapping from (FIXME: arbitrary index??) to line number of breakpoint
-    typedef std::map<int, int> intmap;
+    // Set of breakpoint lines.
+    typedef std::set<int> bp_lines;
 
-    typedef intmap::const_iterator const_intmap_iterator;
-    typedef intmap::iterator intmap_iterator;
+    typedef bp_lines::const_iterator const_bp_lines_iterator;
+    typedef bp_lines::iterator bp_lines_iterator;
 
-    typedef std::map <std::string, intmap> fname_line_map;
+    typedef std::map <std::string, bp_lines> fname_line_map;
 
     typedef fname_line_map::const_iterator const_fname_line_map_iterator;
     typedef fname_line_map::iterator fname_line_map_iterator;
@@ -77,17 +77,25 @@
     typedef fname_bp_map::iterator fname_bp_map_iterator;
 
     // Add a breakpoint at the nearest executable line.
-    intmap add_breakpoint (const std::string& fname = "",
+    int add_breakpoint (const std::string& fname = "",
+                        const std::string& class_name = "",
+                        int line = 1, const std::string& condition = "");
+
+    // Add a set of breakpoints at the nearest executable lines.
+    bp_lines add_breakpoint (const std::string& fname = "",
                            const std::string& class_name = "",
-                           const intmap& lines = intmap (),
+                           const bp_lines& lines = bp_lines (),
                            const std::string& condition = "");
 
-    // Remove a breakpoint from a line in file.
+    // Remove a breakpoint from the given line in file.
+    int remove_breakpoint (const std::string& fname = "", int line = 1);
+
+    // Remove a set of breakpoints from the given lines in file.
     int remove_breakpoint (const std::string& fname = "",
-                           const intmap& lines = intmap ());
+                           const bp_lines& lines = bp_lines ());
 
     // Remove all the breakpoints in a specified file.
-    intmap remove_all_breakpoints_in_file (const std::string& fname,
+    bp_lines remove_all_breakpoints_in_file (const std::string& fname,
                                            bool silent = false);
 
     // Remove all the breakpoints registered with octave.
@@ -127,7 +135,7 @@
 
     void parse_dbfunction_params (const char *who, const octave_value_list& args,
                                   std::string& func_name, std::string& class_name,
-                                  bp_table::intmap& lines, std::string& cond);
+                                  bp_table::bp_lines& lines, std::string& cond);
 
   private:
 
@@ -155,14 +163,14 @@
                           std::set<std::string>& id_list);
 
     bool add_breakpoint_1 (octave_user_code *fcn, const std::string& fname,
-                           const intmap& line, const std::string& condition,
-                           intmap& retval);
+                           const bp_lines& line, const std::string& condition,
+                           bp_lines& retval);
 
     int remove_breakpoint_1 (octave_user_code *fcn, const std::string&,
-                             const intmap& lines);
+                             const bp_lines& lines);
 
-    intmap remove_all_breakpoints_in_file_1 (octave_user_code *fcn,
-                                             const std::string& fname);
+    bp_lines remove_all_breakpoints_in_file_1 (octave_user_code *fcn,
+                                               const std::string& fname);
   };
 }