Reputation: 3905
I have a program which has a significant number of statically defined variables. If I start it up in GDB, with a break point in main, and then run pmap, I see there is about 100MB of data already allocated:
08838000 107576K rw--- [ anon ]
I've already found a pile of functions that have enormous statically defined arrays (e.g. 200,000 ints) and got rid of them as I've found them.
Is there any way to find out what the largest items are on the heap / data segments? Either in GDB or through any other means?
Upvotes: 3
Views: 873
Reputation: 3459
The information can be found by using the object code inspection utilities like nm(1):
nm --size-sort <object-file.o>
Also, objdump can give additional insights for the completely linked program, given enough debug information.
The utilities are often target platform specific, so when cross-compiling care must be taken to use the correct program (i.e. something like x86_64-linux-gnu-gcc-nm
instead of just nm
).
Upvotes: 5