[#35027] [Ruby 1.9-Bug#4352][Open] [patch] Fix eval(s, b) backtrace; make eval(s, b) consistent with eval(s) — "James M. Lawrence" <redmine@...>

Bug #4352: [patch] Fix eval(s, b) backtrace; make eval(s, b) consistent with eval(s)

16 messages 2011/02/01

[#35114] [Ruby 1.9-Bug#4373][Open] http.rb:677: [BUG] Segmentation fault — Christian Fazzini <redmine@...>

Bug #4373: http.rb:677: [BUG] Segmentation fault

59 messages 2011/02/06

[#35171] [Ruby 1.9-Bug#4386][Open] encoding: directive does not affect regex expressions — mathew murphy <redmine@...>

Bug #4386: encoding: directive does not affect regex expressions

9 messages 2011/02/09

[#35237] [Ruby 1.9-Bug#4400][Open] nested at_exit hooks run in strange order — Suraj Kurapati <redmine@...>

Bug #4400: nested at_exit hooks run in strange order

12 messages 2011/02/15

[ruby-core:35359] Re: eval'ing large strings runs out of stack space?

From: Kurt Stephens <ks@...>
Date: 2011-02-24 03:24:23 UTC
List: ruby-core #35359
On 2/23/11 7:55 PM, Ryan Davis wrote:
>
> 10003 % ruby19 -v -e 'eval (["000000000"]*500000).inspect'
> ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.5.0]
> (eval):0: stack level too deep (SystemStackError)
> 10004 % ruby -v -e 'eval (["000000000"]*500000).inspect'
> ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
> 10005 %

#inspect isn't the problem:

  > ruby-1.9.2-p136 --version -e '(['000000000']*500000).inspect'
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0]

My guess (I don't know 1.9 very well, yet.):

The issue may be related to the parse.y args -> aref_args production.
the args grammer production is left-recursive.

http://www.gnu.org/software/bison/manual/html_node/Recursion.html

"Any kind of sequence can be defined using either left recursion or 
right recursion, but you should always use left recursion, because it 
can parse a sequence of any number of elements with bounded stack space. 
Right recursion uses up space on the Bison stack in proportion to the 
number of elements in the sequence, because all the elements must be 
shifted onto the stack before the rule can be applied even once. See The 
Bison Parser Algorithm, for further explanation of this. "

I'm not sure if this also implies C stack usage but it maybe due to 
mmap()'ed fiber stacks.  Does changing 
FIBER_MACHINE_STACK_ALLOCATION_SIZE help?

It might be triggered by the mprotect() in cont.c or here:

vm_eval.c:1028

	/* kick */
	CHECK_STACK_OVERFLOW(th->cfp, iseq->stack_max);


  > gdb --args ./ruby -e 'eval((["000000000"] * 500000).inspect)'
GNU gdb 6.3.50-20050815 (Apple version gdb-1510) (Wed Sep 22 02:45:02 
UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain 
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for 
shared libraries ... done

(gdb) b rb_exc_raise
The program is not being run.
(gdb) r
Starting program: /Users/stephens/local/src/ruby-trunk-git/ruby -e 
eval\(\(\[\"000000000\"\]\ \*\ 500000\).inspect\)
Reading symbols for shared libraries ++... done

Breakpoint 1, rb_exc_raise (mesg=4303807840) at eval.c:461
warning: Source file is more recent than executable.
461	{
(gdb) c
Continuing.

Breakpoint 1, rb_exc_raise (mesg=4303798400) at eval.c:461
461	{
(gdb) c
Continuing.

Breakpoint 1, rb_exc_raise (mesg=4303796920) at eval.c:461
461	{
(gdb) c
Continuing.

Breakpoint 1, rb_exc_raise (mesg=4303729480) at eval.c:461
461	{
(gdb) c
Continuing.

Breakpoint 1, rb_exc_raise (mesg=4303728360) at eval.c:461
461	{
(gdb) c
Continuing.

Breakpoint 1, rb_exc_raise (mesg=4303824080) at eval.c:461
461	{
(gdb) bt
#0  rb_exc_raise (mesg=4303824080) at eval.c:461
#1  0x000000010016c870 in eval_string_with_cref (self=4303884640, 
src=4303721440, scope=4, cref=0x0, file=0x100199113 "(eval)", line=1) at 
vm_eval.c:1019
#2  0x000000010016cb02 in rb_f_eval (argc=1, argv=<value temporarily 
unavailable, due to optimizations>, self=4303884640) at vm_eval.c:1062
#3  0x0000000100175bf1 in vm_call_cfunc [inlined] () at 
/Users/stephens/local/src/ruby-trunk-git/vm_insnhelper.c:402
#4  0x0000000100175bf1 in vm_call_method (th=0x1003016b0, 
cfp=0x1004ffef8, num=1, blockptr=0x1, flag=8, id=<value temporarily 
unavailable, due to optimizations>, me=0x10031d440, recv=4303884640) at 
vm_insnhelper.c:524
#5  0x0000000100163f45 in vm_exec_core (th=0x1003016b0, initial=<value 
temporarily unavailable, due to optimizations>) at insns.def:1006
#6  0x000000010016bb83 in vm_exec (th=0x1003016b0) at vm.c:1145
#7  0x000000010016be8f in rb_iseq_eval_main (iseqval=4303721960) at 
vm.c:1386
#8  0x000000010003bb22 in ruby_exec_internal (n=0x1008595e8) at eval.c:214
#9  0x000000010003e4ec in ruby_exec_node [inlined] () at 
/Users/stephens/local/src/ruby-trunk-git/eval.c:261
#10 0x000000010003e4ec in ruby_run_node (n=<value temporarily 
unavailable, due to optimizations>) at eval.c:254
#11 0x000000010000086f in main (argc=3, argv=0x7fff5fbfec50) at main.c:35
(gdb) c
Continuing.

Breakpoint 1, rb_exc_raise (mesg=4303824080) at eval.c:461
461	{
(gdb) bt
#0  rb_exc_raise (mesg=4303824080) at eval.c:461
#1  0x000000010016c4e8 in eval_string_with_cref (self=4303884640, 
src=4303721440, scope=4, cref=0x0, file=0x100199113 "(eval)", line=1) at 
vm_eval.c:1052
#2  0x000000010016cb02 in rb_f_eval (argc=1, argv=<value temporarily 
unavailable, due to optimizations>, self=4303884640) at vm_eval.c:1062
#3  0x0000000100175bf1 in vm_call_cfunc [inlined] () at 
/Users/stephens/local/src/ruby-trunk-git/vm_insnhelper.c:402
#4  0x0000000100175bf1 in vm_call_method (th=0x1003016b0, 
cfp=0x1004ffef8, num=1, blockptr=0x1, flag=8, id=<value temporarily 
unavailable, due to optimizations>, me=0x10031d440, recv=4303884640) at 
vm_insnhelper.c:524
#5  0x0000000100163f45 in vm_exec_core (th=0x1003016b0, initial=<value 
temporarily unavailable, due to optimizations>) at insns.def:1006
#6  0x000000010016bb83 in vm_exec (th=0x1003016b0) at vm.c:1145
#7  0x000000010016be8f in rb_iseq_eval_main (iseqval=4303721960) at 
vm.c:1386
#8  0x000000010003bb22 in ruby_exec_internal (n=0x1008595e8) at eval.c:214
#9  0x000000010003e4ec in ruby_exec_node [inlined] () at 
/Users/stephens/local/src/ruby-trunk-git/eval.c:261
#10 0x000000010003e4ec in ruby_run_node (n=<value temporarily 
unavailable, due to optimizations>) at eval.c:254
#11 0x000000010000086f in main (argc=3, argv=0x7fff5fbfec50) at main.c:35
(gdb) c
Continuing.
(eval):0: stack level too deep (SystemStackError)

Program exited with code 01.
(gdb)


-- Kurt




In This Thread