Objective
In recent work, some programs need to be debugged. The depressing fact is that these programs cannot be debugged directly in the IDE because they depend on the command line that is passed by other processes and on shared memory created by other processes. F5 I do not use WinDbg debug program, so I think of some ways, you can step into the IDE to debug.
1. Fixed command-line arguments passed
This is the simplest case, directly in the IDE, to set the command line to start.
2. Variable command-line arguments passed
The parent process may create some kernel objects and pass the handle of the kernel objects to the child processes, so the parameters are different each time it is started.
What's going to happen? You can first prepare an EXE, "disguise" as a child process, and then let the parent process pull up. Then open the Task Manager, look at the command line parameters and fill it in the IDE's boot parameters, so you can happily debug ~
3. The child process relies on the shared memory created by the parent process
If the name of the shared memory is fixed, then the use of 2 can be resolved. If the name of the shared memory changes dynamically, for example, the parent process writes a shared memory name of "data+ child process ID".
We can of course start the parent process first, then determine the shared memory name, and then through the code of the child process to debug, but each debugging to change the code, too cumbersome.
My solution is to directly modify the parent process code, let it write the shared memory name fixed, the sub-process also make corresponding changes, so it can also use 2 debugging. After debugging OK, the code resumes.
4. Debug with Log
In the code, it is necessary to play log in a key place. Facilitate the development of testing and positioning of external network problems. Remember a teacher said, hit log debugging efficiency, two times of single-step debugging!
Summarize
It's still necessary to learn WinDbg, the first three methods apply only when the parent process creates a child process, and does not let the child process inherit the parent process handle.
Simple way to debug an EXE pulled by another process