-
Notifications
You must be signed in to change notification settings - Fork 29
How to use valgrind to detect QEMU memory leakage
- Check out the code from SVN
git clone git://sourceware.org/git/valgrind.git
-
cd
into the source directory. - Run
./autogen.sh
to setup the environment (you need the standard autoconf tools to do so). - Run
./configure
, with some options if you wish. The only interesting one is the usual --prefix=/where/you/want/it/installed. - Run
make
. - Run
make install
, possibly as root if the destination permissions require that. - See if it works. Try
valgrind ls -l
. Either this works, or it bombs out with some complaint.
- Accessing memory you shouldn't, e.g. overrunning and underrunning heap blocks, overrunning the top of the stack, and accessing memory after it has been freed.
- Using undefined values, i.e. values that have not been initialised, or that have been derived from other undefined values.
- Incorrect freeing of heap memory, such as double-freeing heap blocks, or mismatched use of malloc/new/new[] versus free/delete/delete[]
- Overlapping src and dst pointers in memcpy and related functions.
- Passing a fishy (presumably negative) value to the size parameter of a memory allocation function.
- Memory leaks.
-
--tool=memcheck
: To use memcheck tool, you can specify--tool=memcheck
on the Valgrind command line. -
--leak-check=full
: Memcheck will give details for each definitely lost or possibly lost block, including where it was allocated. -
--log-file
: Specifies that Valgrind should send all of its messages to the specified file. If the file name is empty, it causes an abort.
sudo valgrind --tool=memcheck --leak-check=full --log-file=qemu.log <qemu-command>
full command example:
sudo valgrind --tool=memcheck --leak-check=full --log-file=qemu.log qemu-system-x86_64 -vnc :1 -name default-node -device sga --enable-kvm -smbios file=/home/infrasim/.infrasim/default/data/dell_r730_smbios.bin -boot order=ncd,splash=/usr/local/infrasim/data/boot_logo.jpg -machine q35,usb=off,vmport=off -chardev socket,path=/home/infrasim/.infrasim/default/.serial,id=serial0,reconnect=10 -device isa-serial,chardev=serial0 -uuid c55d539a-e4c1-43f2-b6ec-cc92340a4321 -cpu Haswell,+vmx -smp 2,sockets=2,cores=1,threads=1 -m 1024 -device ahci,id=sata0 -drive format=qcow2,cache=writeback,id=sata0-0-0-0,file=/home/infrasim/.infrasim/default/disk00.img,if=none -device ide-hd,bus=sata0.0,drive=sata0-0-0-0,id=dev-sata0-0-0-0 -netdev user,id=netdev0 -device e1000,netdev=netdev0,mac=00:60:16:9f:3a:f4 -chardev socket,host=127.0.0.1,port=9002,id=ipmi0,reconnect=10 -device ipmi-bmc-extern,chardev=ipmi0,id=bmc0 -device isa-ipmi-kcs,bmc=bmc0 -chardev socket,host=127.0.0.1,port=2345,id=monitorchardev,server,nowait -mon chardev=monitorchardev,mode=readline