调试而暂停和'无法评估EX pression“ [英] Debugging whilst paused and 'cannot evaluate expression'

查看:232
本文介绍了调试而暂停和'无法评估EX pression“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Visual Studio,连接到一个流程和pressing暂停后(打和所有),切换到所需的线程,并使用快速监视窗口来检查了一些数据,说

Using Visual Studio, after attaching to a Process and pressing Pause (Break-All), you switch to the desired thread and use the Quick Watch window to check out some data, say

MySingletonClass.Instance.Data

有时候,我要么得到这样的:

Sometimes I either get this:

无法计算EX pression因为当前线程处于休眠,等待,或加入

Cannot evaluate expression because the current thread is in a sleep, wait, or join

或本(试图查看数据的某些属性时):

or this (when trying to view certain properties of the data):

无法计算EX pression,因为本机框架是在调用堆栈的顶部。

Cannot evaluate expression because a native frame is on top of the call stack.

坦率地说,我不在乎,我只是想看到的数据!我知道有很多不同的方法来解决这个问题,即:

Quite frankly, I don't care, I just want to see the data! I know there are various ways to get around this, namely:

  1. 设置断点的线程和等待,直到它被击中(繁琐,并不总是可能的)
  2. 在服用过程中的转储和装载回VS(即使这样,我仍然得到第二误差)
  3. 的WinDbg

由于您的可以的看到,如果你presumably使用WinDbg的为什么是我们都不能走的更容易和prettier VS优势附加到时候检查对象这个数据一个进程?

Given you could see this data if you presumably used windbg why is it we all can't take advantage of the much easier and prettier VS to inspect objects when attaching to a process?

推荐答案

为什么我们不能做到这一点?:我们不能这样做,因为Visual Studio的监视窗口不只是检索数据从存储器并显示它。实际上,它的执行管理code 的(这就是它所说的评估EX pression)。特别是,它几乎总是执行的ToString()的方法来显示用户可读的结果。

Why can’t we do this? We can’t do this because the Visual Studio watch window doesn’t just retrieve data from memory and display it. It actually executes managed code (that’s what it means by "evaluate the expression"). In particular, it almost always executes the ToString() method to display the user-readable result.

的关键在于,它执行该code的的过程中/线程正在调试的。这确保了前pression评估会,如果它实际上是在code,你正在调试的方式相同。这使得它只能管理指令的执行在下行,但不同时原生code是积极的,而不是在一个阻塞的线程。

The crux is that it executes this code within the process/thread you are debugging. This ensures that the expression evaluates the same way it would if it were actually in the code you are debugging. This leaves the downside that it can only be executed in between managed instructions, but not while native code is active, and not in a blocked thread.

我们可以做些什么呢?如果你实际上是调试托管应用程序,而你是在本地的StackFrame,只需preSS F10或Shift + F11,直到你回来管理code。然后,你可以评估EX pressions。然而,对于全本机进程,并为处于阻塞状态的线程,我不知道有任何变通办法。

What can we do about it? If you are actually debugging a managed application, and you are in a native stackframe, just press F10 or Shift+F11 repeatedly until you are back in managed code. Then you can evaluate expressions. However, for fully-native processes, and for threads in a blocked state, I am not aware of any workaround.

这篇关于调试而暂停和'无法评估EX pression“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