Typora-copy-images-to:imagewindows under Compile and debug Nginx
Linux uses the GDB tracking code is inefficient, in the tracking code for source analysis, and positioning complex logic problems, if there is a simple and easy to use debugging environment can greatly improve efficiency. Because do not want to toss Linux desktop system, also worry X-window link performance problem, gu consider under Windows to compile Nginx and debugging.
The compiler I'm using is MinGW's GCC suite, with the interface using VS code.
The 2 core reference links are as follows:
Building Nginx on the Win32 platform with Visual C
C + + for VS Code
Installing the MinGW Kit
Download installation Address: http://www.mingw.org/
After the installation is a MINGGW installation Manager, you can choose between Mingw32-base and Msys-base two packages.
The mingw32-base includes the basic GCC suite, Msys-base has some basic Linux command tools that you need to use when performing configure later.
Download Nginx source and dependent library
Download the source code must be downloaded through Http://hg.nginx.org/nginx, not the release of the source package, otherwise it will not support the Windows compilation. You can choose to download it on the webpage or download it via HG.
You can now rely on third-party libraries as shown in the "Building Nginx on the Win32 platform with Visual C" link.
If you are only using code-trace debugging, you can remove the dependency on third-party libraries by adjusting the compilation parameters first. The compilation parameters provided below do not require the use of third-party libraries
Compiling Nginx
After extracting the source code, start Minge Msys.bat, enter the source directory, execute the following command to generate makefile. Msys performs configure slowly, and needs to wait patiently.
./auto/configure --with-cc=gcc --with-cc-opt=-O0 --with-debug --prefix= --conf-path=conf/nginx.conf --pid-path=logs/nginx.pid --http-log-path=logs/access.log --error-log-path=logs/error.log --sbin-path=nginx.exe --http-client-body-temp-path=temp/client_body_temp --http-proxy-temp-path=temp/proxy_temp --http-fastcgi-temp-path=temp/fastcgi_temp --http-scgi-temp-path=temp/scgi_temp --http-uwsgi-temp-path=temp/uwsgi_temp --without-http_rewrite_module --without-http_gzip_module --with-select_module
Some of the differences between my scripts and official links are:
- Use GCC as a compiler instead of CL for VS
- Add-o0 parameters to facilitate code trace debugging
- No added Http_ssl_module, Http_rewrite_module, Http_gzip_module omit third-party library dependencies
After a successful build makefile is compiled by executing the make command, the result of the compilation is Objs\nginx.exe
Debug Nginx
Configure the Launch.json file by referencing the C + + for VS Code.
{ "Version": "0.2.0", "Configurations": [ { "Name": "(gdb) Launch", "Type": "cppdbg", "Request": "Launch", "program": "${workspacefolder}/objs/nginx.exe", "args": [], "Stopatentry": false, "CWD": "${workspacefolder}/objs", "Environment": [], "Externalconsole": false, "Mimode": "GDB", "Midebuggerpath": "D:/mingw/bin/gdb.exe", "Setupcommands": [ { "description": "Enable pretty-printing for GdB", "Text": "-enable-pretty-printing", "Ignorefailures": true } ] } ]}
Modified the program, CWD, midebuggerpath three parameters in the template.
In order to debug Nginx convenient, you can configure the following parameters in the nginx.conf.
daemon off;master_process off;worker_processes 1;
Note Msys does not support dynamic breakpoints, you need to set breakpoints before you start debugging or in the debug state.
Windows compile and debug Nginx