This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: size of non local variables


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.





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]