SlideShare a Scribd company logo
1 of 38
Download to read offline
리눅스 커널 디버거 KGDB/KDB
2015.08.31
SW Maestro 과정 연수생 한만종
리눅스 커널 디버거
• KGDB (v2.6.26 +)
• KDB (v2.6.35 +)
KGDB란?
• linsyssoft.com에서 진행했던 소스 레벨 리눅스 커널 디버거.
v2.6.26부터 리눅스 메인라인에 포함.
• 타깃보드에 접속해 GDB를 원격으로 사용할 수 있는 환경을 커널
에서 제공.
KGDB를 사용하려면
• 두 대 이상의 머신이 필요 (개발머신과 테스트머신)
• 테스트 머신에서는 v2.6.26 이상의 버전과 KGDB 옵션이 켜진
커널 필요
• 개발 머신에서는 GDB 필요
• 개발 머신과 테스트 머신은 시리얼 또는 이더넷 통신을 사용
KGDB 사용하기
1. 테스트 머신 커널 빌드
CONFIG_DEBUG_INFO=y
# CONFIG_DEBUG_RODATA is not set
CONFIG_FRAME_POINTER=y
CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y
KGDB 사용하기
2. 테스트 머신(QEMU) 구동 및 개발 머신과 연결(시리얼)
$ qemu-system-x86_64 -kernel bzImage -append
"kgdboc=ttyS0,115200" -serial pty
KGDB 사용하기
2. 테스트 머신(QEMU) 구동 및 개발 머신과 연결(시리얼)
$ qemu-system-x86_64 -kernel bzImage -append
"kgdboc=ttyS0,115200" -serial pty
리눅스 커널 이미지
앞서 빌드한 커널로 부팅
KGDB 사용하기
2. 테스트 머신(QEMU) 구동 및 개발 머신과 연결(시리얼)
$ qemu-system-x86_64 -kernel bzImage -append
"kgdboc=ttyS0,115200" -serial pty
커널 커맨드 라인 인자 kgdboc 옵션을 이용하여
ttyS0 장치에 115200Bd로 연결
KGDB 사용하기
2. 테스트 머신(QEMU) 구동 및 개발 머신과 연결(시리얼)
$ qemu-system-x86_64 -kernel bzImage -append
"kgdboc=ttyS0,115200" -serial pty
커널 커맨드 라인 인자 kgdboc 옵션을 이용하여
ttyS0 장치에 115200Bd로 연결
?
kgdboc와 kgdboe
• KGDB는 시리얼 및 이더넷 통신 가능
• sysfs 또는 커널 부트 옵션에서 지정 가능
kgdboc
• “KGDB Over Console”
• 시리얼 콘솔 장치를 프라이머리 콘솔로 이용할 경우 사용
• CONFIG_KGDBOC=y
• kgdboc=<tty-device-port>, [baud]
• echo <tty-device-port> > /sys/module/kgdboc/
parameters/kgdboc
kgdboe
• “KGDB Over Ethernet”
• 같은 LAN에 연결되어 있는 테스트 머신에 접속할 경우 사용
• 사용중인 이더넷 장치의 드라이버에 NETPOLL API가 구현되어
있어야 함. 또한, 사용중인 커널이 NETPOLL을 지원해야 함
• kgdboe=[src-port]@<src-ip>/[dev],[tgt-port]@<tgt-ip>/
[tgt-macaddr]
• echo “@/,@10.0.0.2/” > /sys/module/kgdboe/
parameters/kgdboe
KGDB 사용하기
2. 테스트 머신(QEMU) 구동 및 개발 머신과 연결(시리얼)
$ qemu-system-x86_64 -kernel bzImage -append
"kgdboc=ttyS0,115200" -serial pty
시리얼 디바이스
리눅스 가상터미널 장치
pty에 시리얼 연결
KGDB 사용하기
2. 테스트 머신(QEMU) 구동 및 개발 머신과 연결(시리얼)
$ qemu-system-x86_64 -kernel bzImage -append
"kgdboc=ttyS0,115200" -serial pty
KGDB 사용하기
2. 테스트 머신(QEMU) 구동 및 개발 머신과 연결(시리얼)
$ qemu-system-x86_64 -kernel bzImage -append
"kgdboc=ttyS0,115200" -serial pty
KGDB 사용하기
3. 개발머신에서 gdb 실행 및 테스트머신과 연결
$ gdb -q vmlinux
(gdb) set serial baud 115200
(gdb) target remote /dev/pts/24
KGDB는
• GDB를 커널 디버깅에도 사용할 수 있다!
• GDB로 제어권이 넘어오는 시점은?
1. 커널패닉/웁스가 발생했을 경우
2. breakpoint에 도달했을 경우
3. MagicSysrq 키를 눌렀을 경우 (CONFIG_MAGIC_SYSRQ)
KGDB는
• 강제로 GDB로 제어권을 넘기고 싶다면?
MagicSysrq키를 누른다.
(누를 수 없는 상황이라면 다음과 같은 명령어 사용.)
# echo g > /proc/sysrq-trigger
KGDB는
• MagicSysrq키를 누르는 것이 번거롭다면..
다음과 같이 시스템콜 sync()를 이용한다.
1. 우선 다음과 같이 sys_sync에 breakpoint를 걸어둔다.
(gdb) break sys_sync
2. 디버깅이 필요한 경우, 다음과 같이 sync를 실행하여 KGDB로
제어권을 넘긴다.
# sync
KDB란?
• SGI에서 오픈소스 프로젝트로 진행했던 내장 커널 디버거.
v2.6.35부터 리눅스 메인라인에 포함.
• 브레이크포인트 설정, 메모리 및 자료구조 확인 등을 별도의 외부
시스템 없이 단독으로 가능케함.
KDB를 사용하려면
• 원격 시리얼 접속이 가능한 환경
• v2.6.35 이상의 버전과 CONFIG_KGDB_KDB 커널 빌드 옵션
이 켜진 커널 필요
KDB 사용하기
1. KDB의 사용이 가능한 커널 빌드
CONFIG_KGDB_KDB=y
KDB 사용하기
2. 테스트머신(QEMU) 구동 및 KDB 진입
$ qemu-system-x86_64 -kernel bzImage -hda
rootfs.img -serial pty -append “console=ttyS0,115200
kgdboc=ttyS0 root=/dev/sda”
KDB 사용하기
2. 테스트머신(QEMU) 구동 및 KDB 진입
$ qemu-system-x86_64 -kernel bzImage -hda
rootfs.img -serial pty -append “console=ttyS0,115200
kgdboc=ttyS0 root=/dev/sda”
KDB 사용하기
3. 원격 터미널(minicom)로 테스트머신에 접속
$ minicom -p /dev/pts/24 -b 115200
KDB 사용하기
4. 커널 웁스, 폴트가 발생할 때 KDB로 진입할 수 있으며, 커널 빌
드 config 중 하나인 CONFIG_MAGIC_SYSRQ를 켰었다면 다
음과 같이 수동으로 진입할 수도 있다.
# echo g > /proc/sysrq-trigger
KDB는
• “help” 명령어를 통해 더 많은 명령어들을 볼 수 있다.
• 몇 개의 유용한 명령어들은 다음과 같다.
lsmod - 로드된 커널 모듈 리스트
ps - 현재 동작중인 프로세스 목록
ps A - 모든 프로세스 목록
summary - 커널 버전 정보, 메모리 사용량
bt - 현재 프로세스의 backtrace 출력
dmesg - 커널 syslog 버퍼 출력
go - 시스템을 계속 재개
KGDB/KDB 연동하기
1. 테스트머신(QEMU) 구동
$ qemu-system-x86_64 -kernel bzImage -hda
rootfs.img -serial pty -append “console=ttyS0,115200
kgdboc=ttyS0 root=/dev/sda”
KGDB/KDB 연동하기
2. agent-proxy 다운로드하기
$ git clone git://git.kernel.org/pub/scm/utils/kernel/
kgdb/agent-proxy.git
$ cd agent-proxy
$ make
KGDB/KDB 연동하기
3. agent-proxy를 통해 kgdb와 kdb를 모두 연결할 수 있도록 셋
팅하기 (gdb 접속 1234 포트, console 접속 4567 포트)
$ agent-proxy 1234^4567 0 /dev/pts/0,115200
KGDB/KDB 연동하기
4. console에 접속
$ telnet localhost 1234
KGDB/KDB 연동하기
4. 커널 패닉/웁스 발생 시 KDB로 제어 가능
KGDB/KDB 연동하기
5. KDB에서 KGDB로 제어를 넘기려면 <테스트머신에서>
kdb> kgdb
KGDB/KDB 연동하기
5. KDB에서 KGDB로 제어를 넘기려면 <호스트머신에서>
$ gdb -q vmlinux
KGDB/KDB 연동하기
6. gdb에서 monitor 명령을 이용하면 lsmod, ps, dmesg 등과
같이 KDB에서 사용가능한 명령어를 바로 사용할 수 있다.
$ monitor lsmod
KGDB/KDB 연동하기
7. 다음 명령어를 사용하면 다시 KDB로 제어를 넘긴다.
$ maint packet 3
참고문헌
• http://studyfoss.egloos.com/5490783
• http://studyfoss.egloos.com/5491083
• http://studyfoss.egloos.com/5491211
• https://www.kernel.org/pub/linux/kernel/people/jwessel/kdb/index.html
• https://kgdb.wiki.kernel.org/index.php/
Main_Page#The_new_KDB_and_KGDB_documentation_.28kernel_.3E.
3D_2.6.35.29
• http://www.makelinux.net/books/lkd2/ch18lev1sec8
• http://oss.sgi.com/projects/kgdb/
• http://pds11.egloos.com/pds/200811/14/28/linuxdebug3-wankyuk.pdf
감사합니다.

