VS CODE is so powerful, not only for front-end development, but also for debugging HotSpot and Nginx! The key is free!

I’ve been working on Nginx recently, so here’s how to debug Nginx using VS CODE.

One: compile and run Nginx

  1. Change ngx_compile_opt=”-c” to ngx_compile_opt=”-c -g” in /auto/cc/conf
  2. / sudo./auto/configure –prefix=nginx project directory/sudo./auto/configure –prefix=nginx project directory Brew Install pcre
  3. Executing sudo make
  4. Run./objs/nginx, open your browser to 127.0.0.1, and see the welcome screen for nginx if there is no problem.

Debug the Master process

Nginx is divided into Master process and Worker process. Let’s debug the Master process first

  1. Turn off the Nginx daemon and add a line to /conf/nginx.conf:
daemon off;
Copy the code

2. Add VSCODE debugging configuration

Create and modify launch.json

{// Use IntelliSense to learn about related attributes. // Hover to view descriptions of existing properties. / / for more information, please visit: https://go.microsoft.com/fwlink/?linkid=830387 "version" : "0.2.0," "configurations: [{" name" : "(lldb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/objs/nginx", "args": [], "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "lldb" } ] }Copy the code

3. Start debugging, great!


3: Debug Worker process

  1. Check the Worker process PID

2. Edit launch.json and add Attach configuration

{ "name": "(lldb) Attach", "type": "cppdbg", "request": "attach", "program": "${workspaceFolder}/objs/nginx", "processId": "806{// Use IntelliSense to learn about the properties. // Hover to view descriptions of existing properties. / / for more information, please visit: https://go.microsoft.com/fwlink/?linkid=830387 "version" : "0.2.0," "configurations: [{" name" : "(lldb) Attach", "type": "cppdbg", "request": "attach", "program": "${workspaceFolder}/objs/nginx", "processId": "80636", // Enter Worker process PID "MIMode": "LLDB"}, {"name": "(LLDB) Launch", "type": "CPPDBG ", "request": "launch", "program": "${workspaceFolder}/objs/nginx", "args": [], "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "lldb" } ] }Copy the code

3. Switch the debug mode to ATTACH


4. Start debugging, break the Http request parsing point, refresh the browser, cool again!


Is not very convenient, next, follow the source code travel to the top of your heart!