[kgtp] r1551 committed - Add while-stepping to doc

  • From: kgtp@xxxxxxxxxxxxxx
  • To: kgtp@xxxxxxxxxxxxx
  • Date: Wed, 08 May 2013 06:39:22 +0000

Revision: 1551
Author:   teawater
Date:     Tue May  7 23:39:05 2013
Log:      Add while-stepping to doc

http://code.google.com/p/kgtp/source/detail?r=1551

Modified:
 /wiki/HOWTO.wiki
 /wiki/HOWTOCN.wiki

=======================================
--- /wiki/HOWTO.wiki    Wed Apr 17 01:32:07 2013
+++ /wiki/HOWTO.wiki    Tue May  7 23:39:05 2013
@@ -1,5 +1,5 @@
 #labels Phase-QA,Phase-Deploy
-Update in 2013-04-16
+Update in 2013-05-08
 <wiki:toc max_depth="4" />
 = What is KGTP =
*KGTP* is a *flexible* , *lightweight* and *realtime* Linux *debugger* and *tracer*.<br>
@@ -1273,6 +1273,74 @@
 }}}
Define a normal tracepoint that stop the tracepoint that watch file->f_pos and file->f_op.

+== Use while-stepping let Linux kernel do single step ==
+=== Howto use while-stepping ===
+while-stepping is a special tracepoint action that include some actions with it.<br> +When tracepoints that its actions include "while-stepping n" execute, it will do n times single steps and executes the actions of while-stepping. For example:
+{{{
+trace vfs_read
+#Because single step will make system slow, so use passcount or condition to limit the execution times of tracepoint is better.
+passcount 1
+  commands
+    collect $bt
+    collect $step_count
+    #do 2000 times single steps.
+    while-stepping 2000
+      #Following part is actions of "while-stepping 2000".
+ #Because step maybe execute to other functions, so does not access local variables is better.
+      collect $bt
+      collect $step_count
+    end
+  end
+}}}
+Please *note* that tracepoint will disable the interrupt of current CPU when it do single step. +Access *$step_count* in actions will get the count of this step that begin with 1.
+
+=== Read the traceframe of while-stepping ===
+The data of different step that is recorded by while-stepping actions will be saved in different traceframe that you can use tfind ([#Use_tfind_select_the_entry_inside_the_trace_frame_info]) to select them.<br> +Or you can switch KGTP to replay mode to select all the traceframe of a while-stepping tracepoint with GDB execution and reverse-execution commands. For example:
+{{{
+#Use tfind select one the traceframe of a while-stepping tracepoint.
+(gdb) tfind
+Found trace frame 0, tracepoint 1
+#0 vfs_read (file=0xffff8801f7bd4c00, buf=0x7fff74e4edb0 <Address 0x7fff74e4edb0 out of bounds>, count=16, + pos=0xffff8801f4b45f48) at /build/buildd/linux-3.2.0/fs/read_write.c:365
+365    {
+#Following commands will swith KGTP to replay mode.
+(gdb) monitor replay
+(gdb) tfind -1
+No longer looking at any trace frame
+#0 vfs_read (file=0xffff8801f7bd4c00, buf=0x7fff74e4edb0 <Address 0x7fff74e4edb0 out of bounds>, count=16, + pos=0xffff8801f4b45f48) at /build/buildd/linux-3.2.0/fs/read_write.c:365
+365    {
+#Then you can use execution commands.
+(gdb) n
+368            if (!(file->f_mode & FMODE_READ))
+(gdb) p file->f_mode
+$5 = 3
+#Set breakpoints (Just valid in replay mode, will not affect Linux kernel execution).
+(gdb) b 375
+Breakpoint 2 at 0xffffffff81179b75: file /build/buildd/linux-3.2.0/fs/read_write.c, line 375.
+(gdb) c
+Continuing.
+
+Breakpoint 2, vfs_read (file=0xffff8801f7bd4c00, buf=0x7fff74e4edb0 <Address 0x7fff74e4edb0 out of bounds>, count=16, + pos=0xffff8801f4b45f48) at /build/buildd/linux-3.2.0/fs/read_write.c:375
+375            ret = rw_verify_area(READ, file, pos, count);
+(gdb) s
+rw_verify_area (read_write=0, file=0xffff8801f7bd4c00, ppos=0xffff8801f4b45f48, count=16)
+    at /build/buildd/linux-3.2.0/fs/read_write.c:300
+300            inode = file->f_path.dentry->d_inode;
+#Use reverse-execution commands.
+(gdb) rs
+
+Breakpoint 2, vfs_read (file=0xffff8801f7bd4c00, buf=0x7fff74e4edb0 <Address 0x7fff74e4edb0 out of bounds>, count=16, + pos=0xffff8801f4b45f48) at /build/buildd/linux-3.2.0/fs/read_write.c:375
+375            ret = rw_verify_area(READ, file, pos, count);
+(gdb) rn
+372            if (unlikely(!access_ok(VERIFY_WRITE, buf, count)))
+}}}
+GDB commands tstart, tfind or quit can auto close the replay mode.
 == Howto show a variable whose value has been optimized away  ==
 Sometimes, GDB will output some value like:
 {{{
=======================================
--- /wiki/HOWTOCN.wiki  Wed Apr 17 01:32:07 2013
+++ /wiki/HOWTOCN.wiki  Tue May  7 23:39:05 2013
@@ -1,5 +1,5 @@
 #labels Phase-QA,Phase-Deploy
-Update in 2013-04-16
+Update in 2013-05-08
 <wiki:toc max_depth="4" />
 = 什么是KGTP =
 *KGTP* 是一个 *灵活* *轻量级* *实时* Linux *调试器* 和 *跟踪器* 。<br>
@@ -1274,6 +1274,74 @@
 }}}
在函数file_sb_list_del中定义一个普通tracepoint,其将停止监视file->f_pos和 file->f_op。

+== 使用while-stepping让Linux内核做单步 ==
+=== 如何使用 while-stepping ===
+while-stepping 是一种可以包含actions的特殊tracepoint action。<br>
+当一个actions中包含了“while-stepping n”的tracepoint执行的时候,其将做n次单 步并执行while-stepping的actions。例如:
+{{{
+trace vfs_read
+#因为单步会影响系统速度,所以最好用passcount或者condition限制tracepoint的执 行次数。
+passcount 1
+  commands
+    collect $bt
+    collect $step_count
+    #做2000次单步。
+    while-stepping 2000
+      #下面这部分是"while-stepping 2000"的actions。
+      #因为单步可能会执行到其他函数,所以最好不要访问局部变量。
+      collect $bt
+      collect $step_count
+    end
+  end
+}}}
+请 *注意* tracepoint在执行单步的时候会关闭当前CPU的中断。
+在actions中访问 *$step_count* 将得到从1开始的这步的计数。
+
+=== 读while-stepping的traceframe ===
+不同step的数据将会被记录到不同的traceframe中,你可以用tfind ([https://code.google.com/p/kgtp/wiki/HOWTOCN#用tfind选择trace帧缓存里面的条 目]) 选择他们。<br> +或者你可以将KGTP切换到回放模式,这样GDB可以用执行和反向执行命令选择一个 while-stepping tracepoint的traceframe。例如:
+{{{
+#用tfind选择一个while-stepping的traceframe。
+(gdb) tfind
+Found trace frame 0, tracepoint 1
+#0 vfs_read (file=0xffff8801f7bd4c00, buf=0x7fff74e4edb0 <Address 0x7fff74e4edb0 out of bounds>, count=16, + pos=0xffff8801f4b45f48) at /build/buildd/linux-3.2.0/fs/read_write.c:365
+365    {
+#下面的命令将切换KGTP到回放模式。
+(gdb) monitor replay
+(gdb) tfind -1
+No longer looking at any trace frame
+#0 vfs_read (file=0xffff8801f7bd4c00, buf=0x7fff74e4edb0 <Address 0x7fff74e4edb0 out of bounds>, count=16, + pos=0xffff8801f4b45f48) at /build/buildd/linux-3.2.0/fs/read_write.c:365
+365    {
+#于是可以使用执行命令。
+(gdb) n
+368            if (!(file->f_mode & FMODE_READ))
+(gdb) p file->f_mode
+$5 = 3
+#设置断点 (只在回放模式下有效,不会影响到Linux内核执行)。
+(gdb) b 375
+Breakpoint 2 at 0xffffffff81179b75: file /build/buildd/linux-3.2.0/fs/read_write.c, line 375.
+(gdb) c
+Continuing.
+
+Breakpoint 2, vfs_read (file=0xffff8801f7bd4c00, buf=0x7fff74e4edb0 <Address 0x7fff74e4edb0 out of bounds>, count=16, + pos=0xffff8801f4b45f48) at /build/buildd/linux-3.2.0/fs/read_write.c:375
+375            ret = rw_verify_area(READ, file, pos, count);
+(gdb) s
+rw_verify_area (read_write=0, file=0xffff8801f7bd4c00, ppos=0xffff8801f4b45f48, count=16)
+    at /build/buildd/linux-3.2.0/fs/read_write.c:300
+300            inode = file->f_path.dentry->d_inode;
+#使用反向执行命令。
+(gdb) rs
+
+Breakpoint 2, vfs_read (file=0xffff8801f7bd4c00, buf=0x7fff74e4edb0 <Address 0x7fff74e4edb0 out of bounds>, count=16, + pos=0xffff8801f4b45f48) at /build/buildd/linux-3.2.0/fs/read_write.c:375
+375            ret = rw_verify_area(READ, file, pos, count);
+(gdb) rn
+372            if (unlikely(!access_ok(VERIFY_WRITE, buf, count)))
+}}}
+GDB命令tstart,tstop,tfind或者quit可以自动关闭回放模式。
 == 如何显示被优化掉的变量值 ==
 有时GDB会这样输出信息:
 {{{

Other related posts:

  • » [kgtp] r1551 committed - Add while-stepping to doc - kgtp