More Related Content

What's hot

[232] 성능어디까지쥐어짜봤니 송태웅
[232] 성능어디까지쥐어짜봤니 송태웅[232] 성능어디까지쥐어짜봤니 송태웅
[232] 성능어디까지쥐어짜봤니 송태웅NAVER D2
 
malloc & vmalloc in Linux
malloc & vmalloc in Linuxmalloc & vmalloc in Linux
malloc & vmalloc in LinuxAdrian Huang
 
Decompressed vmlinux: linux kernel initialization from page table configurati...
Decompressed vmlinux: linux kernel initialization from page table configurati...Decompressed vmlinux: linux kernel initialization from page table configurati...
Decompressed vmlinux: linux kernel initialization from page table configurati...Adrian Huang
 
Breaking Down the Entry Barriers on Linux Kernel Networking Stack
Breaking Down the Entry Barriers on Linux Kernel Networking StackBreaking Down the Entry Barriers on Linux Kernel Networking Stack
Breaking Down the Entry Barriers on Linux Kernel Networking StackJuhee Kang
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)shimosawa
 
Leveling Up My Linux Kernel Contributions : Troubleshooting the kernel panic
Leveling Up My Linux Kernel Contributions : Troubleshooting the kernel panicLeveling Up My Linux Kernel Contributions : Troubleshooting the kernel panic
Leveling Up My Linux Kernel Contributions : Troubleshooting the kernel panicJuhee Kang
 
