steven

Using KGDB tracepoint module(KGTP)

steven | 05 September, 2010 22:06

Using KGDB tracepoint module(KGTP)
                         To trace your real-time program

Steven Yang, DSLab
Aug 2010


Asa powerful debug tool, GDB tracepoint could observe the behavior your real-time program whose orrectness depends on its real-time behavior, delays introduced by a debugger might cause the program to change its behavior drastically, or perhaps fail, even when the code itself is correct.

http://sourceware.org/gdb/current/onlinedocs/gdb/Tracepoints.html#Tracepoints

http://code.google.com/p/kgtp/

I tested the GTP on
    Intel Pentium 3 CPU
    GDB 7.2
    -O0 kernel
    GTP20100830 or later

The steps are as following:

1 Compile kernel with -O0 optimization
===================
  1) Disable CONFIG_CC_OPTIMIZE_FOR_SIZE
     General setup
    -> Optimize for size
  2) And then modify the Makefile of kernel:
     replace
      KBUILD_CFLAGS   += -O2
     with
        KBUILD_CFLAGS   += -O0
 
  Also even -O0 optimizes out values - you could mark those values volatile to prevent that from happening though.

2 Install the latest GDB(7.2)
===================
  #wget ftp://ftp.gnu.org/gnu/gdb/gdb-7.2.tar.gz
  #tar -xzf gdb-7.2.tar.gz
  #cd gdb
  #./configure
  #make
  #make install
  Note: I found gdb fail to 'collect' some global variables and local variables using gdb 6.8 on Intel-Pentium 3.

3 Get the latest GTP source code
===================
  #svn checkout http://kgtp.googlecode.com/svn/ kgtp
  Further info please refer to http://code.google.com/p/kgtp/

4 Compile and load KGTP
===================
  #cd kgtp/trunk/
  #make
  #insmod gtp.ko

5 Trace kernel functions
===================
    ------------------------------------screen snapshot begin
    debian:/home/linux-2.6.33.6# whereis gdb
    gdb: /usr/local/bin/gdb
    debian:/home/linux-2.6.33.6# /usr/local/bin/gdb vmlinux
    GNU gdb (GDB) 7.2
    Copyright (C) 2010 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "i686-pc-linux-gnu".
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>...
    Reading symbols from /home/linux-2.6.33.6/vmlinux...done.
    (gdb) target remote /proc/gtp
    Remote debugging using /proc/gtp
    0x00000000 in ?? ()
    (gdb) trace vfs_readdir
    Tracepoint 1 at 0xc11756a0: file fs/readdir.c, line 24.
    (gdb) trace fs/readdir.c:29
    Tracepoint 2 at 0xc11756ca: file fs/readdir.c, line 29.
    (gdb) actions 1
    Enter actions for tracepoint 1, one per line.
    End with a line saying just "end".
    >collect *file
    >end
    (gdb) actions 2
    Enter actions for tracepoint 2, one per line.
    End with a line saying just "end".
    >collect res
    >end
    (gdb) tstart
    (gdb) shell ls
    COPYING        Module.symvers  crypto    ipc              net       usr
    CREDITS        README          drivers   kernel           samples   virt
    Documentation  REPORTING-BUGS  firmware  lib              scripts   vmlinux
    Kbuild         System.map      fs        mm               security  vmlinux.o
    MAINTAINERS    arch            include   modules.builtin  sound     vmlinux_O2
    Makefile       block           init      modules.order    tools
    (gdb) tstop
    (gdb) tfind
    Found trace frame 0, tracepoint 1
    #0  0xc11756a1 in vfs_readdir (file=0xc3082800, filler=0, buf=0x0)
        at fs/readdir.c:24
    24              struct inode *inode = file->f_path.dentry->d_inode;
    (gdb) p *file
    $1 = {f_u = {fu_list = {next = 0xc6d8b780, prev = 0xc7ade480}, fu_rcuhead = {
          next = 0xc6d8b780, func = 0xc7ade480}}, f_path = {mnt = 0xc6c05300,
        dentry = 0xc761d440}, f_op = 0xc1709a20, f_lock = {{rlock = {raw_lock = {
          slock = 0}}}}, f_count = {counter = 2}, f_flags = 624640,
      f_mode = 29, f_pos = 0, f_owner = {lock = {raw_lock = {lock = 16777216}},
        pid = 0x0, pid_type = PIDTYPE_PID, uid = 0, euid = 0, signum = 0},
      f_cred = 0xc3082780, f_ra = {start = 0, size = 0, async_size = 0,_pos = -1}, fte_data = 0x0, f_ep_links = {
        next = 0xc3082874, prev = 0xc3082874}, f_mapping = 0xc761c74c}
    (gdb) tfind
    Found trace frame 1, tracepoint 2
    0xc11756cb      29              res = security_file_permission(file, MAY_READ);
    (gdb) p res
    $2 = -20
    (gdb) list
    24              struct inode *inode = file->f_path.dentry->d_inode;
    25              int res = -ENOTDIR;
    26              if (!file->f_op || !file->f_op->readdir)
    27                      goto out;
    28
    29              res = security_file_permission(file, MAY_READ);
    30              if (res)
    31                      goto out;
    32
    33              res = mutex_lock_killable(&inode->i_mutex);
    (gdb)
    ------------------------------------screen snapshot end
      
