From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24108 invoked by alias); 24 Jul 2013 12:23:52 -0000 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 Received: (qmail 24080 invoked by uid 89); 24 Jul 2013 12:23:52 -0000 X-Spam-SWARE-Status: No, score=-4.1 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,RDNS_NONE,TW_BJ,TW_CX,TW_DC,TW_GC,TW_GT,TW_GX autolearn=no version=3.3.1 Received: from Unknown (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 24 Jul 2013 12:23:50 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1V1y6Y-0006rt-Ps from Hafiz_Abid@mentor.com ; Wed, 24 Jul 2013 05:23:42 -0700 Received: from SVR-IES-FEM-02.mgc.mentorg.com ([137.202.0.106]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 24 Jul 2013 05:23:43 -0700 Received: from EU-MBX-02.mgc.mentorg.com ([169.254.3.165]) by SVR-IES-FEM-02.mgc.mentorg.com ([137.202.0.106]) with mapi id 14.02.0247.003; Wed, 24 Jul 2013 13:23:42 +0100 From: "Abid, Hafiz" To: Ender Dai , "gdb@sourceware.org" Subject: RE: gdb behavior on tight loop Date: Wed, 24 Jul 2013 12:23:00 -0000 Message-ID: References: <87r4eopqdb.fsf@cortana.d.cs.uoregon.edu> In-Reply-To: <87r4eopqdb.fsf@cortana.d.cs.uoregon.edu> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-SW-Source: 2013-07/txt/msg00079.txt.bz2 > -----Original Message----- > From: gdb-owner@sourceware.org [mailto:gdb-owner@sourceware.org] On > Behalf Of Ender Dai > Sent: 24 July 2013 04:51 > To: gdb@sourceware.org > Subject: gdb behavior on tight loop >=20 > Hi, >=20 > I just find some counterintuitive (to me) behavior of gdb on tight loop. > Please see the gdb session below. When I run "next" on line 5, the tight > loop, it will take several seconds before gdb stop on line 6 and I regain > control. Strace shows that it looks like gdb is doing some magic in every > iteration. >=20 > If I set an additional breackpoint on line 6, and "continue" on line 5 in= stead > of "next", everything looks good. >=20 > Is this supposed behavior? What is gdb doing undercover? For 'next', GDB keeps doing low level step until It goes out of the range o= f current line. When you issue next on line 5, GDB steps one instruction and checks the PC.= It will keep doing steps until PC is out of the Range of line 5 [0x4004b8-0x4004cd]. It is stopping after every instruction= and then checking PC that is taking the time. 5 for (i=3D0; i<100000; i++); 0x00000000004004b8 <+4>: movl $0x0,-0x4(%rbp) 0x00000000004004bf <+11>: jmp 0x4004c5 0x00000000004004c1 <+13>: addl $0x1,-0x4(%rbp) 0x00000000004004c5 <+17>: cmpl $0x1869f,-0x4(%rbp) 0x00000000004004cc <+24>: jle 0x4004c1 6 return 0; 0x00000000004004ce <+26>: mov $0x0,%eax=20 You can get more details of what GDB is doing undercover using "set debug i= nfrun 1" command. > (There is a warning message about vdso, but google tell me that it should= be > fine...) >=20 > Thanks, > Ender >=20 > $ gdb a.out > GNU gdb (GDB) 7.6 (Debian 7.6-5) > Copyright (C) 2013 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. Type "show > copying" > and "show warranty" for details. > This GDB was configured as "x86_64-linux-gnu". > For bug reporting instructions, please see: > ... > Reading symbols from /home/ender/src/tmp/a.out...done. > (gdb) l > 1 int > 2 main(void) > 3 { > 4 int i; > 5 for (i=3D0; i<100000; i++); > 6 return 0; > 7 } > (gdb) b 5 > Breakpoint 1 at 0x4004b1: file loop.c, line 5. > (gdb) r > Starting program: /home/xdai/src/tmp/a.out > warning: no loadable sections found in added symbol-file system-supplied > DSO at 0x7ffff7ffa000 > warning: Could not load shared library symbols for linux-vdso.so.1. > Do you need "set solib-search-path" or "set sysroot"? >=20 > Breakpoint 1, main () at loop.c:5 > 5 for (i=3D0; i<100000; i++); > (gdb) n > 6 return 0; > (gdb) >=20 > $ uname -a > Linux cortana 3.9-1-amd64 #1 SMP Debian 3.9.8-1 x86_64 GNU/Linux >=20 > $ gcc -v > Using built-in specs. > COLLECT_GCC=3Dgcc > COLLECT_LTO_WRAPPER=3D/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper > Target: x86_64-linux-gnu > Configured with: ../src/configure -v --with-pkgversion=3D'Debian 4.8.1-7' > --with-bugurl=3Dfile:///usr/share/doc/gcc-4.8/README.Bugs > --enable-languages=3Dc,c++,java,go,d,fortran,objc,obj-c++ --prefix=3D/usr > --program-suffix=3D-4.8 --enable-shared --enable-linker-build-id -- > libexecdir=3D/usr/lib --without-included-gettext --enable-threads=3Dposix > --with-gxx-include-dir=3D/usr/include/c++/4.8 --libdir=3D/usr/lib --enabl= e-nls -- > with-sysroot=3D/ --enable-clocale=3Dgnu --enable-libstdcxx-debug --enable- > libstdcxx-time=3Dyes --enable-gnu-unique-object --enable-plugin --with-sy= stem- > zlib --disable-browser-plugin --enable-java-awt=3Dgtk --enable-gtk-cairo = --with- > java-home=3D/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre > --enable-java-home > --with-jvm-root-dir=3D/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 > --with-jvm-jar-dir=3D/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 > --with-arch-directory=3Damd64 > --with-ecj-jar=3D/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enabl= e- > multiarch --with-arch-32=3Di586 --with-abi=3Dm64 > --with-multilib-list=3Dm32,m64,mx32 --with-tune=3Dgeneric --enable- > checking=3Drelease --build=3Dx86_64-linux-gnu --host=3Dx86_64-linux-gnu -- > target=3Dx86_64-linux-gnu Thread model: posix gcc version 4.8.1 (Debian 4= .8.1- > 7)