SlideShare a Scribd company logo
GDB Rocks!    GDB
             The GNU Project
Kent Chen       Debugger
Kent Chen (chenkaie)
chenkaie@gmail.com
http://chenkaie.blogspot.com
@chenkaie on GitHub
@chenkaie on SlideShare
@chenkaie on LinkedIn
@chenkaie on Twitter
為什麼要學
 GDB
Why everybody learns GDB?
非互動式/交談式
 Non-Interactive
   Debugging
strace - system call, signal

   ltrace - library call
printf / printk
 “打印”久了
也挺煩人的
Debugging by Endless Printing
GDB
Source-Level
  Debugger
互動式/交談式
 你叫它幹麻它就幹麻

Interactive Debugging
有了Debugger
Coding是彩色的
         - by Jserv/宅色夫大大

No Debugger, No Happy Coding
學會了GDB
我有種山頂洞人
學會用火的感動
                       - by 張至


張至是誰?! 我也不認識, Google到的,某某鄉民吧!
GDB
Front Ends
gdbtui
cgdb
ddd (Joe’s Fav)
insight
clewn / vim + gdb
pyclewn
gdbmgr
分享小弟
     入門經驗
Sharing my real-world GDB experience
牛刀小試
幼幼班
GDB Beginner’s training
Change memory contents on-the-fly
Change memory contents on-the-fly
stack backtrace
Attach to a process
Jump $pc (program counter)
core dump
core dump (cont.)
core dump (cont.)
Patch binary file
Patch binary file (cont.)

$objdump -d -S -l -shrt dump1.out   Change “ef01” to “ef00”
奇技淫巧
進階班
Advanced GDB Tricks
奇技淫巧:
奇異而眩人耳目の
  技能或事物

    (from 教育部國語辭典)
SIGSEGV + GDB
C interpreter
1. $ gdb `which gdb`
2. (gdb) start
3. Enjoy your world…
• Example:
  (gdb)  p  1  +  2  +  abs(-­‐3)
  (gdb)  p  strcmp("VIVOTEK",  "AXIS")
  (gdb)  x/s  getenv(“HOME”)
  (gdb)  p  (char*)getenv("HOME")
  (gdb)  p  (char)*getenv("HOME")
  (gdb)  p  printf("%dn",  12345678)
Signal Handler
Terminal hang / Reboot PC
  You have to close terminal (e.g., PuTTY, iTerm,...)
Conventional solution
                          (gdb)  handle  SIGHUP

  GNU Screen / Tmux       Signal                Stop            Print      Pass  to  program  Description
                          SIGHUP                Yes              Yes          Yes                          Hangup
                          (gdb)  handle  SIGHUP  nopass
                          Signal                Stop            Print      Pass  to  program  Description
  nohup                   SIGHUP                Yes              Yes          No                            Hangup

                          Program  received  signal  SIGHUP,  Hangup.
GDB solution              0x0000003ac7a954e0  in  __nanosleep_nocancel  ()  from  /lib64/libc.so.6
                          (gdb)
                          Continuing.

  $ gdb [program] [pid]
  (gdb) handle SIGHUP nopass
  (gdb) continue
經典案例
實戰探討
A real-world case study
案例一、
 Case 1
GNU C Library
   (glibc)
  debugging / 除錯
Why?
追求
    卓越
Pursuit of excellence :)
DieLink
呆吝蚵
江湖中
流傳已久
A well-know issue
某某
Daemon
 之死
Process crash issue
dmesg
cat /proc/`pidof configer`/maps
SIGSEGV
@libc-2.5.90.so
WTF!!
不會吧(驚)
ㄎㄎ
 我有學過
Core dump
無敵の gdb core dump
backtrace (bt)
_IO_strn_overflow ()
     vfprintf ()

C language !?
WTF!!
不會吧(驚驚)
欲窮千里目
更上一層樓
ㄎㄎ我有學過
gdb frame UP
frame [index] / up / down
WTF!!
ARM assembly
組合語言
 什麼鬼呀
大學修完課後就通通還給老師了
C Code & ARM assembly
看似
專業 Pro
 Looks “GEEK”
In fact
實際上
發現 gcc -O3
    TMD
  實在太難看了
It’s god damn hard to read after gcc -O3
我們需要
Source Level
 Debugging
Use the
Source
Loser... Orz
May
The Source
  Be With
    You
How?
RTFM
   Read The
Fucking Manual
load by symbol-file cmd
Re-build
debug version
shared library
  with "-g"
set solib-absolute-prefix
Source be with You
發現傳入
 snprintf()
の資料都正確
OMFG!
電梯繼續向下
gdb frame down
到了
  /lib/libc.so.6
-> libc-2.5.90.so
Shit!
 若仿照
上面作法
難不成要自己
 build debug
版のlibc-2.5.90
Oh No !
使用大廠の
偷偷Solution
你有權利
Say NO
MontaVista
已經幫我們
 Build 好了
lib*.*.so.*.debug
glibc source level debug
DEMO
Null pointer access issue
多虧了
神器 GDB
我們終於學會
Shared Library
  Debugging