6 Trace kernel module
===================
debian:~# cat /proc/modules | grep 3c59x
3c59x 42521 0 - Live 0xc86dd000
debian:~# modinfo 3c59x
filename:       /lib/modules/2.6.33.6-tp/kernel/drivers/net/3c59x.ko
author:         Donald Becker <becker@scyld.com>
description:    3Com 3c59x/3c9xx ethernet driver

    -------------------------------------------SCREEN SNAPSHOT BEGIN
    debian:/home/linux-2.6.33.6# /usr/local/bin/gdb vmlinux
    GNU gdb (GDB) 7.2
    Copyright (C) 2010 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "i686-pc-linux-gnu".
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>...
    Reading symbols from /home/linux-2.6.33.6/vmlinux...done.
    (gdb) target remote /proc/gtp
    Remote debugging using /proc/gtp
    0x00000000 in ?? ()
    (gdb) add-symbol-file /lib/modules/2.6.33.6-tp/kernel/drivers/net/3c59x.ko 0xc86dd000
    add symbol table from file "/lib/modules/2.6.33.6-tp/kernel/drivers/net/3c59x.ko" at
        .text_addr = 0xc86dd000
    (y or n) y
    Reading symbols from /lib/modules/2.6.33.6-tp/kernel/drivers/net/3c59x.ko...done.
    (gdb) trace boomerang_start_xmit
    Tracepoint 1 at 0xc86df4bc: file drivers/net/3c59x.c, line 2094.
    (gdb) actions
    Enter actions for tracepoint 1, one per line.
    End with a line saying just "end".
    >collect *dev
    >end
    (gdb) trace drivers/net/3c59x.c:2107
    Tracepoint 2 at 0xc86df509: file drivers/net/3c59x.c, line 2107.
    (gdb) actions
    Enter actions for tracepoint 2, one per line.
    End with a line saying just "end".
    >collect ioaddr
    >collect vp->cur_tx
    >end
    (gdb) tstart
        //...wait until packet received
    (gdb) tstop
    (gdb) tfind
    Found trace frame 0, tracepoint 1
    #0  0xc86df4bd in boomerang_start_xmit (skb=0x0, dev=0xc7a39800)
        at drivers/net/3c59x.c:2094
    2094            struct vortex_private *vp = netdev_priv(dev);
    (gdb) p *dev
    $1 = {name = "eth0", '00' <repeats 11 times>, name_hlist = {next = 0x0,
        pprev = 0xc785aec0}, ifalias = 0x0, mem_end = 0, mem_start = 0,
      base_addr = 3364381696, irq = 5, if_port = 8 '\b', dma = 0 '00',
      state = 3, dev_list = {next = 0xc1a91e18, prev = 0xc7a0d834}, napi_list = {
        next = 0xc7a3983c, prev = 0xc7a3983c}, unreg_list = {next = 0xc7a39844,
        prev = 0xc7a39844}, features = 2051, ifindex = 4, iflink = 4, stats = {
        rx_packets = 13880, tx_packets = 6880, rx_bytes = 1359797,
        tx_bytes = 1356809, rx_errors = 0, tx_errors = 0, rx_dropped = 0,
        tx_dropprx_length_errors 0, rx_frame_errors = 0,
        //...omit some content
    (gdb) tfind
    Found trace frame 1, tracepoint 2
    0xc86df50a      2107            if (vp->cur_tx - vp->dirty_tx >= TX_RING_SIZE) {
    (gdb) p ioaddr
    $2 = (void *) 0xc8886400
    (gdb) p vp->cur_tx
    $3 = 7049
    (gdb) list
    2102                    pr_debug("boomerang_start_xmit()\n");
    2103                    pr_debug("%s: Trying to send a packet, Tx index %d.\n",
    2104                               dev->name, vp->cur_tx);
    2105            }
    2106
    2107            if (vp->cur_tx - vp->dirty_tx >= TX_RING_SIZE) {
    2108                    if (vortex_debug > 0)
    2109                            pr_warning("%s: BUG! Tx Ring full, refusing to send buffer.\n",
    2110                                       dev->name);
    2111
        (gdb)
    -------------------------------------------SCREEN SNAPSHOT END




7 Trace my hello module
===================

#insmod hello.ko
#cat /proc/modules | grep hello
hello 1092 0 - Live 0xc95f7000
#cat /sys/module/hello/sections/.bss
0xc95f7308

    -------------------------------------------SCREEN SNAPSHOT BEGIN
    #gdb vmlinux
    GNU gdb (GDB) 7.2
    Copyright (C) 2010 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "i686-pc-linux-gnu".
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>...
    Reading symbols from /home/linux-2.6.33.6/vmlinux...done.
    (gdb) target remote /proc/gtp
    Remote debugging using /proc/gtp
    0x00000000 in ?? ()
    (gdb) add-symbol-file /home/steven/hello/hello.ko 0xc95f7000 -s .bss 0xc95f7308
    add symbol table from file "/home/steven/hello/hello.ko" at
        .text_addr = 0xc95f7000
        .bss_addr = 0xc95f7308
    (y or n) y
    Reading symbols from /home/steven/hello/hello.ko...done.
    (gdb) trace /home/steven/hello/hello.c:22
    Tracepoint 1 at 0xc95f7094: file /home/steven/hello/hello.c, line 22.
    (gdb) actions
    Enter actions for tracepoint 1, one per line.
    End with a line saying just "end".
    >collect tv,year,cnt
    >end
    (gdb) tstart
              //wait until your tracepoint has been trigger...
[90603.898148] tv_sec: 1283802951 - 6
[90603.903361] tv_sec: 1283802951 - 2010
   (gdb) tstop
    (gdb) tfind
    Found trace frame 0, tracepoint 1
    #0  0xc95f7095 in test_thread (data=0x0) at /home/steven/hello/hello.c:22
    22            cnt++;
    (gdb) p tv
    $1 = {tv_sec = 1283802951, tv_usec = 313616}
    (gdb) p cnt
    $2 = 6
    (gdb) p year
    $3 = 2010
    (gdb)

    -------------------------------------------SCREEN SNAPSHOT END

hello.c


  1 #include <linux/kthread.h>
  2 #include <linux/module.h>
  3 #include <linux/init.h>
  4
  5 static struct task_struct *test_task;
  6 volatile struct timeval tv;
  7 int year;
  8
  9 int test_thread(void *data)
 10 {
 11         volatile int cnt = 0;
 12         set_current_state(TASK_INTERRUPTIBLE);
 13         schedule_timeout(1 * HZ); /* wait for the terminal ready */
 14
 15         while(1){
 16                 set_current_state(TASK_INTERRUPTIBLE); /* this is required, or thread never sleep*/
 17                 if(kthread_should_stop()) break;
 18
 19                 year = 2010;
 20                 do_gettimeofday (&tv);
 21                 printk("\ntv_sec: %d - %d\n", (int)tv.tv_sec, cnt);
 22                 cnt++;
 23
 24                 do_gettimeofday (&tv);
 25                 printk("tv_sec: %d - %d\n", (int)tv.tv_sec, year);
 26                 cnt++;
 27
 28                 //reschedule after 5 seconds(approximately)
 29                 schedule_timeout(60 * HZ);
 30         }
 31
 32         return 0;
 33 }
 34
 35 static int __init mt_init(void)
 36 {
 37         int err;
 38         test_task = kthread_create(test_thread, NULL, "test_task");
 39         if(IS_ERR(test_task)){
 40                 printk("Unable to start kernel thread.\n");
 41                 err = PTR_ERR(test_task);
 42                 test_task = NULL;
 43                 return err;
 44         }
 45         wake_up_process(test_task);
 46         return 0;
 47 }
 48
 49
 50 static void __exit mt_cleanup(void)
 51 {
 52         if(test_task){
 53                 kthread_stop(test_task);
 54                 test_task = NULL;
 55         }
 56 }
 57
 58 module_init(mt_init);
 59 module_exit(mt_cleanup);
 60
 61 MODULE_LICENSE("GPL");

 

Notice:
1) Do not change the path of your module after you compile it and before you debug it.
2) If I use add-symbol-file /home/steven/hello/hello.ko 0xc95f7000, gdb can not print the variables correctly(only get zero).
3) Please use gdb 7.2 or later version.

 

