From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 759 invoked by alias); 18 May 2009 17:43:18 -0000 Received: (qmail 748 invoked by uid 22791); 18 May 2009 17:43:17 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.45.13) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 18 May 2009 17:43:12 +0000 Received: from zps35.corp.google.com (zps35.corp.google.com [172.25.146.35]) by smtp-out.google.com with ESMTP id n4IHhAxY005289 for ; Mon, 18 May 2009 10:43:10 -0700 Received: from qw-out-1920.google.com (qwc5.prod.google.com [10.241.193.133]) by zps35.corp.google.com with ESMTP id n4IHh8mr021701 for ; Mon, 18 May 2009 10:43:08 -0700 Received: by qw-out-1920.google.com with SMTP id 5so2308917qwc.48 for ; Mon, 18 May 2009 10:43:08 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.96.1 with SMTP id f1mr2989653qcn.103.1242668588225; Mon, 18 May 2009 10:43:08 -0700 (PDT) In-Reply-To: <547db2260905180946u3c7dbec5s830511b49e15947e@mail.gmail.com> References: <547db2260905180946u3c7dbec5s830511b49e15947e@mail.gmail.com> Date: Mon, 18 May 2009 17:43:00 -0000 Message-ID: <8ac60eac0905181043i46a817d6nbb9a31f7c22d497d@mail.gmail.com> Subject: =?windows-1252?Q?Re=3A_Doubt_regarding_a_tail_optimized_code_under_=91g?= =?windows-1252?Q?db=92?= From: Paul Pluzhnikov To: Amit Saha Cc: gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-System-Of-Record: true 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: 2009-05/txt/msg00123.txt.bz2 On Mon, May 18, 2009 at 9:46 AM, Amit Saha wrote: > Out of sheer curiosity, I tried to run a tail optimised code under > 'gdb'. Consider a tail recursive factorial implementation in C: Debugging optimized code is tricky; you need to know what you are doing and know how to read disassembly :-) > I place a breakpoint in 'factorial' and I run the above under 'gdb'. > The breakpoint is never hit. Assuming that its tail call optimised (I > have compiled it using gcc -O2), it should hit the breakpoint, at > least once. I get the final result without hitting any breakpoint. I can reproduce this with gcc-4.3.1 on i386, but not with gcc-4.4.0. This doesn't have anything to do with tail-recursion though: gcc-4.3.1 simply inlines factorial() into main: looking at disassembly, the only CALLs from main are to scanf and printf. Compiling with -fno-inline makes it work as expected under gcc-4.3.1 as well. Cheers, -- Paul Pluzhnikov