jemalloc 세미나
jemalloc 세미나jemalloc 세미나
jemalloc 세미나Jang Hoon
 
XPDDS19: [ARM] OP-TEE Mediator in Xen - Volodymyr Babchuk, EPAM Systems
XPDDS19: [ARM] OP-TEE Mediator in Xen - Volodymyr Babchuk, EPAM SystemsXPDDS19: [ARM] OP-TEE Mediator in Xen - Volodymyr Babchuk, EPAM Systems
XPDDS19: [ARM] OP-TEE Mediator in Xen - Volodymyr Babchuk, EPAM SystemsThe Linux Foundation
 
Launch the First Process in Linux System
Launch the First Process in Linux SystemLaunch the First Process in Linux System
Launch the First Process in Linux SystemJian-Hong Pan
 
Memory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux KernelMemory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux KernelAdrian Huang
 
Meet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracingMeet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracingViller Hsiao
 
Introduction to yocto
Introduction to yoctoIntroduction to yocto
Introduction to yoctoAlex Gonzalez
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File SystemAdrian Huang
 
Build your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectBuild your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectYen-Chin Lee
 
KVM tools and enterprise usage
KVM tools and enterprise usageKVM tools and enterprise usage
KVM tools and enterprise usagevincentvdk
 
Kdump and the kernel crash dump analysis
Kdump and the kernel crash dump analysisKdump and the kernel crash dump analysis
Kdump and the kernel crash dump analysisBuland Singh
 
Kernel_Crash_Dump_Analysis
Kernel_Crash_Dump_AnalysisKernel_Crash_Dump_Analysis
Kernel_Crash_Dump_AnalysisBuland Singh
 
Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Adrian Huang
 

What's hot (20)

Linux scheduler
Linux schedulerLinux scheduler
Linux scheduler
 
[232] 성능어디까지쥐어짜봤니 송태웅
[232] 성능어디까지쥐어짜봤니 송태웅[232] 성능어디까지쥐어짜봤니 송태웅
[232] 성능어디까지쥐어짜봤니 송태웅
 
malloc & vmalloc in Linux
malloc & vmalloc in Linuxmalloc & vmalloc in Linux
malloc & vmalloc in Linux
 
Spi drivers
Spi driversSpi drivers
Spi drivers
 
Decompressed vmlinux: linux kernel initialization from page table configurati...
Decompressed vmlinux: linux kernel initialization from page table configurati...Decompressed vmlinux: linux kernel initialization from page table configurati...
Decompressed vmlinux: linux kernel initialization from page table configurati...
 
Breaking Down the Entry Barriers on Linux Kernel Networking Stack
Breaking Down the Entry Barriers on Linux Kernel Networking StackBreaking Down the Entry Barriers on Linux Kernel Networking Stack
Breaking Down the Entry Barriers on Linux Kernel Networking Stack
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
Leveling Up My Linux Kernel Contributions : Troubleshooting the kernel panic
Leveling Up My Linux Kernel Contributions : Troubleshooting the kernel panicLeveling Up My Linux Kernel Contributions : Troubleshooting the kernel panic
Leveling Up My Linux Kernel Contributions : Troubleshooting the kernel panic
 
jemalloc 세미나
jemalloc 세미나jemalloc 세미나
jemalloc 세미나
 
XPDDS19: [ARM] OP-TEE Mediator in Xen - Volodymyr Babchuk, EPAM Systems
XPDDS19: [ARM] OP-TEE Mediator in Xen - Volodymyr Babchuk, EPAM SystemsXPDDS19: [ARM] OP-TEE Mediator in Xen - Volodymyr Babchuk, EPAM Systems
XPDDS19: [ARM] OP-TEE Mediator in Xen - Volodymyr Babchuk, EPAM Systems
 
Launch the First Process in Linux System
Launch the First Process in Linux SystemLaunch the First Process in Linux System
Launch the First Process in Linux System
 
Memory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux KernelMemory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux Kernel
 
Meet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracingMeet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracing
 
