[Linux] GDB (GNU Debugger) 사용하기 - 6

 

  • 코어 덤프

프로그램이 죽었을 때, 코어 덤프를 남겨 봅시다.

쉘에서 다음과 같이 명령어를 입력 해 봅시다.

ulimit -a

core file size가 0 이므로, 프로그램이 죽어도 코어덤프가 생성 되지 않습니다.


그럼 core file size를 unlimited로 변경 해 봅시다.

unlimit -c unlimited


그런다음 이전 포스트에서 사용 했던 코드를 사용하여 프로그램을 실행 하였을 떄 core가 생성 되는지 확인 해 봅니다.

// seg_free.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char* str;

void allocate(void)
{
        str = (char*)malloc(sizeof(char) * 10);
}

void deallocate(void)
{
        free(str);
        free(str);
}

void assign(void)
{
        strcpy(str, "Hello World");
}

int main(void)
{
        printf("Start\n");

        allocate();
        assign();
        printf("str = %s\n", str);

        deallocate();

        printf("End\n");

        return 0;
}


프로그램을 실행하면, 죽고나서 core를 남깁니다.


gdb에서는 이 core 파일을 가지고 디버깅 할 수도 있습니다.

gdb [프로그램] core



이 블로그의 인기 게시물

Crusader Kings 3 - Converting DNA code using Portrait Editor