Skip to content

Commit

Permalink
fix bt on nested break points
Browse files Browse the repository at this point in the history
`di_body()` doesn't filter C locations.
  • Loading branch information
ko1 committed Dec 11, 2023
1 parent 52694a9 commit 557233a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
16 changes: 12 additions & 4 deletions ext/debug/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,23 @@ di_body(const rb_debug_inspector_t *dc, void *ptr)
long i;

for (i=1; i<len; i++) {
VALUE loc, e;
VALUE e;
VALUE iseq = rb_debug_inspector_frame_iseq_get(dc, i);
VALUE loc = RARRAY_AREF(locs, i);
VALUE path;

if (!NIL_P(iseq)) {
VALUE path = iseq_realpath(iseq);
if (!NIL_P(path) && !NIL_P(skip_path_prefix) && str_start_with(path, skip_path_prefix)) continue;
path = iseq_realpath(iseq);
}
else {
// C frame
path = rb_funcall(loc, rb_intern("path"), 0);
}

if (!NIL_P(path) && !NIL_P(skip_path_prefix) && str_start_with(path, skip_path_prefix)) {
continue;
}

loc = RARRAY_AREF(locs, i);
e = di_entry(loc,
rb_debug_inspector_frame_self_get(dc, i),
rb_debug_inspector_frame_binding_get(dc, i),
Expand Down
27 changes: 24 additions & 3 deletions test/console/nested_break_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def program
2| b = a + 1 # break
3| end
4| def bar
5| x = 1 # break
5| x = 1 # break
6| end
7| bar
8| x = 2
Expand All @@ -35,7 +35,7 @@ def test_nested_break
type 'p a'
assert_line_text(/42/)
type 'c'
assert_line_num 7
assert_line_num 7 # because restored `up` line
end

# pop nested break
Expand All @@ -48,6 +48,27 @@ def test_nested_break
end
end

def test_nested_break_bt
debug_code program do
type 'break 2'
type 'break 5'
type 'c'

assert_line_num 5
type 'p foo(42)'

if TracePoint.respond_to? :allow_reentry
# nested break
assert_line_num 2
type 'bt'
assert_no_line_text 'thread_client.rb'
type 'c'
end

type 'c'
end
end

def test_multiple_nested_break
debug_code program do
type 'break 2'
Expand All @@ -62,7 +83,7 @@ def test_multiple_nested_break
assert_line_num 2
type 'p foo(142)'
type 'bt'
assert_line_text(/\#9/) # TODO: can be changed
assert_line_text(/\#7\s+<main>/) # TODO: can be changed

type 'c'
assert_line_text(/143/)
Expand Down

0 comments on commit 557233a

Please sign in to comment.