From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 81592 invoked by alias); 21 Oct 2016 22:22:39 -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 81574 invoked by uid 89); 21 Oct 2016 22:22:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DATE_IN_PAST_12_24,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy=H*F:D*mail.com, sponge, H*r:74.208.4, nicely X-HELO: mout.gmx.com Received: from mout.gmx.com (HELO mout.gmx.com) (74.208.4.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 21 Oct 2016 22:22:37 +0000 Received: from ulgy_thing ([64.134.190.82]) by mail.gmx.com (mrgmxus002) with ESMTPSA (Nemesis) id 0LZhcY-1ceVja1AVA-00lSAG; Sat, 22 Oct 2016 00:22:34 +0200 Date: Fri, 21 Oct 2016 22:22:00 -0000 From: doark@mail.com To: gdb@sourceware.org Cc: pengyu.ut@gmail.com Subject: Re: How to print info of each function by running an executable (compiled with -g) in gdb? Message-ID: <20161020235720.0f3ef16a@ulgy_thing> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-UI-Out-Filterresults: notjunk:1;V01:K0:eizOiM7ASbo=:9I8QiJI3DcwZhNieIe0Fhc 24AjwFQb0Zoh5TEdM9xfvcXt/904AgjVhRg4E/Iyi9R6OITY9e3EH9UJdYDSixpxMiGe1j5xG k/yaGFzt4FdVmc7H599hzDd3UCxlOZsMeyXvOGg099M74/+sTbbQoINwqx+hyzOH9Tbl0p951 xqXOUXoT8ou1wGlqgIpprTD0VVHj48NN2pesqHn7dK/alVnaBWijZ+nP9SP1h/aJ1GUlI6S79 fsU5mj3nhuyZB1cV9BAeZJxr/Z23sUGW6hEKm8UQlavSgcEt1BbR4vgFrLX0QaE8mRzBaqvj5 LpR5BINh2qWK68dKYGDIhfxh+QUMO+mZxrQVjdEC2VY7VuAc6PzdrxSbCASip8Xn9yZ0QlDGp qBlt1GydqA7jDLGaGL9BN6WRpB9r7KsuQBB9wm5EoB88yCxjwmUQVLGXuiZyyaYCwB1HXD1ny 4Lh50tUFtw6H4SdUw4D5CNY/3CB4ZIXkkWBOSzSSXyr1AAaZ8NsYZYr22vJ1v+Ys8q6GR18CC 47hnSsUums7kfZqV1MmBB5X7ri6xOHLaeJvQ50gAhiDlArNrRq96dNRXNp5hrh+nmmeNw/uWK fdCwdnKO5QKX8ewJ1nXhJX5VBGqAenQ22iPIOIEq/IIZsn7k59rrSRhAEOiAopY55l2ZwBXsG PlSzJk3j7vvfP2MGX1SttBZdefVZ2w0vCYgVGUp3Wbf5JfvPSRs+CGl4/ZwXiLKFXfcHxdNlr 1taWtLyJZAIEYQHZiL7QazBlarfNZc0TikH6n/MzUKMqQaFafvUPxbo1Xxez6kaGZ4Xoc4Nt+ v8PwCS8 X-SW-Source: 2016-10/txt/msg00037.txt.bz2 Hope this is not too late, I've been catching up on my mail. On Sat, 1 Oct 2016 00:11:58 Peng Yu wrote: > Hi, I am currently inserting the following line into functions for > which I want to print the function info. However, this can be tedious > if the source code is large. > > fprintf(stderr, "%s:%d:%s\n", __FILE__, __LINE__, __PRETTY_FUNCTION__); > > Is there a way to automatically print the information of each function > being called using gdb? Don't know, but you can do (in the shell, and you will need moreutils and gawk (gnu awk)): for i in SOURCE; do gawk '{ if($0 ~ /^{/){ printf("{\n fprintf(stderr, " "\"%%s:%%d:%%s\n\", __FILE__, __LINE__, __PRETTY_FUNCTION__);\n"); } else { print $0; } }' $i | sponge $i; done To undo: for i in SOURCE; do grep -v 'fprintf(stderr, "%s:%d:%s\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);' $i | sponge $i; done I've done similar things before, it's simple if you've formatted your code nicely (and put your unions and structs in your headers)! Sincerely, David