调试断言失败

发布于 2024-12-02 13:01:05 字数 365 浏览 1 评论 0原文

我的 C++ 代码出现此错误: http://imageshack.us/photo/my-images/193/vcerror。 png/

唯一的问题是它没有指出问题出在哪里...我知道字符串下标超出了范围,但我不知道它可能在哪里。

我想知道我是否能找到它在哪里?我有一个粗略的想法,所以我在那里放置了一个断点,但是 VC++ 如何设置断点是可怕的。我单步执行,但它只向我显示 C++ 文件本身的代码,而不是我自己的代码。

所以,我跨过去,错误立即显示出来。

我怎样才能找到这个问题?

I am getting this error with my c++ code:
http://imageshack.us/photo/my-images/193/vcerror.png/

The only problem is it doesn't point me to where the problem is... I understand the string subscript is out of range but I have no idea where it could be.

I was wondering if there is anyway I am able to find where it is? I have a rough idea so I have put a breakpoint in there but how VC++ does breakpoints is horrible. I step-through but it only shows me the code from the C++ files themselves, not my own code.

So, I step over and the error shows straight away.

How can I track down this problem?

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

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

发布评论

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

评论(1

夏雨凉 2024-12-09 13:01:05

基本上,您需要查看调用堆栈并设置所有符号。

我将进行大胆猜测并建议您可能不知道如何使用“调用堆栈”窗口。

在程序的调试会话中且未设置断点时,允许程序运行直到遇到断言对话框。按“重试”以允许将控制权传递给调试器。可能会弹出另一个对话框,提示您“中断”或“继续”。选择休息。此时您应该进入调试器。

然后确保您可以看到调用堆栈并且至少有一个监视窗口。

Debug->Windows->Call Stack.
Debug->Windows->Watch->Watch 1

您可以双击调用堆栈窗口中的任何项目,以跳转到执行预期返回的确切代码行。 (有时编辑器窗口上的小箭头指向上一个调用返回后要运行的下一行代码)。双击位于顶部调用堆栈行正下方的调用堆栈窗口中的函数行。这可能是 std::basic_string::operator。传递给该函数的值是什么?如果将鼠标悬停在变量名称上不起作用,请将其添加到“监视”窗口。另外,添加“this”的监视,以便您可以分析字符串的实际大小和容量。

双击当前所在调用堆栈中的函数调用。这应该将您带到程序中实际有错误的代码行。为字符串变量添加另一个监视,应该能够找出问题所在。

剩下的就取决于你了。

我假设这是一个独立的 EXE 项目,所有内容均由 IDE 构建。如果不是,请确保生成的每个二进制文件中的 PDB 文件与相应的二进制文件位于同一目录中。同样,如果这是 Visual Studio 中的简单 EXE 项目,则这是自动的。可以肯定的是,请确保首先“清理”您的构建,然后进行完整的重建。这有时可以解决调试问题。

Basically, you need to look at the callstack and have all your symbols setup.

I'm going to take a wild guess and suggest that you may not know how to use the "call stack" window.

In a debug session of your program and no breakpoints set, allow your program to run until it hits the assert dialog. Press "retry" to allow control to be passed to the debugger. Another dialog may pop up to prompt you to "break" or "continue". Select break. You should be broken into the debugger at this point.

Then make sure you can see the call stack and have at least one watch window up.

Debug->Windows->Call Stack.
Debug->Windows->Watch->Watch 1

You can double-click on any item in the call stack window to jump to the exact line of code where execution is expected to return to. (Sometimes the little arrow on the editor window is pointing to the next line of code to run after the previous call returns). Double click on the function line in the call-stack window that is directly below the top call stack line. That's likely std::basic_string::operator. What value is getting passed into this function? If hovering over the variable name doesn't work, add it to the "Watch" window. Also, add a watch for "this" so you can analyze the actual size and capacity of the string.

Double click on the function call in the call-stack below where you are currently at. This should take you to the actual buggy line of code in your program. Add another watch for the string variable and should be able to figure out what went wrong.

The rest is up to you.

I'm assuming this is a standalone EXE project with everything build by the IDE. If it is not, then make sure the PDB files from each binary produced is in the same directory as the corresponding binary. Again, if this is a simple EXE project in Visual Studio, this is automatic. Just to be sure, make sure you "Clean" your build first, then do a complete rebuild. That sometimes fixes debugging kinks.

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