마음의 안정을 찾기 위하여 - 프로그램의 메모리 릭(leak)을 체크할 수 있는 도구 (DMALLOC)
2266166
503
804
관리자새글쓰기
태그위치로그방명록
별일없다의 생각
dawnsea's me2day/2010
색상(RGB)코드 추출기(Color...
Connection Generator/2010
최승호PD, '4대강 거짓말 검...
Green Monkey**/2010
Syng의 생각
syng's me2DAY/2010
천재 작곡가 윤일상이 기획,...
엘븐킹's Digital Factory/2010
프로그램의 메모리 릭(leak)을 체크할 수 있는 도구 (DMALLOC)
리눅스/리눅스 프로그래밍 | 2009/01/28 17:16
일전에 프로그램의 메모리 누수와 관련해서 유용한 툴을 소개한 적이 있었다.

프로그램의 메모리 누수(Memory Leak) 체크

이번에 소개할 툴(?) 역시 메모리 누수를 체크할 수 있는 유용한 프로그램인데, 다른 유용한 툴들이 있지만 dmalloc 또한 유용한 툴이기에 소개하고자 한다.

1. dmalloc 설치

http://dmalloc.com 사이트에서 패키지를 다운로드 한후 적당한 디렉토리에 압축을 해제한다.

설치 과정은 매우 간단해서 ./configure 를 실행한후 make ; make install 만 해주면 설치가 완료된다. 이때 설치는 root 계정으로 수행해야 한다.


2. 환경설정

# dmalloc -l logfile -I 100 high > dmalloc_setup
# cat dmalloc_setup
DMALLOC_OPTIONS=debug=0x4f47d03,inter=100,log=logfile
export DMALLOC_OPTIONS
# source dmalloc_setup
# dmalloc
Debug Malloc Utility: http://dmalloc.com/
  For a list of the command-line options enter: dmalloc --usage
Debug-Flags 0x4f47d03 (83131651) (high)
Address      not-set
Interval     100
Lock-On      not-set
Logpath      './logfile'
Start-File   not-set



3. dmalloc 테스트

#include <stdio.h>
#ifdef DMALLOC
#include <dmalloc.h>
#endif
int main(void)
{
  char *p = (char *) malloc(100);
  return 0;
}

# gcc -g -DDMALLOC sample01.c -ldmalloc -o sample01
# cat logfile
1233132319: 1: Dmalloc version '4.8.1' from 'http://dmalloc.com/'
1233132319: 1: flags = 0x4f47503, logfile './logfile'
1233132319: 1: interval = 100, addr = 0, seen # = 0
1233132319: 1: starting time = 1233132319
1233132319: 1: free bucket count/bits:  31/7
1233132319: 1: basic-block 4096 bytes, alignment 8 bytes, heap grows up
1233132319: 1: heap: 0x804a000 to 0x804d000, size 12288 bytes (3 blocks)
1233132319: 1: heap checked 0
1233132319: 1: alloc calls: malloc 1, calloc 0, realloc 0, free 0
1233132319: 1: alloc calls: recalloc 0, memalign 0, valloc 0
1233132319: 1:  total memory allocated: 100 bytes (1 pnts)
1233132319: 1:  max in use at one time: 100 bytes (1 pnts)
1233132319: 1: max alloced with 1 call: 100 bytes
1233132319: 1: max alloc rounding loss: 28 bytes (21%)
1233132319: 1: max memory space wasted: 3940 bytes (96%)
1233132319: 1: final user memory space: basic 0, divided 1, 4068 bytes
1233132319: 1:  final admin overhead: basic 1, divided 1, 8192 bytes (66%)
1233132319: 1:  final external space: 0 bytes (0 blocks)
1233132319: 1: top 10 allocations:
1233132319: 1:  total-size  count in-use-size  count  source
1233132319: 1:         100      1         100      1  sample01.c:8
1233132319: 1:         100      1         100      1  Total of 1
1233132319: 1: dumping not-freed pointers changed since 0:
1233132319: 1:  not freed: '0x804c008|s1' (100 bytes) from 'sample01.c:8'
1233132319: 1:  total-size  count  source
1233132319: 1:         100      1  sample01.c:8
1233132319: 1:         100      1  Total of 1
1233132319: 1:  known memory: 1 pointer, 100 bytes
1233132319: 1: ending time = 1233132319, elapsed since start = 0:00:00



※ Dmalloc 제약사항
* Dmalloc 은 오직 힙 관련 메모리 문제들만 감지 할 수 있으며 스택 혹은 정적 메모리에서의 문제점은 감지해낼 수 없음.
* 메모리가 malloc() 에 의해 할당되었을때만 버그를 감지해낼 수 있으며 sbrk() 혹은 mmap() 에 의해 할당됐을 경우 사용이 불가능함.
* 아래와 같은 문제점들은 감지해 낼 수 없고 이것은 dbx DTC, Purify 그리고 Valgrind 같은 다른 좀더 복잡한 툴들(malloc, realloc, free 의 교체 보다 훨씬 더 많은 기능을 제공하는) 에 의해서 가능 함:
  o 스택 메모리 체크
  o 할당되지 않은 메모리 읽기 혹은 쓰기
  o 할당됐지만 초기화 되지 않은 메모리 읽기
  o 읽기전용 메모리에 쓰기
2009/01/28 17:16 2009/01/28 17:16
Article tag list Go to top
View Comment 2
Trackback URL :: 이 글에는 트랙백을 보낼 수 없습니다
From. 구차니 2009/01/29 11:24
답글달기삭제
예전에 소개해주신 valgrind 를 써보지도 못했는데 ㅠ.ㅠ
자꾸만 신기술을 소개 해주시면 언제 써볼려나 걱정만 늘어 간답니다 ^^;

새해복 많이 받으셨는지요?
From. 그리움 2009/01/29 11:43
삭제
신기술을 소개하려고 하기 보다는..
개인적으로 만들고 있는 프로그램에 워낙 버그가 많다보니 다양한 툴을 찾게 되게 되네요.

그리고 제가 잊지 않기 위해 남기는 목적도 있구요. ^^

새해 복 많이 받으세요...

곧 한국을 벗어나게 되시겠네요. ^^
PREV : [1] : NEXT
 
 
 
 
: [1] ... [412][413][414][415][416][417][418][419][420] ... [1317] :
«   2024/03   »
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
전체 (1317)
출판 준비 (0)
My-Pro... (41)
사는 ... (933)
블로그... (22)
My Lib... (32)
게임 ... (23)
개발관... (3)
Smart ... (1)
Delphi (93)
C Builder (0)
Object... (0)
VC, MF... (10)
Window... (1)
Open API (3)
Visual... (0)
Java, JSP (2)
ASP.NET (0)
PHP (5)
Database (12)
리눅스 (29)
Windows (25)
Device... (1)
Embedded (1)
게임 ... (0)
Web Se... (2)
Web, S... (21)
잡다한... (6)
프로젝트 (0)
Personal (0)
대통령... (13)
Link (2)