调试
🌐 Debugging
rust-lldb
rust-lldb 可用于从调试版本获取 panic 信息。
🌐 rust-lldb can be used to get panic information from debug builds.
启用调试符号:
🌐 Enable debug symbols:
[profile.release]
debug = true
strip = false
panic = "unwind"构建二进制文件:
🌐 Build the binary:
cargo build --release --bin oxlint --features allocator运行二进制文件:
🌐 Run the binary:
rust-lldb -- ./target/release/oxlint启动后,按 r 运行程序。
🌐 Once it launches, press r for running the program.
在 VSCode 中调试 TypeScript
🌐 Debug TypeScript in VSCode
根据他们的调试指南,在 TypeScript 仓库中:
🌐 According to their debugging guide, in the TypeScript repository:
- 将
.vscode/launch.template.json重命名为launch.json - 添加
tests/cases/compiler/foo.ts - 将
"${fileBasenameNoExtension}"改为foo.ts - 在 TypeScript 的源代码中某处设置断点
- 从菜单“运行 - 调试”,或按 F5
- 在调试时,tsc 会在目标测试文件之前评估全局
.d.ts文件 src/compiler/debug.ts的Debug.formatXXX(value)可以用来打印枚举值- 使用“监视”部分来“查看”感兴趣的值
在 VSCode 中调试 Linter
🌐 Debug Linter in VSCode
使用 CodeLLDB 可以很容易地在其他地方调试 npm 项目的 Linter。
🌐 It's easy to debug Linter for a npm project somewhere else with CodeLLDB.
在 .vscode/launch.json 中,根据需要更改配置字段:
🌐 In .vscode/launch.json, change config fields to your need:
cwd:npm 项目的绝对路径args:传递给代码检查器的参数
{
"type": "lldb",
"request": "launch",
"name": "Debug Oxlint",
"cargo": {
"env": {
"RUSTFLAGS": "-g"
},
"args": ["build", "--bin=oxlint", "--package=oxlint"],
"filter": {
"name": "oxlint",
"kind": "bin"
}
},
"cwd": "PATH-TO-TEST-PROJECT",
"args": ["--ARGS-TO-OXLINT"]
}打开 VS Code 调试面板并选择 Debug Oxlint,然后开始调试。
🌐 Open VS Code Debugging panel and select Debug Oxlint, then start debugging.
调试过程将使用指定的 cwd 启动,就像在测试项目中运行代码检查器并将调试器附加到其中一样。
🌐 The debug process will be launched with specified cwd, like running linter in testing project and attaching debugger into it.
