SlideShare a Scribd company logo
1 of 14
© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Kernel Debugging & Profiling
2© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What to Expect?
Kernel Debugging Tools & Techniques
Kernel Profiling Tools & Mechanism
Kernel Testing Ways
3© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Debugging by Printing
printk & dmesg
int klogctl(int cmd, char *bufp, int len);
syslogd
#include <syslog.h>
void openlog(char *ident, int option, int facility);
void syslog ( int priority, char *format, …);
void closelog( void );
ident – typically short program name
option - LOG_CONS, LOG_PERROR, LOG_PID, …
facility - LOG_AUTHPRIV, LOG_CRON, LOG_DAEMON, LOG_USER, ...
priority - LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR,
LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG
klogd – bridge between kernel ring buffer and syslogd
4© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Debugging by Querying
Through Kernel Windows
/proc
Process related stuff
General system information: cpuinfo, meminfo, …
Drivers related info: devices, iomem, interrupts, ...
/sys (Utilities: sysfsutils, sysdiag)
Buses, Classes, Devices, ...
Using ioctl
Through specific drivers
Using custom commands
5© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Crash Dumping & Analysis
Oops Analysis
CONFIG_BUG, CONFIG_KALLSYMS
Call Trace
cat /proc/kallsyms
objdump -d | -S <obj | exe>
Crash Dumping (using 2 kernel images – could be same)
System Kernel: CONFIG_KEXEC, CONFIG_DEBUG_INFO
Dump-capture Kernel: CONFIG_CRASH_DUMP, CONFIG_PROC_VMCORE, Other
Architecture specific CONFIG_s
Boot System Kernel with crashkernel=size@offset, or crashkernel=range:size
Overlay Dump-capture Kernel using kexec
After Crash (Simulated using SysRq+c, Or real)
System reboots w/ Dump-capture Kernel
Collect the dump using kdump, Or simply cp /proc/vmcore <dump file>
Analyse using <gdb | crash> vmlinux <dump file>
6© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Kernel Hacking Related Options
CONFIG_DEBUG_INFO (gcc -g)
CONFIG_DEBUG_FS
CONFIG_DYNAMIC_DEBUG
CONFIG_DEBUG_STACKOVERFLOW
CONFIG_KMEMCHECK
CONFIG_DEBUG_KMEMLEAK, CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE, ...
CONFIG_LOCKUP_DETECTOR
CONFIG_DEBUG_SPINLOCK, CONFIG_DEBUG_MUTEXES, ...
CONFIG_MAGIC_SYSRQ
CONFIG_EARLY_PRINTK
CONFIG_DEBUG_SLAB, CONFIG_DEBUG_VM, ...
CONFIG_DEBUG_STACK_USAGE
CONFIG_PANIC_ON_OOPS
CONFIG_PANIC_ON_OOPS_VALUE
7© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Kernel Debuggers
Kernel Debugger (Frontend): kdb
CONFIG_DEBUG_INFO, CONFIG_MAGIC_SYSRQ
CONFIG_KGDB, CONFIG_KGDB_KDB,
CONFIG_KGDB_SERIAL_CONSOLE
Basic Operations over Serial Console
Remote Debugging using
kgdb (Kernel Debug Server)
Remote connection & debug through gdb vmlinux
gdb <kernel src>/vmlinux /proc/kcore
Only to gather current kernel debug information
8© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Miscellaneous Tools & Techniques
Early Init Debugs
CONFIG_SERIAL_EARLYCON
CONFIG_EARLY_PRINTK (direct on h/w)
Light & Sound
JTAG
Hardware Protocol Debug
Hardware Protocol Analyzers
Network Debugging
Driver level: ethtool [options] <dev i/f>
Packet level: tcpdump [options, e.g. -vv] -i <dev i/f>
9© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Kernel Probes
kprobes → CONFIG_KPROBES
jprobes → Specialized Kprobes
For probing function entry points
kretprobes → Return Kprobes
For probing function exit points
10© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Tracing
Single Process Tracing using strace
Traces the system calls made by an application
Command: strace [options] <application>
Excellent options to tune to get only desired output
Linux Trace Toolkit
Patch @ http://www.opersys.com/LTT
Core Module
Code using Trace Services
Daemon: tracedaemon
Utilities: tracereader, tracevisualizer
Function Tracer
CONFIG_FUNCTION_TRACER & co
/sys/kernel/debug/tracing
11© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Profiling & Code Coverage
System Profiling
From /proc using LTTng
Kernel Profiling: Oprofile
CONFIG_PROFILING, CONFIG_OPROFILE, CONFIG_APIC
Daemon: oprofiled
Utilities: opcontrol, opreport, op_help, ...
Kernel Performance Profiling using perf
CONFIG_PERF_EVENTS & co
stat, list, top, record, report, ...
Kernel Code Coverage:
CONFIG_GCOV_KERNEL, CONFIG_GCOV_PROFILE_ALL
12© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Testing Possibilities
Linux Test Project (LTP)
Hosted @ http://ltp.sourceforge.net
Suite of around 3000 tests
Exercises various parts of the Kernel
Mostly automated, except net & storage ones
Command: runltp -p -l logfile
User Mode Linux (UML)
Hosted @ http://user-mode-linux.sourceforge.net
A Kernel Instance as a User Mode Process
Kernel Debugging without “oops”ing
Good for testing & experimenting with unstable kernels
13© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What all have we learnt?
Kernel Debugging Tools & Techniques
Debugging by Printing & Querying
Crash Dumping & Analysis
Kernel Hacking Options
Kernel Debuggers
Miscellaneous Tools & Techniques
Kernel Probes
Tracing
Kernel Profiling Tools & Mechanism
Kernel Testing Ways
14© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Any Queries?

