views:

705

answers:

3

In Visual Studio for my native C++ program I want to get a plot of some variables during debug. Mostly I use textual representation of the objects by editing autoexp.dat. But for some of the variables it is better to have a plot rather than having values in textual form.

So far I have used a function plot(const void* address,const char* type) , and called it from Immediate Window giving the variable address & the type, and internally casting it to proper type.

But this method has two disadvantage.

  • First is that, function overloading almost never works when calling a function from debugger (so I had to pass type as a second parameter), and the function call occasionally crashes, though it works perfectly when called from within code.
  • Second is, instead of writing a C++ function for plotting, I am interested to have a scripting language (like autoexp.dat or a VBScript) to give the internal data of the C++ object without writing any wrapper, so that I can use the script to store the data in a file or plot it.

In general I am interested to have something like Matlab or Ch IDE, where I can plot certain variable externally when the program is at a debug break.

A: 

Could you use gnuplot for this? Spit out the data you want to plot as debug prints, and then while you're sitting at a breakpoint, copy it to an external file and run it through the plotter.

Parappa
+2  A: 

Since VS 2005, Visual Studio has included Visualizers, which could almost have been designed specifically for your problem. MSDN explains the concept better than I can:

Visualizers are a new component of the Visual Studio debugger user interface. A visualizer creates a dialog box or other interface to displays a variable or object in a meaningful way that is appropriate to its data type. For example, an HTML visualizer interprets an HTML string and displays the result as it would appear in a browser window, a bitmap visualizer interprets a bitmap structure and displays the graphic it represents, and so on. Some visualizers allow you to edit as well as view the data.

See here for a tutorial on how to write one.

Stu Mackellar
Visualizers are good. But unfortunately I hadn't found any proper way to use it for native C++ application. They are for .NET based applications.
abir
Mixed C++ / C++CLI app? It seems the restirction exists because the debuggee side of the Visualizer needs to expose a .NET interface. It shouldn't matter where it gets its data from.
MSalters
+1  A: 

As others have noted, I'm not sure exactly what do you wish to plot. I usually understand, when someone says he wants to "plot something", he usually means some array with numerical values. If this is true in your case, Intel's Array Visualizer is maybe of some help. It can be downloaded freely, it integrates into visual studio, and you can use it in two ways: as a standalone application or while debugging ("while in some breakpoint") so you can plot array values "while program is running".

ldigas