在Visual Studio调试器中查看命名空间的全局变量? [英] Viewing namespaced global variables in Visual Studio debugger?

查看:227
本文介绍了在Visual Studio调试器中查看命名空间的全局变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio 2008中调试非托管C ++项目时,我偶尔想看到一个全局变量的值。我们没有很多这些,但那些在那里的那些都被称为全球的命名空间。例如

When debugging a non-managed C++ project in Visual Studio 2008, I occasionally want to see the value of a global variable. We don't have a lot of these but those that are there all declared within a namespace called 'global'. e.g.

namespace global
{
  int foo;
  bool bar;

  ...
}

问题是,代码在断点处停止,默认调试工具提示(指向变量名称)和quickwatch(变量名称上的shift-f9)不考虑命名空间,因此不起作用。

The problem is that when the code is stopped at a breakpoint, the default debugging tooltip (from pointing at the variable name) and quickwatch (shift-f9 on the variable name) don't take the namespace into consideration and hence won't work.

所以例如我可以指向'foo',没有任何东西出现。如果我在foo上shift-f9,它会弹出快速表,然后说'CXX0017:Error:symbolfoonot found'。我可以通过手动编辑quickwatch窗口中的变量名称来将其改为global ::(这是很麻烦的,考虑到你每次想要快速查看都要做),但是没有修复工具提示我可以锻炼出来设置项目属性的默认命名空间并不起作用。

So for example I can point at 'foo' and nothing comes up. If I shift-f9 on foo, it will bring up the quickwatch, which then says 'CXX0017: Error: symbol "foo" not found'. I can get around that by manually editing the variable name in the quickwatch window to prefix it with "global::" (which is cumbersome considering you have to do it each time you want to quickwatch), but there is no fix for the tooltip that I can work out. Setting the 'default namespace' of the project properties doesn't help.

如何让VS调试器使用它已经知道变量被声明的命名空间(因为它有声明在那里),或者,或者,告诉它一个默认命名空间来寻找变量,如果它没有找到它们

How can I tell the VS debugger to use the namespace that it already knows the variable is declared in (since it has the declaration right there), or, alternatively, tell it a default namespace to look for variables in if it doesn't find them?

我的谷歌 - fu没有找到答案。 此报告列出了同样的问题,MS说它是设计,但即使如此,我希望有一些办法解决它(可能巧妙地使用autoexp.dat?)

My google-fu has failed to find an answer. This report lists the same problem, with MS saying it's "by design", but even so I am hoping there is some way to work around it (perhaps with clever use of autoexp.dat?)

推荐答案

使用源中的命名空间的全名解决了它。

Using the full name including the namespace in the source solved it for me.

eg:write

global::bar = (global::foo==0)

而不是

bar = (foo==0)

这篇关于在Visual Studio调试器中查看命名空间的全局变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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