使用 Visual Studio 2005 进行调试时调用函数?

发布于 2024-07-08 04:37:40 字数 370 浏览 12 评论 0原文

这是我知道可能有可能但我从未成功做到的事情
在VS2005(C++)中,在调试时,能够从我正在调试的代码中调用函数。
在调试复杂的数据结构时,此功能有时是必不可少的,仅使用监视窗口的正常功能无法轻松探索这些数据结构。
监视窗口似乎允许编写函数调用,但每次我尝试它时,它都会给我一个或另一个错误。

错误:找不到符号“func”
错误:参数列表与函数不匹配
错误:成员函数不存在

有人成功地使其正常工作吗? 我在这里缺少什么?

编辑:显然,调用的函数应该是调试器当前作用域中存在的符号。

Here's something I know is probably possible but I've never managed to do
In VS2005(C++), While debugging, to be able to invoke a function from the code which I'm debugging.
This feature is sometimes essential when debugging complex data structures which can't be explored easily using just the normal capabilities of the watch window.
The watch window seem to allow writing function calls but every time I try it it gives me one error or another.

Error: symbol "func" not found
Error: argument list does not match function
Error: member function not present

Did anyone ever succeed in making this work properly?
What am I missing here?

Edit: clearly, the function called should be a symbol that exists in the current scope the debugger is in.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

完美的未来在梦里 2024-07-15 04:37:41

根据我的经验,即时窗口存在一些缺点。 如果类来自不同的 DLL,则无法调用类的成员函数,但会收到误导性的错误消息。 如果同一个 DLL 中有任何内容(例如,通过静态链接所有其他内容),则调用成员是相当可靠的。 但正如其他人提到的,复杂的东西可能有效,也可能无效。

In my experience, there are some shortcomings with the immediate window. You can't call your classes' member functions if the classes come from a different DLL, but get misleading error messages. If anything is in the same DLL (e.g. by statically linking in all other stuff), calling members is fairly reliable. But complex stuff may or may not work, as mentioned by others.

已下线请稍等 2024-07-15 04:37:40

好的,这就是我发现的
CXX0040 表示“C 表达式计算器不支持涉及构造函数调用的隐式转换。
CXX0047 的意思是“只有在参数精确匹配或者不需要构造对象的匹配时才能调用重载函数。

这样组合起来就意味着如果我想调用一个函数任何参数都不应具有隐式转换,并且任何参数都不应需要构造。
在这种情况下,“隐式转换”似乎包括一些琐碎的事情,例如将 'String' 转换为 'const String&'
“构造”似乎包括琐碎的复制构造。 因此,按值传递任何非基本类型的内容都会导致错误。

所以这基本上留下了只接受原始类型或指针的函数。
我刚刚成功地测试了这个理论。

因此,如果您希望能够从监视窗口调用方法,请添加一个仅接受指针和基元的重载,并在监视窗口中适当地传递参数。 要传递不是基元的对象,请传递其地址。

Ok, Here's what I found
CXX0040 means that "The C expression evaluator does not support implicit conversions involving constructor calls."
CXX0047 means that "Overloaded functions can be called only if there is an exact parameter match or a match that does not require the construction of an object."

So combined it means that If I want to call a function none of the arguments should have an implicit conversion and none of the arguments should need a construction.
"implicit conversion" in this context seem to include trivial things like converting 'String' to 'const String&'.
"construction" seem to include trivial copy-construction. so passing by value anything that is not a primitive type will result in an error.

So this basically leaves functions that take only primitive types or pointers.
I have just tested this theory successfully.

So if you want to be able to call a method from the watch window, add an overload which takes only pointers and primitives and in the watch window pass the arguments appropriately. To pass an object that is not a primitive pass its address.

孤芳又自赏 2024-07-15 04:37:40

监视窗口受到当前代码所在上下文的限制,例如,当您的代码进入一个函数并且您尝试访问隐藏在当前函数范围内的另一个函数时,它将无法工作。

如果您在监视窗口中调用函数,请确保该函数在当前范围内可见且可访问。

The watch window is limited by the context wherein your current code is, e.g., when your code enters a function and you try to access another function that is hidden from the scope of your current function, it won't work.

If you invoke a function in the watch window, make sure that it is visible and accessible from the current scope.

国粹 2024-07-15 04:37:40

据我所知,在调试非托管 C++ 时无法从“监视”窗口执行代码。 这确实适用于 C#(可能还有 VB.NET 和托管 C++,但我对此并不乐观)。 它很可能允许它,因为它适用于某些语言,但不适用于其他语言。

To my knowledge, you can't execute code from the Watch window while debugging unmanaged C++. This does work for C# (and probably VB.NET and managed C++, but I'm not positive on that). So likely it allows it because it works for some languages, but not others.

陌路黄昏 2024-07-15 04:37:40

我们发现这种方法的效果非常偶然。 一些非常简单的函数(包括成员函数)可以工作,通常是简单的属性获取器。 其他更复杂的功能不起作用并给出错误。

一直没能搞清楚具体的规则...

We find this works in a very hit and miss manner. Some very simple functions (incl. member functions) work, typically simple property getters. Other more complex functions don't work and give an error.

I've never been able to discern the precise rules ...

起风了 2024-07-15 04:37:40

我还没有测试过这个,但我一直认为这就是立即窗口的用途(执行代码)

Cameron

I haven't tested this, but I always thought that was what the immediate window was for (executing code)

Cameron

旧街凉风 2024-07-15 04:37:40

这就是您想要的“立即”窗口。 并且您只能看到从当前断点所在位置可见的内容。 该类(或全局变量)上的局部变量和函数

It's the "Immediate" window that you want. And you're limited to what's visible from where your current breakpoint is. Local variables, and functions on that class (or globals)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文