Tuesday, July 3, 2012

Valgrind for MIPS

Support for the MIPS architecture was recently added to Valgrind.

If you want to build Valgrind for your MIPS target, you should definitely refer to the README.mips file, but I wanted to outline the general steps it took to me to successfully build and run Valgrind:

  1. Get the latest source code - support for MIPS was just recently integrated into the main tree, and currently no official release support it:
    svn co svn://svn.valgrind.org/valgrind/trunk valgrind
  2. cd into the valgrind directory.
  3. ./autogen.sh
  4. ./configure --host=mipsel-linux-gnu --with-pagesize=4 CC=my-mips-xccompiler CXX=my-mips-xcppcompiler CFLAGS="-I/path/to/target/kernel -I/path/to/target/kernel/include -D__STRUCT_EXEC_OVERRIDE__ --prefix=/path/to/installation/dir
  5. make
  6. make install
Some notes on step [4]:
  • --host=mipsel-linux-gnu - mipsel is for little endian architecture and mips is for big endian.
  • with-pagesize=4 - this should be set to whatever your kernel's PAGE_SIZE is configured.
  • -D__STRUCT_EXEC_OVERRIDE__ - not sure why, but my kernel is missing the a.out.h in the arch/mips directory, which is needed by Valgrind. I had to define this so Valgrind will not include a.out.h.
  • --prefix - you want to set this up - this will create three directories - /bin, /lib and include, which you want in your target's root filesystem.
Before you can run Valgrind on the target, you'll need to issue the following command:
export VALGRIND_LIB=/lib/valgrind

That's it, your'e all set - type 'valgrind --help' for all available options.

2 comments:

Gregory said...

Thanks for documenting your MIPS valgrind build experience! You've helped at least one other person out.

Unknown said...

Thanks for your sharing.

I have one question about building valgrind. After I execute "make install", there are 4 folders (bin, include , lib, share) under the --prefix folder.

Should I copy all the binary to my MIPS system?
It seems that I have to copy the memcheck binary , right?

Thanks a lot.