Borys Bradel's Blog
Debugging on Solaris using MDB
Tags: programming March 7, 2009
I recently tried to debug an application on Solaris. The following is what I learned in the process.
The debugger on Solaris is called the Modular Debugger, aka mdb.
First, elfdump can be used to figure out the addresses of functions. Then ldd can be used to figure out which libraries a program uses. Then, the program can be debugged by calling mdb. I used each function with one, the name of the executable. Also, mdb can be called with its parameter being the core file of a core dump.
Once mdb is started, the environment variables can be seen with the command ::getenv. They can be set with ::setenv var=value. A breakpoint can be set with the command :b or :br preceded by the address of the breakpoint (e.g. if the start of function f() is 0x001b1bc a breakpoint can be set with 1b1bc:b). A list of existing breakpoints can be seen with the ::events command. ::delete n will remove the nth breakpoint on the list. The command ::run args can be used to start the program. ::kill will terminate the program.
When a breakpoint occurs, the :c command can be used to continue past it. Alternatively, the :s command can be used to step through one instruction at a time. Also, ctrl-z interrupts execution.
There are many functions that can print information. The $e command prints global symbols. The $m command prints a map of memory. The ::print command preceded by an address prints data at that address. The ::stack commands prints the stack. The ::regs command prints the registers. And the ::dis command preceded by the address prints assembly code at a certain location. There are many more available commands. Help is available inside mdb through the ::help and ::dcmds commands.
Once there is nothing more to debug, ::quit will exit mdb.
Four sources of useful information are Solaris Modular Debugger Guide, Don't be afraid of mdb, and GDB to MDB Migration Part One and Part Two.
Copyright © 2009 Borys Bradel. All rights reserved. This post is only my possibly incorrect opinion.