How to extract ELF cores from 'gcore' generated qemu core files for use with the 'crash' utility
Environment
- Red Hat Enterprise Linux (RHEL) 7
qemu-kvm-[rhev]on RHEL 7 KVM based hosts.gcoreon RHEL 7 KVM based hosts.
Note: In the RHEL 7.4 time-frame, with an upgrade to libvirt-3.2.0, the default setting for dump-guest-core has been changed from on to off. This means that when a process core file is generated by/from qemu-kvm-[rhev], it will not include any guest memory pages.
Issue
- Core dumps of running programs can be obtained for
qemu-kvmguest processes as follows:
# ps -ef | grep <VM name> # To obtain a virtual guest's PID.
# gcore <PID>
-
What steps are required in order to extract ELF cores from resultant
gcoreoutput files for use with thecrashutility? -
As of RHEL 7.4 with
libvirt-3.2.0, the default setting fordump-guest-coreisoff.
Resolution
- The following process can be followed in order to extract a
crashcompatible virtual memory core from agcoregenerated core file:
-
The
dump-guest-memory.pygdbscript is installed as part of theqemu-kvm-[rhev]package installation on the host system. This is located under/usr/share/qemu-kvm/dump-guest-memory.py. -
Ensure that the
qemuprocess that has been dumped had the command line option -machine dump-guest-core=on. In RHEL 6 and 7 prior to the 7.4 time-frame, the default ison. However, in the RHEL 7.4 time-frame, the default changed to dump-guest-core=off. If you see this, please contact Red Hat Technical Support for assistance. -
Install the same
qemu-kvm-[rhev]andqemu-kvm-[rhev]-debuginfoRPM versions on the debugging host as were installed on theqemu-kvmbased hypervisor upon which thegcore <pid>command was run when thegcorewas captured. Ensure that the host is of the same release and architecture also. -
Initiate
gdbpassing the following arguments:
# gdb <qemu-kvm binary path used by original host> <gcore_file>
For example:
# gdb /usr/libexec/qemu-kvm qemu-kvm-core
- Once
gdbhas initiated, source thedump-guest-memory.pyscript referenced in point (1) above:
(gdb) source /usr/share/qemu-kvm/dump-guest-memory.py
- Ensuring that there is enough available space within the current working directory (at least as much as the original
gcorefile should suffice in most cases), extract the ELF core as follows from the(gdb)prompt (assuming here that thegcorefile also resides in the current working directory). Thisgdbcommand re-implements the dump-guest-memory QMP command in Python, using the representation of guest memory as captured in theqemucoredump:
(gdb) dump-guest-memory <output_file>
For example:
(gdb) dump-guest-memory elf_core
guest RAM blocks:
target_start target_end host_addr message count
---------------- ---------------- ---------------- ------- -----
0000000000000000 00000000000a0000 00007f0004000000 added 1
00000000000c0000 00000000000ca000 00007f00040c0000 added 2
00000000000ca000 00000000000cd000 00007f00040ca000 joined 2
00000000000cd000 00000000000ec000 00007f00040cd000 joined 2
00000000000ec000 00000000000f0000 00007f00040ec000 joined 2
00000000000f0000 0000000000100000 00007f00040f0000 joined 2
0000000000100000 00000000c0000000 00007f0004100000 joined 2
00000000fc000000 00000000fd000000 00007f021c200000 added 3
00000000fffc0000 0000000100000000 00007f021d600000 added 4
0000000100000000 0000000240000000 00007f00c4000000 added 5
dumping range at 00007f0004000000 for length 00000000000a0000
dumping range at 00007f00040c0000 for length 00000000bff40000
dumping range at 00007f021c200000 for length 0000000001000000
dumping range at 00007f021d600000 for length 0000000000040000
dumping range at 00007f00c4000000 for length 0000000140000000
NOTE: In more recent releases the format requires an ARCH argument, e.g.;
(gdb) dump-guest-memory elf_core
No valid arch type specified.
Currently supported types:
aarch64-be, aarch64-le, X86_64, 386, s390, ppc64-be, ppc64-le
(gdb) dump-guest-memory elf_core X86_64
guest RAM blocks:
target_start target_end host_addr message count
---------------- ---------------- ---------------- ------- -----
0000000000000000 00000000000a0000 00007f0004000000 added 1
........ etc., etc., ........
- The resultant file can then be loaded into the
crashutility, provided that you reference thevmlinuxextracted from thekernel-debuginfofile of the same version as the kernel running in the guest when thegcorewas captured (as per standardcrashprocedure):
# crash <output_file> <vmlinux_file>
- The following additional article provides some detail on extracting
vmlinuxfiles fromkernel-debuginfoRPMs, How to create a basic centralized crash analysis system to analyze vmcore locally .
NOTE:
For RHEL 7.4 systems with libvirt-3.2.0, the following is required in order for a complete dump of the guest's memory to be obtained;
-
Upgrade
gdbtogdb-7.6.1-100.el7_4.1.x86_64or later, per This content is not included.BZ 1524312. -
Run
gcore -a, e.g.
# ps -ef | grep <VM name> # To obtain a virtual guest's PID.
# gcore -a <PID>
- Then follow the sequence above.
Root Cause
virsh dump --verbose --memory-only <VM name> <dump file>saves cores usingsave-vmto extract a virtual memory core whereasgcore <PID>collects a core relating to a whole process. Subsequently, further extraction is required againstgcoreoutput files in order to prepare an ELF virtual memory core which is usable with thecrashutility.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.