Infinite Loop

Hi everybody,

I 've written a fairly big ruby programm that works mostly ok.
Sometimes the programm seems to enter an infinite loop :frowning: Does anyone
have a neat idea, how to debug this problem? Perhaps there is a hook
in the interpreter to count recursive method calls that I can exploit
or something similar?

thanks in advance,
George Moschovitis

In interactive GUI applications I tried similar things. In console
applications I have no problems locating infinit loops.
I think I need more info about your project in order to help.

Which kind of application are you working on ?

  • interactive GUI app.
  • mod_ruby dynamic-html stuff.
  • non-interactive application.

Are your using mutexes, semaphores, processes, threads ?

···

On Thu, 05 Jun 2003 08:14:09 +0000, George Moschovitis wrote:

I 've written a fairly big ruby programm that works mostly ok.
Sometimes the programm seems to enter an infinite loop :frowning: Does anyone
have a neat idea, how to debug this problem? Perhaps there is a hook
in the interpreter to count recursive method calls that I can exploit
or something similar?


Simon Strandgaard

such a hook already exists:

/usr/home/howardat/eg/ruby > ruby -e ‘def foo;foo();end; foo();’
-e:1:in `foo’: stack level too deep (SystemStackError)


so you can rule out recursive method calls and narrow it down to loops for
which the exit condition never becomes false, perhaps one which returns ‘0’
(which is true in ruby) or something like that. of course you could be blocked
on io or a mutex and not actually in a loop - but that’s another subject all
together. in many cases strace (or similar) is very valuable at finding such
problems, for example running:

/usr/home/howardat/eg/ruby > strace ruby -e ‘STDIN.gets’ 2>&1 | tee out

gives:

execve(“/usr/local/bin/ruby”, [“ruby”, “-e”, “STDIN.gets”], [/* 39 vars */]) = 0
brk(0) = 0x80d9280
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40014000
open(“/etc/ld.so.preload”, O_RDONLY) = -1 ENOENT (No such file or directory)
open(“/etc/ld.so.cache”, O_RDONLY) = 3

more nonsense
</snip much nonsense>
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40015000
ioctl(0, TCGETS, {B9600 opost isig icanon echo …}) = 0
read(0,
^
^
^
cursor…

so whether or not the output makes complete sense, this program clears blocks
on i/o. ruby is not so far from c/system calls that it is difficult to make
good guesses at where in the ruby program a particular line in strace has
originated from… if it’s a gui program strace can attach to a pid to do the
same.

-a

···

On Thu, 5 Jun 2003, George Moschovitis wrote:

I 've written a fairly big ruby programm that works mostly ok.
Sometimes the programm seems to enter an infinite loop :frowning: Does anyone
have a neat idea, how to debug this problem? Perhaps there is a hook
in the interpreter to count recursive method calls that I can exploit
or something similar?

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ara.t.howard@noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
~ > ruby -e ‘p(%.\x2d\x29…intern)’
====================================

“Simon Strandgaard” 0bz63fz3m1qt3001@sneakemail.com schrieb im
Newsbeitrag news:pan.2003.06.05.15.49.19.101201@sneakemail.com

···

On Thu, 05 Jun 2003 08:14:09 +0000, George Moschovitis wrote:

I 've written a fairly big ruby programm that works mostly ok.
Sometimes the programm seems to enter an infinite loop :frowning: Does anyone
have a neat idea, how to debug this problem? Perhaps there is a hook
in the interpreter to count recursive method calls that I can exploit
or something similar?

In interactive GUI applications I tried similar things. In console
applications I have no problems locating infinit loops.
I think I need more info about your project in order to help.

Which kind of application are you working on ?

  • interactive GUI app.
  • mod_ruby dynamic-html stuff.
  • non-interactive application.

Are your using mutexes, semaphores, processes, threads ?

Also: goes CPU utilization up or down. i.e., does it hang or spin
endlessly?

robert

hi Ara,

such a hook already exists:

together. in many cases strace (or similar) is very valuable at finding such
problems, for example running:

many thanks for the usefull advice, I 'll try it.

best regards,
George