Mercurial > hg > octave-avbm
diff src/toplev.cc @ 7736:a059b5679fbb
implement dbstack
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 25 Apr 2008 15:11:03 -0400 |
parents | 2dee19385d32 |
children | 40c428ea3408 |
line wrap: on
line diff
--- a/src/toplev.cc +++ b/src/toplev.cc @@ -175,73 +175,69 @@ } Octave_map -octave_call_stack::do_backtrace (void) const +octave_call_stack::do_backtrace (int n) const { Octave_map retval; - size_t nframes = cs.size () - 1; - - Cell keys (4, 1); + int nframes = cs.size () - n; - keys(0) = "file"; - keys(1) = "name"; - keys(2) = "line"; - keys(3) = "column"; + if (nframes > 0) + { + Cell keys (4, 1); - Cell file (nframes, 1); - Cell name (nframes, 1); - Cell line (nframes, 1); - Cell column (nframes, 1); + keys(0) = "file"; + keys(1) = "name"; + keys(2) = "line"; + keys(3) = "column"; - const_iterator p = cs.begin (); - - // Skip innermost function as it will be the dbstatus function - // itself. FIXME -- Is it best to do this here? - p++; + Cell file (nframes, 1); + Cell name (nframes, 1); + Cell line (nframes, 1); + Cell column (nframes, 1); + + octave_idx_type k = 0; - octave_idx_type k = 0; - - while (p != cs.end ()) - { - const call_stack_elt& elt = *p; - - octave_function *f = elt.fcn; - - if (f) + for (const_iterator p = cs.begin () + n; p != cs.end (); p++) { - file(k) = f->fcn_file_name (); - name(k) = f->name (); + const call_stack_elt& elt = *p; + + octave_function *f = elt.fcn; - tree_statement *stmt = elt.stmt; + if (f) + { + file(k) = f->fcn_file_name (); + name(k) = f->name (); + + tree_statement *stmt = elt.stmt; - if (stmt) - { - line(k) = stmt->line (); - column(k) = stmt->column (); + if (stmt) + { + line(k) = stmt->line (); + column(k) = stmt->column (); + } + else + { + line(k) = -1; + column(k) = -1; + } } else { + file(k) = "<unknown>"; + name(k) = "<unknown>"; line(k) = -1; column(k) = -1; } - } - else - { - file(k) = "<unknown>"; - name(k) = "<unknown>"; - line(k) = -1; - column(k) = -1; + + k++; } - k++; - p++; + retval.assign ("file", file); + retval.assign ("name", name); + retval.assign ("line", line); + retval.assign ("column", column); } - retval.assign ("file", file); - retval.assign ("name", name); - retval.assign ("line", line); - retval.assign ("column", column); - return retval; }