[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
Kernel Extensions and Device Support Programming Concepts

Trace Subcommands for the KDB Kernel Debugger and kdb Command


bt Subcommand

Note: This subcommand is only available within the kdb command; it is not included in the KDB Kernel Debugger.

Trace break point bt may be used to trace each execution occurence of the specified address. Without argument, the break point table is printed. Adding break points, there is a maximum of 32 trace break points.

The segment id (sid) is always used to identify a break point, effective address could have multiple translations in several virtual spaces. kdb needs to reinstall the right instruction when execution is resumed. During this short time (one step if no interrupt) it is possible to miss the trace on others processors.

It is possible to specify if the address is physical or virtual with -p or -v option. By default KDB chooses the current state of the machine: if the subcommand is entered before VMM inititialisation, the address is physical (real address), else virtual (effective address).

Example

   KDB(0)> bt open enable trace on open()
   KDB(0)> bt display current active traces
   0:      .open+000000 (sid:00000000)  trace {hit: 0}
   KDB(0)> e exit debugger
   ...
   open+00000000 (2FF7FF2B, 00000000, DEADBEEF)
   open+00000000 (2FF7FF2F, 00000000, DEADBEEF)
   open+00000000 (2FF7FF33, 00000000, DEADBEEF)
   open+00000000 (2FF7FF37, 00000000, DEADBEEF)
   open+00000000 (2FF7FF3B, 00000000, DEADBEEF)
   ...
   KDB(0)> bt display current active traces
   0:      .open+000000 (sid:00000000)  trace {hit: 5}
   KDB(0)>

ct and cat Subcommands

Note: This subcommand is only available within the kdb command; it is not included in the KDB Kernel Debugger.

To clear trace break point, cat subcommand erases all of them and ct subcommand erases only the specified trace (by slot number, symbol or address).

It is possible to specify if the address is physical or virtual with -p or -v option. By default KDB chooses the current state of the machine: if the subcommand is entered before VMM inititialisation, the address is physical (real address), else virtual (effective address).

WARNING: Slot numbers are not fixed. To clear slot 1 and slot 2 enter ct 2; ct 1 or ct 1; ct 1, do not enter ct 1; ct 2

Example

   KDB(0)> bt open enable trace on open()
   KDB(0)> bt close enable trace on close()
   KDB(0)> bt readlink enable trace on readlink()
   KDB(0)> bt display current active traces
   0:      .open+000000 (sid:00000000)  trace {hit: 0}
   1:      .close+000000 (sid:00000000)  trace {hit: 0}
   2:      .readlink+000000 (sid:00000000)  trace {hit: 0}
   KDB(0)> ct 1 clear trace slot 1
   KDB(0)> bt display current active traces
   0:      .open+000000 (sid:00000000)  trace {hit: 0}
   1:      .readlink+000000 (sid:00000000)  trace {hit: 0}
   KDB(0)> cat clear all active traces
   KDB(0)> bt display current active traces
   No breakpoints are set.
   KDB(0)>

bt script Subcommand

By default the top of the stack is displayed, but it is possible to specified a script of kdb subcommands. These subcommands are executed when the trace break point is hit.

Example

Open routine is traced with a script asking to display iar and lr registers and to show what is pointed by r3, the first parameter. Here open() is called on "sbin" from svc_flih().

   KDB(0)> bt open "dr iar; dr lr; d @r3" enable trace on open()
   KDB(0)> bt display current active traces
   0:      .open+000000 (sid:00000000)  trace {hit: 0} {script: dr iar; dr lr;d @r3}
   KDB(0)> e exit debugger
   iar : 001C5BA0
   .open+000000    mflr    r0                  <.svc_flih+00011C>
   lr  : 00003B34
   .svc_flih+00011C     lwz    toc,4108(0)         toc=TOC,4108=g_toc
   2FF7FF3F: 7362 696E  0074 6D70  0074 6F74  6F00 7500   sbin.tmp.toto.u.
   KDB(0)> bt display current active traces
   0:      .open+000000 (sid:00000000)  trace {hit: 1} {script: dr iar; dr lr;d @r3}
   KDB(0)> ct open clear trace on open
   KDB(0)>

bt [ cond ] Subcommand

With a conditionnal subcommand, it is possible to stop inside kdb when the condition is true.

Example

This example shows how to trace and stop when a condition is true. Here we are waiting for time global data to be greater than the specified value, and 923 hits have been necessary to win.

   KDB(0)> bt sys_timer "[ @time >= 2b8c8c00 ] " enable trace on sys_timer()
   KDB(0)> e exit debugger
   ...
   Enter kdb [ @time >= 2b8c8c00 ]
   KDB(0)> bt display current active traces
   0:      .sys_timer+000000 (sid:00000000)  trace {hit: 923} {script: [ @time >= 2b8c8c00 ] }
   KDB(0)> cat clear all traces

[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]