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.
这里我知道的可能是可能的,但我从来没有设法在VS2005(C ++)中,在调试时,能够从我正在调试的代码中调用一个函数。在调试复杂数据结构时,此功能有时是必不可少的,这些数据结构只能使用监视窗口的常规功能轻松探索。监视窗口似乎允许编写函数调用,但每次我尝试它时都会给我一个错误或另一个错误。
Error: symbol "func" not found
Error: argument list does not match function
Error: member function not present
错误:未找到符号“func”错误:参数列表与函数不匹配错误:成员函数不存在
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.
编辑:显然,调用的函数应该是调试器所在的当前范围中存在的符号。
7 个解决方案
#1
11
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.
"
好的,这就是我发现的CXX0040意味着“C表达式求值程序不支持涉及构造函数调用的隐式转换。” CXX0047意味着“仅当存在精确的参数匹配或不需要构造对象的匹配时,才能调用重载函数。”
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.
因此组合它意味着如果我想调用一个函数,那么参数都不应该有隐式转换,并且所有参数都不需要构造。在这种情况下,“隐式转换”似乎包括将'String'转换为'const String&'等微不足道的事情。 “建筑”似乎包括琐碎的复制结构。所以通过值传递任何非原始类型的东西都会导致错误。
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.
因此,如果您希望能够从监视窗口调用方法,请添加一个只接受指针和基元的重载,并在监视窗口中相应地传递参数。传递非原始对象传递其地址。
#2
0
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.
如果在监视窗口中调用某个函数,请确保它在当前作用域中可见且可访问。
#3
0
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.
据我所知,在调试非托管C ++时,您无法从Watch窗口执行代码。这适用于C#(可能还有VB.NET和托管C ++,但我对此并不乐观)。很可能它允许它,因为它适用于某些语言,但不适用于其他语言。
#4
0
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.
我们发现这种方式非常受欢迎。一些非常简单的函数(包括成员函数)工作,通常是简单的属性getter。其他更复杂的功能不起作用并产生错误。
I've never been able to discern the precise rules ...
我从来没有能够辨别出精确的规则......
#5
0
I haven't tested this, but I always thought that was what the immediate window was for (executing code)
我没有对此进行测试,但我一直认为这就是即时窗口(执行代码)
Cameron
#6
0
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)
这是你想要的“立即”窗口。而且你只能看到当前断点所在的位置。局部变量和该类(或全局变量)上的函数
#7
0
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.
根据我的经验,即时窗口存在一些缺点。如果类来自不同的DLL,则无法调用类的成员函数,但会收到误导性的错误消息。如果任何东西在同一个DLL中(例如通过静态链接所有其他东西),调用成员是相当可靠的。但其他人提到,复杂的东西可能会或可能不会起作用。
#1
11
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.
"
好的,这就是我发现的CXX0040意味着“C表达式求值程序不支持涉及构造函数调用的隐式转换。” CXX0047意味着“仅当存在精确的参数匹配或不需要构造对象的匹配时,才能调用重载函数。”
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.
因此组合它意味着如果我想调用一个函数,那么参数都不应该有隐式转换,并且所有参数都不需要构造。在这种情况下,“隐式转换”似乎包括将'String'转换为'const String&'等微不足道的事情。 “建筑”似乎包括琐碎的复制结构。所以通过值传递任何非原始类型的东西都会导致错误。
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.
因此,如果您希望能够从监视窗口调用方法,请添加一个只接受指针和基元的重载,并在监视窗口中相应地传递参数。传递非原始对象传递其地址。
#2
0
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.
如果在监视窗口中调用某个函数,请确保它在当前作用域中可见且可访问。
#3
0
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.
据我所知,在调试非托管C ++时,您无法从Watch窗口执行代码。这适用于C#(可能还有VB.NET和托管C ++,但我对此并不乐观)。很可能它允许它,因为它适用于某些语言,但不适用于其他语言。
#4
0
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.
我们发现这种方式非常受欢迎。一些非常简单的函数(包括成员函数)工作,通常是简单的属性getter。其他更复杂的功能不起作用并产生错误。
I've never been able to discern the precise rules ...
我从来没有能够辨别出精确的规则......
#5
0
I haven't tested this, but I always thought that was what the immediate window was for (executing code)
我没有对此进行测试,但我一直认为这就是即时窗口(执行代码)
Cameron
#6
0
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)
这是你想要的“立即”窗口。而且你只能看到当前断点所在的位置。局部变量和该类(或全局变量)上的函数
#7
0
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.
根据我的经验,即时窗口存在一些缺点。如果类来自不同的DLL,则无法调用类的成员函数,但会收到误导性的错误消息。如果任何东西在同一个DLL中(例如通过静态链接所有其他东西),调用成员是相当可靠的。但其他人提到,复杂的东西可能会或可能不会起作用。