某Daemon之死
至今仍是個謎  (驚)
案例二、
 Case 2
劫持 FDs
File Descriptors Hijacking
時間有限
   下回揭曉
File Descriptor Hijacking / 劫持 FDs 之奇技淫巧
Reference
快快樂樂學 GNU Debugger (gdb) Part I + II (Jserv)
  http://jserv.sayya.org/debugger/
http://pyclewn.sourceforge.net/
http://clewn.sourceforge.net/
http://reverse.put.as/
GDB的妙用 (vgod)
[GDB Tricks] File Descriptor Hijacking / 劫持 FDs 之奇技淫巧

More Related Content

PDF
Q2.12: Debugging with GDB
Linaro
 
PPT
Introduction to gdb
Owen Hsu
 
PDF
Interpreter, Compiler, JIT from scratch
National Cheng Kung University
 
PDF
Macro-processor
Temesgen Molla
 
PPTX
Design of a two pass assembler
Dhananjaysinh Jhala
 
PPTX
Single pass assembler
Bansari Shah
 
PPTX
Cubic
deawoo Kim
 
PDF
How A Compiler Works: GNU Toolchain
National Cheng Kung University
 
Q2.12: Debugging with GDB
Linaro
 
Introduction to gdb
Owen Hsu
 
Interpreter, Compiler, JIT from scratch
National Cheng Kung University
 
Macro-processor
Temesgen Molla
 
Design of a two pass assembler
Dhananjaysinh Jhala
 
Single pass assembler
Bansari Shah
 
Cubic
deawoo Kim
 
How A Compiler Works: GNU Toolchain
National Cheng Kung University
 

What's hot (20)

PDF
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
National Cheng Kung University
 
PPTX
Understand more about C
Yi-Hsiu Hsu
 
PDF
Learn C Programming Language by Using GDB
National Cheng Kung University
 
PDF
from Source to Binary: How GNU Toolchain Works
National Cheng Kung University
 
PDF
The Internals of "Hello World" Program
National Cheng Kung University
 
PDF
用十分鐘 向jserv學習作業系統設計
鍾誠 陳鍾誠
 
PDF
淺談探索 Linux 系統設計之道
National Cheng Kung University
 
PDF
Linux kernel tracing
Viller Hsiao
 
PDF
Virtual Machine Constructions for Dummies
National Cheng Kung University
 
PDF
ARM Trusted FirmwareのBL31を単体で使う!
Mr. Vengineer
 
PDF
DevConf 2014 Kernel Networking Walkthrough
Thomas Graf
 
PPTX
Linux Network Stack
Adrien Mahieux
 
PDF
Working Remotely (via SSH) Rocks!
Kent Chen
 
PDF
LinuxのFull ticklessを試してみた
Hiraku Toyooka
 
PDF
BPF - in-kernel virtual machine
Alexei Starovoitov
 
PDF
Dockerからcontainerdへの移行
Kohei Tokunaga
 
PDF
What Can Compilers Do for Us?
National Cheng Kung University
 
PDF
Memory Mapping Implementation (mmap) in Linux Kernel
Adrian Huang
 
PDF
Kernel Recipes 2015: Kernel packet capture technologies
Anne Nicolas
 
PDF
GNU ld的linker script簡介
Wen Liao
 
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
National Cheng Kung University
 
Understand more about C
Yi-Hsiu Hsu
 
Learn C Programming Language by Using GDB
National Cheng Kung University
 
from Source to Binary: How GNU Toolchain Works
National Cheng Kung University
 
The Internals of "Hello World" Program
National Cheng Kung University
 
用十分鐘 向jserv學習作業系統設計
鍾誠 陳鍾誠
 
淺談探索 Linux 系統設計之道
National Cheng Kung University
 
Linux kernel tracing
Viller Hsiao
 
Virtual Machine Constructions for Dummies
National Cheng Kung University
 
ARM Trusted FirmwareのBL31を単体で使う!
Mr. Vengineer
 
DevConf 2014 Kernel Networking Walkthrough
Thomas Graf
 
Linux Network Stack
Adrien Mahieux
 
Working Remotely (via SSH) Rocks!
Kent Chen
 
LinuxのFull ticklessを試してみた
Hiraku Toyooka
 
BPF - in-kernel virtual machine
Alexei Starovoitov
 
Dockerからcontainerdへの移行
Kohei Tokunaga
 
What Can Compilers Do for Us?
National Cheng Kung University
 
Memory Mapping Implementation (mmap) in Linux Kernel
Adrian Huang
 
Kernel Recipes 2015: Kernel packet capture technologies
Anne Nicolas
 
GNU ld的linker script簡介
Wen Liao
 
Ad

Viewers also liked (20)

PPTX
Advanced Debugging with GDB
David Khosid
 
PDF
Vim Rocks!
Kent Chen
 
PDF
TMUX Rocks!
Kent Chen
 
PDF
面試面試面試,因為很重要所以要說三次!
Chih-Hsuan Kuo
 
PDF
Tmux tips and_tricks
Arc & Codementor
 
