GDB to MDB Migration, Part Two

So talking to Ben last night convinced me I needed to finish up the GDB to MDB reference that I started last month. So here's part two.

GDBMDBDescription

Program Stack

backtrace n::stack
$C
Display stack backtrace for the current thread
-thread::findstack -v Display a stack for a given thread. In the kernel, thread is the address of the kthread_t. In userland, it's the thread identifier.
info ...- Display information about the current frame. MDB doesn't support the debugging data necessary to maintain the frame abstraction.

Execution Control

continue
c
:c Continue target.
stepi
si
::step
]
Step to the next machine instruction. MDB does not support stepping by source lines.
nexti
ni
::step over
[
Step over the next machine instruction, skipping any function calls.
finish::step out Continue until returning from the current frame.
jump \*addressaddress>reg Jump to the given location. In MDB, reg depends on your platform. For SPARC it's 'pc', for i386 its 'eip', and for amd64 it's 'rip'.

Display

print expraddr::print expr Print the given expression. In GDB you can specify variable names as well as addresses. For MDB, you give a particular address and then specify the type to display (which can include dereferencing of members, etc).
print /faddr/f Print data in a precise format. See ::formats for a list of MDB formats.
disassem addraddr::dis Dissasemble text at the given address, or the current PC if no address is specified

This is just a primer. Both programs support a wide variety of additional options. Running 'mdb -k', you can quickly see just how many commands are out there:

> ::dcmds ! wc -l
     385
> ::walkers ! wc -l
     436

One helpful trick is ::dcmds ! grep thing, which searches the description of each command. Good luck, and join the discussion over at the OpenSolaris MDB community if you have any questions or tips of your own.

Technorati tag:
Technorati tag:
Technorati tag:

Comments:

Gosh, based on that primer one would think gdb is clearly a better choice. Twice you had to say that mdb just couldn't do something gdb did -- and they were pretty major things like looking at your frame and stepping by source line... And the commands for mdb are pretty esoteric. Why is step prefixed by two colons but continue by one? What's the logic spelling bracktrace "$C"?

Posted by guest on June 17, 2005 at 06:26 AM PDT #

Anonymous coward -

As has been mentioned many times before, MDB is not a source level debugger because it was not the design center. The things I mentioned above are things MDB can't do because we can't do source level debugging. But we're also orders of magnitude ahead of GDB in terms of post mortem debugging and kernel debugging. So MDB is not the right tool for every job, it's better at some things and GDB is better at others.

As for the language, it's a necessary complication do to historical reasons: compatibility with adb(1). I should have noted that '$C' (the old adb version) can be replaced by '::stack' to be more modern. See the OpenSolaris community for more possible enhancements and further discussion.

Posted by Eric Schrock on June 17, 2005 at 06:32 AM 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