使用lldb调试tvm中C++代码

Table of Contents

准备阶段

  • 编译安装llvm和tvm,其中,llvm需要lldb,tvm使用Debug模式编译,参考这里
  • vscode扩展
    • C/C++
    • Python
    • CodeLLDB
    • FFI Navigator 可能需要安装对应python包 pip install ffi-navigator

配置阶段

配置launch.json和tasks.json文件。

launch.json:

{
  "version": "0.2.0",
  "configurations": [
      {
	  "name": "PyTest",
	  "type": "python",
	  "stopOnEntry": false,
	  "request": "launch",
	  "module": "pytest",
	  "args": [
	      "-sv"
	  ],
	  "cwd": "${workspaceFolder}/tests/myTest",//指向自己的py测试文件夹
	  "preLaunchTask": "myShellCommand",
	  "env": {},
	  "envFile": "${workspaceFolder}/.env"
      },
      {
	  "type": "lldb",
	  "request": "attach",
	  "name": "LLDB-Attach-TVM",
	  "pid": "${command:pickMyProcess}"
      },
  ]
}

tasks.json:

{
  "version": "2.0.0",
  "tasks":[
      {
	  "label":"myShellCommand",
	  "type":"shell",
	  "command": "echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope "
      }
  ]
}

调试

在python和对应C++文件中打好断点后,在python文件中使用Pytest调试。

调试开始后在Debug Console里输入命令获取pid

import os
os.getpid()

将获取的pid复制,选择Attach-TVM,点击绿色启动按钮,出现输入框,将pid复制进输入框。点击中间调试按钮进入C++文件。

参考资料

Author: Frank

Created: 2021-04-15 周四 01:29

Validate