PDF
Introduction to Tmux - Codementor Tmux Office Hours Part 1
Arc & Codementor
 
PPT
효과적인 임베디드 디버깅 환경구축
guest0ad316e
 
PPT
How to debug a perl script using gdb
akirahiguchi
 
PDF
From printk to QEMU: Xen/Linux Kernel debugging
The Linux Foundation
 
PDF
Hunting segfaults (for beginners)
uwevoelker
 
PDF
Advanced Tracing features using GDB and LTTng
marckhouzam
 
PDF
Crash Dump Analysis 101
John Howard
 
PDF
Debugger Principle Overview & GDB Tricks
dutor
 
KEY
淺入淺出 GDB
Jim Chang
 
PDF
簡易的面試心得分享
Jack Wang
 
PDF
Aag c45 697761
HP IN Rajesh Goel
 
PDF
Reverse, Multi-Process and Non-Stop Debugging come to the CDT
marckhouzam
 
PPT
Real time debugging: using non-intrusive tracepoints to debug live systems
marckhouzam
 
PDF
面試心得
澐 向
 
Advanced Debugging with GDB
David Khosid
 
Vim Rocks!
Kent Chen
 
TMUX Rocks!
Kent Chen
 
面試面試面試,因為很重要所以要說三次!
Chih-Hsuan Kuo
 
Tmux tips and_tricks
Arc & Codementor
 
Introduction to Tmux - Codementor Tmux Office Hours Part 1
Arc & Codementor
 
효과적인 임베디드 디버깅 환경구축
guest0ad316e
 
How to debug a perl script using gdb
akirahiguchi
 
From printk to QEMU: Xen/Linux Kernel debugging
The Linux Foundation
 
Hunting segfaults (for beginners)
uwevoelker
 
Advanced Tracing features using GDB and LTTng
marckhouzam
 
Crash Dump Analysis 101
John Howard
 
Debugger Principle Overview & GDB Tricks
dutor
 
淺入淺出 GDB
Jim Chang
 
簡易的面試心得分享
Jack Wang
 
Aag c45 697761
HP IN Rajesh Goel
 
Reverse, Multi-Process and Non-Stop Debugging come to the CDT
marckhouzam
 
Real time debugging: using non-intrusive tracepoints to debug live systems
marckhouzam
 
面試心得
澐 向
 
Ad

Similar to GDB Rocks! (20)

PDF
lab1-ppt.pdf
AbdelrahmanElewah1
 
PPT
Debugging Applications with GNU Debugger
Priyank Kapadia
 
PPTX
Debuging like a pro
Vicente Bolea
 
PPTX
Debugging Modern C++ Application with Gdb
SenthilKumar Selvaraj
 
PDF
gdb-tutorial.pdf
ligi14
 
PDF
Gdb tutorial-handout
Suraj Kumar
 
PDF
Usage of GDB
Jongseok Choi
 
PDF
GDB tutorial
Anurag Patel
 
PDF
ELC-E Linux Awareness
Peter Griffin
 
PDF
LAS16-403 - GDB Linux Kernel Awareness
Peter Griffin
 
PDF
LAS16-403: GDB Linux Kernel Awareness
Linaro
 
PDF
05-Debug.pdf
KalaiselviDevaraj
 
PDF
Introduction to segmentation fault handling
Larion
 
PDF
GPU Accelerated Domain Decomposition
Richard Southern
 
PDF
Ctrl-C redesign for gcc cauldron in 2022 in prague
ssuser866937
 
PDF
Debugging of (C)Python applications
Roman Podoliaka
 
ODP
Отладка в GDB
Anthony Shoumikhin
 
PPT
Gccgdb
selva raj
 
PPTX
Extending GDB with Python
Lisa Roach
 
PDF
Debug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code Meetup
Jian-Hong Pan
 
lab1-ppt.pdf
AbdelrahmanElewah1
 
Debugging Applications with GNU Debugger
Priyank Kapadia
 
Debuging like a pro
Vicente Bolea
 
Debugging Modern C++ Application with Gdb
SenthilKumar Selvaraj
 
gdb-tutorial.pdf
ligi14
 
Gdb tutorial-handout
Suraj Kumar
 
Usage of GDB
Jongseok Choi
 
GDB tutorial
Anurag Patel
 
ELC-E Linux Awareness
Peter Griffin
 
LAS16-403 - GDB Linux Kernel Awareness
Peter Griffin
 
LAS16-403: GDB Linux Kernel Awareness
Linaro
 
05-Debug.pdf
KalaiselviDevaraj
 
Introduction to segmentation fault handling
Larion
 
GPU Accelerated Domain Decomposition
Richard Southern
 
Ctrl-C redesign for gcc cauldron in 2022 in prague
ssuser866937
 
Debugging of (C)Python applications
Roman Podoliaka
 
Отладка в GDB
Anthony Shoumikhin
 
Gccgdb
selva raj
 
Extending GDB with Python
Lisa Roach
 
Debug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code Meetup
Jian-Hong Pan
 

Recently uploaded (20)

PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
The Future of Artificial Intelligence (AI)
Mukul
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 

GDB Rocks!