Introduction to yocto
Introduction to yoctoIntroduction to yocto
Introduction to yocto
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File System
 
Build your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectBuild your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto project
 
KVM tools and enterprise usage
KVM tools and enterprise usageKVM tools and enterprise usage
KVM tools and enterprise usage
 
Kdump and the kernel crash dump analysis
Kdump and the kernel crash dump analysisKdump and the kernel crash dump analysis
Kdump and the kernel crash dump analysis
 
Kernel_Crash_Dump_Analysis
Kernel_Crash_Dump_AnalysisKernel_Crash_Dump_Analysis
Kernel_Crash_Dump_Analysis
 
Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...
 

Viewers also liked

유니브북 출시부터 운영까지
유니브북 출시부터 운영까지유니브북 출시부터 운영까지
유니브북 출시부터 운영까지Manjong Han
 
About IssueTracker
About IssueTrackerAbout IssueTracker
About IssueTrackerManjong Han
 
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기Manjong Han
 
Android 5.0 & Material Design
Android 5.0 & Material DesignAndroid 5.0 & Material Design
Android 5.0 & Material DesignManjong Han
 
gradle로 안드로이드 앱 빌드하기
gradle로 안드로이드 앱 빌드하기gradle로 안드로이드 앱 빌드하기
gradle로 안드로이드 앱 빌드하기Manjong Han
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 
Univbook 파트너십 제안서
Univbook 파트너십 제안서Univbook 파트너십 제안서
Univbook 파트너십 제안서ROTAEJUN
 
Presentacion del deporte
Presentacion del deportePresentacion del deporte
Presentacion del deporte52663322
 
Q2.12: Debugging with GDB
Q2.12: Debugging with GDBQ2.12: Debugging with GDB
Q2.12: Debugging with GDBLinaro
 
DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)beom kyun choi
 
IoT Developer Survey 2015
IoT Developer Survey 2015IoT Developer Survey 2015
IoT Developer Survey 2015Ian Skerrett
 
Linux Performance Tools
Linux Performance ToolsLinux Performance Tools
Linux Performance ToolsBrendan Gregg
 
[Td 2015]디버깅, 어디까지 해봤니 당신이 아마도 몰랐을 디버깅 꿀팁 공개(김희준)
[Td 2015]디버깅, 어디까지 해봤니 당신이 아마도 몰랐을 디버깅 꿀팁 공개(김희준)[Td 2015]디버깅, 어디까지 해봤니 당신이 아마도 몰랐을 디버깅 꿀팁 공개(김희준)
[Td 2015]디버깅, 어디까지 해봤니 당신이 아마도 몰랐을 디버깅 꿀팁 공개(김희준)Sang Don Kim
 
Docker 활용법: dumpdocker
Docker 활용법: dumpdockerDocker 활용법: dumpdocker
Docker 활용법: dumpdockerJaehwa Park
 
Linux Systems Performance 2016
Linux Systems Performance 2016Linux Systems Performance 2016
Linux Systems Performance 2016Brendan Gregg
 
IoT Developer Survey 2016
IoT Developer Survey 2016IoT Developer Survey 2016
IoT Developer Survey 2016Ian Skerrett
 
Upfront vc analysis 2016
Upfront vc analysis 2016Upfront vc analysis 2016
Upfront vc analysis 2016Mark Suster
 
Introduction to segmentation fault handling
Introduction to segmentation fault handling Introduction to segmentation fault handling
Introduction to segmentation fault handling Larion
 

Viewers also liked (20)

유니브북 출시부터 운영까지
유니브북 출시부터 운영까지유니브북 출시부터 운영까지
유니브북 출시부터 운영까지
 
About IssueTracker
About IssueTrackerAbout IssueTracker
About IssueTracker
 
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기
 
Android 5.0 & Material Design
Android 5.0 & Material DesignAndroid 5.0 & Material Design
Android 5.0 & Material Design
 
gradle로 안드로이드 앱 빌드하기
gradle로 안드로이드 앱 빌드하기gradle로 안드로이드 앱 빌드하기
gradle로 안드로이드 앱 빌드하기
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 
Univbook 파트너십 제안서
Univbook 파트너십 제안서Univbook 파트너십 제안서
Univbook 파트너십 제안서
 
DDD
DDDDDD
DDD
 
Presentacion del deporte
Presentacion del deportePresentacion del deporte
Presentacion del deporte
 
Q2.12: Debugging with GDB
Q2.12: Debugging with GDBQ2.12: Debugging with GDB
Q2.12: Debugging with GDB
 
DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)
 
IoT Developer Survey 2015
IoT Developer Survey 2015IoT Developer Survey 2015
IoT Developer Survey 2015
 
Linux Performance Tools
Linux Performance ToolsLinux Performance Tools
Linux Performance Tools
 
[Td 2015]디버깅, 어디까지 해봤니 당신이 아마도 몰랐을 디버깅 꿀팁 공개(김희준)
[Td 2015]디버깅, 어디까지 해봤니 당신이 아마도 몰랐을 디버깅 꿀팁 공개(김희준)[Td 2015]디버깅, 어디까지 해봤니 당신이 아마도 몰랐을 디버깅 꿀팁 공개(김희준)
[Td 2015]디버깅, 어디까지 해봤니 당신이 아마도 몰랐을 디버깅 꿀팁 공개(김희준)
 
