From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13315 invoked by alias); 18 Dec 2010 18:19:47 -0000 Received: (qmail 13301 invoked by uid 22791); 18 Dec 2010 18:19:47 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.67) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 18 Dec 2010 18:19:42 +0000 Received: from hpaq1.eem.corp.google.com (hpaq1.eem.corp.google.com [172.25.149.1]) by smtp-out.google.com with ESMTP id oBIIJdgq000632 for ; Sat, 18 Dec 2010 10:19:40 -0800 Received: from vws10 (vws10.prod.google.com [10.241.21.138]) by hpaq1.eem.corp.google.com with ESMTP id oBIIJcU7009232 for ; Sat, 18 Dec 2010 10:19:38 -0800 Received: by vws10 with SMTP id 10so699021vws.14 for ; Sat, 18 Dec 2010 10:19:37 -0800 (PST) MIME-Version: 1.0 Received: by 10.220.176.74 with SMTP id bd10mr566531vcb.266.1292696377658; Sat, 18 Dec 2010 10:19:37 -0800 (PST) Received: by 10.220.210.12 with HTTP; Sat, 18 Dec 2010 10:19:37 -0800 (PST) In-Reply-To: References: Date: Sat, 18 Dec 2010 18:19:00 -0000 Message-ID: Subject: Re: Trace each statement From: Doug Evans To: Haitao Dan Cc: gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 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: 2010-12/txt/msg00054.txt.bz2 On Thu, Dec 16, 2010 at 3:37 AM, Haitao Dan wrote: > Dear All, > > Is there a way to output the execution path of the run of a c program using GDB? > > Thank you very much! This is a simplistic example that can be built on if you want. $ cat trace-prog.c int x; int main () { int i; for (i = 0; i < 10; ++i) x += i; return 0; } $ cat trace-prog.gdb # -*- python -*- python gdb.execute ("start") while True: try: gdb.execute ("step") except: break $ gcc -g trace-prog.c -o trace-prog $ ./gdb --batch -q -x trace-prog.gdb trace-prog.x32 Temporary breakpoint 1 at 0x80483a5: file trace-prog.c, line 9. Temporary breakpoint 1, main () at trace-prog.c:9 9 for (i = 0; i < 10; ++i) 10 x += i; 9 for (i = 0; i < 10; ++i) 10 x += i; 9 for (i = 0; i < 10; ++i) 10 x += i; 9 for (i = 0; i < 10; ++i) 10 x += i; 9 for (i = 0; i < 10; ++i) 10 x += i; 9 for (i = 0; i < 10; ++i) 10 x += i; 9 for (i = 0; i < 10; ++i) 10 x += i; 9 for (i = 0; i < 10; ++i) 10 x += i; 9 for (i = 0; i < 10; ++i) 10 x += i; 9 for (i = 0; i < 10; ++i) 10 x += i; 9 for (i = 0; i < 10; ++i) 12 return 0; 13 } 0x0048f6e5 in __libc_start_main () from /lib/libc.so.6 Single stepping until exit from function __libc_start_main, which has no line number information. Program exited normally. $