gpt4 book ai didi

.net - 有关调试器使用的调试引擎的信息

转载 作者:行者123 更新时间:2023-12-04 04:35:20 25 4
gpt4 key购买 nike

在Visual Studio中,如果要将调试器附加到任何进程,则可以选择一些特定的引擎(代码类型)或要使用的一组引擎:

接下来(选择任何引擎和进程之后),如果单击“附加”按钮,则将启动调试器附加操作。然后还会触发与调试相关的事件。 IDebugEventCallback2::Event可用于grab这样的事件(例如,提取调试器实际附加到的进程的名称):

public int Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program,
IDebugThread2 thread, IDebugEvent2 debugEvent, ref Guid riidEvent,
uint attributes)
{
if (debugEvent is IDebugProcessCreateEvent2)
{
string processname;
if(process != null)
process.GetName((uint) enum_GETNAME_TYPE.GN_FILENAME, out processname);
//...
}
}

是否有类似的方法来获取有关已选择的引擎的信息?

更新:更加详细的代码:
public class DebugEventsHunter : IVsDebuggerEvents, IDebugEventCallback2
{
private readonly IVsDebugger _debugger;
private uint _cookie;

public DebugEventsHunter(IVsDebugger debugger) { _debugger = debugger; }

public void Start()
{
_debugger.AdviseDebuggerEvents(this, out _cookie);
_debugger.AdviseDebugEventCallback(this);
}

public int Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program,
IDebugThread2 thread, IDebugEvent2 debugEvent, ref Guid riidEvent, uint attributes)
{
if (debugEvent is IDebugProcessCreateEvent2)
{
// get process name (shown before)
}
if (debugEvent is IDebugEngineCreateEvent2)
{
// why execution flow never enters this scope?
IDebugEngine2 e;
((IDebugEngineCreateEvent2)debugEvent).GetEngine(out e);
}
// engine parameter is also always null within this scope
return VSConstants.S_OK;
}

public int OnModeChange(DBGMODE mode) { /*...*/ }
}

和用法:
var debugger = GetService(typeof(SVsShellDebugger)) as IVsDebugger;
var hunter = new DebugEventsHunter(debugger);
hunter.Start();

最佳答案

当调试引擎启动某个进程或将其附加到现有进程时,它将及时发送 IDebugLoadCompleteEvent2 事件。您可以使用此事件来确定要调试的调试引擎的确切位置。

编辑:要确定调试引擎的名称,可以使用上述事件附带的IDebugProgram2实例,并调用 IDebugProgram2.GetEngineInfo 方法。此方法提供调试引擎的名称和ID。请注意,调试引擎的名称可能与您在调试器对话框中看到的名称不匹配,在这种情况下,您将需要使用自己的映射实现将此方法返回的规范名称转换为“友好”名称。

关于.net - 有关调试器使用的调试引擎的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16038814/

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