Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one approximate virtual memory used (VSZ) using a core dump and gdb on Linux?

Tags:

linux

gdb

I'm writing a tool for core dump analysis and one thing I'd like to print is an estimate of how much virtual memory the process was using at the time of the dump. These core dumps could be due to crashes or could be manually taken using gcore (e.g. for sizing). Essentially, I'd like to print the equivalent of the PS VSZ column.

I've looked into readelf and gdb and have focused on the latter. For example, I've got a simple program that just hangs and I see in PS:

$ ps auxwww | grep a.out
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     16644  0.0  0.0   4108   472 pts/5    S+   13:51   0:00 ./a.out

I take a core using gcore, at which point it's using 4,206,592 bytes VSZ. Then I wrote a quick script that parses info target output and sums the address ranges and I get 1,814,528 bytes. I also tried info proc mappings but that seems to only work if the process is running.

Any ideas?

like image 446
user379184 Avatar asked Nov 13 '22 11:11

user379184


1 Answers

In my case the output of gdb and ps shows the same info

root      3976  0.0  0.0   1636   640 tty6     Ss+  08:00   0:00 /sbin/mingetty tty6

pmap also show the same 1636

3976:   /sbin/mingetty tty6
00110000      4K r-x--    [ anon ]
001c3000    100K r-x--  /lib/ld-2.5.so
001dc000      4K r-x--  /lib/ld-2.5.so
001dd000      4K rwx--  /lib/ld-2.5.so
001e0000   1256K r-x--  /lib/libc-2.5.so
0031a000      8K r-x--  /lib/libc-2.5.so
0031c000      4K rwx--  /lib/libc-2.5.so
0031d000     12K rwx--    [ anon ]
08048000     12K r-x--  /sbin/mingetty
0804b000      4K rw---  /sbin/mingetty
08dd3000    132K rw---    [ anon ]
b7f69000      8K rw---    [ anon ]
b7f79000      4K rw---    [ anon ]
bff4d000     84K rw---    [ stack ]
total     1636K

Here's gdb info proc mapping

(gdb) info proc mappings
process 3976

cmdline = '/sbin/mingetty'
cwd = '/'
exe = '/sbin/mingetty'
Mapped address spaces:

    Start Addr   End Addr       Size     Offset objfile
      0x110000   0x111000     0x1000   0x110000           [vdso]
      0x1c3000   0x1dc000    0x19000          0     /lib/ld-2.5.so
      0x1dc000   0x1dd000     0x1000    0x19000     /lib/ld-2.5.so
      0x1dd000   0x1de000     0x1000    0x1a000     /lib/ld-2.5.so
      0x1e0000   0x31a000   0x13a000          0     /lib/libc-2.5.so
      0x31a000   0x31c000     0x2000   0x139000     /lib/libc-2.5.so
      0x31c000   0x31d000     0x1000   0x13b000     /lib/libc-2.5.so
      0x31d000   0x320000     0x3000   0x31d000        
     0x8048000  0x804b000     0x3000          0      /sbin/mingetty
     0x804b000  0x804c000     0x1000     0x2000      /sbin/mingetty
     0x8dd3000  0x8df4000    0x21000  0x8dd3000        
    0xb7f69000 0xb7f6b000     0x2000 0xb7f69000        
    0xb7f79000 0xb7f7a000     0x1000 0xb7f79000        
    0xbff4d000 0xbff62000    0x15000 0xbff4d000           [stack]

Can you show more info about the process?

like image 192
Serx_Mz Avatar answered Nov 16 '22 00:11

Serx_Mz