【发布时间】:2020-05-24 20:13:26
【问题描述】:
我正在尝试编写 WinDbg 扩展命令并遇到一些问题。我从this 项目开始,并尝试对其进行修改以在调试器中提供自定义命令。
但是,当我运行 TestCommand 时,出现以下错误。
The command was: !TestCommand this is a test0:000> !TestCommand this is a test
No export TestCommand found
我拥有的完整代码如下。我尝试将 [Export] 修饰符添加到 TestCommand 函数,但这并没有纠正这种情况。如何让 WinDbg 识别命令?
完整的扩展代码:
using System.ComponentModel.Composition;
using DbgX.Interfaces;
using DbgX.Interfaces.Enums;
using DbgX.Interfaces.Listeners;
using DbgX.Interfaces.Services;
using DbgX.Util;
namespace WinDbgExt.LoadSos
{
[Export(typeof(IDbgCommandExecutionListener))]
[Export(typeof(IDbgStartupListener))]
public class ToggleSosViewModel : IDbgCommandExecutionListener, IDbgStartupListener
{
private bool _engineLoaded;
[Import]
private IDbgConsole _console;
[Import]
private IDbgEngineState _engineState;
public void OnCommandExecuted(string command)
{
if (command.StartsWith("!TestCommand"))
{
TstCommand(command);
}
}
public void TestCommand(string command)
{
_console.PrintTextToConsole("The command was: " + command);
}
public void OnStartup()
{
}
}
}
作为一个额外的问题,我需要获得 WinDbg 所附加的进程的句柄。有没有一种简单的方法可以将它添加到上述扩展中?
【问题讨论】: