lecture/linux 개발환경

gdb & core dump

infra 2021. 10. 31. 23:11

 GNU 디버거(GNU DeBugger)는 GNU 소프트웨어 시스템을 위한 기본 디버거.

 

GDB는 다양한 유닉스 기반의 시스템에서 동작하는 이식성있는 디버거로,

에이다, C, C++, 포트란 등의 여 러 프로그래밍 언어를 지원한다.

 

특징
•        프로그램을  줄  단위로  실행하거나  특정  지점에서  멈추도록  할  수  있다.
•        프로그램  수행  중간에  각각의  변수에  어떤  값이  할당되어  있는지  확인할  수  있다.
•        원하는  값을  변수에  할당  후  어떤  일이  벌어지는지  확인할  수  있다.

 

gdb를 통해 수행 장점

 

 

 

 

gdb 설치

gdb 를 설치했을 때 관련된 파일의 라이브러리나, 컴파일러 등의 다른 파일이

dependency는 따로 없다. gdb만 설치된다.

더보기

 

 

[root@centos7 limits.d]# yum install gdb
Loaded plugins: fastestmirror
base                                                                                 | 3.6 kB  00:00:00
extras                                                                               | 2.9 kB  00:00:00
updates                                                                              | 2.9 kB  00:00:00
Loading mirror speeds from cached hostfile
 * base: mirror.kakao.com
 * extras: mirror.kakao.com
 * updates: ftp.tsukuba.wide.ad.jp
Resolving Dependencies
--> Running transaction check
---> Package gdb.x86_64 0:7.6.1-120.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================
 Package              Arch                    Version                           Repository             Size
============================================================================================================
Installing:
 gdb                  x86_64                  7.6.1-120.el7                     base                  2.4 M

Transaction Summary
============================================================================================================
Install  1 Package

Total download size: 2.4 M
Installed size: 7.0 M
Is this ok [y/d/N]: y

 

...

 Installing : gdb-7.6.1-120.el7.x86_64                                                                 1/1
  Verifying  : gdb-7.6.1-120.el7.x86_64                                                                 1/1

Installed:
  gdb.x86_64 0:7.6.1-120.el7

Complete!
[root@centos7 limits.d]# gdb -v
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.el7

Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.

 

* core dump

 

  •  시점에 작업 중이던 메모리 상태를 기록한 것
  • 프로그램이 비정상적으로 종료했을 때 만들어진다.

컴퓨터 프로그램이 특정 시점에 작업 중이던 메모리 상태를 기록한 것으로, 보통 프로그램이 비정상적으로 종료했을 때 만들어진다. 실제로는, 그 외에 중요한 프로그램 상태도 같이 기록되곤  하는데, 프로그램  카운터, 스택  포인터  등  CPU 레지스터나, 메모리  관리  정보, 그  외 프로세서  및  운영  체제  플래그  및  정보  등이  포함된다. 코어  덤프는  프로그램  오류  진단과  디버깅에  쓰인다.

 

core dump 설정 방법

 

 

 

1.코어  파일  생성  위치  확인

 

CentOS의  경우  상기와  같이  core_pattern의 첫  문자가  파이프(|)일  경우  systemd로 리다이렉션한다. 코어  덤프  파일  실습을  위하여  특정  위치(일반적으로  /var/crash)에 코어  덤프가  생성되도록  수정
# vi /etc/sysctl.conf
kernel.core_pattern = /var/crash/core.%e.%p.%h.%t %e – executable filename.
%p – PID of dumped process.
%t – time of dump (seconds since 0:00h, 1 Jan 1970). %h – hostname (same as ’nodename’ returned by uname(2)).
# vi /etc/sysctl.conf fs.suid_dumpable = 2

2(suidsafe) – 일반적으로 모든 바이너리는 루트만 읽을 수 있도록 덤프됩니다. 이를 통해 최종 사용자는 그 덤프를 제거할 수 있지만 직접 액세스 할 수 없습니다. 보안상의 이유로 이 모드의 코어 덤프는 서로 또는 다른 파일을 덮어 쓰지 않습니다. 이 모드는 관리자가 일반 환경에서 문제를 디버그하려고 할 때 적합합니다.
설정  재로딩

 # sysctl -p

 

 

 

 

'lecture > linux 개발환경' 카테고리의 다른 글

gcc  (0) 2021.10.29