2

There is a program (a WPF app written in C#) that calls the other program ( commandline program written in C++) . They both are in the same solution. At some points, the caller gets some stuff done by using the other program by using the methodology provided in System.Diagnostics.Process. I want to debug the both programs while testing this project. How to do that? is there some easy method like "attaching" which we do to libraries?

--EDIT--
Process A starts the process B. Then A waits until process B exits. Furthermore, B something very small like dir on the command prompt which exits quickly.

Deamonpog
  • 805
  • 1
  • 10
  • 24
  • Try strart the first project nad then start new instance to the other – kostas ch. Nov 13 '13 at 10:19
  • Is this the same question as [Can Visual Studio be made to debug child processes like WinDBG?](http://stackoverflow.com/questions/771039/can-visual-studio-be-made-to-debug-child-processes-like-windbg)? – chwarr Nov 13 '13 at 10:23
  • Maybe you can replace run process to call method? – progpow Nov 13 '13 at 10:29
  • 1
    I think it`s answer to your question http://stackoverflow.com/questions/4814361/how-can-i-start-another-process-in-debug-mode-in-visual-studio-2010 – progpow Nov 13 '13 at 10:37

4 Answers4

2
  • Since it was hitting the deadline there was no time to wrap C++ with managed code as suggested by Wilbert.
  • Running the two programs on separate VS also doesn't work ( confirmed by trying out ) since program B is run only when necessary by the program A and each time command line arguments for starting B were different and generated at run-time. ( cannot be done even in same VS since debugging one process seems to pause execution of the other process )
  • Calling Debug in the program is not possible since B is a native C++ application. To access visual studio extensions, the project needs to be a managed project. Converting the current project to managed was not possible due to a problem with my version of VS. ( after installing Net Framework 4.5, VS 2010 needs to be updated to SP1 to be able to work use some features )

Applied Solution:

  1. In source of A , put a break-point below the place where command line arguments are generated for B (I put it at where proc.Start() is called).
    e.g.

    Process otherProcess = new Process();
    ...
    otherProcess.StartInfo.Arguments = "abc" + foo() + "," + bar();// what we need
    ...
    otherProcess.Start(); // break-point is here
    
  2. Run A in debug mode until the break-point is reached.

  3. Read the value of proc.StartInfo.Arguments and copy the value for later usage.
  4. Safely exit debugging A (stop debugging).
  5. Set command line arguments of B as the copied values (Project Properties > Debugging > Command Line Arguments)
  6. Start debugging B (right click on project > debug > start a new instance).
Deamonpog
  • 805
  • 1
  • 10
  • 24
1

If I understand you correctly, just attach the debugger to the other process. From one instance of Visual Studio you can attach to more than just one process, but you cannot attach two debuggers to the same process. Make sure however, you attach the right debugger to each process, i.e. the native debugger to the C++ application and the managed debugger to the WPF application.

You can switched between the debugger processes from the Processes tool window (given they are both paused at breakpoints). The call stack and all the others are updated for the currently selected process there.

Marius Bancila
  • 16,053
  • 9
  • 49
  • 91
  • +1 I think I actually faced north towards Redmond and blurted out a hallelujah when this feature was finally added to VS. You can even *start* another process in debug-mode within your solution by simply right-clicking the project, and selecting "Debug new instance..." or similar (can't remember the exact text; sry). – WhozCraig Nov 13 '13 at 10:26
0

Run another instance of VS, open solution and try to connect to running process http://msdn.microsoft.com/en-us/library/vstudio/3s68z0b3.aspx

progpow
  • 1,560
  • 13
  • 26
0

You could also write a small class that uses C++/Cli. To the outside, your class looks like any C# class, and can be used directly from C#. But inside the C++/Cli, you can freely call into C++. That way, you can remove the use of System.Diagnostics.Process and directly use the other program.

It's a bit of work up-front, but it allows you to directly step into the C++ code as you do with the C# code right now.

Wilbert
  • 7,251
  • 6
  • 51
  • 91