问题
I have some code in MS VC++ 6.0 that I am debugging. For some reason, at this certain point where I am trying to delete some dynamically allocated memory, it breaks and I get a pop up message box saying "User Breakpoint called from code at blah blah".. then the Disassembly window pops up and I see
*memory address* int 3
The odd thing is, there is NOWHERE in the code that I am calling an assembly instruction like this (I think asm int 3 is a hardware break command for x86?)..
what could be causing this?
EDIT: ANSWER: My code was "walking off the end" of an array, but only in the locations marked by Visual Studio debug with 0xFDFDFDFD, which is called a NoMan'sLand fence.. I think its also called an Off-by-one error.. This array was unrelated to the point where i was freeing the memory when the error was occuring. Which made it harder to spot.. :(
回答1:
You're probably hitting code in the debug heap routines that have found heap corruption.
What does the call stack look like when you've hit the Int 3?
Edit: Based on the stack trace in your comments, the routine _CrtIsValidHeapPointer()
is saying that the pointer being freed is bad. Here's the snippet of code from MSVC's DBGHEAP.C source:
/*
* If this ASSERT fails, a bad pointer has been passed in. It may be
* totally bogus, or it may have been allocated from another heap.
* The pointer MUST come from the 'local' heap.
*/
_ASSERTE(_CrtIsValidHeapPointer(pUserData));
pUserData
would be the value of the pointer you're deleteing.
回答2:
(I think asm int 3 is a hardware break command for x86?
It is. It's called "hardware breakpoint". If you're using the VS debugger with the project source code, it's just like a breakpoint (but in the code). Since vs2005, if your application is launched without any debugger, the application will simply crash, like if it launched an unmanaged exception.
In lot of company, there is a simple macro used to add that breakpoint in the code. That can replace asserts and exceptions in some (hard and rare) cases :
#define BREAKPOINT __asm { int 3; }
BREAKPOINT;
See :
- http://msdn.microsoft.com/en-us/library/45yd4tzz(VS.80).aspx
- http://www.highprogrammer.com/alan/windev/visualstudio.html
So i suggest looking for some Macro or object doing this, or maybe it appen in a module (dll/lib) that you don't have the code of?
来源:https://stackoverflow.com/questions/385370/user-breakpoint-from-nowhere