Skip to content

Commit 68754c6

Browse files
committed
[GR-22031] Always show core source sections, with format <internal:core> core/file.rb:line.
PullRequest: truffleruby/1752
2 parents 8c707d6 + 4e6c441 commit 68754c6

File tree

27 files changed

+129
-153
lines changed

27 files changed

+129
-153
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ New features:
1010
* `foreign_object.class` now calls `getMetaObject()` (except for Java classes, same as before).
1111
* Add basic support for Linux ARM64.
1212
* `foreign_object.name = value` will now call `Interoplibrary#writeMember("name", value)` instead of `invokeMember("name=", value)`.
13+
* Always show the Ruby core library files in backtraces (#1414).
1314

1415
Bug fixes:
1516

doc/contributor/debugging.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

doc/user/debugging.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Debugging TruffleRuby
2+
3+
## Printing Exceptions
4+
5+
There are two ways to print exceptions, which can be useful to find the source of an error:
6+
7+
* the standard Ruby `-d` flag which print the `file:line` where each exception was raised.
8+
* `--backtraces-raise` which show the full backtrace on each exception raised.
9+
10+
Both print all exceptions even if the exceptions are later rescued.
11+
12+
Java exceptions can be printed with `exceptions-print-uncaught-java` or
13+
`--exceptions-print-java`.
14+
15+
See other `--backtraces-*` and `--exceptions-*` options for more possibilities.
16+
17+
## More Information in Backtraces
18+
19+
We try to match MRI's backtrace format as closely as possible. This sometimes means
20+
that we don't display extra information that we actually do have available.
21+
When debugging you may want to see this information.
22+
23+
An option to show more information is `--backtraces-interleave-java=true`
24+
which shows you the Java methods involved in executing each Ruby method.
25+
26+
When you are interoperating with other languages, including C extensions,
27+
backtraces for Java exceptions may be missing information, as the Java frames
28+
are gone by the time Ruby has a chance to format them into a backtrace.

spec/ruby/core/exception/backtrace_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
# This regexp is deliberately imprecise to account for the need to abstract out
4444
# the paths of the included mspec files and the desire to avoid specifying in any
4545
# detail what the in `...' portion looks like.
46-
line.should =~ /^[^ ]+\:\d+(:in `[^`]+')?$/
46+
line.should =~ /^.+:\d+:in `[^`]+'$/
4747
end
4848
end
4949

spec/ruby/core/thread/backtrace/location/lineno_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,14 @@
1010
it 'returns the absolute path of the call frame' do
1111
@frame.lineno.should == @line
1212
end
13+
14+
it 'should be the same line number as in #to_s, including for core methods' do
15+
# Get the caller_locations from a call made into a core library method
16+
locations = [:non_empty].map { caller_locations }[0]
17+
18+
locations.each do |location|
19+
line_number = location.to_s[/:(\d+):/, 1]
20+
location.lineno.should == Integer(line_number)
21+
end
22+
end
1323
end

spec/ruby/core/thread/backtrace/location/path_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@
8787
end
8888
end
8989

90+
it 'should be the same path as in #to_s, including for core methods' do
91+
# Get the caller_locations from a call made into a core library method
92+
locations = [:non_empty].map { caller_locations }[0]
93+
94+
locations.each do |location|
95+
filename = location.to_s[/^(.+):\d+:/, 1]
96+
path = location.path
97+
98+
path.should == filename
99+
end
100+
end
101+
90102
context "canonicalization" do
91103
platform_is_not :windows do
92104
before :each do

spec/truffle/thread/backtrace/location/absolute_path_spec.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@
1010

1111
describe 'Thread::Backtrace::Location#absolute_path' do
1212

13-
it 'should be the same absolute path as in the formatted description for core methods' do
13+
it 'returns an existing and canonical path for core methods' do
1414
# Get the caller_locations from a call made into a core method.
1515
locations = [:non_empty].map { caller_locations }.flatten
1616

1717
locations.each do |location|
18-
filename, _line_number, _in_method = location.to_s.split(':')
1918
path = location.absolute_path
19+
path.should_not.include?('(core)')
2020

21-
path.should_not == '(core)'
22-
path.start_with?('resource:/').should be_false
23-
location.absolute_path.should == File.expand_path(filename)
21+
if path.include?('resource:')
22+
skip
23+
else
24+
File.should.exist?(location.absolute_path)
25+
File.realpath(location.absolute_path).should == location.absolute_path
26+
end
2427
end
2528
end
2629

spec/truffle/thread/backtrace/location/lineno_spec.rb

Lines changed: 0 additions & 23 deletions
This file was deleted.

spec/truffle/thread/backtrace/location/path_spec.rb

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/main/java/org/truffleruby/core/exception/ExceptionNodes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ protected Object backtraceLocations(DynamicObject exception,
189189
Object backtraceLocations = Layouts.EXCEPTION.getBacktraceLocations(exception);
190190
if (hasLocationsProfile.profile(backtraceLocations == null)) {
191191
Backtrace backtrace = Layouts.EXCEPTION.getBacktrace(exception);
192-
backtraceLocations = backtrace.getBacktraceLocations(GetBacktraceException.UNLIMITED, null);
192+
backtraceLocations = backtrace
193+
.getBacktraceLocations(getContext(), GetBacktraceException.UNLIMITED, null);
193194
Layouts.EXCEPTION.setBacktraceLocations(exception, backtraceLocations);
194195
}
195196
return backtraceLocations;

0 commit comments

Comments
 (0)