开发者
资源
VSCode上配置鲲鹏编译插件笔记分享
VSCode上配置鲲鹏编译插件笔记分享
发表于2024/02/27
2.8k1

配置远程环境

1.在VSCode上选择“文件 > 首选项 > 设置”,选择“工作区”,并在输入框搜索“kunpeng.remote.ssh.vmachineinfo”, 然后在setting.json中编辑环境信息。

2.配置远程环境信息,包括SSH连接IP地址、端口、登录用户名、工作目录。

"kunpeng.remote.ssh.vmachineinfo": [
  {
      "label": "xxx",
      "ip": "xxx.xxx.xxx.xxx",
      "port": "xxx",
      "user": "xxx",  /*非root用户名*/
      "workspace": "xxx"
  },
  {
      "label": "xxx",
      "ip": "xxx.xxx.xxx.xxx",
      "port": "xxx",
      "user": "xxx",  /*非root用户名*/
      "workspace": "xxx"
  }
 ]

配置本地SSH公私钥登录

配置本地SSH公私钥登录(以Windows为例)

  1. 1.制作公私钥对。

    Windows下可以通过cmd执行ssh-keygen命令生成公私钥对,默认回车即可。生成的公私钥对默认保存在“~/.ssh/目录”下的id_rsa、id_rsa.pub文件中。

  2. 2.导入公钥

  3. 拷贝本地.ssh文件夹到SSH服务端(即要连接的远程环境),然后将公钥文件中的内容导入到authorized_keys文件中。

  4. cd ~/.ssh cat id_rsa.pub >> authorized_keys

  5. 3.配置目录权限。

    • authorized_keys权限配置为600

      chmod 600 ~/.ssh/authorized_keys

    • .ssh目录权限配置为700

      chmod 700 ~/.ssh

    • SSH服务端用户目录权限配置为700

      chmod 700 ~

  6. 4.配置本地SSH客户端地址。

    在VSCode上选择“文件 > 首选项 > 设置”),选择“工作区”,并在输入框搜索“kunpeng.remote.ssh.clientpath”,,然后在编辑框填写本地SSH客户端可执行文件所在的路径。

    路径格式为:x:\xxx\xxx\xxx\xxx

配置本地SSH私钥文件id_rsa的路径

在VSCode上选择“文件 > 首选项 > 设置”,选择“工作区”,并在输入框搜索“kunpeng.remote.ssh.privatekeypath”,,然后在编辑框填写私钥文件id_rsa的路径。

路径格式为:x:\xxx\xxx\xxx\id_rsa

配置编译任务(tasks.json)

您可以按照如下模板在.vscode/tasks.json中添加编译任务。

{
  "type": "shell",
  "group": {
      "kind": "build",
      "isDefault": true
  },
  "options": {
      "env": {
          "xxx": "xxx" 
      }
  },
  "presentation": {
      "echo": true,
      "reveal": "always",
      "focus": false,
      "panel": "shared"
  },
  "label": "xxx",   /*编译任务名称*/
  "command": "xxx", /*编译命令,相对路径*/
  "problemMatcher": {
      "owner": "cpp",
      "fileLocation": [
          "relative",
          "${workspaceRoot}"
      ],
      "pattern": {
          "regexp": "^([^:]*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
          "file": 1,
          "line": 2,
          "column": 3,
          "severity": 4,
          "message": 5
      }
  }
 }

配置调试任务(launch.json)

您可以按照如下模板在.vscode/launch.json中添加调试任务。

{
  "name": "xxx", /*调试任务名称*/
  "type": "cppdbg",
  "request": "launch",
  "program": "./swm_llt", /*要调试的二进制名称*/
  "args": [],
  "stopAtEntry": true,
  "cwd": "${command:remotessh.remoteworkspace}/xxx/xxx/xxx/swm_llt",/*要调试的二进制路径*/
  "externalConsole": true,
  "MIMode": "gdb",
  "pipeTransport": {
      "pipeCwd": "",
      "pipeProgram": "${command:remotessh.sshclientpath}",
      "pipeArgs": [
          "-p",
          "${command:remotessh.remoteport}",
          "${command:remotessh.remoteuser}@${command:remotessh.remoteip}"
      ],
      "debuggerPath": "/usr/bin/gdb"
  },
  "sourceFileMap": {
      "${command:remotessh.remoteworkspace}": "${workspaceRoot}"
  },
  "setupCommands": [
      {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
      },
      {
          "text": "handle SIGPIPE nostop noprint pass",
          "description": "ignore SIGPIPE",
          "ignoreFailures": true
      }
  ],
  "preLaunchTask": "xxx" /*调试依赖的前置编译任务名称*/
 }

编译调试

插件安装完成后在左侧工具栏会显示三个视图,依次是编译任务视图、调试任务视图和当前使用的VM列表视图,如下图所示。

开始启动编译调试前,需要将本地工程手动拷贝一份至SSH远端服务器,路径为“kunpeng.remote.ssh.vmachineinfo”中定义的“workspace”,也可以使用rsync工具同步代码工程至远端“workspace”。同步完成即可启动编译任务和调试任务:

启动编译任务

启动调试任务

收藏举报
Level 1
0
帖子
0
粉丝
0
获赞