Skip to content

Commit 557233a

Browse files
committed
fix bt on nested break points
`di_body()` doesn't filter C locations.
1 parent 52694a9 commit 557233a

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

ext/debug/debug.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,23 @@ di_body(const rb_debug_inspector_t *dc, void *ptr)
6262
long i;
6363

6464
for (i=1; i<len; i++) {
65-
VALUE loc, e;
65+
VALUE e;
6666
VALUE iseq = rb_debug_inspector_frame_iseq_get(dc, i);
67+
VALUE loc = RARRAY_AREF(locs, i);
68+
VALUE path;
6769

6870
if (!NIL_P(iseq)) {
69-
VALUE path = iseq_realpath(iseq);
70-
if (!NIL_P(path) && !NIL_P(skip_path_prefix) && str_start_with(path, skip_path_prefix)) continue;
71+
path = iseq_realpath(iseq);
72+
}
73+
else {
74+
// C frame
75+
path = rb_funcall(loc, rb_intern("path"), 0);
76+
}
77+
78+
if (!NIL_P(path) && !NIL_P(skip_path_prefix) && str_start_with(path, skip_path_prefix)) {
79+
continue;
7180
}
7281

73-
loc = RARRAY_AREF(locs, i);
7482
e = di_entry(loc,
7583
rb_debug_inspector_frame_self_get(dc, i),
7684
rb_debug_inspector_frame_binding_get(dc, i),

test/console/nested_break_test.rb

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def program
1010
2| b = a + 1 # break
1111
3| end
1212
4| def bar
13-
5| x = 1 # break
13+
5| x = 1 # break
1414
6| end
1515
7| bar
1616
8| x = 2
@@ -35,7 +35,7 @@ def test_nested_break
3535
type 'p a'
3636
assert_line_text(/42/)
3737
type 'c'
38-
assert_line_num 7
38+
assert_line_num 7 # because restored `up` line
3939
end
4040

4141
# pop nested break
@@ -48,6 +48,27 @@ def test_nested_break
4848
end
4949
end
5050

51+
def test_nested_break_bt
52+
debug_code program do
53+
type 'break 2'
54+
type 'break 5'
55+
type 'c'
56+
57+
assert_line_num 5
58+
type 'p foo(42)'
59+
60+
if TracePoint.respond_to? :allow_reentry
61+
# nested break
62+
assert_line_num 2
63+
type 'bt'
64+
assert_no_line_text 'thread_client.rb'
65+
type 'c'
66+
end
67+
68+
type 'c'
69+
end
70+
end
71+
5172
def test_multiple_nested_break
5273
debug_code program do
5374
type 'break 2'
@@ -62,7 +83,7 @@ def test_multiple_nested_break
6283
assert_line_num 2
6384
type 'p foo(142)'
6485
type 'bt'
65-
assert_line_text(/\#9/) # TODO: can be changed
86+
assert_line_text(/\#7\s+<main>/) # TODO: can be changed
6687

6788
type 'c'
6889
assert_line_text(/143/)

0 commit comments

Comments
 (0)