GDB to MDB Migration, Part One

May 10, 2005

In past comments, it has been pointed out that a transition guide between GDB and MDB would be useful to some developers out there. A full comparison would also cover dbx(1), but I’ll defer this to a later point. Given the number of available commands, I’ll be dividing up this post into at least two pieces.

Before diving into too much detail, it should be noted that MDB and GDB have slightly different design goals. MDB (and KMDB) replaced the aging adb(1) and crash(1M), and was designed primarily for post-mortem analysis and live kernel analysis. To this end, MDB presents the same interface when debugging a crash dump as when examining a live kernel. Solaris corefiles have been enhanced so that all the information for the process (including library text and type information) is present in the corefile. MDB can examine and run live processes, but lacks some of the features (source level debugging, STABS/DWARF support, conditional breakpoints, scripting language) that are standard for developer-centric tools like GDB (or dbx). GDB was designed for interactive process debugging. While you can use GDB on corefiles (and even LKCD crash dumps or Linux kernels – locally and remotely), you often need the original object files to take advantage of GDB’s features.

Before going too far into MDB, be sure to check out Jonathan’s MDB Cheatsheet as a useful quick reference guide, with some examples of stringing together commands into pipelines. Seeing as how I’m not the most accomplished GDB user in the world, I’ll be basing this comparison off the equivalent GDB reference card.

GDB MDB Description

Starting Up

gdb program mdb path
mdb -p pid
Start debugging a command or running process. GDB will treat numeric arguments as pids, while mdb explicitly requires the ‘-p’ option
gdb program core mdb [ program ] core Debug a corefile associated with ‘program’. For MDB, the program is optional and is generally unnecessary given the corefile enhancements made during Solaris 10.

Exiting

quit ::quit Both programs also exit on Ctrl-D.

Getting Help

help
help command
::help
::help dcmd
::dcmds
::walkers
In mdb, you can list all the available walkers or dcmds, as well as get help on a specific dcmd. Another useful trick is ::dmods -l module which lists walkers and dcmds provided by a specific module.

Running Programs

run arglist ::run arglist Runs the program with the given arguments. If the target is currently running, or is a corefile, MDB will restart the program if possible.
kill ::kill Forcibly kill and release target.
show env ::getenv Display current environment.
set env var string ::setenv var=string Set an environment variable.
get env var ::getenv var Get a specific environment variable.

Shell Commands

shell cmd !
cmd
Execute the given shell command.

Breakpoints and Watchpoints

break func
break *addr
addr::bp Set a breakpoint at the given
address or function.
break file:line - Break at the given line of the file. MDB does not
support source level debugging.
break ... if expr - Set a conditional breakpoint. MDB doesn’t support
conditional breakpoints, though you can get a close approximation via the
-c option (though its complicated enough to warrant its own
post).
watch expr addr::wp -rwx [-L size] Set a watchpoint on the given region of memory.
info break
info watch
::events Display active watchpoints
and breakpoints. MDB will show you signal events as well.
delete [n] ::delete n Delete the given breakpoint or
watchpoints.

I think that's enough for now; hopefully the table is at least readable. More to come in a future post.

2 Responses

  1. Excellent! Thanks Eric. I’ve found mdb extremely confusing and intimidating. GDB is just much more comfortable to use, I’d like to switch but I’ve been dragging my heals, your giving me the motivation and tips to get back in and try it out.

  2. Thanks for the info. Just knowing ::help and ::quit helps enormously! From my ‘kernel core dump analysis’ class I remember that mdb had very powerful scripting. I wonder if anyone has hacked a script to make mdb behave as gdb?

Recent Posts

April 21, 2013
February 28, 2013
August 14, 2012
July 28, 2012

Archives