Simple way to debug an EXE pulled by another process

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.