GDB to MDB Migration, Part One

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.

GDBMDBDescription

Starting Up

gdb programmdb 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 coremdb [ program ] coreDebug 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::quitBoth 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 arglistRuns the program with the given arguments. If the target is currently running, or is a corefile, MDB will restart the program if possible.
kill::killForcibly kill and release target.
show env::getenvDisplay current environment.
set env var string::setenv var=stringSet an environment variable.
get env var::getenv varGet a specific environment variable.

Shell Commands

shell cmd! cmdExecute the given shell command.

Breakpoints and Watchpoints

break func
break \*addr
addr::bpSet 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 expraddr::wp -rwx [-L size] Set a watchpoint on the given region of memory.
info break
info watch
::eventsDisplay active watchpoints and breakpoints. MDB will show you signal events as well.
delete [n]::delete nDelete 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.

Comments:

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.

Posted by benr on May 10, 2005 at 08:19 PM PDT #

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?

Posted by bnitz on May 30, 2005 at 11:34 PM PDT #

Post a Comment:
Comments are closed for this entry.
About

Musings about Fishworks, Operating Systems, and the software that runs on them.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today