Section 13.3. Working with Debugging Targets


13.3. Working with Debugging Targets

MDB can control and interact with live mdb processes or kmdb kernel targets. Typical debugging operations include starting, stopping, and stepping the target. We discuss more about controlling kmdb targets in Chapter 14. The common commands for controlling targets are summarized in Table 13.12.

Table 13.12. Debugging Target dcmds

dcmd

Description

::status


Print summary of current target.

$r ::regs


Display current register values for target.

$c ::stack $C


Print current stack trace ($C: with frame pointers).

addr[, b] ::dump [-g sz] [-e]


Dump at least b bytes starting at address addr. -g sets the group size; for 64-bit debugging, -g 8 is useful.

addr::dis


Disassemble text, starting around addr.

[ addr ] :b [ addr ] ::bp [+/-dDestT] [-c cmd] [-n count] sym ... addr [cmd ... ]


Set breakpoint at addr.

$b ::events [-av] $b [-av]


Display all breakpoints.

addr ::delete [id | all] addr :d [id | all]


Delete a breakpoint at addr.

:z

Delete all breakpoints.

::cont [SIG] :c [SIG]


Continue the target program, and wait for it to terminate.

id ::evset [+/-dDestT] [-c cmd] [-n count] id ...


Modify the properties of one or more software event specifiers.

::next [SIG] :e [SIG]


Step the target program one instruction, but step over subroutine calls.

::step [branch | over | out] [SIG] :s SIG :u SIG


Step the target program one instruction.

addr [, len]::wp [+/-dDestT] [-rwx] [-ip] [-c cmd] [-n count] addr [, len]:a [cmd... ] addr [, len]:p [cmd... ] addr [, len]:w [cmd... ]


Set a watchpoint at the specified address.


13.3.1. Displaying Stacks

We can print a stack of the current address with the $c command or with $C, which also prints the stack frame address for each stack level.

> $c atomic_add_32+8(0) nfs4_async_inactive+0x3b(dc1c29c0, 0) nfs4_inactive+0x41() fop_inactive+0x15(dc1c29c0, 0) vn_rele+0x4b(dc1c29c0) snf_smap_desbfree+0x59(dda94080) > $C d2a58828 atomic_add_32+8(0) d2a58854 nfs4_async_inactive+0x3b(dc1c29c0, 0) d2a58880 nfs4_inactive+0x41() d2a5889c fop_inactive+0x15(dc1c29c0, 0) d2a588b0 vn_rele+0x4b(dc1c29c0) d2a588c0 snf_smap_desbfree+0x59(dda94080) 


13.3.2. Displaying Registers

We can print a stack of the current address with the $c command or with $C, which also prints the stack frame address for each stack level.

> ::regs (or $r) %cs = 0x0158            %eax = 0x00000000 %ds = 0xd9820160                %ebx = 0xde453000 %ss = 0x0000            %ecx = 0x00000001 %es = 0xfe8d0160                %edx = 0xd2a58de0 %fs = 0xfec30000                %esi = 0xdc062298 %gs = 0xfe8301b0                %edi = 0x00000000 %eip = 0xfe82ca58 atomic_add_32+8 %ebp = 0xd2a58828 %esp = 0xd2a58800 %eflags = 0x00010282   id=0 vip=0 vif=0 ac=0 vm=0 rf=1 nt=0 iopl=0x0   status=<of,df,IF,tf,SF,zf,af,pf,cf>   %uesp = 0xfe89ab0d %trapno = 0xe    %err = 0x2 


13.3.3. Disassembling the Target

We can dissasemble instructions in the target with the ::dis dcmd.

> atomic_add_32+8::dis atomic_add_32:                  movl    0x4(%esp),%eax atomic_add_32+4:                movl    0x8(%esp),%ecx atomic_add_32+8:                lock addl %ecx,(%eax) atomic_add_32+0xb:              ret 


Note that in this example combined with the registers shown in Section 13.3.2, the contents of %eax from $r is zero, causing the movl instruction to trap with a NULL pointer reference at atomic_add_32+4.

13.3.4. Setting Breakpoints

We can set breakpoints in MDB by using :b. Typically, we pass a symbol name to :b (the name of the function of interest).

We can start the target program and then set a breakpoint for the printf function.

> printf:b > :r mdb: stop at 0x8050694 mdb: target stopped at: PLT:printf:     jmp    *0x8060980 


In this example, we stopped at the first symbol matching "printf", which is actually in the procedure linkage table (PLT) (see the Linker and Libraries manual for a description of how dynamic linking works in Solaris). To match the printf we likely wanted, we can increase the scope of the symbol lookup. The :c command continues execution until the next breakpoint or until the program finishes.

> libc`printf:b > :c mdb: stop at libc.so.1`printf mdb: target stopped at: libc.so.1`printf:       pushl  %ebp 





Solaris Performance and Tools(c) Dtrace and Mdb Techniques for Solaris 10 and Opensolaris
Solaris Performance and Tools: DTrace and MDB Techniques for Solaris 10 and OpenSolaris
ISBN: 0131568191
EAN: 2147483647
Year: 2007
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net