Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extend the Visual Studio Debugger with an IronPython shell?

First the problem I am trying to solve: I'm debugging a C# application that has huge object graphs (think Building Information Models, a kind of object oriented CAD). When I hit a breakpoint, I generally have long lists of objects I'd first need to transform to be useful for debugging.

In code, I use LINQ and lambdas to do this. But you can't do that in the Watch window and the Immediate window.

How could I go about adding an IronPython shell extension to Visual Studio 2010 that lets me snoop the same information available to the Immediate window / Watch window?

EDIT: I can figure out how to make a debugger visualizer. But from the API it seems I would only have access to the object being visualized - while I'd actually prefer to have access to all local variables.

EDIT: From the documentation on msdn it seems a DE (Debug Engine) with an EE (Expression Evaluator?) can do the trick. This is for integrating your own language into Visual Studio. I'm trying to hook into the existing DE or at least provide my own EE.

like image 800
Daren Thomas Avatar asked Jul 08 '10 10:07

Daren Thomas


People also ask

How do I change Debug config in Visual Studio?

In Solution Explorer, right-click the project and choose Properties. In the side pane, choose Build (or Compile in Visual Basic). In the Configuration list at the top, choose Debug or Release. Select the Advanced button (or the Advanced Compile Options button in Visual Basic).

What are the ways you can continue debugging from a breakpoint in Visual Studio?

In most languages supported by Visual Studio, you can edit your code in the middle of a debugging session and continue debugging. To use this feature, click into your code with your cursor while paused in the debugger, make edits, and press F5, F10, or F11 to continue debugging.

How do I keep Debug code in Visual Studio?

To run or debug a simple app in VS Code, select Run and Debug on the Debug start view or press F5 and VS Code will try to run your currently active file. However, for most debugging scenarios, creating a launch configuration file is beneficial because it allows you to configure and save debugging setup details.


1 Answers

It turns out its rather easy to write a Visual Studio 2010 Addin: Just download and install the Visual Studio 2010 SDK. Next, create an Addin project.

The OnConnection Method in the Connect class of your Addin will provide you with a DTE2 instance. This can be used to poke around in the Visual Studio Debuggers Expression Evaluator:

DTE2 application; // fill this in OnConnection
application.Debugger.GetExpression("some c# code goes here")

The results are Expression instances, COM objects. Check the Value property.

Homework: Figure out how to wrap that up in a nice pythonic framework to make it seem seamless.

like image 81
Daren Thomas Avatar answered Oct 24 '22 06:10

Daren Thomas