Set up the cyberRT debug environment

Table of contents

Install docker engine

Initialize the docker environment

Check if the docker environment is started

Install vscode docker related environment

enter docker

Install the vscode plugin under docker

Configure the vscode debug environment under docker

start debug


Because the bazel environment in apollo mainly depends on the local link, it will be very troublesome if you want to build a cyberRT debug environment on the host machine. Here we mainly talk about the debug in the docker environment, and the effect is the same as that built under the host.

Install docker engine

Install Docker Engine on Ubuntu

Initialize the docker environment

bash apollo/docker/scripts/dev_start.sh   

Check if the docker environment is started

docker ps

Install vscode docker related environment

enter docker

Find the container in the vscode plugin

Select attach vscode

Select the previously created container to enter

Successfully entered the inside of the docker container, you can and can see the mounted code files

Install the vscode plugin under docker

Configure the vscode debug environment under docker

find.vsocde

create launch.json

I am using gdb here. If you are also using gcc/g++ compiler, you don’t need to change the configuration below. If you are using llvm, you need to change gdb to lldb

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
      {
        "name": "(gdb) Launch Run",
        "preLaunchTask": "Bazel Build (Run)",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/bazel-bin/${relativeFileDirname}/${fileBasenameNoExtension}",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb"
      },
      {
        "name": "(gdb) Launch Run Opt",
        "preLaunchTask": "Bazel Build (Run Opt)",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/bazel-bin/${relativeFileDirname}/${fileBasenameNoExtension}",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb"
      },
      {
        "name": "(gdb) Launch Debug",
        "preLaunchTask": "Bazel Build (Debug)",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/bazel-bin/${relativeFileDirname}/${fileBasenameNoExtension}",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb"
      },
      {
        "preLaunchTask": "Bazel Build (Debug)",
        "name": "Codegdb",
        "type": "gdb",
        "request": "launch",
        "program": "${workspaceFolder}/bazel-bin/${relativeFileDirname}/${fileBasenameNoExtension}",
        "args": [],
        "sourceMap": {
          ".": "${workspaceFolder}"
        },
      },
      {
        "name": "Linux: g++ build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/bazel-bin/${relativeFileDirname}/${fileBasenameNoExtension}",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ],
        "preLaunchTask": "Bazel Build (Debug)",
        "miDebuggerPath": "/usr/bin/gdb"
      }
    ]
  }

Create tasks.json

{
	"version": "2.0.0",
	"tasks": [
	  {
		"label": "Bazel Build (Debug)",
		"type": "shell",
		"command": "bazel  build --cxxopt='-std=c++17' ${relativeFileDirname}:${fileBasenameNoExtension} -c dbg",
		"windows": {
		  "command": "bazel build --cxxopt='-std=c++17' ${relativeFileDirname}:${fileBasenameNoExtension} --experimental_enable_runfiles -c dbg"
		},
		"osx": {
		  "command": "bazel build --cxxopt='-std=c++17' ${relativeFileDirname}:${fileBasenameNoExtension} -c dbg --spawn_strategy=local",
		},
		"group": {
		  "kind": "build",
		  "isDefault": true
		},
	  },
	  {
		"label": "Bazel Build (Run)",
		"type": "shell",
		"command": "bazel  build --cxxopt='-std=c++17' ${relativeFileDirname}:${fileBasenameNoExtension}",
		"windows": {
		  "command": "bazel build --cxxopt='-std=c++17' ${relativeFileDirname}:${fileBasenameNoExtension}"
		},
		"osx": {
		  "command": "bazel build --cxxopt='-std=c++17' ${relativeFileDirname}:${fileBasenameNoExtension}",
		},
		"group": {
		  "kind": "build",
		  "isDefault": true
		},
	  },
	  {
		"label": "Bazel Build (Run Opt)",
		"type": "shell",
		"command": "bazel  build --cxxopt='-std=c++17' ${relativeFileDirname}:${fileBasenameNoExtension} -c opt",
		"windows": {
		  "command": "bazel build --cxxopt='-std=c++17' ${relativeFileDirname}:${fileBasenameNoExtension} -c opt"
		},
		"osx": {
		  "command": "bazel build --cxxopt='-std=c++17' ${relativeFileDirname}:${fileBasenameNoExtension} -c opt",
		},
		"group": {
		  "kind": "build",
		  "isDefault": true
		},
	  }
	]
  }

start debug

Open a test folder under cyberRT

cd /apollo/cyber/example

Open talker.cc, add two breakpoints at will, and press F5

Guess you like

Origin blog.csdn.net/qq_32378713/article/details/129473413