简体   繁体   English

调试断言失败

[英]Debug Assertion Failed

I am getting this error with my c++ code: http://imageshack.us/photo/my-images/193/vcerror.png/ 我的C ++代码出现此错误: 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. 我有一个大概的主意,所以我在其中放置了一个断点,但是VC ++如何做断点令人恐惧。 I step-through but it only shows me the code from the C++ files themselves, not my own code. 我逐步介绍了一下,但它只向我显示了C ++文件本身的代码,而不是我自己的代码。

So, I step over and the error shows straight away. 因此,我走过去,错误立即显示出来。

How can I track down this problem? 我如何找到这个问题?

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. 可能是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. 另外,添加“ this”的监视,以便您可以分析字符串的实际大小和容量。

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. 我假设这是一个独立的EXE项目,所有内容都由IDE构建。 If it is not, then make sure the PDB files from each binary produced is in the same directory as the corresponding binary. 如果不是,那么请确保所生成的每个二进制文件的PDB文件与相应的二进制文件位于同一目录中。 Again, if this is a simple EXE project in Visual Studio, this is automatic. 同样,如果这是Visual Studio中的简单EXE项目,则它是自动的。 Just to be sure, make sure you "Clean" your build first, then do a complete rebuild. 只是要确保先确保“清理”您的构建,然后进行完整的重建。 That sometimes fixes debugging kinks. 有时可以解决调试问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM