chpt_mdb_os.fm Page 123 Monday, January 30, 2006 1:11 PM
3
The Modular Debugger
With contributions from Mike Shapiro, Eric Schrock and Matt Simmons
This chapter broadly explains how to use the Modular Debugger, MDB, to debug systems and applications. It leads to the full reference for MDB, which is available in the Solaris Modular Debugger Guide. We have structured this chapter in the following main sections: “Introduction to the Modular Debugger” on page 123 — background and the- ory of MDB. “Getting Started with MDB” on page 129 — a hands-on tour of MDB features. “Debugging Kernel Cores” on page 154 — a hands-on guide to kernel-related MDB features. Start here if you want skip the longer tutorial on MDB, and jump right into MDB’s core commands. “kmdb, the Kernel Modular Debugger” on page 178 — Debugging a live ker- nel with kmdb. “kmdb Implementation” on page 185 — The architecture and implementation of the kernel MDB. References: GDB-to-MDB Migration; MDB Command Reference.
3.1 Introduction to the Modular Debugger
If you were a detective investigating the scene of a crime, you might interview wit-
nesses and ask them to describe what happened and who they saw. However, if Solaris Internals 2nd Edition: See solarisinternals.com DRAFT FROM
123
chpt_mdb_os.fm Page 124 Monday, January 30, 2006 1:11 PM
124 Chapter 3 The Modular Debugger
there were no witnesses or these descriptions proved insufficient, you might con- sider collecting fingerprints and forensic evidence that could be examined for DNA to help solve the case. Often, software program failures divide into analogous cate- gories: problems that can be solved with source-level debugging tools; and prob- lems that require low-level debugging facilities, examination of core files, and knowledge of assembly language to diagnose and correct. MDB facilitates analysis of this second class of problems. It might not be necessary to use MDB in every case, just as a detective doesn’t need a microscope and DNA evidence to solve every crime. However, when pro- gramming a complex low-level software system such as an operating system, you might frequently encounter these situations. That’s why MDB is designed as a debugging framework that lets you construct your own custom analysis tools to aid in the diagnosis of these problems. MDB also provides a powerful set of built-in commands with which you can analyze the state of your program at the assembly language level.
3.1.1 MDB MDB provides a completely customizable environment for debugging programs, including a dynamic module facility that programmers can use to implement their own debugging commands to perform program-specific analysis. Each MDB mod- ule can examine the program in several different contexts, including live and post- mortem. The Solaris Operating System includes a set of MDB modules that assist programmers in debugging the Solaris kernel and related device drivers and ker- nel modules. Third-party developers might find it useful to develop and deliver their own debugging modules for supervisor or user software.
3.1.2 MDB Features MDB offers an extensive collection of features for analyzing the Solaris kernel and other target programs. Here’s what you can do: Perform postmortem analysis of Solaris kernel crash dumps and user process core dumps. MDB includes a collection of debugger modules that facilitate sophisti- cated analysis of kernel and process state, in addition to standard data dis- play and formatting capabilities. The debugger modules allow you to formulate complex queries to do the following: – Locate all the memory allocated by a particular thread – Print a visual picture of a kernel STREAM DRAFT FROM Solaris Internals 2nd Edition: See solarisinternals.com DRAFT FROM
chpt_mdb_os.fm Page 125 Monday, January 30, 2006 1:11 PM
3.1 INTRODUCTION TO THE MODULAR DEBUGGER 125
– Determine what type of structure a particular address refers to – Locate leaked memory blocks in the kernel – Analyze memory to locate stack traces