changeset 9183:94ae487acd1b

use set instead of map to keep track of debugger breakpoints
author jpswensen@compsci34-754-2010.compscidhcp.jhu.edu
date Tue, 05 May 2009 15:10:25 -0400
parents 23af5910e5f5
children 9861b3ec72a6
files src/ChangeLog src/debug.cc src/debug.h
diffstat 3 files changed, 42 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue May 05 14:11:43 2009 -0400
+++ b/src/ChangeLog	Tue May 05 15:10:25 2009 -0400
@@ -1,3 +1,9 @@
+2009-05-05  John Swensen  <jpswensen@comcast.net>
+
+	* debug.h, debug.cc (breakpoints): Rename from bp_map, use a
+	std::set instead of a std::map object.  Change all uses.
+	(bp_table::do_get_breakpoint_list): Simplify.
+
 2009-05-05  Robert T. Short  <octave@phaselockedsystems.com>
 
 	* ov-class.h, ov-class.cc (octave_class::reconstruct_parents):
--- a/src/debug.cc	Tue May 05 14:11:43 2009 -0400
+++ b/src/debug.cc	Tue May 05 15:10:25 2009 -0400
@@ -277,7 +277,9 @@
 		  retval[i] = cmds->set_breakpoint (lineno);
 
 		  if (retval[i] != 0)
-		    bp_map[fname] = dbg_fcn;
+		    {
+		      bp_set.insert (fname);
+		    }
 		}
 	    }
 	}
@@ -328,10 +330,10 @@
 
 		  results = cmds->list_breakpoints ();
 
-		  breakpoint_map_iterator it = bp_map.find (fname);
+		  bp_set_iterator it = bp_set.find (fname);
+		  if (results.length () == 0 && it != bp_set.end ())
+		    bp_set.erase (it);
 
-		  if (results.length () == 0 && it != bp_map.end ())
-		    bp_map.erase (it);
 		}
 
 	      retval = results.length ();
@@ -370,10 +372,10 @@
 	      retval[i] = lineno;
 	    }
 
-	  breakpoint_map_iterator it = bp_map.find (fname);
+	  bp_set_iterator it = bp_set.find (fname);
+	  if (it != bp_set.end ())
+	    bp_set.erase (it);
 
-	  if (it != bp_map.end ())
-	    bp_map.erase (it);
 	}
     }
   else if (! silent)
@@ -388,9 +390,9 @@
 void 
 bp_table::do_remove_all_breakpoints (void)
 {
-  for (const_breakpoint_map_iterator it = bp_map.begin ();
-       it != bp_map.end (); it++)
-    remove_all_breakpoints_in_file (it->first);
+  for (const_bp_set_iterator it = bp_set.begin (); it != bp_set.end (); it++)
+    remove_all_breakpoints_in_file (*it);
+
 
   tree_evaluator::debug_mode = bp_table::have_breakpoints ();
 }
@@ -419,46 +421,33 @@
 {
   fname_line_map retval;
 
-  // Clear the breakpoints in the function if it has been updated.
-  // FIXME:  This is a bad way of doing this, but I can't think of another.  The
-  // problem is due to the fact that out_of_date_check(...) calls 
-  // remove_breakpoints_in_file(...), which in turn modifies bp_map while we are
-  // in the middle of iterating through it.
-
-  std::list<octave_user_code*> usercode_list;
-
-  for (breakpoint_map_iterator it = bp_map.begin (); it != bp_map.end (); it++)
-    usercode_list.push_back (it->second);
-
-  for (std::list<octave_user_code*>::iterator it = usercode_list.begin ();
-       it != usercode_list.end (); it++)
-    out_of_date_check (*it);
-
-
-  // Iterate through each of the files in the map and get the 
-  // name and list of breakpoints.
-  for (breakpoint_map_iterator it = bp_map.begin (); it != bp_map.end (); it++)
+  for (bp_set_iterator it = bp_set.begin (); it != bp_set.end (); it++)
     {
       if (fname_list.length () == 0
-	  || do_find_bkpt_list (fname_list, it->first) != "")
+	  || do_find_bkpt_list (fname_list, *it) != "")
 	{
-	  octave_user_code *f = it->second;
-	  tree_statement_list *cmds = f->body ();
+	  octave_user_code *f = get_user_code (*it);
 
-	  if (cmds)
+	  if (f)
 	    {
-	      octave_value_list bkpts = cmds->list_breakpoints ();
+	      tree_statement_list *cmds = f->body ();
 
-	      octave_idx_type len = bkpts.length (); 
-
-	      if (len > 0)
+	      if (cmds)
 		{
-		  bp_table::intmap bkpts_vec;
+		  octave_value_list bkpts = cmds->list_breakpoints ();
+		  octave_idx_type len = bkpts.length (); 
 
-		  for (int i = 0; i < len; i++)
-		    bkpts_vec[i] = bkpts (i).double_value ();
+		  if (len > 0)
+		    {
+		      bp_table::intmap bkpts_vec;
+		      
+		      for (int i = 0; i < len; i++)
+			bkpts_vec[i] = bkpts (i).double_value ();
+		      
+		      std::string symbol_name = f->name ();
 
-		  retval[it->first] = bkpts_vec;
+		      retval[symbol_name] = bkpts_vec;
+		    }
 		}
 	    }
 	}
--- a/src/debug.h	Tue May 05 14:11:43 2009 -0400
+++ b/src/debug.h	Tue May 05 15:10:25 2009 -0400
@@ -24,6 +24,7 @@
 #define octave_debug_h 1
 
 #include <map>
+#include <set>
 #include "ov.h"
 #include "dRowVector.h"
 
@@ -116,14 +117,11 @@
 
 private:
 
-  // Map from function names to function objects for functions
-  // containing at least one breakpoint.
-  typedef std::map<std::string, octave_user_code *> breakpoint_map;
+  typedef std::set<std::string>::const_iterator const_bp_set_iterator;
+  typedef std::set<std::string>::iterator bp_set_iterator;
 
-  typedef breakpoint_map::const_iterator const_breakpoint_map_iterator;
-  typedef breakpoint_map::iterator breakpoint_map_iterator;
-
-  breakpoint_map bp_map;
+  // Set of function names containing at least one breakpoint.
+  std::set<std::string> bp_set;
 
   static bp_table *instance;
 
@@ -138,7 +136,7 @@
 
   fname_line_map do_get_breakpoint_list (const octave_value_list& fname_list);
 
-  bool do_have_breakpoints (void) { return (! bp_map.empty ()); }
+  bool do_have_breakpoints (void) { return (! bp_set.empty ()); }
 };
 
 std::string get_file_line (const std::string& fname, size_t line);