Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* size of non local variables
@ 2009-11-30 20:39 ranjith kumar
  2009-11-30 23:18 ` Anmol P. Paralkar
  0 siblings, 1 reply; 5+ messages in thread
From: ranjith kumar @ 2009-11-30 20:39 UTC (permalink / raw)
  To: gdb

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: size of non local variables
  2009-11-30 20:39 size of non local variables ranjith kumar
@ 2009-11-30 23:18 ` Anmol P. Paralkar
       [not found]   ` <31cff80d0911301246p6471c1a5ua95608d22b81a22a@mail.gmail.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Anmol P. Paralkar @ 2009-11-30 23:18 UTC (permalink / raw)
  To: ranjith kumar; +Cc: gdb

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: size of non local variables
       [not found]   ` <31cff80d0911301246p6471c1a5ua95608d22b81a22a@mail.gmail.com>
@ 2009-12-01  0:17     ` Anmol P. Paralkar
  2009-12-01 19:26       ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Anmol P. Paralkar @ 2009-12-01  0:17 UTC (permalink / raw)
  To: ranjith kumar; +Cc: gdb

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: size of non local variables
  2009-12-01  0:17     ` Anmol P. Paralkar
@ 2009-12-01 19:26       ` Tom Tromey
  2009-12-01 21:33         ` Anmol P. Paralkar
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2009-12-01 19:26 UTC (permalink / raw)
  To: Anmol P. Paralkar; +Cc: ranjith kumar, gdb

>>>>> "Anmol" == Anmol P Paralkar <anmol@freescale.com> writes:

Anmol>  On the other hand, GDB Guru's, is there a way one could get a
Anmol>  list of a program's symbols into a list and map over that list,
Anmol>  a function that takes a symbol as an argument and returns an
Anmol>  integer representing it's size? etc...

Anmol>  I tried looking at the Python support documentation to see if
Anmol>  this could be done easily, but could not really tell (I've never
Anmol>  used GDB's Python support nor Python).

I don't believe the Python symbol table code has been merged yet.  And
even on the branch in archer I'm not sure whether this can be done.

Anmol>  Is there a mini-tutorial somewhere that has an example of
Anmol>  getting started with using GDB's Python support? I tried trying
Anmol>  out the Greet snippet here:
Anmol>  http://sourceware.org/gdb/current/onlinedocs/gdb/Functions-In-Python.html#Functions-In-Python
Anmol>  but I'm not sure what I'm doing wrong.

If that didn't work, could you be more specific?  How did it fail, etc?

I wrote a series of blog entries about the python work a while back.
This may be the closest thing to a tutorial; however, some details of
the API have changed since then, so you would have to read it in
conjunction with the gdb manual:

http://tromey.com/blog/?p=494

Tom


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: size of non local variables
  2009-12-01 19:26       ` Tom Tromey
@ 2009-12-01 21:33         ` Anmol P. Paralkar
  0 siblings, 0 replies; 5+ messages in thread
From: Anmol P. Paralkar @ 2009-12-01 21:33 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Anmol P. Paralkar, ranjith kumar, gdb

On Tue, 1 Dec 2009, Tom Tromey wrote:

> Anmol>  Is there a mini-tutorial somewhere that has an example of
> Anmol>  getting started with using GDB's Python support? I tried trying
> Anmol>  out the Greet snippet here:
> Anmol>  http://sourceware.org/gdb/current/onlinedocs/gdb/Functions-In-Python.html#Functions-In-Python
> Anmol>  but I'm not sure what I'm doing wrong.
>
> If that didn't work, could you be more specific?  How did it fail, etc?
>
> I wrote a series of blog entries about the python work a while back.
> This may be the closest thing to a tutorial; however, some details of
> the API have changed since then, so you would have to read it in
> conjunction with the gdb manual:
>
> http://tromey.com/blog/?p=494

  I tried the example at http://tromey.com/blog/?p=501 and it worked just fine;
  I realize that I must have been making some kind of a usage error (and not
  making sense of the error message (should have saved it)).

  But, that's a nice tutorial - pretty much what I was looking for - thank you.

Best Regards,
Anmol.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-12-01 21:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-30 20:39 size of non local variables ranjith kumar
2009-11-30 23:18 ` Anmol P. Paralkar
     [not found]   ` <31cff80d0911301246p6471c1a5ua95608d22b81a22a@mail.gmail.com>
2009-12-01  0:17     ` Anmol P. Paralkar
2009-12-01 19:26       ` Tom Tromey
2009-12-01 21:33         ` Anmol P. Paralkar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox