# Debugger issue

**URL:** <https://rubytalk.org/t/debugger-issue/19277>\
**Category:** ruby-talk\
**Created:** [30 June 2005 18:17 UTC](https://rubytalk.org/t/debugger-issue/19277 "2005-06-30T18:17:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guest15](https://avatars.discourse-cdn.com/v4/letter/g/6de8d8/32.png) [@Guest15](https://rubytalk.org/u/Guest15)\
**Post date:** [30 June 2005 18:17 UTC](https://rubytalk.org/t/debugger-issue/19277/1 "2005-06-30T18:17:48Z")

</div>

I'm running into an unexpected issue with the debugger, and I'm hoping someone  
here can help me out. I' ve got a short program like this (stolen directly  
from zenspider's RubyInline tutorial):

> **···**
>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  
> #!/usr/local/bin/ruby -w
> 
> class Array
> 
> &nbsp;&nbsp;def average  
> &nbsp;&nbsp;&nbsp;&nbsp;result = 0  
> &nbsp;&nbsp;&nbsp;&nbsp;self.each { |x| result += x }  
> &nbsp;&nbsp;&nbsp;&nbsp;result / self.size.to\_f  
> &nbsp;&nbsp;end
> 
> end
> 
> max\_loop = (ARGV.shift || 5).to\_i  
> max\_size = (ARGV.shift || 100\_000).to\_i  
> a = (1..max\_size).to\_a
> 
> 1.upto(max\_loop) do  
> &nbsp;&nbsp;avg = a.average  
> &nbsp;&nbsp;$stderr.print "."  
> end  
> $stderr.puts ""  
> -=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> 
> Everytime I step to line 7 (the self.each ... line) or do a step nnn which  
> executes line 7, the debugger stops there. Neither step or next will move  
> past this line. If I try to continue the program, it will run to the next  
> breakpoint or end of the program.
> 
> -=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  
> pate@linux:~/scripts\> ruby -rdebug averager.rb  
> Debug.rb  
> Emacs support available.
> 
> averager.rb:3:class Array  
> (rdb:1) s 13  
> averager.rb:7: self.each { |x| result += x }  
> (rdb:1) s  
> averager.rb:7: self.each { |x| result += x }  
> (rdb:1) s  
> averager.rb:7: self.each { |x| result += x }  
> (rdb:1) s  
> averager.rb:7: self.each { |x| result += x }  
> (rdb:1) n  
> averager.rb:7: self.each { |x| result += x }  
> (rdb:1) n  
> averager.rb:7: self.each { |x| result += x }  
> (rdb:1) n  
> averager.rb:7: self.each { |x| result += x }  
> (rdb:1) n 20  
> averager.rb:7: self.each { |x| result += x }  
> (rdb:1) c  
> .....  
> pate@linux:~/scripts\>  
> -=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> 
> Any idea what's going on? Is this a bug in the debugger, or am I  
> misunderstanding something?
> 
> --  
> thanks,  
> -pate  
> -------------------------  
> We are often unable to tell people what they need to know, because  
> they want to know something else, and would therefore only  
> misunderstand what we said  
> - the Raven (George MacDonald, Lilith)

---

<div class="post-metadata">

**Author:** ![Florian\_Frank2](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@Florian\_Frank2](https://rubytalk.org/u/Florian_Frank2)\
**Post date:** [30 June 2005 18:36 UTC](https://rubytalk.org/t/debugger-issue/19277/2 "2005-06-30T18:36:15Z")

</div>

pat eyler wrote:

> max\_size = (ARGV.shift || 100\_000).to\_i

max\_size = (ARGV.shift || 10).to\_i

> **···**
>
> > a = (1..max\_size).to\_a
> 
> --  
> Florian Frank

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [1 July 2005 07:55 UTC](https://rubytalk.org/t/debugger-issue/19277/3 "2005-07-01T07:55:43Z")

</div>

pat eyler wrote:

> I'm running into an unexpected issue with the debugger, and I'm  
> hoping someone here can help me out. I' ve got a short program like  
> this (stolen directly from zenspider's RubyInline tutorial):
> 
> -=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  
> #!/usr/local/bin/ruby -w
> 
> class Array
> 
> &nbsp;&nbsp;def average  
> &nbsp;&nbsp;&nbsp;&nbsp;result = 0  
> &nbsp;&nbsp;&nbsp;&nbsp;self.each { |x| result += x }  
> &nbsp;&nbsp;&nbsp;&nbsp;result / self.size.to\_f  
> &nbsp;&nbsp;end
> 
> end
> 
> max\_loop = (ARGV.shift || 5).to\_i  
> max\_size = (ARGV.shift || 100\_000).to\_i  
> a = (1..max\_size).to\_a
> 
> 1.upto(max\_loop) do  
> &nbsp;&nbsp;avg = a.average  
> &nbsp;&nbsp;$stderr.print "."  
> end  
> $stderr.puts ""  
> -=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> 
> Everytime I step to line 7 (the self.each ... line) or do a step nnn  
> which executes line 7, the debugger stops there. Neither step or  
> next will move past this line. If I try to continue the program, it  
> will run to the next breakpoint or end of the program.
> 
> -=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  
> pate@linux:~/scripts\> ruby -rdebug averager.rb  
> Debug.rb  
> Emacs support available.
> 
> averager.rb:3:class Array  
> (rdb:1) s 13  
> averager.rb:7: self.each { |x| result += x }  
> (rdb:1) s  
> averager.rb:7: self.each { |x| result += x }  
> (rdb:1) s  
> averager.rb:7: self.each { |x| result += x }  
> (rdb:1) s  
> averager.rb:7: self.each { |x| result += x }  
> (rdb:1) n  
> averager.rb:7: self.each { |x| result += x }  
> (rdb:1) n  
> averager.rb:7: self.each { |x| result += x }  
> (rdb:1) n  
> averager.rb:7: self.each { |x| result += x }  
> (rdb:1) n 20  
> averager.rb:7: self.each { |x| result += x }  
> (rdb:1) c  
> ....  
> pate@linux:~/scripts\>  
> -=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> 
> Any idea what's going on? Is this a bug in the debugger, or am I  
> misunderstanding something?

My guess would be that Array#each is a method implemented in C and that  
your block is just a single line block. The debugger can't step into  
Array#each and maybe it cannot stop in the block because it's on the same  
line. Did you try to convert the block to a multiline block?

If you step over that line then you execute a single each call, which  
happens to execute multple callbacks of the block.

Kind regards

&nbsp;&nbsp;&nbsp;&nbsp;robert

---

<div class="post-metadata">

**Author:** ![Guest15](https://avatars.discourse-cdn.com/v4/letter/g/6de8d8/32.png) [@Guest15](https://rubytalk.org/u/Guest15)\
**Post date:** [30 June 2005 18:55 UTC](https://rubytalk.org/t/debugger-issue/19277/4 "2005-06-30T18:55:50Z")

</div>

> pat eyler wrote:
> 
> \>max\_size = (ARGV.shift || 100\_000).to\_i  
> \>  
> \>  
> max\_size = (ARGV.shift || 10).to\_i
> 
> \>a = (1..max\_size).to\_a  
> \>

this minimizes, but doesn't solve, the problem. stepping to line 13  
shouldn't trip on line 7 at all should it, or should it?

> **···**
>
> On 6/30/05, Florian Frank \<flori@nixe.ping.de\> wrote:
> 
> > \>  
> > --  
> > Florian Frank
> 
> --  
> thanks,  
> -pate  
> -------------------------  
> We are often unable to tell people what they need to know, because  
> they want to know something else, and would therefore only  
> misunderstand what we said  
> - the Raven (George MacDonald, Lilith)

---

<div class="post-metadata">

**Author:** ![Lothar\_Scholz2](https://avatars.discourse-cdn.com/v4/letter/l/f14d63/32.png) [@Lothar\_Scholz2](https://rubytalk.org/u/Lothar_Scholz2)\
**Post date:** [1 July 2005 08:50 UTC](https://rubytalk.org/t/debugger-issue/19277/5 "2005-07-01T08:50:22Z")

</div>

Hello Robert,

> My guess would be that Array#each is a method implemented in C and that  
> your block is just a single line block. The debugger can't step into  
> Array#each and maybe it cannot stop in the block because it's on the same  
> line. Did you try to convert the block to a multiline block?

Correct it is a fundamental problem with the current ruby  
implementation and it does work when there are two code lines like

&nbsp;&nbsp;&nbsp;def average  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result = 0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.each { |x|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dummy = 1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result += x  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result / self.size.to\_f  
&nbsp;&nbsp;&nbsp;end

> **···**
>
> --  
> Best regards, emailto: scholz at scriptolutions dot com  
> Lothar Scholz [http://www.ruby-ide.com](http://www.ruby-ide.com)  
> CTO Scriptolutions Ruby, PHP, Python IDE 's

---

<div class="post-metadata">

**Author:** ![Florian\_Frank2](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@Florian\_Frank2](https://rubytalk.org/u/Florian_Frank2)\
**Post date:** [30 June 2005 19:19 UTC](https://rubytalk.org/t/debugger-issue/19277/6 "2005-06-30T19:19:37Z")

</div>

pat eyler wrote:

> this minimizes, but doesn't solve, the problem. stepping to line 13 shouldn't trip on line 7 at all should it, or should it?

The block call is a step on its own, you can "s 99990" if you really want. The "line" is a bit misleading, it's probably named after the line event of the trace function.

> **···**
>
> --  
> Florian Frank
