Source code tracing and debugging for Apache in Windows

Source: Internet
Author: User
Wind Ows Environment Apache Source code-level tracking and debuggingSource code debugging of Apache server is not the same as that of common programs, because it is not an independent program that can be directly run from the IDE environment. The author was the first to feel unable to get started. There was very little information on the Internet, and I tried to solve the problem. I wrote it here to help my friends who studied Apache source code. Apache server has a large amount of source code (hundreds of thousands of lines), making it hard to read. However, if you can track the code in the source code-level dynamic debugging, reading the source code in this way will surely get twice the result with half the effort. It should be declared that if you want to perform tracing debugging at the source code level in Windows, you must first compile the source code. The author is compiled through Visual Studio. net2003, Apache version 2.2.4, download name httpd-2.2.4-win32-src, can be downloaded on the official Apache website. It is not easy to compile Apache in visual studio.net. We assume that you have compiled Apache through visual studio.net and installed it on the local computer in debug mode. Assume that your installation root directory is D:/apache22. (1 ) Start Apache first. Server. The command line is as follows:Path D:/apache22/bin # Set the environment variable httpd-K install # Install httpd-K start # Start (2 ) Start visual studio.net ide Environment, and set the breakpointStart the vs.net environment and open the Apache solution. Find the code you are sure to execute an HTTP request (I write a processing module myself. If you do not have a self-written module and only want to read the source code, we recommend that you open the child in the mpm_winnt folder of the libhttpd module in the project. c. Set a breakpoint at the call of ap_process_connection, which is the HTTP connection processing function of l775. All HTTP requests will go through this path. (3 ) Find the Apache ProcessApache runs in a Windows environment with a parent process and a child process. When you open the task manager, you can see that there are two processes named mongohttpd.exe in the process. You can identify the Parent and Child processes by the number of threads. By default, the number of threads owned by the process cannot be viewed. You can choose View in Task Manager> select a column to open the following menu: Check the thread count items, and then confirm to see the number of threads of the process. Among them, the number of threads (about 254) is the sub-process. (4 ) Associate source code with processesSelect vs.net debugging-> process menu to open the following process dialog box: note that the following "Show System Processes" is selected, then select a sub-process, and click the "add" button on the right to open the process as follows:
Select the common language runtime and native items, click OK, and close the process dialog box. You will find that vs.net has processed the debugging status. (5 ) Trigger debuggingEnter "http: // localhost/" in the address bar of the IE browser. If the previous steps are correct, the program will stop at the place where you set the breakpoint (the first time is relatively long, the system needs to load some debugging information ). Then you can follow the breakpoint to easily understand how Apache processes HTTP request messages, and then understand the Apache kernel and working principles.

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.