U E D R , A S I H C RSS

Debugging Seminar_2005/DebugCRT

DCRT

Debug C Runtime ������ �� ��������� �� �������� ������ �������� �������� ������ ����� �����.
��기� �� ����그������ �������� ���� �����기�� ���� ���.

~cpp _crtDbgFlag

_CRTDBG_ALLOC_MEM_DF ����그 �� ���. free store ����
_CRTDBG_DELAY_FREE_MEM_DF ������ delete�� �� �� �����. ���� ���� ���� ���� �� ����
_CRTDBG_CHECK_ALWAYS_DF _CrtCheckMemory() ���� �� new, delete ���� �� �� ���� ������ ��.
���� ���� 공간�� �������� �������� ����. �� domainerror�� 기 ���� access�� ����� �����. �� ��������� ����. 그���� 그���� ����깅�� �������� ������ �� ����.
_CRTDBG_CHECK_CRT_DF ������ �������� ����� ����그������ �� ��������.
_CRTDBG_LEAK_CHECK_DF ����그�� �������� �������� _CrtDumpMemoryLeaks()�� ����. ���� ���� ����� 경�� 그 �� �� �� ����.
_CRTDBG_ALLOC_MEM_DF �� 기�������� on, 기 ����그�� ���� off�� bitwise �������� ���� �����게 ����그�� ����.

~cpp 
int flas = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
flag |= _CRTDBG_LEAK_CHECK_DF;  // ����그 on
flag &= !_CRTDBG_LEAK_CHECK_DF;  // ����그 off
_CrtSetDbgFlag(flag);

Code

~cpp 
//this define must occur before any headers are included.
//������ include ������기�� ���� �������.
#define _CRTDBG_MAP_ALLOC

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>

// include crtdbg.h after all other headers.
// ������ ���� �������� include
#include <crtdbg.h>

int main(int argc, char *argv[]) {
	//turn on the full heap checking
	//DCRT�� ��������� ���기 ���� 기������������고 ��. ������ ����과 � ������ ���� ���� ��
	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF	|
					_CRTDBG_CHECK_ALWAYS_DF	|
					_CRTDBG_DELAY_FREE_MEM_DF	|
					_CRTDBG_LEAK_CHECK_DF	);

	//Allocate some more memory.
	TCHAR* pNew = new TCHAR[200];
	TCHAR* pNew2 = new TCHAR[200];
	TCHAR* pMemLeak = (TCHAR*)malloc (100);

	_tcscpy( pNew, _T("New'd memory...") );
	_tcscpy( pNew2, _T("more New'd memory...") );
	_tcscpy( pMemLeak, _T("Malloc'd memory...") );

	return EXIT_SUCCESS;
}
MFC������ 기�������� ������ ���������� ������� ���� �� ��������.

CRT 기 ��

CRT�� 기�� ������ ���� ����그 ���� ��������. �� �기������ _CrtSetReportMode()���� ���� ���� ���������� ���� �고, _CrtSetReportFile()�� ���� ���������� ���� ����.
~cpp int _CrtSetReportMode(int reportType, int reportMode);

reportType
_CRT_WARN 경고 ���� ��)memory leak
_CRT_ERROR ��구������� ����
_CRT_ASSERT assertion ����(assert() ���� ����)
crtdbg.h�� ASSERT, ASSERTE���� ������ ���� ����. ���� ���� ASSERTE�� assertion ������ �고, ���� � �� ���� ���.

reportMode
_CRTDBG_MODE_DEBUG ����그 ������ ���� �� ����그 ������ ������ ����
_CRTDBG_MODE_FILE output stream
_CRTDBG_MODE_WNDW ���� ��
_CRTDBG_REPORT_MODE ������ ������ ���� ����.
���� �� flag ��������� | �������� ���� �����.


~cpp _HFILE _CrtSetReportFile(int reportType, _HFILE reportFile);
������ ������ ���� �������� _HFILE ���� �������� ������ �������� ���� ����.
_CRTDBG_FILE_STDERR �� ���� ���������� ����
_CRTDBG_FILE_STDOUT �� ���� ���������� ����
_CRTDBG_REPORT_FILE ������ ���� ����.

output in debug console (vc++6)

dcrt_output_debug_console.jpg

after

�� ���������� ���� ���� �� ���� ���� �������� �� '���� '�� �� ������ �������� 경��� ����.
�� �������� ������ 경������ ��, �� ����, �������� ������ ������.
����) The rule of Three

related

after

DCRT�� ��고 ���� ��� ������ ����그���� ���������� �� ����. STL������ ��. - eternalbleu

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:06
Processing time 0.0427 sec