Comments

«Previous   1 2 3 4 5 6 7  Next»

fgdfg

sac chanel pas cher | 15/11/2012, 17:50

Aujourd'hui sac chanel pas cher que ses doctrines ont fini par prévaloir, on la juge avec plus de faveur, et un homme qui

DSFDS

casque beats by dre pas cher | 15/11/2012, 17:50

et dont les casque beats by dre pas cher les sympathies de l'école libérale, sous la Restauration. Le libéralisme fran?ais avait fait

FDGFD

casque beat | 15/11/2012, 17:51

et à rompre ses casque beat liens (2). ? Et comme il ressentait vivement les aiguillons du mal qui le consumait: ? Délivrez-moi

FGDFG

doudoune canada goose | 15/11/2012, 17:51

c'est une belle doudoune canada goose nature champêtre, les bois ? verdissants, les prés, les arbres que j'ai plantés et ? qui me prêtent aujourd'hui

It is content to put on Moncler Down Jacket

aimee | 12/12/2012, 03:09

It is content to put on Moncler Down Jacket in the winter months of moncler ski jacket, chilly climate, which is the the majority of issue in winter moncler ski jackets, and to provide you not merely warmth but mild ease, also carry manner and beauty. In winter, Moncler jackets can make your eyes wide open and gives buy moncler jackets to the people who put on it inside the entire chilly winter season.