More Related Content

What's hot (20)

Real Time Systems
Real Time SystemsReal Time Systems
Real Time Systems
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
 
Toolchain
ToolchainToolchain
Toolchain
 
Signals
SignalsSignals
Signals
 
PCI Drivers
PCI DriversPCI Drivers
PCI Drivers
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Linux Network Management
Linux Network ManagementLinux Network Management
Linux Network Management
 
Character Drivers
Character DriversCharacter Drivers
Character Drivers
 
BeagleBone Black Booting Process
BeagleBone Black Booting ProcessBeagleBone Black Booting Process
BeagleBone Black Booting Process
 
Linux User Space Debugging & Profiling
Linux User Space Debugging & ProfilingLinux User Space Debugging & Profiling
Linux User Space Debugging & Profiling
 
BeagleBoard-xM Booting Process
BeagleBoard-xM Booting ProcessBeagleBoard-xM Booting Process
BeagleBoard-xM Booting Process
 
Linux DMA Engine
Linux DMA EngineLinux DMA Engine
Linux DMA Engine
 
Kernel Programming
Kernel ProgrammingKernel Programming
Kernel Programming
 
Introduction to Linux Drivers
Introduction to Linux DriversIntroduction to Linux Drivers
Introduction to Linux Drivers
 
BeagleBoard-xM Bootloaders
BeagleBoard-xM BootloadersBeagleBoard-xM Bootloaders
BeagleBoard-xM Bootloaders
 
SPI Drivers
SPI DriversSPI Drivers
SPI Drivers
 
Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
 
System Calls
System CallsSystem Calls
System Calls
 
Kernel Timing Management
Kernel Timing ManagementKernel Timing Management
Kernel Timing Management
 
Video Drivers
Video DriversVideo Drivers
Video Drivers
 

Similar to Kernel Debugging & Profiling

Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time OptimizationKan-Ru Chen
 
OSMC 2014: Server Hardware Monitoring done right | Werner Fischer
OSMC 2014: Server Hardware Monitoring done right | Werner FischerOSMC 2014: Server Hardware Monitoring done right | Werner Fischer
OSMC 2014: Server Hardware Monitoring done right | Werner FischerNETWAYS
 
Mod06 new development tools
Mod06 new development toolsMod06 new development tools
Mod06 new development toolsPeter Haase
 
Embedded Android
Embedded AndroidEmbedded Android
Embedded Android晓东 杜
 
Virtual platform
Virtual platformVirtual platform
Virtual platformsean chen
 
HKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with CoresightHKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with CoresightLinaro
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation Jiann-Fuh Liaw
 
Study on Android Emulator
Study on Android EmulatorStudy on Android Emulator
Study on Android EmulatorSamael Wang
 
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법GangSeok Lee
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversAnil Kumar Pugalia
 
