본문 바로가기
프로그래밍 놀이터/iOS

[ios] Memory Management Debugging.

by 돼지왕 왕돼지 2018. 2. 13.
반응형

[ios] Memory Management Debugging.


Crash, debugging, detect, Detecting Double Freed Memory, Detecting Heap Corruption, Detecting Memory Smashing Bugs, enabling guard malloc, Free, guard malloc, guard mallog library, heap chec, log, malloc library, MallocCheckHeapEach, MallocCheckHeapStart, MallocScribble, MallocStackLogging, MallocStackLoggingNoCompact, MallocStackLogginNoCompact, malloc_history, memory allocation, memory block, memory debug, memory debugging, memory error, simulator, Trace, virtual memory page, [ios] Memory Management Debugging.


Enabling Guard Malloc


-

Guard Malloc 은 malloc library 의 스페셜 버전이다.

Guard Malloc 을 enable 하면 debugging 도중에 표준 malloc library 를 Guard mallog library 로 변경한다.



-

Guard Malloc 은 여러 가지 기술을 이용해 메모리 에러가 발생하는 부분에서 crash 를 발생시킨다.

여기서 여러 가지 기술이란 예를 들면 memoery allocation 을 Virtual memory page 에 기록하여 trace 하는 방식으로, 우연히 잘못된 메모리를 access 해도 작동하는 케이스를 방지해준다.



-

Guard Malloc 은 Simulator 에서만 테스트 할 수 있다.




Detecting Double Freed Memory


-

malloc library 는 free 한 영역을 다시 free 하려는 것을 detect 해서 report 해준다.

MallocStackLoggingNoCompact option 을 enable 하면, 어디서 두번째 free 가 발생했는지 log 로 찾아준다.




Detecting Heap Corruption


-

Heap checking 을 하려면, MallocCheckHeapStart, MallocCheckHeapEach environment variable 을 켜줘야 한다.

Heap checking 을 위해서는 위의 두 가지 옵션 모두를 enable 시켜야 한다.




Detecting Memory Smashing Bugs


-

MallocScribble variable 을 켜줘야 한다.

이 변수는 invalid 한 data 를 free 하려고 할 때 exception 을 발생시킨다.


이 variable 을 사용할 때는 MallocStackLogging 과 MallocStackLogginNoCompact variable 을 함께 켜주는 것이 좋다.

exception 이 발생했을 때 malloc_history 커맨드를 통해 memory block 에 대한 정보를 볼 수 있다.




반응형

댓글