gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 01:41:01 29 4
gpt4 key购买 nike

我正在使用扩展中的 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com