summaryrefslogtreecommitdiff
path: root/test/ruby/test_backtrace.rb
AgeCommit message (Collapse)Author
2021-08-08Fix multiple bugs in partial backtrace optimizationJeremy Evans
This fixes multiple bugs found in the partial backtrace optimization added in 3b24b79. These bugs occurs when passing a start argument to caller where the start argument lands on a iseq frame without a pc. Before this commit, the following code results in the same line being printed twice, both for the #each method. ``` def a; [1].group_by { b } end def b; puts(caller(2, 1).first, caller(3, 1).first) end a ``` After this commit and in Ruby 2.7, the lines are different, with the first line being for each and the second for group_by. Before this commit, the following code can either segfault or result in an infinite loop: ``` def foo caller_locations(2, 1).inspect # segfault caller_locations(2, 1)[0].path # infinite loop end 1.times.map { 1.times.map { foo } } ``` After this commit, this code works correctly. In terms of the implementation, this correctly skips iseq frames without pc that occur before the number of frames the caller requested to skip. This rewrites the algorithm used for handling the partial backtraces. It scans from the current frame outward to the earliest frame, until it has found the desired number of frames. It records that frame as the start frame. If needed, it continues scanning backwards until arg->prev_cfp is set, as that is needed to set the location of the first frame. Due to the fact that arg is a void pointer, it's not possible to check this directly, but this calls the iter_skip function in a situation where it knows it will set arg->prev_cfp, and then breaks out of the loop. Fixes [Bug #18053]
2021-04-02merge revision(s) f9f13a4f6d8be706b17efc089c28f7bc617ef549: [Backport #17746]NARUSE, Yui
Ensure that caller respects the start argument Previously, if there were ignored frames (iseq without pc), we could go beyond the requested start frame. This has two changes: 1) Ensure that we don't look beyond the start frame by using last_cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(last_cfp) until the desired start frame is reached. 2) To fix the failures caused by change 1), which occur when a limited number of frames is requested, scan the VM stack before allocating backtrace frames, looking for ignored frames. This is complicated if there are ignored frames before and after the start, in which case we need to scan until the start frame, and then scan backwards, decrementing the start value until we get to the point where start will result in the number of requested frames. This fixes a Rails test failure. Jean Boussier was able to to produce a failing test case outside of Rails. Co-authored-by: Jean Boussier <jean.boussier@gmail.com> --- test/ruby/test_backtrace.rb | 16 ++++++++++++++ vm_backtrace.c | 52 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 66 insertions(+), 2 deletions(-)
2021-03-02merge revision(s) 87437326214e4587a41946c8937e11418d983acd: [Backport #17581]NARUSE, Yui
Fix backtrace to not skip frames with iseq without pc Previously, frames with iseq but no pc were skipped (even before the refactoring in 3b24b7914c16930bfadc89d6aff6326a51c54295). Because the entire backtrace was procesed before the refactoring, this was handled by using later frames instead. However, after the refactoring, we need to handle those frames or they get lost. Keep two iteration counters when iterating, one for the desired backtrace size (so we generate the desired number of frames), and one for the actual backtrace size (so we don't process off the end of the stack). When skipping over an iseq frame with no pc, decrement the counter for the desired backtrace, so it will continue to process the expected number of backtrace frames. Fixes [Bug #17581] --- test/ruby/test_backtrace.rb | 12 ++++++++++++ vm_backtrace.c | 16 +++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-)
2019-03-21Fix a wrong lineno in backtrace for cfuncmame
lineno is an int, and INT2FIX(0) was assigned. [Bug #15719] [ruby-core:91911] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67326 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-28Revert "Add test for cause on pty"naruse
This reverts commit r65422. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-28Add test for cause on ptynaruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65422 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-27fix testnaruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-27Print exception's cause like Javanaruse
Print `cause` of the exception if the exception is not caught and printed its backtraces and error message [Feature #8257] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-08Remove unnecessary `require 'thread'`kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-30Use qualified namesnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-19test/ruby: suppress parser warningsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16Add frozen_string_literal: false for all filesnaruse
When you change this to true, you may need to add more tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-05* proc.c: enable optimization of Proc#call.ko1
[Feature #11569] * NEWS: write about this optimization and incompatibilities. * test/ruby/test_backtrace.rb: catch up this fix. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-01test_backtrace.rb: add testsnobu
* test/ruby/test_backtrace.rb (test_caller_locations_base_label): test for Thread::Backtrace::Location#base_label. * test/ruby/test_backtrace.rb (test_caller_locations_label): test for Thread::Backtrace::Location#label. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-31test_backtrace.rb: add testnobu
* test/ruby/test_backtrace.rb (test_caller_locations_lineno): test for Thread::Backtrace::Location#lineno. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-31test_backtrace.rb: split testnobu
* test/ruby/test_backtrace.rb (test_caller_locations_absolute_path): split from test_caller_locations_path. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49461 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-31test_backtrace.rb: add testnobu
* test/ruby/test_backtrace.rb (test_caller_locations_path): test for Thread::Backtrace::Location#path and #absolute_path. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-26test/ruby: fix leaked threadsnobu
* test/thread/test_backtrace.rb: join work threads not to leak threads. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46132 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-26test/ruby: fix leaked threadsnobu
* test/thread/test_{backtrace,beginendblock,proc,threadgroup}.rb: join work threads not to leak threads. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-21vm.c: rewind cfpnobu
* vm.c (m_core_hash_{from_ary,merge_{ary,ptr,kwd}}): rewind cfp to show proper backtrace. [ruby-dev:35820] [Bug #416] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-21test_backtrace.rb: r18554 testsnobu
* test/ruby/test_backtrace.rb (test_core_backtrace_{alias,undef}): add tests for r18554. [ruby-dev:35820] [Bug #416] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46036 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-02* test/ruby/test_backtrace.rb: get rid of warnings. unused variable,usa
shadowing. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45246 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-25* vm_insnhelper.c (argument_error): insert dummy frame to makeko1
a backtrace object intead of modify backtrace string array. [Bug #9295] * test/ruby/test_backtrace.rb: add a test for this patch. fix test to compare a result of Exception#backtrace with a result of Exception#backtrace_locations. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44411 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-13* error.c: add Exception#backtrace_locations.ko1
Now, there are no setter and independent from Exception#backtrace. [Feature #8960] * eval.c (setup_exception): set backtrace locations for `bt_location' special attribute. * vm_backtrace.c (rb_backtrace_to_location_ary): added. * internal.h: ditto. * test/ruby/test_backtrace.rb: add a test for Exception#backtrace_locations. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44170 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-11revert r44133. See https://bugs.ruby-lang.org/issues/8886 detailsko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44138 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-11* eval.c (rb_raise_jump): pop frame after setup exception.ko1
Patches by deivid (David Rodriguez). [Bug #8886] * test/minitest/test_minitest_unit.rb: catch up this change. * test/ruby/test_backtrace.rb: ditto. * test/ruby/test_settracefunc.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-10* vm_backtrace.c (vm_backtrace_to_ary): Ignore the second argument ifsorah
it is nil. [Bug #8884] [ruby-core:57094] * test/ruby/test_backtrace.rb (test_caller_with_nil_length): Test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42905 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-23test_backtrace.rb: test Thread#backtrace_locations with rangezzak
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-31* test/ruby/test_backtrace.rb: Add test for r37957 [Feature #7434]zzak
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38664 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-01* test/ruby/test_backtrace.rb: add a test forko1
Thread::Backtrace::Location#inspect. BTW, tests for `caller_locations' are not enough. Any volunteers are welcome. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19* thread.c: add `Thread#backtrace_locations' method.ko1
This method is similart to `caller_locations' method for specific method. And fix to accept `level' and `n' parameters for `Thread#backtrace' and `Thread#backtrace_locations'. `caller' (and `caller_locations') do not return `caller' method frame. However, `Thread#backtrace' (and `Thread#backtrace_locations') return `Thread#backtrace' method frame itself if `Thread.current.backtrace' was called. * vm_backtrace.c: ditto. * internal.h: ditto. * test/ruby/test_backtrace.rb: add tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22* test/ruby/test_backtrace.rb: decrease recursion depthko1
to reduce consuming stack size. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-04* test/ruby/test_backtrace.rb: fix test.ko1
Windows path includes `:' character. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35900 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-02* vm_backtrace.c: change names.ko1
(1) Class name: RubyVM::FrameInfo -> RubyVM::Backtrace::Location. (2) Method name: RubyVM::FrameInfo.caller -> Kernel.caller_locations. (3) Instance methods of RubyVM::FrameInfo (RubyVM::Backtrace::Location) (3-1) name -> label (3-2) basename -> base_label (basename is confusing with File.basename) (3-3) line_no -> lineno (We have already similar name File#lineno, commented by kou [ruby-dev:45686]). (3-4) filename -> path. (3-5) filepath -> absolute_path. (3-5) iseq -> removed (we will make other APIs to access iseq and other information of frame for debugging). * test/ruby/test_backtrace.rb: apply above changes. And apply comment from kou [ruby-dev:45686]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-05-26* test/ruby/test_backtrace.rb (test_caller_lev):ko1
decreaze recursion size. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35804 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-05-26* vm.c (RubyVM::FrameInfo): add a class to access each frameko1
information. You don't need to parse strings from caller(). FrameInfo has the following methods: FrameInfo#name: method name, class name, etc with decorations. FrameInfo#basename: name without decorations. FrameInfo#line_no: line number. FrameInfo#filename: file name. FrameInfo#filepath: full filepath. FrameInfo#iseq: iseq if it is iseq frame (defined by ruby script) FrameInfo#to_s: return caller() method style string. RubyVM::FrameInfoFrameInfo.caller(n, lev) returns array of FrameInfo objects. The name "RubyVM::FrameInfoFrameInfo.caller" is long and ambiguous (same as caller() method), we need to change the name before Ruby 2.0 release. Good names or comments are welcome. * test/ruby/test_backtrace.rb: add a test for above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35801 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-05-25* vm_eval.c (rb_f_caller): caller() method accepts second optionalko1
argument `n' which specify how many frames should return. For example, `caller(0, 1)' returns only one frame information which calls caller() method. If there are less than n frame information, then all frame information are returned. If n is 0, then always return []. This fix is part of [ruby-dev:42345] [Ruby 1.9-Feature#3917]. However, performance and features are not enough. RDoc is also not available. * test/ruby/test_backtrace.rb: add a test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-05-25* properties.nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35788 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-05-25* vm.c: refactoring backtrace related funcitons.ko1
(1) unify similar functions (rb_backtrace_each() and backtrace_object()). backtrace_each() is a unified function. variation: a) backtrace_object(): create backtrace object. b) vm_backtrace_str_ary(): create bt as an array of string. c) vm_backtrace_print(): print backtrace to specified file. d) rb_backtrace_print_as_bugreport(): print backtrace on bugreport style. (2) remove rb_backtrace_each(). Use backtrace_each() instead. (3) chang the type of lev parameter to size_t. a) lev == 0 means current frame (exception, etc use it). b) lev == 1 means upper frame (caller(0) use it). * vm_core.h, vm_dump.c, vm_eval.c: ditto. * vm.c (backtrace_object(), vm_backtrace_str_ary()): fix to return a correct size of caller(lev) array. Let n be a "caller(0).size" then ln as caller(lev).size should be (n - lev). However, the previous implementation returns a wrong size array (ln > n - lev). [ruby-dev:45673] * test/ruby/test_backtrace.rb: add tests for backtrace. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35787 b2dd03c8-39d4-4d8f-98ff-823fe69b080e