 |
Forums |
Admin Discussion Forums: help Start New Thread
By: Rocky Bernstein
RE: Strange error when printing variables [ reply ] 2009-02-05 04:34
|
This is a bug and although I can describe why it occurs I understand a little bit about the error message.
The print command is trying to create a print method in the scope of the selected frame; the error message somehow is finding Fixnum, -- the type of the ant() method parameter -- as the scope in which it wants to define that function in. But you can't define a new function in for instance of the Fixnum class. If instead you change the call to ant from ant(n - 4) to say a string: ant('n - 4') you'll get something.
This should probably be filed as a bug so it doesn't get lost.
As to how to debug the debugger. There's no good answer yet although over time I have ideas which to put in place. Many of these ideas I'm testing out in a rewrite of a python debugger.
For what I wrote above, the easiest thing to do was to change eval.rb
and add: require 'debug' # :-)
In other words one can use the built-in debug module from Ruby to debug ruby-debug if the problem is in Ruby code.
There is a "debuggertesting" sub-command under "set", but right now it doesn't do anything. In pydb and the Python debugger rewrite makes some of the debugger frames that are there but hidden from unhidden. Afterwards one can switch to one of these frames and see stuff.
But of course a good debugging strategy is to write modular code where every file can be tested or run separately. And altough ruby-debug is better than some other debuggers it still has a little way to go here. Again I've been doing this in pydbg (http://code.google.com/p/pydbg/
I don't know how to handle a post-mortem yet other than read the traceback. :o)
|
By: Tom Ten Thij
Strange error when printing variables [ reply ] 2009-02-03 23:25
|
I was trying to figure out how ruby-debug works and I ran into some weirdness. This is my code:
require 'ruby-debug'
def ant(n)
context = "ant"
debugger
2 / n
end
def bee(n)
context = "bee"
ant(n - 4)
end
def cockroach(n)
context = "cockroach"
bee(n * n)
end
Debugger.start do
cockroach(2)
end
When I get to the debugger prompt, go to a different frame (e.g. with up), then various things crash the debugger:
> p n
> p 5
> i v (but only sometimes and then doing a > l = after the up prevents the crash)
The error on crash is:
INTERNAL ERROR!!! (eval):2:in `hbinding': no class/module to add method
I was preparing a talk on the coolness of ruby-debug but this flaw makes it a bit hard to demonstrate that :).
This also got me interested in the question: how would I debug the debugger? How would I do a postmortem on the error?
My versions are ruby-debug-0.10.3 and ruby-debug-base-0.10.3.
|
|
 |