# Debugging ruby code in a host

**URL:** <https://www.ruby-forum.com/t/debugging-ruby-code-in-a-host/163675>\
**Category:** IronRuby\
**Created:** [March 23, 2009, 9:01pm UTC](https://www.ruby-forum.com/t/debugging-ruby-code-in-a-host/163675 "2009-03-23T21:01:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [March 23, 2009, 9:01pm UTC](https://www.ruby-forum.com/t/debugging-ruby-code-in-a-host/163675/1 "2009-03-23T21:01:26Z")

</div>

Hi

With my IronRubyMVC implementation I’m far enough to figure out that I  
need  
to be able to put breakpoints in my ruby code 🙂  
Now the question is how, because I think I tried all of the ways that  
are  
described in the wiki but had no success. I have a debug version of  
IronRuby  
and I’m using it in a C# [ASP.NET](http://ASP.NET) MVC project with the  
System.Web.Mvc.IronRuby dll as a reference. The web application hosts  
the  
scriptruntime etc. Now what do I need to do to make visual studio break  
on  
the breakpoint I define?

In merging the latest git pushes into the linux branch I’ve seen a pdb  
generator does that mean I can actually get to more meaningful stack  
traces  
etc. again the question how springs to mind? 🙂

Thanks  
Ivan

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [March 23, 2009, 9:36pm UTC](https://www.ruby-forum.com/t/debugging-ruby-code-in-a-host/163675/2 "2009-03-23T21:36:05Z")

</div>

Is DebugMode property of the ScriptRuntimeSetup of the ScriptRuntime you  
run the script in set to true?

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Ivan Porto  
Carrero  
Sent: Monday, March 23, 2009 12:32 PM  
To: ironruby-core  
Subject: [Ironruby-core] Debugging ruby code in a host

Hi

With my IronRubyMVC implementation I’m far enough to figure out that I  
need to be able to put breakpoints in my ruby code 🙂  
Now the question is how, because I think I tried all of the ways that  
are described in the wiki but had no success. I have a debug version of  
IronRuby and I’m using it in a C# [ASP.NET](http://ASP.NET)[http://ASP.NET](http://ASP.NET) MVC project  
with the System.Web.Mvc.IronRuby dll as a reference. The web application  
hosts the scriptruntime etc. Now what do I need to do to make visual  
studio break on the breakpoint I define?

In merging the latest git pushes into the linux branch I’ve seen a pdb  
generator does that mean I can actually get to more meaningful stack  
traces etc. again the question how springs to mind? 🙂

Thanks  
Ivan

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [March 23, 2009, 9:46pm UTC](https://www.ruby-forum.com/t/debugging-ruby-code-in-a-host/163675/3 "2009-03-23T21:46:40Z")

</div>

When you create the ScriptRuntimeSetup, do this:

setup.Debug = true;

That will tell the DLR to generate debuggable code.

* * *

From: removed\_email\_address@domain.invalid  
[removed\_email\_address@domain.invalid] on behalf of Ivan Porto C.  
[removed\_email\_address@domain.invalid]  
Sent: Monday, March 23, 2009 12:32 PM  
To: ironruby-core  
Subject: [Ironruby-core] Debugging ruby code in a host

Hi

With my IronRubyMVC implementation I’m far enough to figure out that I  
need to be able to put breakpoints in my ruby code 🙂  
Now the question is how, because I think I tried all of the ways that  
are described in the wiki but had no success. I have a debug version of  
IronRuby and I’m using it in a C# [ASP.NET](http://ASP.NET)[http://ASP.NET](http://ASP.NET) MVC project  
with the System.Web.Mvc.IronRuby dll as a reference. The web application  
hosts the scriptruntime etc. Now what do I need to do to make visual  
studio break on the breakpoint I define?

In merging the latest git pushes into the linux branch I’ve seen a pdb  
generator does that mean I can actually get to more meaningful stack  
traces etc. again the question how springs to mind? 🙂

Thanks  
Ivan

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [March 23, 2009, 10:38pm UTC](https://www.ruby-forum.com/t/debugging-ruby-code-in-a-host/163675/4 "2009-03-23T22:38:23Z")

</div>

Yes… I’ll try again… maybe I missed something.  
I should really say that the file that has the ruby code is an assembly  
resource that gets read through an AssemblyReaderStreamContentProvider.  
Should I be providing that content differently?

> <https://github.com/casualjim/ironrubymvc/blob/57cfa96ae7ce03c55e25eeb74a20d1500760b414/IronRubyMvc/Core/RubyEngine.cs#L352>

I use [trace.rb · GitHub](http://gist.github.com/74979) to set a breakpoint.

2009/3/23 Tomas M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [March 23, 2009, 9:47pm UTC](https://www.ruby-forum.com/t/debugging-ruby-code-in-a-host/163675/5 "2009-03-23T21:47:50Z")

</div>

Woops … setup.DebugMode (like Tomas said)

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Jimmy  
Schementi  
Sent: Monday, March 23, 2009 1:32 PM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Debugging ruby code in a host

When you create the ScriptRuntimeSetup, do this:

setup.Debug = true;

That will tell the DLR to generate debuggable code.

* * *

From: removed\_email\_address@domain.invalid  
[removed\_email\_address@domain.invalid] on behalf of Ivan Porto C.  
[removed\_email\_address@domain.invalid]  
Sent: Monday, March 23, 2009 12:32 PM  
To: ironruby-core  
Subject: [Ironruby-core] Debugging ruby code in a host  
Hi

With my IronRubyMVC implementation I’m far enough to figure out that I  
need to be able to put breakpoints in my ruby code 🙂  
Now the question is how, because I think I tried all of the ways that  
are described in the wiki but had no success. I have a debug version of  
IronRuby and I’m using it in a C# [ASP.NET](http://ASP.NET)[http://ASP.NET](http://ASP.NET) MVC project  
with the System.Web.Mvc.IronRuby dll as a reference. The web application  
hosts the scriptruntime etc. Now what do I need to do to make visual  
studio break on the breakpoint I define?

In merging the latest git pushes into the linux branch I’ve seen a pdb  
generator does that mean I can actually get to more meaningful stack  
traces etc. again the question how springs to mind? 🙂

Thanks  
Ivan

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [March 23, 2009, 10:56pm UTC](https://www.ruby-forum.com/t/debugging-ruby-code-in-a-host/163675/6 "2009-03-23T22:56:34Z")

</div>

The file you are setting breakpoint to needs to exists on the disk for  
Visual Studio debugger to work.

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Ivan Porto  
Carrero  
Sent: Monday, March 23, 2009 2:14 PM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Debugging ruby code in a host

Yes… I’ll try again… maybe I missed something.  
I should really say that the file that has the ruby code is an assembly  
resource that gets read through an AssemblyReaderStreamContentProvider.  
Should I be providing that content differently?

> <https://github.com/casualjim/ironrubymvc/blob/57cfa96ae7ce03c55e25eeb74a20d1500760b414/IronRubyMvc/Core/RubyEngine.cs#L352>

I use [trace.rb · GitHub](http://gist.github.com/74979) to set a breakpoint.

2009/3/23 Tomas M.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\>

Is DebugMode property of the ScriptRuntimeSetup of the ScriptRuntime you  
run the script in set to true?

Tomas

From:  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
On Behalf Of Ivan Porto C.  
Sent: Monday, March 23, 2009 12:32 PM  
To: ironruby-core  
Subject: [Ironruby-core] Debugging ruby code in a host

Hi

With my IronRubyMVC implementation I’m far enough to figure out that I  
need to be able to put breakpoints in my ruby code 🙂  
Now the question is how, because I think I tried all of the ways that  
are described in the wiki but had no success. I have a debug version of  
IronRuby and I’m using it in a C# [ASP.NET](http://ASP.NET)[http://ASP.NET](http://ASP.NET) MVC project  
with the System.Web.Mvc.IronRuby dll as a reference. The web application  
hosts the scriptruntime etc. Now what do I need to do to make visual  
studio break on the breakpoint I define?

In merging the latest git pushes into the linux branch I’ve seen a pdb  
generator does that mean I can actually get to more meaningful stack  
traces etc. again the question how springs to mind? 🙂

Thanks  
Ivan

* * *

Ironruby-core mailing list  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [March 23, 2009, 11:31pm UTC](https://www.ruby-forum.com/t/debugging-ruby-code-in-a-host/163675/7 "2009-03-23T23:31:44Z")

</div>

Ok it works when I use  
Engine.RequireRubyFile(“C:\path\to\file\controller.rb”)  
but not when i use a custom streamcontent provider that knows how to  
deal  
with virtual paths.

like

> <https://github.com/casualjim/ironrubymvc/blob/57cfa96ae7ce03c55e25eeb74a20d1500760b414/IronRubyMvc/Core/VirtualPathStreamContentProvider.cs>

Anyway I’ll take the stream content providers out and just put something  
in  
that handles mappath to allow debugging.

But now the question becomes When would I want to use a  
StreamContentProvider and when should I have to create a PAL ? Would  
using  
a PAL be a better idea to when hosting it in a webserver?

2009/3/23 Tomas M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [March 24, 2009, 2:56am UTC](https://www.ruby-forum.com/t/debugging-ruby-code-in-a-host/163675/8 "2009-03-24T02:56:59Z")

</div>

PAL provides more general virtualization of file system (though still  
not complete). By using custom content providers for a ScriptSource it  
only affects one particular ScriptSource while PAL is used by other API  
as well. For example, File#open goes thru PAL:  
context.DomainManager.Platform.OpenInputFileStream(path, fileMode,  
access, share);

Also, content of required files is read via PAL: see  
Microsoft.Scripting\SourceFileContentProvider.cs.

So, PAL allows the host to make basic file IO operations work â€“ you can,  
for example, build virtual file system based on Isolated Storage or some  
database table. The virtualization is not complete, we are looking for  
reasonable set of API that it make sense to virtualize. If you find  
something you would need let us know.

Sadly, Visual Studio debugger requires source files to be physical files  
on disk. If you need to debug some code stored in a database you need to  
save it to a file. You might want to do so only when DebugMode is on. If  
it is not, PDBs are not generated anyways so the code is not debuggable  
by VS.

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Ivan Porto  
Carrero  
Sent: Monday, March 23, 2009 3:18 PM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Debugging ruby code in a host

Ok it works when I use  
Engine.RequireRubyFile(“C:\path\to\file\controller.rb”)  
but not when i use a custom streamcontent provider that knows how to  
deal with virtual paths.

like

> <https://github.com/casualjim/ironrubymvc/blob/57cfa96ae7ce03c55e25eeb74a20d1500760b414/IronRubyMvc/Core/VirtualPathStreamContentProvider.cs>

Anyway I’ll take the stream content providers out and just put something  
in that handles mappath to allow debugging.

But now the question becomes When would I want to use a  
StreamContentProvider and when should I have to create a PAL ? Would  
using a PAL be a better idea to when hosting it in a webserver?  
2009/3/23 Tomas M.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\>

The file you are setting breakpoint to needs to exists on the disk for  
Visual Studio debugger to work.

Tomas

From:  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
On Behalf Of Ivan Porto C.  
Sent: Monday, March 23, 2009 2:14 PM

To: removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: [Ironruby-core] Debugging ruby code in a host

Yes… I’ll try again… maybe I missed something.  
I should really say that the file that has the ruby code is an assembly  
resource that gets read through an AssemblyReaderStreamContentProvider.  
Should I be providing that content differently?

> <https://github.com/casualjim/ironrubymvc/blob/57cfa96ae7ce03c55e25eeb74a20d1500760b414/IronRubyMvc/Core/RubyEngine.cs#L352>

I use [trace.rb · GitHub](http://gist.github.com/74979) to set a breakpoint.

2009/3/23 Tomas M.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\>

Is DebugMode property of the ScriptRuntimeSetup of the ScriptRuntime you  
run the script in set to true?

Tomas

From:  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
On Behalf Of Ivan Porto C.  
Sent: Monday, March 23, 2009 12:32 PM  
To: ironruby-core  
Subject: [Ironruby-core] Debugging ruby code in a host

Hi

With my IronRubyMVC implementation I’m far enough to figure out that I  
need to be able to put breakpoints in my ruby code 🙂  
Now the question is how, because I think I tried all of the ways that  
are described in the wiki but had no success. I have a debug version of  
IronRuby and I’m using it in a C# [ASP.NET](http://ASP.NET)[http://ASP.NET](http://ASP.NET) MVC project  
with the System.Web.Mvc.IronRuby dll as a reference. The web application  
hosts the scriptruntime etc. Now what do I need to do to make visual  
studio break on the breakpoint I define?

In merging the latest git pushes into the linux branch I’ve seen a pdb  
generator does that mean I can actually get to more meaningful stack  
traces etc. again the question how springs to mind? 🙂

Thanks  
Ivan

* * *

Ironruby-core mailing list  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

* * *

Ironruby-core mailing list  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)
