changeset 16598:645672f1c873

handle setting breakpoints in subfunctions in GUI editor * symtab.h (symbol_table::subfunctions_defined_in_scope): Now public. * debug.h, debug.cc (bp_table::do_add_breakpoint_1): New function. (bp_table::do_add_breakpoint): Handle subfunctions. * ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_code::subfunctions, octave_user_function::subfunctions): New functions. * pt-bp.h (tree_breakpoint::get_line): Return 0 if line wasn't found.
author John W. Eaton <jwe@octave.org>
date Tue, 30 Apr 2013 14:32:16 -0400
parents 3ce0c312a40b
children 49832f60282e
files libinterp/interpfcn/debug.cc libinterp/interpfcn/debug.h libinterp/interpfcn/symtab.h libinterp/octave-value/ov-usr-fcn.cc libinterp/octave-value/ov-usr-fcn.h libinterp/parse-tree/pt-bp.h
diffstat 6 files changed, 83 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/interpfcn/debug.cc
+++ b/libinterp/interpfcn/debug.cc
@@ -274,6 +274,36 @@
   return retval;
 }
 
+bool
+bp_table::do_add_breakpoint_1 (octave_user_code *fcn,
+                               const std::string& fname,
+                               const bp_table::intmap& line,
+                               bp_table::intmap& retval)
+{
+  bool found = false;
+
+  tree_statement_list *cmds = fcn->body ();
+
+  std::string file = fcn->fcn_file_name ();
+
+  if (cmds)
+    {
+      retval = cmds->add_breakpoint (file, line);
+
+      for (intmap_iterator p = retval.begin (); p != retval.end (); p++)
+        {
+          if (p->second != 0)
+            {
+              bp_set.insert (fname);
+              found = true;
+              break;
+            }
+        }
+    }
+
+  return found;
+}
+
 bp_table::intmap
 bp_table::do_add_breakpoint (const std::string& fname,
                              const bp_table::intmap& line)
@@ -284,21 +314,21 @@
 
   if (dbg_fcn)
     {
-      tree_statement_list *cmds = dbg_fcn->body ();
-
-      std::string file = dbg_fcn->fcn_file_name ();
+      if (! do_add_breakpoint_1 (dbg_fcn, fname, line, retval))
+        {
+          typedef std::map<std::string, octave_value>::const_iterator
+            subfunction_map_const_iterator;
 
-      if (cmds)
-        {
-          retval = cmds->add_breakpoint (file, line);
+          std::map<std::string, octave_value> subfcns
+            = dbg_fcn->subfunctions ();
 
-          for (intmap_iterator p = retval.begin (); p != retval.end (); p++)
+          for (subfunction_map_const_iterator p = subfcns.begin ();
+               p != subfcns.end (); p++)
             {
-              if (p->second != 0)
-                {
-                  bp_set.insert (fname);
-                  break;
-                }
+              octave_user_code *dbg_subfcn = p->second.user_code_value ();
+
+              if (do_add_breakpoint_1 (dbg_subfcn, fname, line, retval))
+                break;
             }
         }
     }
--- a/libinterp/interpfcn/debug.h
+++ b/libinterp/interpfcn/debug.h
@@ -115,6 +115,9 @@
 
   static void cleanup_instance (void) { delete instance; instance = 0; }
 
+  bool do_add_breakpoint_1 (octave_user_code *fcn, const std::string& fname,
+                            const intmap& line, intmap& retval);
+
   intmap do_add_breakpoint (const std::string& fname, const intmap& lines);
 
   int do_remove_breakpoint (const std::string&, const intmap& lines);
--- a/libinterp/interpfcn/symtab.h
+++ b/libinterp/interpfcn/symtab.h
@@ -2175,6 +2175,26 @@
       p->second.unlock_subfunction (scope);
   }
 
+  static std::map<std::string, octave_value>
+  subfunctions_defined_in_scope (scope_id scope = xcurrent_scope)
+  {
+    std::map<std::string, octave_value> retval;
+
+    for (fcn_table_const_iterator p = fcn_table.begin ();
+         p != fcn_table.end (); p++)
+      {
+        std::pair<std::string, octave_value> tmp
+          = p->second.subfunction_defined_in_scope (scope);
+
+        std::string nm = tmp.first;
+
+        if (! nm.empty ())
+          retval[nm] = tmp.second;
+      }
+
+    return retval;
+  }
+
   static void free_scope (scope_id scope)
   {
     if (scope == xglobal_scope || scope == xtop_scope)
@@ -2796,26 +2816,6 @@
     return retval;
   }
 
-  static std::map<std::string, octave_value>
-  subfunctions_defined_in_scope (scope_id scope = xcurrent_scope)
-  {
-    std::map<std::string, octave_value> retval;
-
-    for (fcn_table_const_iterator p = fcn_table.begin ();
-         p != fcn_table.end (); p++)
-      {
-        std::pair<std::string, octave_value> tmp
-          = p->second.subfunction_defined_in_scope (scope);
-
-        std::string nm = tmp.first;
-
-        if (! nm.empty ())
-          retval[nm] = tmp.second;
-      }
-
-    return retval;
-  }
-
   bool do_is_local_variable (const std::string& name) const
   {
     table_const_iterator p = table.find (name);
--- a/libinterp/octave-value/ov-usr-fcn.cc
+++ b/libinterp/octave-value/ov-usr-fcn.cc
@@ -58,6 +58,13 @@
 // Whether to optimize subsasgn method calls.
 static bool Voptimize_subsasgn_calls = true;
 
+
+std::map<std::string, octave_value>
+octave_user_code::subfunctions (void) const
+{
+  return std::map<std::string, octave_value> ();
+}
+
 // User defined scripts.
 
 DEFINE_OCTAVE_ALLOCATOR (octave_user_script);
@@ -306,6 +313,12 @@
   symbol_table::unlock_subfunctions (local_scope);
 }
 
+std::map<std::string, octave_value>
+octave_user_function::subfunctions (void) const
+{
+  return symbol_table::subfunctions_defined_in_scope (local_scope);
+}
+
 octave_value_list
 octave_user_function::all_va_args (const octave_value_list& args)
 {
--- a/libinterp/octave-value/ov-usr-fcn.h
+++ b/libinterp/octave-value/ov-usr-fcn.h
@@ -59,6 +59,8 @@
 
   bool is_user_code (void) const { return true; }
 
+  virtual std::map<std::string, octave_value> subfunctions (void) const;
+
   virtual tree_statement_list *body (void) = 0;
 
 protected:
@@ -262,6 +264,8 @@
 
   void unlock_subfunctions (void);
 
+  std::map<std::string, octave_value> subfunctions (void) const;
+
   octave_value_list all_va_args (const octave_value_list& args);
 
   void stash_function_name (const std::string& s) { my_name = s; }
--- a/libinterp/parse-tree/pt-bp.h
+++ b/libinterp/parse-tree/pt-bp.h
@@ -134,7 +134,7 @@
 
   octave_value_list get_list (void) { return bp_list; }
 
-  int get_line (void) { return line; }
+  int get_line (void) { return found ? line : 0; }
 
  private: