typescript - 如何使用 DebugSession.customRequest 运行任意 gdb 命令并获取结果

标签 typescript visual-studio-code

我正在使用扩展中的 VSCode 调试 API。我的目标是在调试 session 期间从 gdb/lldb 调试器读取 C++ 程序的 CPU 寄存器。我对当前调试器不提供的其他东西(读取内存、反汇编等)也有类似的要求

我的扩展中有以下内容...如果需要,我可以提供完整的测试用例。是的,我知道我这里有一个错误,在第一次等待之后, session 可能不再处于事件状态并且我没有显示完整的错误检查。

static async getRegisters() {
    const session = vscode.debug.activeDebugSession;
    if (session && text) {      // Make sure we still have a session
        // The following gets me the right result
        const sTrace = await session.customRequest('stackTrace', { threadId: 1 });
        const frameId = sTrace.stackFrames[0].id; 

        // The following does execute but the results are printed to debug console
        // rather than returning the result
        // I tried many variations of arguments and contexts types
        const text = '-exec -data-list-register-names';
        const arg : DebugProtocol.EvaluateArguments = {expression: text, frameId: frameId, context:'hover'};
        session.customRequest('evaluate', arg).then((response) => {
            console.log(response.result); 
        });
    }
}

我希望以某种方式将 gdb 的结果提供回我的扩展。结果被打印到调试控制台,我得到一个空字符串。我还尝试为自定义命令设置事件处理程序 vscode.debug.onDidReceiveDebugSessionCustomEvent 但没有触发。有没有更好的办法?

也许 customRequest 的第一个参数不应该是 'evaluate' 但我在 DebugProtocol spec. 中没有看到任何其他内容将自定义命令发送到实际的调试器。

最佳答案

同样的问题!这是我的解决方案:

  1. 注册一个“DebugAdapterTracker”(相信你已经知道了);
  2. 在跟踪器的“onDidSendMessage(message: any)”中,注意“事件”消息,尤其是当“message.event === “output””时;
  3. 检查“message.body.output”,惊喜!

似乎 DA 没有使用适当的值进行响应,而是直接触发了一个事件以在调试控制台上打印。

关于typescript - 如何使用 DebugSession.customRequest 运行任意 gdb 命令并获取结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55316561/

相关文章:

reactjs - 无法在 Typescript : JSX Element type does not have any construct or call signatures 中编写高阶组件

Typescript 根据是否存在变量更改返回值的类型推断

javascript - 找不到名称 'ReadableStream'(简单 git, Node )

typescript - VS 代码和增量 Typescript 编译

c# - 仅在 Visual Studio Code 中出现编译错误

python - 有时忽略 pylint(import-error) 是最好的解决方案?

flutter - 在vscode中使用fvm更改flutter版本,但flutter版本不起作用?

angular - RxJS 订阅内部订阅,并在错误时执行操作

asp.net - DNU 在 OSX Yosemite 上恢复未知 header

visual-studio-code - 我什么时候想在 WSL2 :Ubuntu vs VsCode Windows? 中安装 VSCode 扩展