如何在VSCode的launch.json配置中执行带管道输出的命令
你的推测完全正确,VSCode 启动配置中的 args 数组会将所有元素直接作为参数传递给 program 指定的可执行文件,而管道符 | 是 Shell 提供的语法能力,不属于程序参数范畴,因此直接写在 args 中会被 llc 识别为非法参数。
以下是两种适用不同场景的解决方案:
场景1:不需要调试 llc,仅需运行整条管道命令
直接将启动的目标程序指定为你使用的 Shell,把整条管道命令作为 Shell 的执行参数传入即可。
类 Unix 系统(macOS/Linux)配置示例:
{ "name": "Test LLC", "type": "lldb", "request": "launch", "program": "/bin/bash", "cwd": "${fileDirname}", "args": ["-c", "path_to_bin/llc -march=arch1 -mcpu=abc ${file} | prog2 -arg2 val2"] }
Windows 系统配置示例:
如果使用 Cmd:
{ "name": "Test LLC", "type": "lldb", "request": "launch", "program": "cmd.exe", "cwd": "${fileDirname}", "args": ["/c", "path_to_bin/llc -march=arch1 -mcpu=abc ${file} | prog2 -arg2 val2"] }
如果使用 PowerShell:
{ "name": "Test LLC", "type": "lldb", "request": "launch", "program": "powershell.exe", "cwd": "${fileDirname}", "args": ["-Command", "path_to_bin/llc -march=arch1 -mcpu=abc ${file} | prog2 -arg2 val2"] }
场景2:需要调试 llc,同时保留管道输出到 prog2 的逻辑
上述方案调试的目标是 Shell 而非 llc,如果你需要正常调试 llc 的代码,可以通过 lldb 的 runCommands 配置项,指定进程启动时的输出管道规则:
{ "name": "Test LLC (Debug llc)", "type": "lldb", "request": "launch", "program": "path_to_bin/llc", "cwd": "${fileDirname}", "args": ["-march=arch1","-mcpu=abc","${file}"], "runCommands": ["process launch -o | prog2 -arg2 val2"] }
该配置会让 lldb 在启动 llc 进程时直接将标准输出通过管道传递给 prog2,不影响你对 llc 加断点、单步调试等操作。
内容的提问来源于stack exchange,提问作者Darshan Bhat
相关产品推荐
相关产品推荐

