Issue #7434 has been updated by sam.saffron (Sam Saffron).


@ko1 will try to write some tests next week. 

On first go I got a segfault: 

(pry):1: [BUG] backtrace_collect: unreachable
ruby 2.0.0dev (2012-11-30) [i686-linux]

-- Control frame information -----------------------------------------------
c:0024 p:---- s:0096 e:000095 CFUNC  :caller_locations
c:0023 p:0009 s:0091 e:000090 EVAL   (pry):1 [FINISH]
c:0022 p:---- s:0089 e:000088 CFUNC  :eval
c:0021 p:0089 s:0083 e:000082 METHOD /home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_instance.rb:275
c:0020 p:0037 s:0076 e:000075 METHOD /home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_instance.rb:251
c:0019 p:0012 s:0071 e:000070 BLOCK  /home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_instance.rb:231 [FINISH]
c:0018 p:---- s:0069 e:000068 CFUNC  :loop
c:0017 p:0007 s:0066 e:000065 BLOCK  /home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_instance.rb:232 [FINISH]
c:0016 p:---- s:0064 e:000063 CFUNC  :catch
c:0015 p:0009 s:0060 e:000059 BLOCK  /home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_instance.rb:229 [FINISH]
c:0014 p:---- s:0058 e:000057 CFUNC  :catch
c:0013 p:0051 s:0054 e:000053 METHOD /home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_instance.rb:228
c:0012 p:0192 s:0048 e:000047 METHOD /home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_class.rb:154
c:0011 p:0204 s:0041 e:000040 BLOCK  /home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/cli.rb:171 [FINISH]
c:0010 p:---- s:0035 e:000034 CFUNC  :call
c:0009 p:0012 s:0031 e:000030 BLOCK  /home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/cli.rb:65 [FINISH]
c:0008 p:---- s:0028 e:000027 CFUNC  :each
c:0007 p:0087 s:0025 e:000024 METHOD /home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/cli.rb:65
c:0006 p:0030 s:0020 e:000019 TOP    /home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/bin/pry:16 [FINISH]
c:0005 p:---- s:0018 e:000017 CFUNC  :load
c:0004 p:0099 s:0014 e:001ac8 EVAL   /home/sam/.rvm/gems/ruby-head/bin/pry:19 [FINISH]
c:0003 p:---- s:0011 e:000010 CFUNC  :eval
c:0002 p:0077 s:0005 e:0019a8 EVAL   /home/sam/.rvm/gems/ruby-head/bin/ruby_noexec_wrapper:14 [FINISH]
c:0001 p:0000 s:0002 e:000574 TOP    [FINISH]

