From: ahoward Date: 2003-06-06T02:20:23+09:00 Subject: Re: Infinite Loop 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 :( 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? 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 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 -- ==================================== | 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)' ====================================