Mercurial > hg > octave-nkf
diff src/debug.cc @ 7719:87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 16 Apr 2008 22:08:15 -0400 |
parents | 3e107d73aeb4 |
children | a059b5679fbb |
line wrap: on
line diff
--- a/src/debug.cc +++ b/src/debug.cc @@ -62,10 +62,10 @@ // empty, search backward for the first user-defined function in the // current call stack. -static octave_user_function * -get_user_function (const std::string& fname = std::string ()) +static octave_user_code * +get_user_code (const std::string& fname = std::string ()) { - octave_user_function *dbg_fcn = 0; + octave_user_code *dbg_fcn = 0; if (fname.empty ()) dbg_fcn = octave_call_stack::caller_user_function (); @@ -74,7 +74,7 @@ octave_value fcn = symbol_table::find_function (fname); if (fcn.is_defined ()) - dbg_fcn = fcn.user_function_value (); + dbg_fcn = fcn.user_code_value (); } return dbg_fcn; @@ -94,10 +94,10 @@ return; // If we are already in a debugging function. - if (octave_call_stack::caller_user_function ()) + if (octave_call_stack::caller_user_code ()) { idx = 0; - symbol_name = get_user_function ()->name (); + symbol_name = get_user_code ()->name (); } else if (args(0).is_map ()) { @@ -154,24 +154,27 @@ octave_idx_type len = line.size (); - octave_user_function *dbg_fcn = get_user_function (fname); + octave_user_code *dbg_fcn = get_user_code (fname); if (dbg_fcn) { tree_statement_list *cmds = dbg_fcn->body (); - for (int i = 0; i < len; i++) + if (cmds) { - const_intmap_iterator p = line.find (i); - - if (p != line.end ()) + for (int i = 0; i < len; i++) { - int lineno = p->second; + const_intmap_iterator p = line.find (i); + + if (p != line.end ()) + { + int lineno = p->second; - retval[i] = cmds->set_breakpoint (lineno); + retval[i] = cmds->set_breakpoint (lineno); - if (retval[i] != 0) - bp_map[fname] = dbg_fcn; + if (retval[i] != 0) + bp_map[fname] = dbg_fcn; + } } } } @@ -197,28 +200,36 @@ } else { - octave_user_function *dbg_fcn = get_user_function (fname); + octave_user_code *dbg_fcn = get_user_code (fname); + if (dbg_fcn) { tree_statement_list *cmds = dbg_fcn->body (); - octave_value_list results = cmds->list_breakpoints (); - if (results.length () > 0) + + if (cmds) { - for (int i = 0; i < len; i++) + octave_value_list results = cmds->list_breakpoints (); + + if (results.length () > 0) { - const_intmap_iterator p = line.find (i); - - if (p != line.end ()) - cmds->delete_breakpoint (p->second); - } - results = cmds->list_breakpoints (); + for (int i = 0; i < len; i++) + { + const_intmap_iterator p = line.find (i); + + if (p != line.end ()) + cmds->delete_breakpoint (p->second); + } - breakpoint_map_iterator it = bp_map.find (fname); - if (results.length () == 0 && it != bp_map.end ()) - bp_map.erase (it); + results = cmds->list_breakpoints (); + + breakpoint_map_iterator it = bp_map.find (fname); + + if (results.length () == 0 && it != bp_map.end ()) + bp_map.erase (it); + } + + retval = results.length (); } - - retval = results.length (); } else error ("remove_breakpoint: unable to find the function requested\n"); @@ -232,24 +243,28 @@ { intmap retval; - octave_user_function *dbg_fcn = get_user_function (fname); + octave_user_code *dbg_fcn = get_user_code (fname); if (dbg_fcn) { tree_statement_list *cmds = dbg_fcn->body (); - octave_value_list bkpts = cmds->list_breakpoints (); - - for (int i = 0; i < bkpts.length (); i++) + if (cmds) { - int lineno = static_cast<int> (bkpts(i).int_value ()); - cmds->delete_breakpoint (lineno); - retval[i] = lineno; + octave_value_list bkpts = cmds->list_breakpoints (); + + for (int i = 0; i < bkpts.length (); i++) + { + int lineno = static_cast<int> (bkpts(i).int_value ()); + cmds->delete_breakpoint (lineno); + retval[i] = lineno; + } + + breakpoint_map_iterator it = bp_map.find (fname); + + if (it != bp_map.end ()) + bp_map.erase (it); } - - breakpoint_map_iterator it = bp_map.find (fname); - if (it != bp_map.end ()) - bp_map.erase (it); } else error ("remove_all_breakpoint_in_file: " @@ -297,16 +312,23 @@ if (fname_list.length () == 0 || do_find_bkpt_list (fname_list, it->first) != "") { - octave_value_list bkpts = it->second->body ()->list_breakpoints (); + octave_user_code *f = it->second; + + tree_statement_list *cmds = f->body (); - octave_idx_type len = bkpts.length (); + if (cmds) + { + octave_value_list bkpts = cmds->list_breakpoints (); - bp_table::intmap bkpts_vec; + octave_idx_type len = bkpts.length (); + + bp_table::intmap bkpts_vec; - for (int i = 0; i < len; i++) - bkpts_vec[i] = bkpts (i).double_value (); + for (int i = 0; i < len; i++) + bkpts_vec[i] = bkpts (i).double_value (); - retval[it->first] = bkpts_vec; + retval[it->first] = bkpts_vec; + } } } @@ -432,7 +454,7 @@ } else { - octave_user_function *dbg_fcn = get_user_function (); + octave_user_code *dbg_fcn = get_user_code (); if (dbg_fcn) { symbol_name = dbg_fcn->name (); @@ -498,7 +520,7 @@ { octave_value retval; - octave_user_function *dbg_fcn = get_user_function (); + octave_user_code *dbg_fcn = get_user_code (); if (dbg_fcn) { @@ -573,7 +595,7 @@ @end deftypefn") { octave_value retval; - octave_user_function *dbg_fcn; + octave_user_code *dbg_fcn; int nargin = args.length (); string_vector argv = args.make_argv ("dbtype"); @@ -583,7 +605,7 @@ switch (nargin) { case 0: // dbtype - dbg_fcn = get_user_function (); + dbg_fcn = get_user_code (); if (dbg_fcn) do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX); @@ -592,13 +614,13 @@ break; case 1: // (dbtype func) || (dbtype start:end) - dbg_fcn = get_user_function (argv[1]); + dbg_fcn = get_user_code (argv[1]); if (dbg_fcn) do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX); else { - dbg_fcn = get_user_function (); + dbg_fcn = get_user_code (); if (dbg_fcn) { @@ -629,7 +651,7 @@ break; case 2: // (dbtype func start:end) , (dbtype func start) - dbg_fcn = get_user_function (argv[1]); + dbg_fcn = get_user_code (argv[1]); if (dbg_fcn) {