sdafsd dsfasf

af df df | 18/12/2012, 02:19

[url=http://www.baidu.com]sadfs asdf[/url] asdf dfd fsas dfasdf

sdafsd dsfasfs

af df df | 18/12/2012, 02:20

adsfd sdaf asdkjfksd jdskjkdshfdsj hdsjds

fake ray ban sunglasses

fake ray ban sunglasses | 15/05/2013, 00:32

Rectangular frames will work great for this, People with small round faces should ray ban sunglasses cheap chose frames that are thin, while people with larger faces should chose frames that are larger and bolder; to help bring out the person's facial features more. Rectangular frames will work great for this, People with small round faces should chose frames that are thin, while people fake ray ban sunglasses with larger faces should chose frames that are larger and bolder; to help bring out the person's facial features more.

fake ray ban sunglasses

fake ray ban sunglasses | 16/05/2013, 19:30

Live music every night, Good wine and beer selection, Casual,2529 Dauphine St, (Marigny) ray ban sunglasses cheap Credit Cards, Hours unclear, Recently, the new owners of Lost Love got rid of the false ceiling, revealing tall (plaster) New Orleans ceilings, which makes this popular bar much less smoky and much more comfortable. Live music every night, Good wine and beer selection, Casual,2529 Dauphine St, (Marigny) Credit Cards, Hours unclear, Recently, fake ray ban sunglasses the new owners of Lost Love got rid of the false ceiling, revealing tall (plaster) New Orleans ceilings, which makes this popular bar much less smoky and much more comfortable.

Re: Using KGDB tracepoint module(KGTP)

oakleyley | 16/05/2013, 22:28

The Sunglass Fix team are professionals in every way, offering topnotch service ray ban sunglasses outlet at affordable prices making adjustment to your old lenses, replacing scratched and broken lenses and designing custom cut lenses while offering complementary service by fixing the screws at no extra cost. The Sunglass Fix team are professionals in every way, offering topnotch service at affordable prices making adjustment to replica ray bans your old lenses, replacing scratched and broken lenses and designing custom cut lenses while offering complementary service by fixing the screws at no extra cost.

fangkormm

fangkormm | 15/08/2013, 00:10

Es gibt grundsätzlich zwei Arten von färbbares Schuhe
Ob es sich um die Fortschritte, die die darauf bestehen, oder die Anforderung, die Schuhe hergestellt Färben mehr lohnt, plötzlich Ehe Geschäften und Schuhgeschäften in nüchtern die kleinste der Städte angeboten Steuern Färben angeheizt. Sofort können Sie färbbares Schuhe in einer Vielzahl von Stilen zu stanzen. Es ist nicht Pumpen prinzipielle überall. Sie können färbbares Mary Janes, Sandalen und ununterbrochene Linie der Partei einen Regenschirm gibt grundsätzlich zwei Arten von färbbares Schuhe: Nike Air Max Fabrik und Sitte. Beide sind "Gewohnheit" in der Einsicht, dass man rig out grenzender jeder Farbe, die Sie wollen, aber Pflanze gefärbt Schuhe sind mehr farbecht dann Schirmherrschaft diejenigen. Individuelle färbbares Schuhe sind im Lager oder zu Hause durchgeführt. Diese milde Farbstoff wird bluten und besudeln, wenn sie nass werden. Die gigantischen Oberhand zu versinken erheben ist, dass man wieder färben diese Schuhe.

Crafts mag: hot-Schneiden, Mikro-Injektion und etc in den Schuhen angewendet werden könnte uns auch helfen. Obwohl gleichen im Aussehen, gefälschte Schuhe immer die Materialien ohne Flexibilität: Angenommen, Sie tragen ein Nike Air Max Women Schuhe im kalten Winter, es gibt Möglichkeiten, dass Ihre Schuhe fracture. No wie ähnlich zwischen der echten und falschen kann man egal. Es gibt immer noch Unterschiede in der Sohle der Schuhe. Manchmal wird der echte fügen Sie einige chemische Rohstoffe, Recycling-Materialien oder Kohlenstoff zu machen Schuhe mehr verschleiß-und rutschfest. Während die gefälschten wird man nicht, dies zu berücksichtigen. Hier ist ein kleiner Trick: Tragen ein Paar echte Air Max Billig Schuhe zu Fuß auf der Kunststoff-Boden, werden Sie einen sehr lauten "knarren" hören, während die gefälschte, unter normalen Umständen, absolut machen konnte keine solche Stimmen.

???? ?????? ??? ??

http://www.antonellescheeseshop.com/????-??????-c-90/ | 17/11/2013, 14:42

???????? ??? ??? http://www.qcproperty.com/???-???-c-101/

?????? ??? ??

http://www.pamaenterprises.com/ | 17/11/2013, 22:13

?????? ??? ????? ????? 2013??? http://www.sabisoftware.com/category-91/
?????? ??? ??

??????? ??? ??

http://www.getbodhi.com/category-82/ | 18/11/2013, 00:14

????? ????????? xlj http://www.icao-tpgs.com/?????-?????????-c-94.html ??????

?????? ??? ????

http://www.maxinefrutkin.com/??????-???-c-80/ | 19/11/2013, 09:42

??????????? ????? ?? http://www.rjjts.com/?????-oakley-c-80.html

???? ?? ??

http://www.antonellescheeseshop.com/ | 19/11/2013, 19:47

?????

????? ??????

http://siroccoresort.com/brandjewelly.html | 20/11/2013, 19:10

??? ??? ????????:http://loewestore.youngdesign83.com/

???? ?????

http://jp-celine-shop.tumblr.com/ | 20/11/2013, 21:45

?????? ??????! http://bvlgaribrand.woosybalaska.com/

UGG ??? ????????

http://chinatourhelp.com/women-boots.html | 22/11/2013, 03:59

?????? ???????????????! http://www.americanbikernews.com/dickiesshirt.html

Cheap North Face Jackets

http://www.recyc-quebec.gouv.qc.ca/client/ | 08/12/2013, 22:56

Very shortly this web page will be famous amid all blogging and site-building people, due to it's good posts|
Cheap North Face Jackets

Add comment
  The code is case-insensitive  If the code is not clear enough, please click the image to refresh | Maximum attempts: 10
«Previous   1 2 3 4 5 6 7  Next»
 
Accessible and Valid XHTML 1.0 Strict and CSS
© DSLab - Powered by LifeType - Design by BalearWeb