/home/sam/.rvm/gems/ruby-head/bin/ruby_noexec_wrapper:14:in `<main>'
/home/sam/.rvm/gems/ruby-head/bin/ruby_noexec_wrapper:14:in `eval'
/home/sam/.rvm/gems/ruby-head/bin/pry:19:in `<main>'
/home/sam/.rvm/gems/ruby-head/bin/pry:19:in `load'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/bin/pry:16:in `<top (required)>'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/cli.rb:65:in `parse_options'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/cli.rb:65:in `each'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/cli.rb:65:in `block in parse_options'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/cli.rb:65:in `call'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/cli.rb:171:in `block in <top (required)>'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_class.rb:154:in `start'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_instance.rb:228:in `repl'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_instance.rb:228:in `catch'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_instance.rb:229:in `block in repl'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_instance.rb:229:in `catch'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_instance.rb:232:in `block (2 levels) in repl'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_instance.rb:232:in `loop'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_instance.rb:231:in `block (3 levels) in repl'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_instance.rb:251:in `rep'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_instance.rb:275:in `re'
/home/sam/.rvm/gems/ruby-head/gems/pry-0.9.10/lib/pry/pry_instance.rb:275:in `eval'
(pry):1:in `__pry__'
(pry):1:in `caller_locations'

-- C level backtrace information -------------------------------------------
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1ab92c) [0xb76d492c] vm_dump.c:646
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x5ad3d) [0xb7583d3d] error.c:306
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(rb_bug+0x40) [0xb7584d40] error.c:325
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1ace51) [0xb76d5e51] vm_backtrace.c:478
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1ace9f) [0xb76d5e9f] vm_backtrace.c:840
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19301e) [0xb76bc01e] vm_insnhelper.c:1318
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1964df) [0xb76bf4df] vm_insnhelper.c:1462
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1a3d77) [0xb76ccd77] vm_insnhelper.c:1552
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19a330) [0xb76c3330] insns.def:1003
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19f757) [0xb76c8757] vm.c:1156
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19fdbe) [0xb76c8dbe] vm_eval.c:1208
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1a02b9) [0xb76c92b9] vm_eval.c:1249
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x6890f) [0xb759190f] proc.c:382
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19301e) [0xb76bc01e] vm_insnhelper.c:1318
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1964df) [0xb76bf4df] vm_insnhelper.c:1462
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1a3d77) [0xb76ccd77] vm_insnhelper.c:1552
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19a91a) [0xb76c391a] insns.def:1018
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19f757) [0xb76c8757] vm.c:1156
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1a4a49) [0xb76cda49] vm.c:627
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(rb_rescue2+0x173) [0xb758c8b3] eval.c:714
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x195442) [0xb76be442] vm_eval.c:981
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19303e) [0xb76bc03e] vm_insnhelper.c:1324
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1964df) [0xb76bf4df] vm_insnhelper.c:1462
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1a3d77) [0xb76ccd77] vm_insnhelper.c:1552
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19a330) [0xb76c3330] insns.def:1003
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19f757) [0xb76c8757] vm.c:1156
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1a538d) [0xb76ce38d] vm.c:627
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(rb_catch_obj+0xc9) [0xb76c0fc9] vm_eval.c:1766
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x198097) [0xb76c1097] vm_eval.c:1742
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19301e) [0xb76bc01e] vm_insnhelper.c:1318
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1964df) [0xb76bf4df] vm_insnhelper.c:1462
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1a3d77) [0xb76ccd77] vm_insnhelper.c:1552
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19a330) [0xb76c3330] insns.def:1003
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19f757) [0xb76c8757] vm.c:1156
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1a538d) [0xb76ce38d] vm.c:627
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(rb_catch_obj+0xc9) [0xb76c0fc9] vm_eval.c:1766
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x198097) [0xb76c1097] vm_eval.c:1742
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19301e) [0xb76bc01e] vm_insnhelper.c:1318
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1964df) [0xb76bf4df] vm_insnhelper.c:1462
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1a3d77) [0xb76ccd77] vm_insnhelper.c:1552
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19a330) [0xb76c3330] insns.def:1003
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19f757) [0xb76c8757] vm.c:1156
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1a06a6) [0xb76c96a6] vm.c:627
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x6ac1d) [0xb7593c1d] proc.c:566
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19301e) [0xb76bc01e] vm_insnhelper.c:1318
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1964df) [0xb76bf4df] vm_insnhelper.c:1462
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1a3d77) [0xb76ccd77] vm_insnhelper.c:1552
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19a91a) [0xb76c391a] insns.def:1018
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19f757) [0xb76c8757] vm.c:1156
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(rb_yield+0x173) [0xb76ce9f3] vm.c:627
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(rb_ary_each+0x54) [0xb754a144] array.c:1677
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19303e) [0xb76bc03e] vm_insnhelper.c:1324
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1964df) [0xb76bf4df] vm_insnhelper.c:1462
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1a3d77) [0xb76ccd77] vm_insnhelper.c:1552
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19a330) [0xb76c3330] insns.def:1003
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19f757) [0xb76c8757] vm.c:1156
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(rb_iseq_eval+0x109) [0xb76cece9] vm.c:1391
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x663ee) [0xb758f3ee] load.c:557
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x66cba) [0xb758fcba] load.c:639
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19301e) [0xb76bc01e] vm_insnhelper.c:1318
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1964df) [0xb76bf4df] vm_insnhelper.c:1462
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1a3d77) [0xb76ccd77] vm_insnhelper.c:1552
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19a330) [0xb76c3330] insns.def:1003
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19f757) [0xb76c8757] vm.c:1156
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19fdbe) [0xb76c8dbe] vm_eval.c:1208
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1a02b9) [0xb76c92b9] vm_eval.c:1249
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19301e) [0xb76bc01e] vm_insnhelper.c:1318
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1964df) [0xb76bf4df] vm_insnhelper.c:1462
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x1a3d77) [0xb76ccd77] vm_insnhelper.c:1552
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19a330) [0xb76c3330] insns.def:1003
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x19f757) [0xb76c8757] vm.c:1156
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(rb_iseq_eval_main+0x15d) [0xb76ceead] vm.c:1404
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(+0x61e3c) [0xb758ae3c] eval.c:250
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(ruby_exec_node+0x24) [0xb758c2a4] eval.c:315
/home/sam/.rvm/rubies/ruby-head/lib/libruby.so.2.0(ruby_run_node+0x36) [0xb758e236] eval.c:307
pry() [0x8048698]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0xb73804d3]
pry() [0x80486c1]

----------------------------------------
Feature #7434: Allow caller_locations and backtrace_locations to receive negative params
https://bugs.ruby-lang.org/issues/7434#change-34170

Author: sam.saffron (Sam Saffron)
Status: Closed
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category: core
Target version: next minor


Further to http://bugs.ruby-lang.org/issues/7051 

It would be nice if caller_locations and backtrace_locations has some parity with range apis.

pry(main)> [1,2,3][0..-2]
=> [1, 2]

Similarly: 

caller_locations(0,-2) # should strip the bottom frame 

This is actually quite important for diagnostics of Rails and other frameworks where the app code starts at a very deep frame. 

At the moment you are forced to materialize all frames just to discard. 







-- 
http://bugs.ruby-lang.org/