Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: "Anmol P. Paralkar" <anmol@freescale.com>
To: ranjith kumar <ranjithproxy@gmail.com>
Cc: gdb@sourceware.org
Subject: Re: size of non local variables
Date: Tue, 01 Dec 2009 00:17:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.64.0911301743520.12536@lds03-tx32> (raw)
In-Reply-To: <31cff80d0911301246p6471c1a5ua95608d22b81a22a@mail.gmail.com>

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 <stdio.h>

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 <anmol@freescale.com> 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.
>>
>
>


  parent reply	other threads:[~2009-12-01  0:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-30 20:39 ranjith kumar
2009-11-30 23:18 ` Anmol P. Paralkar
     [not found]   ` <31cff80d0911301246p6471c1a5ua95608d22b81a22a@mail.gmail.com>
2009-12-01  0:17     ` Anmol P. Paralkar [this message]
2009-12-01 19:26       ` Tom Tromey
2009-12-01 21:33         ` Anmol P. Paralkar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0911301743520.12536@lds03-tx32 \
    --to=anmol@freescale.com \
    --cc=gdb@sourceware.org \
    --cc=ranjithproxy@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox