[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #60531] dbstack(N) not omitting innermost fram
From: |
Rik |
Subject: |
[Octave-bug-tracker] [bug #60531] dbstack(N) not omitting innermost frames as it should |
Date: |
Wed, 5 May 2021 19:52:30 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36 |
Follow-up Comment #2, bug #60531 (project octave):
Perhaps jwe knows why this changed. The code is in do_dbstack in the file
debug.cc. The interesting bit is
octave::tree_evaluator& tw = interp.get_evaluator ();
if (nargout == 0)
{
octave_map stk = tw.backtrace (curr_frame);
octave_idx_type nframes = stk.numel ();
if (nframes > 0)
{
octave::preserve_stream_state stream_state (os);
os << "stopped in:\n\n";
Cell names = stk.contents ("name");
Cell files = stk.contents ("file");
Cell lines = stk.contents ("line");
bool show_top_level = true;
std::size_t max_name_len = 0;
for (octave_idx_type i = nskip; i < nframes; i++)
{
std::string name = names(i).string_value ();
max_name_len = std::max (name.length (), max_name_len);
}
for (octave_idx_type i = nskip; i < nframes; i++)
{
std::string name = names(i).string_value ();
std::string file = files(i).string_value ();
int line = lines(i).int_value ();
if (show_top_level && i == curr_frame)
show_top_level = false;
os << (i == curr_frame ? " --> " : " ")
<< std::setw (max_name_len) << name
<< " at line " << line
<< " [" << file << ']'
<< std::endl;
}
if (tw.at_top_level () && show_top_level)
os << " --> top level" << std::endl;
}
}
else
{
octave_map stk = tw.backtrace (curr_frame, false);
// If current stack frame is not in the list curr_frame will be
// -1 and either nskip caused us to skip it or we are at the top
// level, which is not included in the list of frames. So in the
// interpreter, 0 will be our invalid frame index value.
retval = ovl (stk, curr_frame + 1);
}
When the true branch of the if statement is taken, nskip is used and only the
frames requested are printed. This matches the behavior I mentioned in
comment #1. When the else branch is taken, Octave just gets the entire stack
frame and returns it.
Maybe there is a way to call in to the interpreter and get just the number of
stack_frames desired. I looked at pt-eval.h and call-stack.h, but I wasn't
sure.
Alternatively, all of the stack frames are returned in an octave_map (i.e., a
struct array). One could check for nskip > 0 and if necessary, create a new
appropriately sized octave_map and copy over the desired stack frames in a for
loop. Alternatively, one could use an index() call. If this were in an
m-file, one would write
new_map = old_map(nskip:end);
It should be possible to do something similar in C++.
Or one could keep the old map and use delete_elements() to get rid of the
frames one didn't need.
I've added jwe because I think he might instantly have an intuition about the
best approach.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?60531>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #60531] dbstack(N) not omitting innermost frames as it should, Sébastien Villemot, 2021/05/05
- [Octave-bug-tracker] [bug #60531] dbstack(N) not omitting innermost frames as it should, Rik, 2021/05/05
- [Octave-bug-tracker] [bug #60531] dbstack(N) not omitting innermost frames as it should,
Rik <=
- [Octave-bug-tracker] [bug #60531] dbstack(N) not omitting innermost frames as it should, John W. Eaton, 2021/05/05
- [Octave-bug-tracker] [bug #60531] dbstack(N) not omitting innermost frames as it should, Rik, 2021/05/14
- [Octave-bug-tracker] [bug #60531] dbstack(N) not omitting innermost frames as it should, Markus Mützel, 2021/05/16
- [Octave-bug-tracker] [bug #60531] dbstack(N) not omitting innermost frames as it should, Rik, 2021/05/16
- [Octave-bug-tracker] [bug #60531] dbstack(N) not omitting innermost frames as it should, Markus Mützel, 2021/05/17
- [Octave-bug-tracker] [bug #60531] dbstack(N) not omitting innermost frames as it should, John W. Eaton, 2021/05/17
- [Octave-bug-tracker] [bug #60531] dbstack(N) not omitting innermost frames as it should, Markus Mützel, 2021/05/18
- [Octave-bug-tracker] [bug #60531] dbstack(N) not omitting innermost frames as it should, Markus Mützel, 2021/05/20