views:

299

answers:

5

Hi,

I am looking for a method to monitor a running program that I have the source code. Basically, when the user runs it, I need to know what functions and parameter is called sequentially.

I can write a trace output code to all functions to achieve this. However, I am not allowed to modify the source code. I found out that Tracepoint in Visual Studio 2005 allows me to do this - output log info without modifying the source. But I need to add them to all functions.

As I have thousands of files and functions, I need to find a way to programatically do this. I found out about DTE.Debugger.Breakpoints.Add that able to add a breakpoint. However, I couldnt find any way for tracepoint. Or where is the breakpoint info for a project stored? I couldnt find it in sln or vcproj. Or is there a way to convert breakpoint to tracepoint programatically? I see that I can change it manually by changing the "When Hit" property dialog.

Thanks!

+1  A: 

A .NET profiler will allow you to see which methods are executed and how long each takes without modifying the source code. It basically injects special code into the compiled assembly.

David Brown
Do you mean a performance or memory profiler? I thought of using a code coverage checker too. But I need to know the value of the function parameters/variables too. I think the profiler is unable to log these info right? And I need to know the order of function call too - which function is called first. Using tracepoint, i am able to know these.
Darren
The performance profiler that I currently use (from EQUATEC) allows me to drill down into specific methods in the order that they were called. As for viewing the parameters passed to each method, I'm not sure. I haven't really had a need for something like that. Sorry I couldn't be of more help.
David Brown
A: 

You could also look at Aspect Oriented coding. By my understanding this will change the compiled assembly controlled by attributes and is typically used to add tracing to all methods/properties.

http://stackoverflow.com/questions/559148/how-can-i-add-a-trace-to-every-method-call-in-c

MrTelly
I am reading on AspectC++ as I am working on C++ code. It is able to access to the argument values as well. It should serve my purpose well. Thanks everyone for the help.
Darren
A: 

I too am interested in finding out how to programatically add a tracepoint.

I can programmatically add a breakpoint, but not one that will trigger a macro, which is what I am interested in.

Daniel D Lindmark
A: 

First part of the solution:

DTE.ExecuteCommand("EditorContextMenus.CodeWindow.Breakpoint.InsertTracepoint")

It opens the TP window for the line where the cursor was. You will still have to hit Return to select OK, though. Enough for my needs--at least you don't have to right-click, etc.

leo grrr
A: 

I think this is the solution... this macro adds a breakpoint the Main method of your program, and then turns all breakpoints into tracepoints.

Sub AddBreakpointToMain()
     Dim bp As EnvDTE80.Breakpoint2
     Dim bps As EnvDTE.Breakpoints


     bps = DTE.Debugger.Breakpoints.Add("Main")
     For Each bp In bps
         bp.Tag = "SetByMacro"
         bp.BreakWhenHit = False
         bp.Message = "Hi, this is your tracepoint calling."
     Next
End Sub
Omer Raviv