From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32321 invoked by alias); 1 Dec 2009 00:17:02 -0000 Received: (qmail 32312 invoked by uid 22791); 1 Dec 2009 00:17:01 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from az33egw02.freescale.net (HELO az33egw02.freescale.net) (192.88.158.103) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 01 Dec 2009 00:16:53 +0000 Received: from de01smr01.freescale.net (de01smr01.freescale.net [10.208.0.31]) by az33egw02.freescale.net (8.14.3/az33egw02) with ESMTP id nB10GoFQ004947; Mon, 30 Nov 2009 17:16:50 -0700 (MST) Received: from lds03-tx32 (lds03-tx32.am.freescale.net [10.83.20.63]) by de01smr01.freescale.net (8.13.1/8.13.0) with ESMTP id nB10LI9M009311; Mon, 30 Nov 2009 18:21:18 -0600 (CST) Date: Tue, 01 Dec 2009 00:17:00 -0000 From: "Anmol P. Paralkar" To: ranjith kumar cc: gdb@sourceware.org Subject: Re: size of non local variables In-Reply-To: <31cff80d0911301246p6471c1a5ua95608d22b81a22a@mail.gmail.com> Message-ID: References: <31cff80d0911301216j36328837k673a2e1936f00eb1@mail.gmail.com> <31cff80d0911301246p6471c1a5ua95608d22b81a22a@mail.gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed 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-12/txt/msg00000.txt.bz2 On Tue, 1 Dec 2009, ranjith kumar wrote: > thanks. > But the problem is that I am debugging a large code. > It contains many non local variables. > It is said that 2 global variables are of large size(char arrays). > I cant do 'print sizeof' on all non local variables. > Isn't there another method. Hello Ranjith Kumar, I assume that you want to be able to tell which are your largest global variables? PS: I am not entirely sure that your question pertains to GDB - but I could be wrong. I am including the following in the hope that it'll be of help. (Kindly help keep the discussion from getting off-topic for the GDB list, thank you). -------------------------------------------------------------------------------- $ cat hello.c #include int u = 128; int x; char c; char globals[1<<16]; int n = 1024; char c0 = 'a'; int main(void) { printf ("hello, world!\n"); return 0; } $ gcc hello.c -o hello $ nm --extern-only --print-size --size-sort --radix=d hello | gawk '$3 ~ /[bBdD]/' 0000000006359264 0000000000000001 B c 0000000006293636 0000000000000001 D c0 0000000006293632 0000000000000004 D n 0000000006293628 0000000000000004 D u 0000000006293696 0000000000000004 B x 0000000006293728 0000000000065536 B globals $ -------------------------------------------------------------------------------- -- On the other hand, GDB Guru's, is there a way one could get a list of a program's symbols into a list and map over that list, a function that takes a symbol as an argument and returns an integer representing it's size? etc... I tried looking at the Python support documentation to see if this could be done easily, but could not really tell (I've never used GDB's Python support nor Python). Is there a mini-tutorial somewhere that has an example of getting started with using GDB's Python support? I tried trying out the Greet snippet here: http://sourceware.org/gdb/current/onlinedocs/gdb/Functions-In-Python.html#Functions-In-Python but I'm not sure what I'm doing wrong. Thanks very much. Anmol. > > Thanks in advance. > > On 12/1/09, Anmol P. Paralkar wrote: >> On Tue, 1 Dec 2009, ranjith kumar wrote: >> >>> Hi, >>> I know that gdb will print non local variable names and file name in >>> which they are defined , >>> when we run 'info variables' command. >>> >>> Is it possible to print the size of the non local varibles also? >>> like the size of 'int global[100]' is 400bytes ...like that???? >>> >>> thanks in advance. >> >> Hello Ranjith Kumar, >> >> You could do: >> >> (gdb) print sizeof(global) >> $1 = 400 >> >> -- >> >> - that's an instance of GDB's functionality to evaluate expressions in the >> source language with the 'print' command. >> >> See 'Examining Data' in the User Manual: >> http://sourceware.org/gdb/current/onlinedocs/gdb/Data.html#Data >> >> Best Regards, >> Anmol. >> > >