Docker 활용법: dumpdocker
Docker 활용법: dumpdockerDocker 활용법: dumpdocker
Docker 활용법: dumpdocker
 
Kernel crashdump
Kernel crashdumpKernel crashdump
Kernel crashdump
 
Linux Systems Performance 2016
Linux Systems Performance 2016Linux Systems Performance 2016
Linux Systems Performance 2016
 
IoT Developer Survey 2016
IoT Developer Survey 2016IoT Developer Survey 2016
IoT Developer Survey 2016
 
Upfront vc analysis 2016
Upfront vc analysis 2016Upfront vc analysis 2016
Upfront vc analysis 2016
 
Introduction to segmentation fault handling
Introduction to segmentation fault handling Introduction to segmentation fault handling
Introduction to segmentation fault handling
 

Similar to 리눅스 커널 디버거 KGDB/KDB

[OpenInfra Days Korea 2018] Day 2 - E5: GPU on Kubernetes
[OpenInfra Days Korea 2018] Day 2 - E5: GPU on Kubernetes[OpenInfra Days Korea 2018] Day 2 - E5: GPU on Kubernetes
[OpenInfra Days Korea 2018] Day 2 - E5: GPU on KubernetesOpenStack Korea Community
 
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축Ji-Woong Choi
 
Kubernetes on Premise Practical Guide
Kubernetes on Premise Practical GuideKubernetes on Premise Practical Guide
Kubernetes on Premise Practical GuideChan Shik Lim
 
Cloud for Kubernetes : Session1
Cloud for Kubernetes : Session1Cloud for Kubernetes : Session1
Cloud for Kubernetes : Session1WhaTap Labs
 
F5 container ingress_service_in_kuernetes_with_calico_cni_by_duck_in_korea
F5 container ingress_service_in_kuernetes_with_calico_cni_by_duck_in_koreaF5 container ingress_service_in_kuernetes_with_calico_cni_by_duck_in_korea
F5 container ingress_service_in_kuernetes_with_calico_cni_by_duck_in_koreaInfraEngineer
 
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요Jo Hoon
 
Daily Continuous Deployment를 위한 Custom CLI 개발 및
 AWS Elastic Beanstalk에 적용하기
Daily Continuous Deployment를 위한 Custom CLI 개발 및
 AWS Elastic Beanstalk에 적용하기Daily Continuous Deployment를 위한 Custom CLI 개발 및
 AWS Elastic Beanstalk에 적용하기
Daily Continuous Deployment를 위한 Custom CLI 개발 및
 AWS Elastic Beanstalk에 적용하기Jongwon Han
 
세션3_데보션테크데이_gitopsinfra_v1.1.pdf
세션3_데보션테크데이_gitopsinfra_v1.1.pdf세션3_데보션테크데이_gitopsinfra_v1.1.pdf
세션3_데보션테크데이_gitopsinfra_v1.1.pdfJaesuk Ahn
 
NVIDIA GPU CLOUD로 시작하는 딥러닝 환경설정
NVIDIA GPU CLOUD로 시작하는 딥러닝 환경설정NVIDIA GPU CLOUD로 시작하는 딥러닝 환경설정
NVIDIA GPU CLOUD로 시작하는 딥러닝 환경설정JinYeong Wang
 
postgres_빌드_및_디버깅.pdf
postgres_빌드_및_디버깅.pdfpostgres_빌드_및_디버깅.pdf
postgres_빌드_및_디버깅.pdfLee Dong Wook
 
[Open-infradays 2019 Korea] jabayo on Kubeflow
[Open-infradays 2019 Korea] jabayo on Kubeflow[Open-infradays 2019 Korea] jabayo on Kubeflow
[Open-infradays 2019 Korea] jabayo on Kubeflow석환 홍
 
Source To URL Without Dockerfile
Source To URL Without DockerfileSource To URL Without Dockerfile
Source To URL Without DockerfileWon-Chon Jung
 
[1A6]Docker로 보는 서버 운영의 미래
[1A6]Docker로 보는 서버 운영의 미래[1A6]Docker로 보는 서버 운영의 미래
[1A6]Docker로 보는 서버 운영의 미래NAVER D2
 
Hm10 Research sheets
Hm10 Research sheetsHm10 Research sheets
Hm10 Research sheetsyyooooon
 
2017 k8s and OpenStack-Helm
2017 k8s and OpenStack-Helm2017 k8s and OpenStack-Helm
2017 k8s and OpenStack-HelmSK Telecom
 
Actual PoC guide for Virtual Desktop Infrastructure (Korean)
Actual PoC guide for Virtual Desktop Infrastructure (Korean)Actual PoC guide for Virtual Desktop Infrastructure (Korean)
Actual PoC guide for Virtual Desktop Infrastructure (Korean)Changhyun Lim
 
