Windows 已在 Simulator.exe 中触发一个断点。

wanglian0406 2012-08-30 08:28:15
VS2005调试程序,如下:
/***
*malloc.c - Get a block of memory from the heap
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* Defines the malloc() function.
*
*******************************************************************************/

#include <cruntime.h>
#include <malloc.h>
#include <internal.h>
#include <mtdll.h>
#include <dbgint.h>
#include <rterr.h>

#include <windows.h>
#include <winheap.h>
#include <rtcsup.h>

extern int _newmode; /* malloc new() handler mode */

#ifndef _WIN64

void *V6_HeapAlloc(size_t size)
{
void *pvReturn = NULL;
if ( size <= __sbh_threshold )
{
_mlock( _HEAP_LOCK );
__try {
pvReturn = __sbh_alloc_block((int)size);
}
__finally {
_munlock( _HEAP_LOCK );
}
}
return pvReturn;
}

#ifdef CRTDLL
void *V5_HeapAlloc(size_t size)
{
void * pvReturn = NULL;

/* round up to the nearest paragraph */
if ( size ) {
size = (size + _OLD_PARASIZE - 1) & ~(_OLD_PARASIZE - 1);
} else {
size = _OLD_PARASIZE;
}

if ( size <= __old_sbh_threshold ) {
_mlock(_HEAP_LOCK);
__try {
pvReturn = __old_sbh_alloc_block(size >> _OLD_PARASHIFT);
}
__finally {
_munlock(_HEAP_LOCK);
}
}
return pvReturn;
}
#endif /* CRTDLL */
#endif /* _WIN64 */

#ifdef _DEBUG
#define _heap_alloc _heap_alloc_base
#endif /* _DEBUG */

/***
*void *_heap_alloc_base(size_t size) - does actual allocation
*
*Purpose:
* Same as malloc() except the new handler is not called.
*
*Entry:
* See malloc
*
*Exit:
* See malloc
*
*Exceptions:
*
*******************************************************************************/

__forceinline void * __cdecl _heap_alloc (size_t size)

{
#ifndef _WIN64
void *pvReturn;
#endif /* _WIN64 */

if (_crtheap == 0) {
_FF_MSGBANNER(); /* write run-time error banner */
_NMSG_WRITE(_RT_CRT_NOTINIT); /* write message */
__crtExitProcess(255); /* normally _exit(255) */
}

#ifdef _WIN64
return HeapAlloc(_crtheap, 0, size ? size : 1);
#else /* _WIN64 */
if (__active_heap == __SYSTEM_HEAP) {
return HeapAlloc(_crtheap, 0, size ? size : 1);
} else
if ( __active_heap == __V6_HEAP ) {
if (pvReturn = V6_HeapAlloc(size)) {
return pvReturn;
}
}
//#endif /* _WIN64 */
#ifdef CRTDLL
else if ( __active_heap == __V5_HEAP )
{
if (pvReturn = V5_HeapAlloc(size)) {
return pvReturn;
}
}
#endif /* CRTDLL */

if (size == 0)
size = 1;

size = (size + BYTES_PER_PARA - 1) & ~(BYTES_PER_PARA - 1);

return HeapAlloc(_crtheap, 0, size);

#endif /* _WIN64 */
}


/***
*void *malloc(size_t size) - Get a block of memory from the heap
*
*Purpose:
* Allocate of block of memory of at least size bytes from the heap and
* return a pointer to it.
*
* Calls the new appropriate new handler (if installed).
*
*Entry:
* size_t size - size of block requested
*
*Exit:
* Success: Pointer to memory block
* Failure: NULL (or some error value)
*
*Uses:
*
*Exceptions:
*
*******************************************************************************/

void * __cdecl _malloc_base (size_t size)
{
void *res = NULL;

// validate size
if (size <= _HEAP_MAXREQ) {
for (;;) {

// allocate memory block
res = _heap_alloc(size);

// if successful allocation, return pointer to memory
// if new handling turned off altogether, return NULL

if (res != NULL)
{
break;
}
if (_newmode == 0)
{
errno = ENOMEM;
break;
}

// call installed new handler
if (!_callnewh(size))
break;

// new handler was successful -- try to allocate again
}
} else {
_callnewh(size);
errno = ENOMEM;
return NULL;
}

RTCCALLBACK(_RTC_Allocate_hook, (res, size, 0));
if (res == NULL)
{
errno = ENOMEM;
}
return res;
}

########mallc.c文件
调试出现
Windows 已在 Simulator.exe 中触发一个断点。

其原因可能是堆被损坏,这也说明 Simulator.exe 中或它所加载的任何 DLL 中有 bug。

输出窗口可能提供了更多诊断信息

在下一步就出现如下:
Simulator.exe 中的 0x78247151 (mfc80d.dll) 处未处理的异常: 0xC0000005: 读取位置 0xf78dd810 时发生访问冲突

求解!!!!!!!!
...全文
363 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-12-12
  • 打赏
  • 举报
回复
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处,看不懂时双击下一行,直到能看懂为止。
luciferisnotsatan 2014-12-12
  • 打赏
  • 举报
回复
引用 3 楼 wanglian0406 的回复:
以下是我用vs2005调试出现的问题 请各位多多指教,问题怎么会出在vs2005文件夹内自带的malloc.c函数里面!!
看你这错误,十有八九是这样子的情况 class A { public: void fun(int x){ m_b = x;} private: int m_a; int m_b; } void main() { A *p = NULL; p->fun(1); }
qsword84 2014-12-12
  • 打赏
  • 举报
回复
我同样也遇这问题了,用VS新建一个简单的基于对话框程序运行同样报这错,初步怀疑VS文件损坏
wanglian0406 2012-08-31
  • 打赏
  • 举报
回复
可是我也看不明白为什么有问题啊,这是vc2005自带的malloc.c函数啊,怎么有问题呢!!
赵4老师 2012-08-31
  • 打赏
  • 举报
回复
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处。
shen_wei 2012-08-31
  • 打赏
  • 举报
回复
你应该贴上你,出错的代码。。而不是系统malloc的代码!!!
wanglian0406 2012-08-31
  • 打赏
  • 举报
回复
以下是我用vs2005调试出现的问题




请各位多多指教,问题怎么会出在vs2005文件夹内自带的malloc.c函数里面!!

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