Visual Studio 调试器中的伪变量Pseudovariables in the Visual Studio debugger

伪变量是用于在变量窗口或“快速监视”对话框中显示某些信息的术语。Pseudovariables are terms used to display certain information in a variable window or the QuickWatch dialog box. 你可以像输入普通变量那样输入伪变量。You can enter a pseudovariable the same way you would enter a normal variable. 但伪变量不是变量,它不与程序中的变量名相对应。Pseudovariables are not variables, however, and do not correspond to variable names in your program.

示例Example

假设你在编写本机代码应用程序,并且希望看到此应用程序中分配的句柄数。Suppose you are writing a native code application and want to see the number of handles allocated in your application. 可以在“监视”窗口的“名称”列中输入以下伪变量,然后按“返回”计算它 :In the Watch window, you can enter the following pseudovariable in the Name column, then press Return to evaluate it:

$handles

在本机代码中,可使用的伪变量如下表所示:In native code, you can use the pseudovariables shown in the following table:

伪变量Pseudovariable 函数Function
$err 显示函数 SetLastError 设置的上一个错误值。Displays the last error value set with the function SetLastError. 显示的值代表将由 GetLastError 函数返回的值。The value that is displayed represents what would be returned by the GetLastError function.

使用 $err,hr 查看此值的已解码形式。Use $err,hr to see the decoded form of this value. 例如,如果上一个错误是 3,则 $err,hr 将显示 ERROR_PATH_NOT_FOUND : The system cannot find the path specified.For example, if the last error was 3, the $err,hr would display ERROR_PATH_NOT_FOUND : The system cannot find the path specified.
$handles 显示应用程序中分配的句柄数。Displays the number of handles allocated in your application.
$vframe 显示当前堆栈帧的地址。Displays the address of the current stack frame.
$tid 显示当前线程的线程 ID。Displays the thread ID for the current thread.
$env 在字符串查看器中显示环境块。Displays the environment block in the string viewer.
$cmdline 显示已启动程序的命令行字符串。Displays the command line string that launched the program.
$pid 显示进程 ID。Displays the process ID.
$ registername$ registername

oror

@ registername@ registername
显示寄存器“registerName”的内容。Displays the contents of the register registername.

通常,只需输入寄存器名便可以显示寄存器的内容。Normally, you can display register contents just by entering the register name. 仅在寄存器名重载变量名时才需要使用此语法。The only time you need to use this syntax is when the register name overloads a variable name. 如果寄存器名与当前范围内的某个变量名同名,则调试器将该名称解释为变量名。If the register name is the same as a variable name in the current scope, the debugger interprets the name as a variable name. 这时就需要使用 $ registername 或 @ registername 寄存器名 。That's when $registername or @registername comes in handy.
$clk 以时钟形式显示时间。Displays the time in clock cycles.
$user 显示一个结构,在该结构中含有应用程序运行于的帐户的帐户信息。Displays a structure with account information for the account running the application. 出于安全原因,将不显示密码信息。For security reasons, the password information is not displayed.
$exceptionstack 显示当前 Windows 运行时异常的堆栈跟踪。Displays the stack trace of the current Windows Runtime exception. $ exceptionstack 仅适用于 UWP 应用。$ exceptionstack works only in UWP apps. C++ 异常和 SEH 异常不支持 $ exceptionstack$ exceptionstack is not supported for C++ and SEH exceptions
$returnvalue 显示方法的返回值。Displays the return value of a method.

在 C# 中,可使用的伪变量如下表所示:In C# you can use the pseudovariables shown in the following table:

伪变量Pseudovariable 函数Function
$exception 显示有关上一个异常的信息。Displays information on the last exception. 如果没有发生异常,则计算 $exception 将显示错误消息。If no exception has occurred, evaluating $exception displays an error message.

当“异常助手”处于禁用状态时,如果发生异常,$exception 将自动添加到“局部变量”窗口中。When the Exception Assistant is disabled, $exception is automatically added to the Locals window when an exception occurs.
$user 显示一个结构,在该结构中含有应用程序运行于的帐户的帐户信息。Displays a structure with account information for the account running the application. 出于安全原因,将不显示密码信息。For security reasons, the password information is not displayed.
$returnvalue 显示 .NET 方法的返回值。Displays the return value of a .NET method.

在 Visual Basic 中,可使用的伪变量如下表所示:In Visual Basic, you can use the pseudovariables shown in the following table:

伪变量Pseudovariable 函数Function
$exception 显示有关上一个异常的信息。Displays information on the last exception. 如果没有发生异常,则计算 $exception 将显示错误消息。If no exception has occurred, evaluating $exception displays an error message.
$delete$$delete$delete or $$delete 删除已在“即时”窗口中创建的隐式变量。Deletes an implicit variable that was created in the Immediate window. 语法是 $delete, 变量或 $delete, 变量.The syntax is $delete, variable or$delete, variable.
$objectids$listobjectids$objectids or $listobjectids 将所有活动对象 ID 显示为指定的表达式的子级。Displays all active Object IDs as children of the specified expression. 语法是 $objectid, 表达式或 $listobjectids, 表达式.The syntax is $objectid, expression or$listobjectids, expression.
$ N #$ N # 显示对象 ID 等于 N 的对象。Displays object with Object ID equal to N.
$dynamic 显示这两个特殊“动态视图”实现 IDynamicMetaObjectProvider 的对象的节点。Displays the special Dynamic View node for an object that implements the IDynamicMetaObjectProvider. 接口。Interface. 语法是 $dynamic, 对象。The syntax is $dynamic, object. 此功能仅应用于使用 .NET Framework 版本 4 或更高版本的代码。This feature applies only to code that uses .NET Framework version 4 or later.

请参阅See also