BRKDCT-3144 - Advanced - Troubleshooting Cisco Nexus 7000 Series Switches (20...
BRKDCT-3144 - Advanced - Troubleshooting Cisco Nexus 7000 Series Switches (20...BRKDCT-3144 - Advanced - Troubleshooting Cisco Nexus 7000 Series Switches (20...
BRKDCT-3144 - Advanced - Troubleshooting Cisco Nexus 7000 Series Switches (20...aaajjj4
 
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...Felipe Prado
 
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...Paris Open Source Summit
 
Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Jarod Wang
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debuggingHao-Ran Liu
 

Similar to Kernel Debugging & Profiling (20)

Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
 
OSMC 2014: Server Hardware Monitoring done right | Werner Fischer
OSMC 2014: Server Hardware Monitoring done right | Werner FischerOSMC 2014: Server Hardware Monitoring done right | Werner Fischer
OSMC 2014: Server Hardware Monitoring done right | Werner Fischer
 
Mod06 new development tools
Mod06 new development toolsMod06 new development tools
Mod06 new development tools
 
Embedded Android
Embedded AndroidEmbedded Android
Embedded Android
 
Virtual platform
Virtual platformVirtual platform
Virtual platform
 
HKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with CoresightHKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with Coresight
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation
 
Study on Android Emulator
Study on Android EmulatorStudy on Android Emulator
Study on Android Emulator
 
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
 
Network Drivers
Network DriversNetwork Drivers
Network Drivers
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux Drivers
 
BRKDCT-3144 - Advanced - Troubleshooting Cisco Nexus 7000 Series Switches (20...
BRKDCT-3144 - Advanced - Troubleshooting Cisco Nexus 7000 Series Switches (20...BRKDCT-3144 - Advanced - Troubleshooting Cisco Nexus 7000 Series Switches (20...
BRKDCT-3144 - Advanced - Troubleshooting Cisco Nexus 7000 Series Switches (20...
 
There is more to C
There is more to CThere is more to C
There is more to C
 
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
 
Linux on System z debugging with Valgrind
Linux on System z debugging with ValgrindLinux on System z debugging with Valgrind
Linux on System z debugging with Valgrind
 
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
 
Character drivers
Character driversCharacter drivers
Character drivers
 
Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0
 
SR-IOV Introduce
SR-IOV IntroduceSR-IOV Introduce
SR-IOV Introduce
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
 

More from Anil Kumar Pugalia (20)

File System Modules
File System ModulesFile System Modules
File System Modules
 
Processes
ProcessesProcesses
Processes
 
System Calls
System CallsSystem Calls
System Calls
 
Embedded C
Embedded CEmbedded C
Embedded C
 
Playing with R L C Circuits
Playing with R L C CircuitsPlaying with R L C Circuits
Playing with R L C Circuits
 
Audio Drivers
Audio DriversAudio Drivers
Audio Drivers
 
References
ReferencesReferences
References
 
Functional Programming with LISP
Functional Programming with LISPFunctional Programming with LISP
Functional Programming with LISP
 
Power of vi
Power of viPower of vi
Power of vi
 
gcc and friends
gcc and friendsgcc and friends
gcc and friends
 
"make" system
"make" system"make" system
"make" system
 
Hardware Design for Software Hackers
Hardware Design for Software HackersHardware Design for Software Hackers
Hardware Design for Software Hackers
 
RPM Building
RPM BuildingRPM Building
RPM Building
 
Timers
TimersTimers
Timers
 
Threads
ThreadsThreads
Threads
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Processes
ProcessesProcesses
Processes
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
Linux File System
Linux File SystemLinux File System
Linux File System
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 

Recently uploaded

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Recently uploaded (20)

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

Kernel Debugging & Profiling

  • 1. © 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Kernel Debugging & Profiling
  • 2. 2© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What to Expect? Kernel Debugging Tools & Techniques Kernel Profiling Tools & Mechanism Kernel Testing Ways
  • 3. 3© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Debugging by Printing printk & dmesg int klogctl(int cmd, char *bufp, int len); syslogd #include <syslog.h> void openlog(char *ident, int option, int facility); void syslog ( int priority, char *format, …); void closelog( void ); ident – typically short program name option - LOG_CONS, LOG_PERROR, LOG_PID, … facility - LOG_AUTHPRIV, LOG_CRON, LOG_DAEMON, LOG_USER, ... priority - LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG klogd – bridge between kernel ring buffer and syslogd
  • 4. 4© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Debugging by Querying Through Kernel Windows /proc Process related stuff General system information: cpuinfo, meminfo, … Drivers related info: devices, iomem, interrupts, ... /sys (Utilities: sysfsutils, sysdiag) Buses, Classes, Devices, ... Using ioctl Through specific drivers Using custom commands
  • 5. 5© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Crash Dumping & Analysis Oops Analysis CONFIG_BUG, CONFIG_KALLSYMS Call Trace cat /proc/kallsyms objdump -d | -S <obj | exe> Crash Dumping (using 2 kernel images – could be same) System Kernel: CONFIG_KEXEC, CONFIG_DEBUG_INFO Dump-capture Kernel: CONFIG_CRASH_DUMP, CONFIG_PROC_VMCORE, Other Architecture specific CONFIG_s Boot System Kernel with crashkernel=size@offset, or crashkernel=range:size Overlay Dump-capture Kernel using kexec After Crash (Simulated using SysRq+c, Or real) System reboots w/ Dump-capture Kernel Collect the dump using kdump, Or simply cp /proc/vmcore <dump file> Analyse using <gdb | crash> vmlinux <dump file>
  • 6. 6© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Kernel Hacking Related Options CONFIG_DEBUG_INFO (gcc -g) CONFIG_DEBUG_FS CONFIG_DYNAMIC_DEBUG CONFIG_DEBUG_STACKOVERFLOW CONFIG_KMEMCHECK CONFIG_DEBUG_KMEMLEAK, CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE, ... CONFIG_LOCKUP_DETECTOR CONFIG_DEBUG_SPINLOCK, CONFIG_DEBUG_MUTEXES, ... CONFIG_MAGIC_SYSRQ CONFIG_EARLY_PRINTK CONFIG_DEBUG_SLAB, CONFIG_DEBUG_VM, ... CONFIG_DEBUG_STACK_USAGE CONFIG_PANIC_ON_OOPS CONFIG_PANIC_ON_OOPS_VALUE
  • 7. 7© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Kernel Debuggers Kernel Debugger (Frontend): kdb CONFIG_DEBUG_INFO, CONFIG_MAGIC_SYSRQ CONFIG_KGDB, CONFIG_KGDB_KDB, CONFIG_KGDB_SERIAL_CONSOLE Basic Operations over Serial Console Remote Debugging using kgdb (Kernel Debug Server) Remote connection & debug through gdb vmlinux gdb <kernel src>/vmlinux /proc/kcore Only to gather current kernel debug information
  • 8. 8© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Miscellaneous Tools & Techniques Early Init Debugs CONFIG_SERIAL_EARLYCON CONFIG_EARLY_PRINTK (direct on h/w) Light & Sound JTAG Hardware Protocol Debug Hardware Protocol Analyzers Network Debugging Driver level: ethtool [options] <dev i/f> Packet level: tcpdump [options, e.g. -vv] -i <dev i/f>
  • 9. 9© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Kernel Probes kprobes → CONFIG_KPROBES jprobes → Specialized Kprobes For probing function entry points kretprobes → Return Kprobes For probing function exit points
  • 10. 10© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Tracing Single Process Tracing using strace Traces the system calls made by an application Command: strace [options] <application> Excellent options to tune to get only desired output Linux Trace Toolkit Patch @ http://www.opersys.com/LTT Core Module Code using Trace Services Daemon: tracedaemon Utilities: tracereader, tracevisualizer Function Tracer CONFIG_FUNCTION_TRACER & co /sys/kernel/debug/tracing
  • 11. 11© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Profiling & Code Coverage System Profiling From /proc using LTTng Kernel Profiling: Oprofile CONFIG_PROFILING, CONFIG_OPROFILE, CONFIG_APIC Daemon: oprofiled Utilities: opcontrol, opreport, op_help, ... Kernel Performance Profiling using perf CONFIG_PERF_EVENTS & co stat, list, top, record, report, ... Kernel Code Coverage: CONFIG_GCOV_KERNEL, CONFIG_GCOV_PROFILE_ALL
  • 12. 12© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Testing Possibilities Linux Test Project (LTP) Hosted @ http://ltp.sourceforge.net Suite of around 3000 tests Exercises various parts of the Kernel Mostly automated, except net & storage ones Command: runltp -p -l logfile User Mode Linux (UML) Hosted @ http://user-mode-linux.sourceforge.net A Kernel Instance as a User Mode Process Kernel Debugging without “oops”ing Good for testing & experimenting with unstable kernels
  • 13. 13© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What all have we learnt? Kernel Debugging Tools & Techniques Debugging by Printing & Querying Crash Dumping & Analysis Kernel Hacking Options Kernel Debuggers Miscellaneous Tools & Techniques Kernel Probes Tracing Kernel Profiling Tools & Mechanism Kernel Testing Ways
  • 14. 14© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Any Queries?