# HG changeset patch # User John W. Eaton # Date 1367346736 14400 # Node ID 645672f1c8736d882cc7f031960391346750f9c8 # Parent 3ce0c312a40b696622408b4fd668c742841d72fe 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. diff -r 3ce0c312a40b -r 645672f1c873 libinterp/interpfcn/debug.cc --- a/libinterp/interpfcn/debug.cc Mon Apr 29 18:39:07 2013 -0400 +++ b/libinterp/interpfcn/debug.cc Tue Apr 30 14:32:16 2013 -0400 @@ -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::const_iterator + subfunction_map_const_iterator; - if (cmds) - { - retval = cmds->add_breakpoint (file, line); + std::map 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; } } } diff -r 3ce0c312a40b -r 645672f1c873 libinterp/interpfcn/debug.h --- a/libinterp/interpfcn/debug.h Mon Apr 29 18:39:07 2013 -0400 +++ b/libinterp/interpfcn/debug.h Tue Apr 30 14:32:16 2013 -0400 @@ -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); diff -r 3ce0c312a40b -r 645672f1c873 libinterp/interpfcn/symtab.h --- a/libinterp/interpfcn/symtab.h Mon Apr 29 18:39:07 2013 -0400 +++ b/libinterp/interpfcn/symtab.h Tue Apr 30 14:32:16 2013 -0400 @@ -2175,6 +2175,26 @@ p->second.unlock_subfunction (scope); } + static std::map + subfunctions_defined_in_scope (scope_id scope = xcurrent_scope) + { + std::map retval; + + for (fcn_table_const_iterator p = fcn_table.begin (); + p != fcn_table.end (); p++) + { + std::pair 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 - subfunctions_defined_in_scope (scope_id scope = xcurrent_scope) - { - std::map retval; - - for (fcn_table_const_iterator p = fcn_table.begin (); - p != fcn_table.end (); p++) - { - std::pair 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); diff -r 3ce0c312a40b -r 645672f1c873 libinterp/octave-value/ov-usr-fcn.cc --- a/libinterp/octave-value/ov-usr-fcn.cc Mon Apr 29 18:39:07 2013 -0400 +++ b/libinterp/octave-value/ov-usr-fcn.cc Tue Apr 30 14:32:16 2013 -0400 @@ -58,6 +58,13 @@ // Whether to optimize subsasgn method calls. static bool Voptimize_subsasgn_calls = true; + +std::map +octave_user_code::subfunctions (void) const +{ + return std::map (); +} + // User defined scripts. DEFINE_OCTAVE_ALLOCATOR (octave_user_script); @@ -306,6 +313,12 @@ symbol_table::unlock_subfunctions (local_scope); } +std::map +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) { diff -r 3ce0c312a40b -r 645672f1c873 libinterp/octave-value/ov-usr-fcn.h --- a/libinterp/octave-value/ov-usr-fcn.h Mon Apr 29 18:39:07 2013 -0400 +++ b/libinterp/octave-value/ov-usr-fcn.h Tue Apr 30 14:32:16 2013 -0400 @@ -59,6 +59,8 @@ bool is_user_code (void) const { return true; } + virtual std::map subfunctions (void) const; + virtual tree_statement_list *body (void) = 0; protected: @@ -262,6 +264,8 @@ void unlock_subfunctions (void); + std::map 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; } diff -r 3ce0c312a40b -r 645672f1c873 libinterp/parse-tree/pt-bp.h --- a/libinterp/parse-tree/pt-bp.h Mon Apr 29 18:39:07 2013 -0400 +++ b/libinterp/parse-tree/pt-bp.h Tue Apr 30 14:32:16 2013 -0400 @@ -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: