[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

debugger issue

pat eyler

6/30/2005 6:18:00 PM

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

def average
result = 0
self.each { |x| result += x }
result / self.size.to_f
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
avg = a.average
$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)


5 Answers

Florian Frank

6/30/2005 6:36:00 PM

0

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



pat eyler

6/30/2005 6:56:00 PM

0

On 6/30/05, Florian Frank <flori@nixe.ping.de> wrote:
> 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?


> >
> --
> 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)


Florian Frank

6/30/2005 7:20:00 PM

0

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



Robert Klemme

7/1/2005 7:55:00 AM

0

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
>
> def average
> result = 0
> self.each { |x| result += x }
> result / self.size.to_f
> 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
> avg = a.average
> $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

robert

Lothar Scholz

7/1/2005 8:50:00 AM

0

Hello Robert,


RK> My guess would be that Array#each is a method implemented in C and that
RK> your block is just a single line block. The debugger can't step into
RK> Array#each and maybe it cannot stop in the block because it's on the same
RK> 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

def average
result = 0
self.each { |x|
dummy = 1
result += x
}
result / self.size.to_f
end



--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ru...
CTO Scriptolutions Ruby, PHP, Python IDE 's