From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23896 invoked by alias); 6 Sep 2010 07:51:19 -0000 Received: (qmail 23873 invoked by uid 22791); 6 Sep 2010 07:51:15 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mail-wy0-f169.google.com (HELO mail-wy0-f169.google.com) (74.125.82.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 06 Sep 2010 07:51:08 +0000 Received: by wyb36 with SMTP id 36so5200495wyb.0 for ; Mon, 06 Sep 2010 00:51:06 -0700 (PDT) Received: by 10.216.6.133 with SMTP id 5mr3433713wen.32.1283759466118; Mon, 06 Sep 2010 00:51:06 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.181.213 with HTTP; Mon, 6 Sep 2010 00:50:46 -0700 (PDT) In-Reply-To: References: <1283504768.2100.43.camel@steven> <1283590584.1685.39.camel@steven> <1283592366.1685.50.camel@steven> <1283616109.1685.98.camel@steven> <1283618879.1685.110.camel@steven> From: Hui Zhu Date: Mon, 06 Sep 2010 07:51:00 -0000 Message-ID: Subject: Re: Linux Kernel GDB tracepoint module 2010-8-30 release To: Steven Cc: "gdb@sourceware.org" , linux-kernel@vger.kernel.org, Michael Snyder , Marc Khouzam , Thiago Jung Bauermann , "Frank Ch. Eigler" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2010-09/txt/msg00037.txt.bz2 cat /sys/module/hello/sections/.bss 0xf81b92ec add-symbol-file ~/kernel/tmp/h/hello.ko 0xf81b9000 -s .bss 0xf81b92ec (gdb) tstart (gdb) tstatus Trace is running on the target. Collected 0 trace frames. Trace buffer has 86255744 bytes of 86255744 bytes free (0% full). Trace will stop if GDB disconnects. Not looking at any trace frame. (gdb) tstop (gdb) tfind Found trace frame 0, tracepoint 1 #0 0xf81b9068 in test_thread (data=3D) at /home/teawater/kernel/tmp/h/hello.c:22 22 cnt++; (gdb) p cnt $1 =3D 106 (gdb) p tv $2 =3D {tv_sec =3D 1283760246, tv_usec =3D 784020} (gdb) p year $3 =3D 2010 (gdb) Looks I need update HOWTO now. To get all the module message with hand is uncool. I will make it more automated when I have time. Thanks, Hui On Mon, Sep 6, 2010 at 15:21, Hui Zhu wrote: > Sep =A06 15:17:06 teawater kernel: [514552.780031] gtp_kp_pre_handler: > tracepoint 1 > Sep =A06 15:17:06 teawater kernel: [514552.780034] gtp_parse_x: cmd 23 > Sep =A06 15:17:06 teawater kernel: [514552.780035] gtp_parse_x: cmd 22 > Sep =A06 15:17:06 teawater kernel: [514552.780037] gtp_parse_x: cmd c > Sep =A06 15:17:06 teawater kernel: [514552.780039] > gtp_action_memory_read: id:1 0000054c 8 > Sep =A06 15:17:06 teawater kernel: [514552.780043] > gtp_action_memory_read: id:1 read 0000054c 8 get error. > Sep =A06 15:17:06 teawater kernel: [514552.780048] gtp_kp_pre_handler: > tracepoint 1 stop. > Sep =A06 15:17:06 teawater kernel: [514552.780051] tv_sec: 1283757426 - 2= 010 > Sep =A06 15:17:06 teawater kernel: [514552.780053] gtp_kp_pre_handler: > tracepoint 2 > Sep =A06 15:17:06 teawater kernel: [514552.780055] gtp_parse_x: cmd 23 > Sep =A06 15:17:06 teawater kernel: [514552.780056] gtp_parse_x: cmd 22 > Sep =A06 15:17:06 teawater kernel: [514552.780057] gtp_parse_x: cmd c > Sep =A06 15:17:06 teawater kernel: [514552.780058] > gtp_action_memory_read: id:2 0000054c 8 > Sep =A06 15:17:06 teawater kernel: [514552.780061] > gtp_action_memory_read: id:2 read 0000054c 8 get error. > Sep =A06 15:17:06 teawater kernel: [514552.780063] gtp_kp_pre_handler: > tracepoint 2 stop. > Sep =A06 15:17:06 teawater kernel: [514552.780068] gtp_stop: tracepoint 1 > Sep =A06 15:17:06 teawater kernel: [514552.792059] gtp_stop: tracepoint 2 > > (gdb) add-symbol-file ~/kernel/tmp/h/hello.ko 0xf81b9000 > add symbol table from file "/home/teawater/kernel/tmp/h/hello.ko" at > =A0 =A0 =A0 =A0.text_addr =3D 0xf81b9000 > (y or n) y > Reading symbols from /home/teawater/kernel/tmp/h/hello.ko...done. > (gdb) p year > Cannot access memory at address 0x554 > (gdb) p tv > Cannot access memory at address 0x54c > > Looks GDB didn't get the right address of this val. > > Export them maybe handle this issue. > > Thanks, > Hui > > > > On Sun, Sep 5, 2010 at 00:47, Steven wrote: >> On Sun, 2010-09-05 at 00:42 +0800, Hui Zhu wrote: >>> Could you post the other part of this code? =A0Then I can try to reprod= uce on it. >> >> hello.c >> ------------------------------------------------ >> #include >> #include >> #include >> >> static struct task_struct *test_task; >> volatile struct timeval tv; >> int year; >> >> int test_thread(void *data) >> { >> =A0 =A0 =A0 =A0volatile int cnt =3D 0; >> =A0 =A0 =A0 =A0set_current_state(TASK_INTERRUPTIBLE); >> =A0 =A0 =A0 =A0schedule_timeout(1 * HZ); /* wait for the terminal ready = */ >> >> =A0 =A0 =A0 =A0while(1){ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0set_current_state(TASK_INTERRUPTIBLE); /*= this is >> required, or thread never sleep*/ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if(kthread_should_stop()) break; >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0year =3D 2010; >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0do_gettimeofday (&tv); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk("\ntv_sec: %d - %d\n", (int)tv.tv_= sec, cnt); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cnt++; >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0do_gettimeofday (&tv); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk("tv_sec: %d - %d\n", (int)tv.tv_se= c, year); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cnt++; >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//reschedule after 5 seconds(approximatel= y) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0schedule_timeout(60 * HZ); >> =A0 =A0 =A0 =A0} >> >> =A0 =A0 =A0 =A0return 0; >> } >> >> static int __init mt_init(void) >> { >> =A0 =A0 =A0 =A0int err; >> =A0 =A0 =A0 =A0test_task =3D kthread_create(test_thread, NULL, "test_tas= k"); >> =A0 =A0 =A0 =A0if(IS_ERR(test_task)){ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk("Unable to start kernel thread.\n"= ); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk("Unable to start kernel thread.\n"= ); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D PTR_ERR(test_task); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0test_task =3D NULL; >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return err; >> =A0 =A0 =A0 =A0} >> =A0 =A0 =A0 =A0wake_up_process(test_task); >> =A0 =A0 =A0 =A0return 0; >> } >> >> >> static void __exit mt_cleanup(void) >> { >> =A0 =A0 =A0 =A0if(test_task){ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0kthread_stop(test_task); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0test_task =3D NULL; >> =A0 =A0 =A0 =A0} >> } >> >> module_init(mt_init); >> module_exit(mt_cleanup); >> >> MODULE_LICENSE("GPL"); >> ------------------------------------------------ >> >> >> Makefile >> ------------------------------------------------ >> obj-m :=3D hello.o >> >> KERNELBUILD :=3D /lib/modules/`uname -r`/build >> >> default: >> =A0 =A0 =A0 =A0make -C $(KERNELBUILD) M=3D$(shell pwd) modules >> >> clean: >> =A0 =A0 =A0 =A0rm -rf *.o *.cmd *.ko *.mod.c .tmp-versions *.symvers >> ------------------------------------------------ >> >> >> >>> Thanks, >>> Hui >>> >>> On Sun, Sep 5, 2010 at 00:01, Steven wrote: >>> > Dear All, >>> > >>> > As I mentioned before, I could collect the variables of kernel functi= on >>> > such as vfs_readdir(ext3 is built in kernel not module). And I tried I >>> > could collect variables of kernel's module(such as my ethernet card >>> > driver 3c59x.ko). I will collect these info later. >>> > >>> > BUT, I can not collect the value of my testing module, neither global >>> > nor local. I think there is some thing wrong with my compile option or >>> > Makefile, any one know it? Thanks very much. >>> > >>> > Program: >>> > ------------------------------------------------- >>> > =A06 volatile struct timeval tv; >>> > =A07 int year; >>> > =A08 >>> > =A09 int test_thread(void *data) >>> > =A010 { >>> > =A011 =A0 =A0 =A0 =A0 volatile int cnt =3D 0; >>> > =A012 =A0 =A0 =A0 =A0 set_current_state(TASK_INTERRUPTIBLE); >>> > =A013 =A0 =A0 =A0 =A0 schedule_timeout(1 * HZ); /* wait for the termi= nal ready */ >>> > =A014 >>> > =A015 =A0 =A0 =A0 =A0 while(1){ >>> > =A016 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 set_current_state(TASK_INTERRUP= TIBLE); >>> > =A017 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if(kthread_should_stop()) break; >>> > =A018 >>> > =A019 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 year =3D 2010; >>> > =A020 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 do_gettimeofday (&tv); >>> > =A021 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk("\ntv_sec: %d - %d\n", (= int)tv.tv_sec, cnt); >>> > =A022 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cnt++; >>> > =A023 >>> > =A024 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 do_gettimeofday (&tv); >>> > =A025 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk("tv_sec: %d - %d\n", (in= t)tv.tv_sec, year); >>> > =A026 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cnt++; >>> > =A027 >>> > =A028 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 //reschedule after 5 seconds(ap= proximately) >>> > =A029 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 schedule_timeout(60 * HZ); >>> > =A030 =A0 =A0 =A0 =A0 } >>> > =A031 >>> > =A032 =A0 =A0 =A0 =A0 return 0; >>> > =A033 } >>> > ------------------------------------------------- >>> > >>> > Makefile >>> > ------------------------------------------------- >>> > obj-m :=3D hello.o >>> > >>> > KERNELBUILD :=3D /lib/modules/`uname -r`/build >>> > >>> > default: >>> > =A0 =A0 =A0 =A0make -C $(KERNELBUILD) M=3D$(shell pwd) modules >>> > ------------------------------------------------- >>> > >>> > >>> > Screen log >>> > ------------------------------------------------- >>> > 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 >>> > >>> > This is free software: you are free to change and redistribute it. >>> > There is NO WARRANTY, to the extent permitted by law. =A0Type "show >>> > copying" >>> > and "show warranty" for details. >>> > This GDB was configured as "i686-pc-linux-gnu". >>> > For bug reporting instructions, please see: >>> > ... >>> > Reading symbols from /home/linux-2.6.33.6/vmlinux...[ 3909.310118] >>> > [ 3909.310124] tv_sec: 1283648666 - 16 >>> > [ 3909.315385] tv_sec: 1283648666 - 2010 >>> > done. >>> > (gdb) target remote /proc/gtp >>> > Remote debugging using /proc/gtp >>> > 0x00000000 in ?? () >>> > (gdb) add-symbol-file /home/steven/hello/hello.ko 0xc8b2b000 >>> > add symbol table from file "/home/steven/hello/hello.ko" at >>> > =A0 =A0 =A0 =A0.text_addr =3D 0xc8b2b000 >>> > (y or n) y >>> > Reading symbols from /home/steven/hello/hello.ko...done. >>> > (gdb) trace /home/steven/hello/hello.c:22 >>> > Tracepoint 1 at 0xc8b2b094: file /home/steven/hello/hello.c, line 22. >>> > (gdb) trace /home/steven/hello/hello.c:26 >>> > Tracepoint 2 at 0xc8b2b0c1: file /home/steven/hello/hello.c, line 26. >>> > (gdb) actions 1 >>> > Enter actions for tracepoint 1, one per line. >>> > End with a line saying just "end". >>> >> >>> >>collect tv, year, cnt >>> >>end >>> > (gdb) actions 2 >>> > Enter actions for tracepoint 2, one per line. >>> > End with a line saying just "end". >>> >>collect tv, year, cnt >>> >>end >>> > (gdb) tstart >>> > [ 4029.328129] >>> > [ 4029.328136] tv_sec: 1283648786 - 20 >>> > [ 4029.333456] tv_sec: 1283648786 - 2010 >>> > tstop >>> > (gdb) tfind >>> > Found trace frame 0, tracepoint 1 >>> > #0 =A00xc8b2b095 in test_thread (data=3D0x0) >>> > at /home/steven/hello/hello.c:22 >>> > 22 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cnt++; >>> > (gdb) p tv >>> > $1 =3D {tv_sec =3D 0, tv_usec =3D 0} >>> > (gdb) p cnt >>> > $2 =3D 0 >>> > (gdb) p year >>> > $3 =3D 0 >>> > (gdb) tfind >>> > Found trace frame 1, tracepoint 2 >>> > 0xc8b2b0c2 =A0 =A0 =A026 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0c= nt++; >>> > (gdb) p cnt >>> > $4 =3D 0 >>> > (gdb) p tv >>> > $5 =3D {tv_sec =3D 0, tv_usec =3D 0} >>> > (gdb) p year >>> > $6 =3D 0 >>> > ------------------------------------------------- >>> > >>> > Thanks, >>> > Steven >>> > >>> > On Sat, 2010-09-04 at 22:58 +0800, Hui Zhu wrote: >>> >> On Sat, Sep 4, 2010 at 17:26, Steven wrote: >>> >> > On Sat, 2010-09-04 at 17:17 +0800, Hui Zhu wrote: >>> >> >> On Sat, Sep 4, 2010 at 16:56, Steven wrote: >>> >> >> > On Sat, 2010-09-04 at 11:41 +0800, Hui Zhu wrote: >>> >> >> >> BTW, looks GCC and GDB don't want handle the optimization debug >>> >> >> >> trouble (all they want is rewrite the GCC in C++ :P). >>> >> >> >> So I think make linux kernel can close optimization is better = idea, do >>> >> >> >> you know some way or some patch to do it? >>> >> >> >> >>> >> >> > >>> >> >> > Just disable CONFIG_CC_OPTIMIZE_FOR_SIZE and modify the Makefil= e of >>> >> >> > kernel: >>> >> >> > KBUILD_CFLAGS =A0 +=3D -O2 >>> >> >> > to >>> >> >> > KBUILD_CFLAGS =A0 +=3D -O0 >>> >> >> >>> >> >> Cool, =A0:) >>> >> >> >>> >> >> I try just change the compile option of readdir.c to without -O2,= it >>> >> >> works OK. =A0I think maybe it's a GDB bug too. >>> >> >> Could you try the second issue with gdb 7.2? >>> >> > >>> >> > I have covered the two issues in the previous mail that I could co= llect >>> >> > both global variables and locals(-O0 kernel + gdb7.2): >>> >> > >>> >> > =A0 =A0 =A0 =A0-------- >>> >> > =A0 =A0 =A0 =A0(gdb) trace vfs_readdir >>> >> > =A0 =A0 =A0 =A0Tracepoint 3 at 0xc11756a0: file fs/readdir.c, line= 24. >>> >> > =A0 =A0 =A0 =A0(gdb) actions >>> >> > =A0 =A0 =A0 =A0Enter actions for tracepoint 3, one per line. >>> >> > =A0 =A0 =A0 =A0End with a line saying just "end". >>> >> > =A0 =A0 =A0 =A0>collect *file >>> >> > =A0 =A0 =A0 =A0>end >>> >> > =A0 =A0 =A0 =A0(gdb) trace fs/readdir.c:29 >>> >> > =A0 =A0 =A0 =A0Tracepoint 4 at 0xc11756ca: file fs/readdir.c, line= 29. >>> >> > =A0 =A0 =A0 =A0(gdb) actions >>> >> > =A0 =A0 =A0 =A0Enter actions for tracepoint 4, one per line. >>> >> > =A0 =A0 =A0 =A0End with a line saying just "end". >>> >> > =A0 =A0 =A0 =A0>collect res >>> >> > =A0 =A0 =A0 =A0>end >>> >> > =A0 =A0 =A0 =A0(gdb) tstart >>> >> > =A0 =A0 =A0 =A0(gdb) tstop >>> >> > =A0 =A0 =A0 =A0(gdb) tfind >>> >> > =A0 =A0 =A0 =A0Found trace frame 0, tracepoint 3 >>> >> > =A0 =A0 =A0 =A0#0 =A00xc11756a1 in vfs_readdir (file=3D0xc7b2cf00,= filler=3D0, >>> >> > =A0 =A0 =A0 =A0buf=3D0x0) >>> >> > =A0 =A0 =A0 =A0 =A0 =A0at fs/readdir.c:24 >>> >> > =A0 =A0 =A0 =A024 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct inode *inode = =3D >>> >> > =A0 =A0 =A0 =A0file->f_path.dentry->d_inode; >>> >> > =A0 =A0 =A0 =A0(gdb) p *file >>> >> > =A0 =A0 =A0 =A0$4 =3D {f_u =3D {fu_list =3D {next =3D 0xc6dca500, = prev =3D 0xc7ade480}, >>> >> > =A0 =A0 =A0 =A0fu_rcuhead =3D { >>> >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0next =3D 0xc6dca500, func =3D 0xc7ade48= 0}}, f_path =3D {mnt =3D >>> >> > =A0 =A0 =A0 =A00xc6c05300, >>> >> > =A0 =A0 =A0 =A0 =A0 =A0dentry =3D 0xc761d440}, f_op =3D 0xc1709a20= , f_lock =3D {{rlock =3D >>> >> > =A0 =A0 =A0 =A0{raw_lock =3D { >>> >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0slock =3D 0}}}}, f_count =3D {c= ounter =3D 2}, f_flags =3D >>> >> > =A0 =A0 =A0 =A0624640, >>> >> > =A0 =A0 =A0 =A0 =A0f_mode =3D 29, f_pos =3D 0, f_owner =3D {lock = =3D {raw_lock =3D {lock =3D >>> >> > =A0 =A0 =A0 =A016777216}}, >>> >> > =A0 =A0 =A0 =A0 =A0 =3D 0start =3D 0, size =3D 0, async_size =3D 0, >>> >> > =A0 =A0 =A0 =A0 =A0 =A0ra_pages =3D 32, mmap_miss =3D 0, prev_pos = =3D -1}, f_version =3D >>> >> > =A0 =A0 =A0 =A00, >>> >> > =A0 =A0 =A0 =A0 =A0f_security =3D 0xc7b30120, private_data =3D 0x0= , f_ep_links =3D { >>> >> > =A0 =A0 =A0 =A0 =A0 =A0next =3D 0xc7b2cf74, prev =3D 0xc7b2cf74}, = f_mapping =3D >>> >> > =A0 =A0 =A0 =A00xc761c74c} >>> >> > =A0 =A0 =A0 =A0(gdb) p res >>> >> > =A0 =A0 =A0 =A0$5 =3D 0 >>> >> > =A0 =A0 =A0 =A0(gdb) tfind >>> >> > =A0 =A0 =A0 =A0Found trace frame 1, tracepoint 4 >>> >> > =A0 =A0 =A0 =A00xc11756cb =A0 =A0 =A029 =A0 =A0 =A0 =A0 =A0 =A0 = =A0res =3D >>> >> > =A0 =A0 =A0 =A0security_file_permission(file, MAY_READ); >>> >> > =A0 =A0 =A0 =A0(gdb) p res >>> >> > =A0 =A0 =A0 =A0$6 =3D -20 >>> >> > =A0 =A0 =A0 =A0-------- >>> >> > >>> >> > >>> >> > >>> >> >>> >> Great. =A0:) >>> >> >>> >> Hui >>> > >>> > >> >> >> >