Debugger 对象用于询问和操作调试器和正在调试的程序的状态。
命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)
语法
声明
<GuidAttribute("338FB9A0-BAE5-11D2-8AD1-00C04F79E479")> _
Public Interface Debugger
[GuidAttribute("338FB9A0-BAE5-11D2-8AD1-00C04F79E479")]
public interface Debugger
[GuidAttribute(L"338FB9A0-BAE5-11D2-8AD1-00C04F79E479")]
public interface class Debugger
[<GuidAttribute("338FB9A0-BAE5-11D2-8AD1-00C04F79E479")>]
type Debugger =  interface end
public interface Debugger
Debugger 类型公开以下成员。
属性
| 名称 | 说明 | |
|---|---|---|
| .gif) | AllBreakpointsLastHit | 获取最后同时命中的绑定断点的集合。 | 
| .gif) | BreakpointLastHit | 获取最后命中的断点。 | 
| .gif) | Breakpoints | 获取断点的集合。 | 
| .gif) | CurrentMode | 获取集成开发环境 (IDE) 上下文中调试器的当前模式。 | 
| .gif) | CurrentProcess | 设置或获取活动进程。 | 
| .gif) | CurrentProgram | 设置或获取活动程序。 | 
| .gif) | CurrentStackFrame | 设置或获取当前堆栈帧。 | 
| .gif) | CurrentThread | 设置或获取正在调试的当前线程。 | 
| .gif) | DebuggedProcesses | 获取当前正在调试的进程的列表。 | 
| .gif) | DTE | 获取顶级扩展性对象。 | 
| .gif) | HexDisplayMode | 获取或设置是以十六进制还是以十进制格式输出表达式。 | 
| .gif) | HexInputMode | 获取或设置是以十六进制还是以十进制格式计算表达式。 | 
| .gif) | Languages | 获取调试器所支持的语言的列表。 | 
| .gif) | LastBreakReason | 获取程序中断的最终原因。如果程序正在运行,它将返回 DBG_REASON_NONE。 | 
| .gif) | LocalProcesses | 获取该计算机上当前正在运行的进程列表。 | 
| .gif) | Parent | 获取 Debugger 对象的直接父对象。 | 
页首
方法
| 名称 | 说明 | |
|---|---|---|
| .gif) | Break | 使给定进程暂停执行以便可以分析其当前状态。 | 
| .gif) | DetachAll | 从所有附加程序分离出来。 | 
| .gif) | ExecuteStatement | 执行指定的语句。如果 TreatAsExpression 标志为 true,则将字符串解释为表达式,然后向“命令”窗口发送输出。 | 
| .gif) | GetExpression | 根据当前的堆栈帧计算表达式。如果表达式可以进行分析但无法计算,则将返回不包含有效值的对象。 | 
| .gif) | Go | 从当前语句开始执行程序。 | 
| .gif) | RunToCursor | 执行程序直至源文件光标的当前位置。 | 
| .gif) | SetNextStatement | 根据当前源文件中的光标位置设置要执行的下一个指令。 | 
| .gif) | StepInto | 如果可能,单步执行下一个函数调用。 | 
| .gif) | StepOut | 跳出当前函数。 | 
| .gif) | StepOver | 转到下一个函数调用。 | 
| .gif) | Stop | 停止调试、终止或与所有附加进程分离。 | 
| .gif) | TerminateAll | 终止所有进程。 | 
页首
备注
调试器可通过 DTE 对象的 Debugger 属性获得,如下例所示。 对于开发环境的每个实例,均有一个调试器对象可用。
示例
下面的示例演示如何使用调试器对象。
Imports EnvDTE
Imports System.Diagnostics
Public Module Module1
    ' This function returns true if the debugger is actively debugging.
    Function IsDebugging() As Boolean
        Dim debugger As EnvDTE.Debugger
        debugger = DTE.Debugger
        If (debugger Is Nothing) Then
            MsgBox("Debugger doesn't exist! Fatal error.")
            IsDebugging = false
        Else
            IsDebugging = (debugger.CurrentMode <> dbgDebugMode.dbgDesignMode)
        End If
    End Function
End Module
// The following small C++ program can be run from the command line.
// It detects whether an instance of Visual Studio is currently 
// running,and if so, prints a message stating whether its debugger
// is actively debugging.
#include <stdio.h>
#import "dte.olb" raw_interfaces_only named_guids
using namespace EnvDTE;
int main(void)
{
    int nRet = 0;
    CoInitialize(NULL);
    IUnknownPtr pUnk;
    GetActiveObject(CLSID_DTE, NULL, &pUnk);
    if (pUnk == NULL) {
        printf ("No instance of Visual Studio is running.\n");
    }
    else {
        _DTEPtr pDTE = pUnk;
        if (pDTE) {
            DebuggerPtr pDebugger;
            if (SUCCEEDED(pDTE->get_Debugger(&pDebugger)) && pDebugger != NULL){
                dbgDebugMode mode;
                if (SUCCEEDED(pDebugger->get_CurrentMode(&mode))) {
                    if (mode != dbgDesignMode) {
                        printf("Debugger is active.\n");
                        nRet = 1;
                    }
                    else {
                        printf("Debugger is not active.\n");
                    }
                }
            }
        }
    }
    CoUninitialize();
    return nRet;
}