rogerhu/gdb-heap

Don't read /proc/$PID/maps for core files

doctau opened this issue · 5 comments

iter_mmap_heap_chunks() tries to read /proc/$PID/maps which only works if the process is currently running. If you are using a core file, it will fail with an exceptions.IOError.

Having iter_mmap_chunks() return immediately if we are processing a core file rather than having an attached process solves it.

Do you have a PR?

Not yet, I just added a "return" to the top temporarily to work on the core file I'm looking at. I can do one later after I've had a chance to look at the gdb API which I haven't used before (unless you fix it first)

If we return immediately, it presumably won't find the mmapped chunks.

I'm told that

(gdb) info proc mappings

works for core files from NT_FILE; this could be a way to find them when running on a coredump.

Same problem hiere:

(gdb) heap
Python Exception <class 'FileNotFoundError'> [Errno 2] No such file or directory: '/proc/4951/maps':
Error occurred in Python command: [Errno 2] No such file or directory: '/proc/4951/maps'

There is another util for analyzing heap in core dumps: https://github.com/vmware/chap
If you want, you can dump allocation list via comand "list allocations" in chap. After that you need to parse this list to get allocations for gdbheap instead of porcfs.
I also tried parse allocations via gdbheap based on gdb command "info files", but this method failed.