Mercurial > hg > octave-lyh
diff src/debug.cc @ 10315:57a59eae83cc
untabify src C++ source files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 11 Feb 2010 12:41:46 -0500 |
parents | 0efd486813fe |
children | 65bc065bec95 |
line wrap: on
line diff
--- a/src/debug.cc +++ b/src/debug.cc @@ -73,20 +73,20 @@ std::ifstream file (fname.c_str (), std::ios::in|std::ios::binary); if (file) - { - std::string buf (sz+1, 0); + { + std::string buf (sz+1, 0); - file.read (&buf[0], sz+1); + file.read (&buf[0], sz+1); - if (file.eof ()) - { - // Expected to read the entire file. + if (file.eof ()) + { + // Expected to read the entire file. - retval = buf; - } - else - error ("error reading file %s", fname.c_str ()); - } + retval = buf; + } + else + error ("error reading file %s", fname.c_str ()); + } } return retval; @@ -109,16 +109,16 @@ char c = buf[i]; if (c == '\r' && ++i < len) - { - c = buf[i]; + { + c = buf[i]; - if (c == '\n') - offsets.push_back (i+1); - else - offsets.push_back (i); - } + if (c == '\n') + offsets.push_back (i+1); + else + offsets.push_back (i); + } else if (c == '\n') - offsets.push_back (i+1); + offsets.push_back (i+1); } offsets.push_back (len); @@ -153,7 +153,7 @@ size_t eol = offsets[line+1]; while (eol > 0 && (buf[eol-1] == '\n' || buf[eol-1] == '\r')) - eol--; + eol--; retval = buf.substr (bol, eol - bol); } @@ -177,7 +177,7 @@ octave_value fcn = symbol_table::find_function (fname); if (fcn.is_defined () && fcn.is_user_code ()) - dbg_fcn = fcn.user_code_value (); + dbg_fcn = fcn.user_code_value (); } return dbg_fcn; @@ -185,7 +185,7 @@ static void parse_dbfunction_params (const char *who, const octave_value_list& args, - std::string& symbol_name, bp_table::intmap& lines) + std::string& symbol_name, bp_table::intmap& lines) { int nargin = args.length (); int idx = 0; @@ -211,7 +211,7 @@ { symbol_name = args(0).string_value (); if (error_state) - return; + return; idx = 1; } else @@ -220,38 +220,38 @@ for (int i = idx; i < nargin; i++ ) { if (args(i).is_string ()) - { - int line = atoi (args(i).string_value().c_str ()); - if (error_state) - break; - lines[list_idx++] = line; - } + { + int line = atoi (args(i).string_value().c_str ()); + if (error_state) + break; + lines[list_idx++] = line; + } else if (args(i).is_map ()) - octave_stdout << who << ": accepting a struct" << std::endl; + octave_stdout << who << ": accepting a struct" << std::endl; else - { - const NDArray arg = args(i).array_value (); - - if (error_state) - break; - - for (octave_idx_type j = 0; j < arg.nelem (); j++) - { - int line = static_cast<int> (arg.elem (j)); - if (error_state) - break; - lines[list_idx++] = line; - } - - if (error_state) - break; - } + { + const NDArray arg = args(i).array_value (); + + if (error_state) + break; + + for (octave_idx_type j = 0; j < arg.nelem (); j++) + { + int line = static_cast<int> (arg.elem (j)); + if (error_state) + break; + lines[list_idx++] = line; + } + + if (error_state) + break; + } } } bp_table::intmap bp_table::do_add_breakpoint (const std::string& fname, - const bp_table::intmap& line) + const bp_table::intmap& line) { intmap retval; @@ -264,24 +264,24 @@ tree_statement_list *cmds = dbg_fcn->body (); if (cmds) - { - for (int i = 0; i < len; i++) - { - const_intmap_iterator p = line.find (i); + { + for (int i = 0; i < len; i++) + { + const_intmap_iterator p = line.find (i); - if (p != line.end ()) - { - int lineno = p->second; + 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_set.insert (fname); - } - } - } - } + if (retval[i] != 0) + { + bp_set.insert (fname); + } + } + } + } } else error ("add_breakpoint: unable to find the function requested\n"); @@ -294,7 +294,7 @@ int bp_table::do_remove_breakpoint (const std::string& fname, - const bp_table::intmap& line) + const bp_table::intmap& line) { int retval = 0; @@ -310,36 +310,36 @@ octave_user_code *dbg_fcn = get_user_code (fname); if (dbg_fcn) - { - tree_statement_list *cmds = dbg_fcn->body (); + { + tree_statement_list *cmds = dbg_fcn->body (); - if (cmds) - { - octave_value_list results = cmds->list_breakpoints (); + if (cmds) + { + octave_value_list results = cmds->list_breakpoints (); - if (results.length () > 0) - { - for (int i = 0; i < len; i++) - { - const_intmap_iterator p = line.find (i); + if (results.length () > 0) + { + for (int i = 0; i < len; i++) + { + const_intmap_iterator p = line.find (i); - if (p != line.end ()) - cmds->delete_breakpoint (p->second); - } + if (p != line.end ()) + cmds->delete_breakpoint (p->second); + } - results = cmds->list_breakpoints (); + results = cmds->list_breakpoints (); - bp_set_iterator it = bp_set.find (fname); - if (results.length () == 0 && it != bp_set.end ()) - bp_set.erase (it); + bp_set_iterator it = bp_set.find (fname); + if (results.length () == 0 && it != bp_set.end ()) + bp_set.erase (it); - } + } - retval = results.length (); - } - } + retval = results.length (); + } + } else - error ("remove_breakpoint: unable to find the function requested\n"); + error ("remove_breakpoint: unable to find the function requested\n"); } tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging; @@ -350,7 +350,7 @@ bp_table::intmap bp_table::do_remove_all_breakpoints_in_file (const std::string& fname, - bool silent) + bool silent) { intmap retval; @@ -361,25 +361,25 @@ tree_statement_list *cmds = dbg_fcn->body (); if (cmds) - { - octave_value_list bkpts = cmds->list_breakpoints (); + { + 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; - } + for (int i = 0; i < bkpts.length (); i++) + { + int lineno = static_cast<int> (bkpts(i).int_value ()); + cmds->delete_breakpoint (lineno); + retval[i] = lineno; + } - bp_set_iterator it = bp_set.find (fname); - if (it != bp_set.end ()) - bp_set.erase (it); + bp_set_iterator it = bp_set.find (fname); + if (it != bp_set.end ()) + bp_set.erase (it); - } + } } else if (! silent) error ("remove_all_breakpoint_in_file: " - "unable to find the function requested\n"); + "unable to find the function requested\n"); tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging; @@ -398,17 +398,17 @@ std::string do_find_bkpt_list (octave_value_list slist, - std::string match) + std::string match) { std::string retval; for (int i = 0; i < slist.length (); i++) { if (slist (i).string_value () == match) - { - retval = slist(i).string_value (); - break; - } + { + retval = slist(i).string_value (); + break; + } } return retval; @@ -423,33 +423,33 @@ 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) != "") - { - octave_user_code *f = get_user_code (*it); + || do_find_bkpt_list (fname_list, *it) != "") + { + octave_user_code *f = get_user_code (*it); - if (f) - { - tree_statement_list *cmds = f->body (); + if (f) + { + tree_statement_list *cmds = f->body (); - if (cmds) - { - octave_value_list bkpts = cmds->list_breakpoints (); - octave_idx_type len = bkpts.length (); + if (cmds) + { + octave_value_list bkpts = cmds->list_breakpoints (); + octave_idx_type len = bkpts.length (); - 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 (); + 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[symbol_name] = bkpts_vec; - } - } - } - } + retval[symbol_name] = bkpts_vec; + } + } + } + } } return retval; @@ -467,10 +467,10 @@ bp_table::const_intmap_iterator p = line.find (i); if (p != line.end ()) - { - int lineno = p->second; - retval(idx++) = lineno; - } + { + int lineno = p->second; + retval(idx++) = lineno; + } } retval.resize (dim_vector (1, idx)); @@ -567,22 +567,22 @@ if (nargin == 1) { if (args(0).is_string ()) - { - symbol_name = args(0).string_value (); - fcn_list(0) = symbol_name; - bp_list = bp_table::get_breakpoint_list (fcn_list); - } + { + symbol_name = args(0).string_value (); + fcn_list(0) = symbol_name; + bp_list = bp_table::get_breakpoint_list (fcn_list); + } else - gripe_wrong_type_arg ("dbstatus", args(0)); + gripe_wrong_type_arg ("dbstatus", args(0)); } else { octave_user_code *dbg_fcn = get_user_code (); if (dbg_fcn) - { - symbol_name = dbg_fcn->name (); - fcn_list(0) = symbol_name; - } + { + symbol_name = dbg_fcn->name (); + fcn_list(0) = symbol_name; + } bp_list = bp_table::get_breakpoint_list (fcn_list); } @@ -592,20 +592,20 @@ // Print out the breakpoint information. for (bp_table::fname_line_map_iterator it = bp_list.begin (); - it != bp_list.end (); it++) - { - octave_stdout << "Breakpoint in " << it->first << " at line(s) "; + it != bp_list.end (); it++) + { + octave_stdout << "Breakpoint in " << it->first << " at line(s) "; - bp_table::intmap m = it->second; + bp_table::intmap m = it->second; - size_t nel = m.size (); + size_t nel = m.size (); - for (size_t j = 0; j < nel; j++) - octave_stdout << m[j] << ((j < nel - 1) ? ", " : "."); + for (size_t j = 0; j < nel; j++) + octave_stdout << m[j] << ((j < nel - 1) ? ", " : "."); - if (nel > 0) - octave_stdout << std::endl; - } + if (nel > 0) + octave_stdout << std::endl; + } return octave_value (); } else @@ -618,13 +618,13 @@ Cell line (dim_vector (bp_list.size (), 1)); for (bp_table::const_fname_line_map_iterator it = bp_list.begin (); - it != bp_list.end (); it++) - { - names(i) = it->first; - line(i) = intmap_to_ov (it->second); - file(i) = do_which (it->first); - i++; - } + it != bp_list.end (); it++) + { + names(i) = it->first; + line(i) = intmap_to_ov (it->second); + file(i) = do_which (it->first); + i++; + } retval.assign ("name", names); retval.assign ("file", file); @@ -652,11 +652,11 @@ std::string name = dbg_fcn->fcn_file_name (); if (name.empty ()) - { - have_file = false; + { + have_file = false; - name = dbg_fcn->name (); - } + name = dbg_fcn->name (); + } octave_stdout << name << ":"; @@ -671,26 +671,26 @@ int l = octave_call_stack::current_line (); if (l > 0) - { - octave_stdout << " line " << l; + { + octave_stdout << " line " << l; - int c = octave_call_stack::current_column (); + int c = octave_call_stack::current_column (); - if (c > 0) - octave_stdout << ", column " << c; + if (c > 0) + octave_stdout << ", column " << c; - octave_stdout << std::endl; + octave_stdout << std::endl; - if (have_file) - { - std::string line = get_file_line (name, l); + if (have_file) + { + std::string line = get_file_line (name, l); - if (! line.empty ()) - octave_stdout << l << ": " << line << std::endl; - } - } + if (! line.empty ()) + octave_stdout << l << ": " << line << std::endl; + } + } else - octave_stdout << " (unknown line)\n"; + octave_stdout << " (unknown line)\n"; } else error ("dbwhere: must be inside of a user function to use dbwhere\n"); @@ -710,30 +710,30 @@ std::ifstream fs (ff.c_str (), std::ios::in); if (fs) - { - char ch; - int line = 1; - - if (line >= start && line <= end) - os << line << "\t"; - - while (fs.get (ch)) - { - if (line >= start && line <= end) - { - os << ch; - } + { + char ch; + int line = 1; + + if (line >= start && line <= end) + os << line << "\t"; + + while (fs.get (ch)) + { + if (line >= start && line <= end) + { + os << ch; + } - if (ch == '\n') - { - line++; - if (line >= start && line <= end) - os << line << "\t"; - } - } - } + if (ch == '\n') + { + line++; + if (line >= start && line <= end) + os << line << "\t"; + } + } + } else - os << "dbtype: unable to open `" << ff << "' for reading!\n"; + os << "dbtype: unable to open `" << ff << "' for reading!\n"; } else os << "dbtype: unknown function " << name << "\n"; @@ -757,91 +757,91 @@ if (! error_state) { switch (nargin) - { - case 0: // dbtype - dbg_fcn = get_user_code (); + { + case 0: // dbtype + dbg_fcn = get_user_code (); - if (dbg_fcn) - do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX); - else - error ("dbtype: must be in a user function to give no arguments to dbtype\n"); - break; + if (dbg_fcn) + do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX); + else + error ("dbtype: must be in a user function to give no arguments to dbtype\n"); + break; - case 1: // (dbtype func) || (dbtype start:end) - dbg_fcn = get_user_code (argv[1]); + case 1: // (dbtype func) || (dbtype start:end) + 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_code (); + if (dbg_fcn) + do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX); + else + { + dbg_fcn = get_user_code (); - if (dbg_fcn) - { - std::string arg = argv[1]; + if (dbg_fcn) + { + std::string arg = argv[1]; - size_t ind = arg.find (':'); + size_t ind = arg.find (':'); - if (ind != std::string::npos) - { - std::string start_str = arg.substr (0, ind); - std::string end_str = arg.substr (ind + 1); + if (ind != std::string::npos) + { + std::string start_str = arg.substr (0, ind); + std::string end_str = arg.substr (ind + 1); - int start = atoi (start_str.c_str ()); - int end = atoi (end_str.c_str ()); - - if (std::min (start, end) <= 0) - error ("dbtype: start and end lines must be >= 1\n"); + int start = atoi (start_str.c_str ()); + int end = atoi (end_str.c_str ()); + + if (std::min (start, end) <= 0) + error ("dbtype: start and end lines must be >= 1\n"); - if (start <= end) - do_dbtype (octave_stdout, dbg_fcn->name (), start, end); - else - error ("dbtype: start line must be less than end line\n"); - } - else - error ("dbtype: line specification must be `start:end'"); - } - } - break; + if (start <= end) + do_dbtype (octave_stdout, dbg_fcn->name (), start, end); + else + error ("dbtype: start line must be less than end line\n"); + } + else + error ("dbtype: line specification must be `start:end'"); + } + } + break; - case 2: // (dbtype func start:end) , (dbtype func start) - dbg_fcn = get_user_code (argv[1]); + case 2: // (dbtype func start:end) , (dbtype func start) + dbg_fcn = get_user_code (argv[1]); - if (dbg_fcn) - { - std::string arg = argv[2]; - int start = 0; - int end = 0; - size_t ind = arg.find (':'); + if (dbg_fcn) + { + std::string arg = argv[2]; + int start = 0; + int end = 0; + size_t ind = arg.find (':'); - if (ind != std::string::npos) - { - std::string start_str = arg.substr (0, ind); - std::string end_str = arg.substr (ind + 1); + if (ind != std::string::npos) + { + std::string start_str = arg.substr (0, ind); + std::string end_str = arg.substr (ind + 1); - start = atoi (start_str.c_str ()); - end = atoi (end_str.c_str ()); - - } - else - { - start = atoi (arg.c_str ()); - end = start; - } + start = atoi (start_str.c_str ()); + end = atoi (end_str.c_str ()); + + } + else + { + start = atoi (arg.c_str ()); + end = start; + } - if (std::min (start, end) <= 0) - error ("dbtype: start and end lines must be >= 1\n"); - - if (start <= end) - do_dbtype (octave_stdout, dbg_fcn->name (), start, end); - else - error ("dbtype: start line must be less than end line\n"); - } - break; + if (std::min (start, end) <= 0) + error ("dbtype: start and end lines must be >= 1\n"); + + if (start <= end) + do_dbtype (octave_stdout, dbg_fcn->name (), start, end); + else + error ("dbtype: start line must be less than end line\n"); + } + break; - default: - error ("dbtype: expecting zero, one, or two arguments\n"); - } + default: + error ("dbtype: expecting zero, one, or two arguments\n"); + } } return retval; @@ -870,18 +870,18 @@ octave_value arg = args(0); if (arg.is_string ()) - { - std::string s_arg = arg.string_value (); + { + std::string s_arg = arg.string_value (); - n = atoi (s_arg.c_str ()); - } + n = atoi (s_arg.c_str ()); + } else - n = args(0).int_value (); + n = args(0).int_value (); if (n > 0) - nskip = n; + nskip = n; else - error ("dbstack: expecting N to be a nonnegative integer"); + error ("dbstack: expecting N to be a nonnegative integer"); } if (! error_state) @@ -889,36 +889,36 @@ Octave_map stk = octave_call_stack::backtrace (nskip, curr_frame); if (nargout == 0) - { - octave_idx_type nframes_to_display = stk.numel (); + { + octave_idx_type nframes_to_display = stk.numel (); - if (nframes_to_display > 0) - { - octave_stdout << "Stopped in:\n\n"; + if (nframes_to_display > 0) + { + octave_stdout << "Stopped in:\n\n"; - Cell names = stk.contents ("name"); - Cell lines = stk.contents ("line"); - Cell columns = stk.contents ("column"); + Cell names = stk.contents ("name"); + Cell lines = stk.contents ("line"); + Cell columns = stk.contents ("column"); - for (octave_idx_type i = 0; i < nframes_to_display; i++) - { - octave_value name = names(i); - octave_value line = lines(i); - octave_value column = columns(i); + for (octave_idx_type i = 0; i < nframes_to_display; i++) + { + octave_value name = names(i); + octave_value line = lines(i); + octave_value column = columns(i); - octave_stdout << (i == curr_frame ? "--> " : " ") - << name.string_value () - << " at line " << line.int_value () - << " column " << column.int_value () - << std::endl; - } - } - } + octave_stdout << (i == curr_frame ? "--> " : " ") + << name.string_value () + << " at line " << line.int_value () + << " column " << column.int_value () + << std::endl; + } + } + } else - { - retval(1) = curr_frame < 0 ? 1 : curr_frame + 1; - retval(0) = stk; - } + { + retval(1) = curr_frame < 0 ? 1 : curr_frame + 1; + retval(0) = stk; + } } return retval; @@ -934,22 +934,22 @@ octave_value arg = args(0); if (arg.is_string ()) - { - std::string s_arg = arg.string_value (); + { + std::string s_arg = arg.string_value (); - n = atoi (s_arg.c_str ()); - } + n = atoi (s_arg.c_str ()); + } else - n = args(0).int_value (); + n = args(0).int_value (); } if (! error_state) { if (who == "dbup") - n = -n; + n = -n; if (! octave_call_stack::goto_frame_relative (n, true)) - error ("%s: invalid stack frame", who.c_str ()); + error ("%s: invalid stack frame", who.c_str ()); } } @@ -1007,51 +1007,51 @@ int nargin = args.length (); if (nargin > 1) - print_usage (); + print_usage (); else if (nargin == 1) - { - if (args(0).is_string ()) - { - std::string arg = args(0).string_value (); + { + if (args(0).is_string ()) + { + std::string arg = args(0).string_value (); - if (! error_state) - { - if (arg == "in") - { - Vdebugging = false; + if (! error_state) + { + if (arg == "in") + { + Vdebugging = false; - tree_evaluator::dbstep_flag = -1; - } - else if (arg == "out") - { - Vdebugging = false; + tree_evaluator::dbstep_flag = -1; + } + else if (arg == "out") + { + Vdebugging = false; - tree_evaluator::dbstep_flag = -2; - } - else - { - int n = atoi (arg.c_str ()); + tree_evaluator::dbstep_flag = -2; + } + else + { + int n = atoi (arg.c_str ()); - if (n > 0) - { - Vdebugging = false; + if (n > 0) + { + Vdebugging = false; - tree_evaluator::dbstep_flag = n; - } - else - error ("dbstep: invalid argument"); - } - } - } - else - error ("dbstep: expecting character string as argument"); - } + tree_evaluator::dbstep_flag = n; + } + else + error ("dbstep: invalid argument"); + } + } + } + else + error ("dbstep: expecting character string as argument"); + } else - { - Vdebugging = false; + { + Vdebugging = false; - tree_evaluator::dbstep_flag = 1; - } + tree_evaluator::dbstep_flag = 1; + } } else error ("dbstep: can only be called in debug mode"); @@ -1071,13 +1071,13 @@ if (Vdebugging) { if (args.length () == 0) - { - Vdebugging = false; + { + Vdebugging = false; tree_evaluator::reset_debug_state (); - } + } else - print_usage (); + print_usage (); } else error ("dbcont: can only be called in debug mode"); @@ -1095,15 +1095,15 @@ if (Vdebugging) { if (args.length () == 0) - { - Vdebugging = false; + { + Vdebugging = false; tree_evaluator::reset_debug_state (); - octave_throw_interrupt_exception (); - } + octave_throw_interrupt_exception (); + } else - print_usage (); + print_usage (); } else error ("dbquit: can only be called in debug mode");