Build envoy vscode debugging environment
After a week of tossing and turning, I can finally successfully debug envy source code. I stepped on countless pits halfway. Here's a record.
Tried the following means, including
- Jetbrains clion debugging
- vscode Mac native gdb(lldb) debugging
- vscode docker container debugging
In the end, only the last method succeeds and the rest fails.
clion debugging
At first, vscode was used in conjunction with Microsoft's C/C + + plug-in to view the envoy source code, but the accuracy of the jump code was not high. Some very clear function jumps would also allow you to choose from a pile of functions with duplicate names. Previously, I had a good experience using jetbrain, including java idea, go goland and python pycharm. Therefore, I searched c + + for the corresponding clion ide.
Use Clion to view the source code, but Clion can only recognize the CMakeLists file. You need to install the bazel plug-in,
adopt Bazel cmakelists tool Convert envoy's bazel to cmake
However, the conversion has been reporting errors. The conversion object is too large. java oom has tried. All parameters are invalid. The conversion tool has not been updated for several years.
There is a cmake project file CMakeLists.txt generated by netizens on the Internet, reference resources , the effect is not satisfactory
vscode Mac native debugging
The compilation is OK, but the breakpoint hit by * * is invalid and cannot enter the breakpoint**
# Install dependent tools brew install coreutils wget cmake libtool go bazel automake ninja clang-format autoconf aspell # Install bazelisk (recommended by macos) # Because there are many versions of bazel, different istio proxy (envy) versions depend on different versions of bazel. We can directly install bazelisk, a tool for bazel multi version management. It can automatically identify the. bazelversion file in the project and select the specified version of bazel for construction (the corresponding version of bazel binary can be downloaded automatically) brew install bazel bazelisk go get -u github.com/bazelbuild/buildtools/buildifie go get -u github.com/bazelbuild/buildtools/buildoze # Start compilation. Compilation is super slow. Wait patiently (3h) # [8063 projects] # You must set -- spawn\_strategy=local, disable sandbox, otherwise lldb cannot find the symbol table, and the assembly instruction is displayed instead of the code # In fact, adding this parameter is useless bazel build -c dbg --spawn\_strategy=local //source/exe:envoy-static # Compilation complete # INFO: Elapsed time: 8825.094s, Critical Path: 6888.96s # INFO: 5724 processes: 3 internal, 5721 darwin-sandbox. # INFO: Build completed successfully, 5724 total actions # Generate debugging files in vscode environment tools/vscode/generate\_debug\_config.py //source/exe:envoy-static --args "-c envoy-config.json" --debugger lldb # Generate Cland configuration file tools/vscode/refresh\_compdb.sh
Remote container remote debugging
principle
Mount the local code into a container installed with the necessary tools for debugging envoy, start the container, and enter the container through vscode to realize debugging
Pre step
Adjust docker resource size!!! Otherwise, the compilation step will report an error due to insufficient resources
The steps are as follows:
- Open envoy/.devcontainer/devcontainer.json
- The lower right corner of Vscde will prompt to open in devcontainer mode. If there is no prompt, press F1 to search for remote container: reopen
- At this time, the dockerfile will be packaged into an image. It will take some time. Please wait patiently. If the image is packaged successfully, the container will be started and enter the container through vscode
- Note: you need to increase the resources of the virtual machine occupied by docker, otherwise an error will be reported if the compilation resources are insufficient
- Open the command line in vscode and execute the following command (inside the container at this time)
- Generate configuration file: tools/vscode/refresh_compdb.sh, this step will generate various complies_ Commands.json file
- Generate vscode debug files: tools/vscode/generate_debug_config.py //source/exe:envoy-static --args "-c envoy-config.json"
# compile tools/vscode/generate\_debug\_config.py //source/exe:envoy-static --args "-c envoy-config.json" --debugger lldb # Generate Cland configuration file tools/vscode/refresh\_compdb.sh
Generated complie_commands.json file
lanch.json file
The above steps are completed, F5 debugging, and finally found the breakpoint. It's done!!!
summary
The emergence of container solves the problem of application publishing. devcontainer plug-in can realize cross operating system debugging. There is no need to install a pile of dependent packages. All environments are packaged in containers. It is really powerful!