# Problem step-in debug through instance\_eval

**URL:** <https://www.ruby-forum.com/t/problem-step-in-debug-through-instance-eval/179301>\
**Category:** Ruby\
**Created:** [November 21, 2009, 3:13pm UTC](https://www.ruby-forum.com/t/problem-step-in-debug-through-instance-eval/179301 "2009-11-21T15:13:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexandremutel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a88e4f/32.png) [@alexandremutel](https://www.ruby-forum.com/u/alexandremutel)\
**Post date:** [November 21, 2009, 3:13pm UTC](https://www.ruby-forum.com/t/problem-step-in-debug-through-instance-eval/179301/1 "2009-11-21T15:13:14Z")

</div>

I’m trying to debug an external dsl and i have found some problems to  
step in the code (at least under windows)

I have a main.rb file (file are attached in test\_debug.7z) :  
puts “In Main before eval”  
instance\_eval(File.read(“dyn.dsl”),“dyn.dsl”)  
puts “In Main after eval”

and a dyn.dsl file :  
puts “In dyn line 1”  
x = 1 + 1  
puts “x = #{x}”

Using Rubymine2.0 with ruby-debug-ide 0.4.9 correctly compiled (it was  
quite hard to get there by the way…), the debugger is able to set a  
breakpoint correctly on file “dyn.dsl”. I’m able to step in this file.  
Everything is ok.

Now, if i try to debug it from the comman line : [ruby -r debug  
main.rb], i’m not able to see the source file of dyn.dsl code :  
E:\Code\RubyTest\>ruby -r debug main.rb  
Debug.rb  
Emacs support available.

main.rb:1:puts “In Main before eval”  
(rdb:1) break dyn.dsl:1  
Set breakpoint 1 at dyn.dsl:1  
(rdb:1) cont  
In Main before eval  
Breakpoint 1, toplevel at dyn.dsl:1  
dyn.dsl:1:  
(rdb:1) list  
[-4, 5] in dyn.dsl  
No sourcefile available for dyn.dsl

Ruby version is : ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

Worst is that with ruby 1.9.1, I’m no longer able to debug through  
instance\_eval on an IDE, at least tested Rubymine2.0 or Netbeans.

Do you have any explanations?

---

<div class="post-metadata">

**Author:** ![alexandremutel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a88e4f/32.png) [@alexandremutel](https://www.ruby-forum.com/u/alexandremutel)\
**Post date:** [November 21, 2009, 10:33pm UTC](https://www.ruby-forum.com/t/problem-step-in-debug-through-instance-eval/179301/2 "2009-11-21T22:33:23Z")

</div>

> instance\_eval(File.read(“dyn.dsl”),“dyn.dsl”)

Could you not just do this instead?

load “dyn.dsl”

The ‘self’ object context would be lost. But at worst you could pass  
that through a constant or a global or thread-local variable, e.g.  
dyn.dsl contains

$SELF.instance\_eval { … original content …  
}

> Do you have any explanations?

A debugger is probably not going to be able to find the source file if  
the source is not in a file but is in a String.

---

<div class="post-metadata">

**Author:** ![alexandremutel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a88e4f/32.png) [@alexandremutel](https://www.ruby-forum.com/u/alexandremutel)\
**Post date:** [November 21, 2009, 11:47pm UTC](https://www.ruby-forum.com/t/problem-step-in-debug-through-instance-eval/179301/3 "2009-11-21T23:47:29Z")

</div>

Brian C. wrote:

> > instance\_eval(File.read(“dyn.dsl”),“dyn.dsl”)
> 
> Could you not just do this instead?
> 
> load “dyn.dsl”
> 
> The ‘self’ object context would be lost. But at worst you could pass  
> that through a constant or a global or thread-local variable, e.g.  
> dyn.dsl contains
> 
> $SELF.instance\_eval { … original content …  
> }

I would prefer another option… I would like to keep the dsl code  
clean, and yes, I need the self…

> A debugger is probably not going to be able to find the source file if  
> the source is not in a file but is in a String.

Well, with the 2nd argument of the instance\_eval, even if it’s more used  
to report a correct error, could be used for that (and I believe that  
this is used probably by some of those debuggers). Seems that there is  
an inconsistency between the different debuggers : JRuby 1.4.0 seems to  
be able to step in the code without no problem. The ruby-debug-ide 0.4.9  
is working well. The ruby-debug-ide19 is not working on this, the -r  
debug command line is not working… weird…

Anyway, i can still live with that. It’s working at least from an ide on  
1.8.6 and in jruby 1.4.0. I’m also curious if it’s a bug (not being able  
to step in the code) or a feature that is undocumented…