Cloud-Barista 제7차 컨퍼런스 : 멀티클라우드 인프라 서비스 연동 (CB-Spider)
Cloud-Barista 제7차 컨퍼런스 : 멀티클라우드 인프라 서비스 연동 (CB-Spider)Cloud-Barista 제7차 컨퍼런스 : 멀티클라우드 인프라 서비스 연동 (CB-Spider)
Cloud-Barista 제7차 컨퍼런스 : 멀티클라우드 인프라 서비스 연동 (CB-Spider)Cloud-Barista Community
 
[slideshare]k8s.pptx
[slideshare]k8s.pptx[slideshare]k8s.pptx
[slideshare]k8s.pptxssuserb8551e
 

Similar to 리눅스 커널 디버거 KGDB/KDB (20)

[OpenInfra Days Korea 2018] Day 2 - E5: GPU on Kubernetes
[OpenInfra Days Korea 2018] Day 2 - E5: GPU on Kubernetes[OpenInfra Days Korea 2018] Day 2 - E5: GPU on Kubernetes
[OpenInfra Days Korea 2018] Day 2 - E5: GPU on Kubernetes
 
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
 
Kubernetes on Premise Practical Guide
Kubernetes on Premise Practical GuideKubernetes on Premise Practical Guide
Kubernetes on Premise Practical Guide
 
Cloud for Kubernetes : Session1
Cloud for Kubernetes : Session1Cloud for Kubernetes : Session1
Cloud for Kubernetes : Session1
 
Kafka slideshare
Kafka   slideshareKafka   slideshare
Kafka slideshare
 
F5 container ingress_service_in_kuernetes_with_calico_cni_by_duck_in_korea
F5 container ingress_service_in_kuernetes_with_calico_cni_by_duck_in_koreaF5 container ingress_service_in_kuernetes_with_calico_cni_by_duck_in_korea
F5 container ingress_service_in_kuernetes_with_calico_cni_by_duck_in_korea
 
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
 
Daily Continuous Deployment를 위한 Custom CLI 개발 및
 AWS Elastic Beanstalk에 적용하기
Daily Continuous Deployment를 위한 Custom CLI 개발 및
 AWS Elastic Beanstalk에 적용하기Daily Continuous Deployment를 위한 Custom CLI 개발 및
 AWS Elastic Beanstalk에 적용하기
Daily Continuous Deployment를 위한 Custom CLI 개발 및
 AWS Elastic Beanstalk에 적용하기
 
세션3_데보션테크데이_gitopsinfra_v1.1.pdf
세션3_데보션테크데이_gitopsinfra_v1.1.pdf세션3_데보션테크데이_gitopsinfra_v1.1.pdf
세션3_데보션테크데이_gitopsinfra_v1.1.pdf
 
NVIDIA GPU CLOUD로 시작하는 딥러닝 환경설정
NVIDIA GPU CLOUD로 시작하는 딥러닝 환경설정NVIDIA GPU CLOUD로 시작하는 딥러닝 환경설정
NVIDIA GPU CLOUD로 시작하는 딥러닝 환경설정
 
postgres_빌드_및_디버깅.pdf
postgres_빌드_및_디버깅.pdfpostgres_빌드_및_디버깅.pdf
postgres_빌드_및_디버깅.pdf
 
[Open-infradays 2019 Korea] jabayo on Kubeflow
[Open-infradays 2019 Korea] jabayo on Kubeflow[Open-infradays 2019 Korea] jabayo on Kubeflow
[Open-infradays 2019 Korea] jabayo on Kubeflow
 
Source To URL Without Dockerfile
Source To URL Without DockerfileSource To URL Without Dockerfile
Source To URL Without Dockerfile
 
[1A6]Docker로 보는 서버 운영의 미래
[1A6]Docker로 보는 서버 운영의 미래[1A6]Docker로 보는 서버 운영의 미래
[1A6]Docker로 보는 서버 운영의 미래
 
Hm10 Research sheets
Hm10 Research sheetsHm10 Research sheets
Hm10 Research sheets
 
2017 k8s and OpenStack-Helm
2017 k8s and OpenStack-Helm2017 k8s and OpenStack-Helm
2017 k8s and OpenStack-Helm
 
Actual PoC guide for Virtual Desktop Infrastructure (Korean)
Actual PoC guide for Virtual Desktop Infrastructure (Korean)Actual PoC guide for Virtual Desktop Infrastructure (Korean)
Actual PoC guide for Virtual Desktop Infrastructure (Korean)
 
K8s in action02
K8s in action02K8s in action02
K8s in action02
 
Cloud-Barista 제7차 컨퍼런스 : 멀티클라우드 인프라 서비스 연동 (CB-Spider)
Cloud-Barista 제7차 컨퍼런스 : 멀티클라우드 인프라 서비스 연동 (CB-Spider)Cloud-Barista 제7차 컨퍼런스 : 멀티클라우드 인프라 서비스 연동 (CB-Spider)
Cloud-Barista 제7차 컨퍼런스 : 멀티클라우드 인프라 서비스 연동 (CB-Spider)
 
[slideshare]k8s.pptx
[slideshare]k8s.pptx[slideshare]k8s.pptx
[slideshare]k8s.pptx
 

