对LLVM的Pass进行调试的vscode配置
文件夹结构
安装LLVM的过程省去,假设当前目录下有:
- CMakeLists.txt文件;编译pass
- include文件夹:pass的头文件
- src文件夹;pass的源码
- test文件夹:用于静态分析pass的测试代码(.c文件)
以下是CMakeLists.txt的内容,需要设置模式为Debug
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23cmake_minimum_required(VERSION 3.10)
find_package(LLVM 8 REQUIRED CONFIG)
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(HandleLLVMOptions)
include(AddLLVM)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS} include)
link_directories(${LLVM_LIBRARY_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_BUILD_TYPE Debug)
add_llvm_library(DivZeroPass MODULE
src/PointerAnalysis.cpp
src/DivZeroAnalysis.cpp
src/Transfer.cpp
src/ChaoticIteration.cpp
src/Domain.cpp
src/Utils.cpp
)
安装必要软件
安装lldb
1 | sudo apt update |
配置vscode
填写json文件
在.vscode文件夹下新建launch.json
文件,填写如下内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22{
"version": "0.2.0",
"configurations": [
{
"name": "Debug LLVM Pass",
"type": "cppdbg",
"request": "launch",
"program": "/usr/bin/opt",
"args": [
"-load", "${workspaceFolder}/build/DivZeroPass.so",
"-DivZero", "${fileDirname}/${fileBasenameNoExtension}.ll",
"-disable-output"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "compile-llvm"
}
]
}tasks.json
文件,填写如下内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17{
"version": "2.0.0",
"tasks": [
{
"label": "compile-llvm",
"type": "shell",
"command": "clang",
"args": [
"-g", "-emit-llvm", "-S", "-fno-discard-value-names", "-Xclang", "-disable-O0-optnone", "-c", "-o", "${fileDirname}/${fileBasenameNoExtension}.ll", "${file}"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
调试
因为有设置prelaunch
task,在test
目录下打开一个.c
文件,按下F5即可开始调试当前活动的.c
文件,调试前会自动编译。断点要设置在pass的源码中。
对LLVM的Pass进行调试的vscode配置