리눅스 커널 디버거 KGDB/KDB

  • 1. 리눅스 커널 디버거 KGDB/KDB 2015.08.31 SW Maestro 과정 연수생 한만종
  • 2. 리눅스 커널 디버거 • KGDB (v2.6.26 +) • KDB (v2.6.35 +)
  • 3. KGDB란? • linsyssoft.com에서 진행했던 소스 레벨 리눅스 커널 디버거. v2.6.26부터 리눅스 메인라인에 포함. • 타깃보드에 접속해 GDB를 원격으로 사용할 수 있는 환경을 커널 에서 제공.
  • 4. KGDB를 사용하려면 • 두 대 이상의 머신이 필요 (개발머신과 테스트머신) • 테스트 머신에서는 v2.6.26 이상의 버전과 KGDB 옵션이 켜진 커널 필요 • 개발 머신에서는 GDB 필요 • 개발 머신과 테스트 머신은 시리얼 또는 이더넷 통신을 사용
  • 5. KGDB 사용하기 1. 테스트 머신 커널 빌드 CONFIG_DEBUG_INFO=y # CONFIG_DEBUG_RODATA is not set CONFIG_FRAME_POINTER=y CONFIG_KGDB=y CONFIG_KGDB_SERIAL_CONSOLE=y
  • 6. KGDB 사용하기 2. 테스트 머신(QEMU) 구동 및 개발 머신과 연결(시리얼) $ qemu-system-x86_64 -kernel bzImage -append "kgdboc=ttyS0,115200" -serial pty
  • 7. KGDB 사용하기 2. 테스트 머신(QEMU) 구동 및 개발 머신과 연결(시리얼) $ qemu-system-x86_64 -kernel bzImage -append "kgdboc=ttyS0,115200" -serial pty 리눅스 커널 이미지 앞서 빌드한 커널로 부팅
  • 8. KGDB 사용하기 2. 테스트 머신(QEMU) 구동 및 개발 머신과 연결(시리얼) $ qemu-system-x86_64 -kernel bzImage -append "kgdboc=ttyS0,115200" -serial pty 커널 커맨드 라인 인자 kgdboc 옵션을 이용하여 ttyS0 장치에 115200Bd로 연결
  • 9. KGDB 사용하기 2. 테스트 머신(QEMU) 구동 및 개발 머신과 연결(시리얼) $ qemu-system-x86_64 -kernel bzImage -append "kgdboc=ttyS0,115200" -serial pty 커널 커맨드 라인 인자 kgdboc 옵션을 이용하여 ttyS0 장치에 115200Bd로 연결 ?
  • 10. kgdboc와 kgdboe • KGDB는 시리얼 및 이더넷 통신 가능 • sysfs 또는 커널 부트 옵션에서 지정 가능
  • 11. kgdboc • “KGDB Over Console” • 시리얼 콘솔 장치를 프라이머리 콘솔로 이용할 경우 사용 • CONFIG_KGDBOC=y • kgdboc=<tty-device-port>, [baud] • echo <tty-device-port> > /sys/module/kgdboc/ parameters/kgdboc
  • 12. kgdboe • “KGDB Over Ethernet” • 같은 LAN에 연결되어 있는 테스트 머신에 접속할 경우 사용 • 사용중인 이더넷 장치의 드라이버에 NETPOLL API가 구현되어 있어야 함. 또한, 사용중인 커널이 NETPOLL을 지원해야 함 • kgdboe=[src-port]@<src-ip>/[dev],[tgt-port]@<tgt-ip>/ [tgt-macaddr] • echo “@/,@10.0.0.2/” > /sys/module/kgdboe/ parameters/kgdboe
  • 13. KGDB 사용하기 2. 테스트 머신(QEMU) 구동 및 개발 머신과 연결(시리얼) $ qemu-system-x86_64 -kernel bzImage -append "kgdboc=ttyS0,115200" -serial pty 시리얼 디바이스 리눅스 가상터미널 장치 pty에 시리얼 연결
  • 14. KGDB 사용하기 2. 테스트 머신(QEMU) 구동 및 개발 머신과 연결(시리얼) $ qemu-system-x86_64 -kernel bzImage -append "kgdboc=ttyS0,115200" -serial pty
  • 15. KGDB 사용하기 2. 테스트 머신(QEMU) 구동 및 개발 머신과 연결(시리얼) $ qemu-system-x86_64 -kernel bzImage -append "kgdboc=ttyS0,115200" -serial pty
  • 16. KGDB 사용하기 3. 개발머신에서 gdb 실행 및 테스트머신과 연결 $ gdb -q vmlinux (gdb) set serial baud 115200 (gdb) target remote /dev/pts/24
  • 17. KGDB는 • GDB를 커널 디버깅에도 사용할 수 있다! • GDB로 제어권이 넘어오는 시점은? 1. 커널패닉/웁스가 발생했을 경우 2. breakpoint에 도달했을 경우 3. MagicSysrq 키를 눌렀을 경우 (CONFIG_MAGIC_SYSRQ)
  • 18. KGDB는 • 강제로 GDB로 제어권을 넘기고 싶다면? MagicSysrq키를 누른다. (누를 수 없는 상황이라면 다음과 같은 명령어 사용.) # echo g > /proc/sysrq-trigger
  • 19. KGDB는 • MagicSysrq키를 누르는 것이 번거롭다면.. 다음과 같이 시스템콜 sync()를 이용한다. 1. 우선 다음과 같이 sys_sync에 breakpoint를 걸어둔다. (gdb) break sys_sync 2. 디버깅이 필요한 경우, 다음과 같이 sync를 실행하여 KGDB로 제어권을 넘긴다. # sync
  • 20. KDB란? • SGI에서 오픈소스 프로젝트로 진행했던 내장 커널 디버거. v2.6.35부터 리눅스 메인라인에 포함. • 브레이크포인트 설정, 메모리 및 자료구조 확인 등을 별도의 외부 시스템 없이 단독으로 가능케함.
  • 21. KDB를 사용하려면 • 원격 시리얼 접속이 가능한 환경 • v2.6.35 이상의 버전과 CONFIG_KGDB_KDB 커널 빌드 옵션 이 켜진 커널 필요
  • 22. KDB 사용하기 1. KDB의 사용이 가능한 커널 빌드 CONFIG_KGDB_KDB=y
  • 23. KDB 사용하기 2. 테스트머신(QEMU) 구동 및 KDB 진입 $ qemu-system-x86_64 -kernel bzImage -hda rootfs.img -serial pty -append “console=ttyS0,115200 kgdboc=ttyS0 root=/dev/sda”
  • 24. KDB 사용하기 2. 테스트머신(QEMU) 구동 및 KDB 진입 $ qemu-system-x86_64 -kernel bzImage -hda rootfs.img -serial pty -append “console=ttyS0,115200 kgdboc=ttyS0 root=/dev/sda”
  • 25. KDB 사용하기 3. 원격 터미널(minicom)로 테스트머신에 접속 $ minicom -p /dev/pts/24 -b 115200
  • 26. KDB 사용하기 4. 커널 웁스, 폴트가 발생할 때 KDB로 진입할 수 있으며, 커널 빌 드 config 중 하나인 CONFIG_MAGIC_SYSRQ를 켰었다면 다 음과 같이 수동으로 진입할 수도 있다. # echo g > /proc/sysrq-trigger
  • 27. KDB는 • “help” 명령어를 통해 더 많은 명령어들을 볼 수 있다. • 몇 개의 유용한 명령어들은 다음과 같다. lsmod - 로드된 커널 모듈 리스트 ps - 현재 동작중인 프로세스 목록 ps A - 모든 프로세스 목록 summary - 커널 버전 정보, 메모리 사용량 bt - 현재 프로세스의 backtrace 출력 dmesg - 커널 syslog 버퍼 출력 go - 시스템을 계속 재개
  • 28. KGDB/KDB 연동하기 1. 테스트머신(QEMU) 구동 $ qemu-system-x86_64 -kernel bzImage -hda rootfs.img -serial pty -append “console=ttyS0,115200 kgdboc=ttyS0 root=/dev/sda”
  • 29. KGDB/KDB 연동하기 2. agent-proxy 다운로드하기 $ git clone git://git.kernel.org/pub/scm/utils/kernel/ kgdb/agent-proxy.git $ cd agent-proxy $ make
  • 30. KGDB/KDB 연동하기 3. agent-proxy를 통해 kgdb와 kdb를 모두 연결할 수 있도록 셋 팅하기 (gdb 접속 1234 포트, console 접속 4567 포트) $ agent-proxy 1234^4567 0 /dev/pts/0,115200
  • 31. KGDB/KDB 연동하기 4. console에 접속 $ telnet localhost 1234
  • 32. KGDB/KDB 연동하기 4. 커널 패닉/웁스 발생 시 KDB로 제어 가능
  • 33. KGDB/KDB 연동하기 5. KDB에서 KGDB로 제어를 넘기려면 <테스트머신에서> kdb> kgdb
  • 34. KGDB/KDB 연동하기 5. KDB에서 KGDB로 제어를 넘기려면 <호스트머신에서> $ gdb -q vmlinux
  • 35. KGDB/KDB 연동하기 6. gdb에서 monitor 명령을 이용하면 lsmod, ps, dmesg 등과 같이 KDB에서 사용가능한 명령어를 바로 사용할 수 있다. $ monitor lsmod
  • 36. KGDB/KDB 연동하기 7. 다음 명령어를 사용하면 다시 KDB로 제어를 넘긴다. $ maint packet 3
  • 37. 참고문헌 • http://studyfoss.egloos.com/5490783 • http://studyfoss.egloos.com/5491083 • http://studyfoss.egloos.com/5491211 • https://www.kernel.org/pub/linux/kernel/people/jwessel/kdb/index.html • https://kgdb.wiki.kernel.org/index.php/ Main_Page#The_new_KDB_and_KGDB_documentation_.28kernel_.3E. 3D_2.6.35.29 • http://www.makelinux.net/books/lkd2/ch18lev1sec8 • http://oss.sgi.com/projects/kgdb/ • http://pds11.egloos.com/pds/200811/14/28/linuxdebug3-wankyuk.pdf