Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Valgrind on an Embedded project

Currently I am working on an Embedded Project. I am using IAR Embedded Workbench IDE and target platform is 8051-based microcontroller. Is it possible to use Valgrind tool to check the code I wrote?

like image 356
Lerok Persea Avatar asked Jul 30 '13 06:07

Lerok Persea


2 Answers

No, and Yes*.

No: As another commenter said, Valgrind does not run on 8051 architectures, so you can't use Valgrind as you would on an x86 system.

Yes*: (the asterisk (*) is because it's a limited "yes")

But you can use Valgrind on the non-8051/IAR-specific parts of your code if you:

  1. Separate the 8051-specific and IAR-specific code from the architecture/compiler agnostic code.
    • You'll probably want to do this so the code doesn't get any bigger as a result of separating the agnostic code. (I'm assuming code size is at a premium since you're working on an 8051.)
  2. Compile the architecture/compiler agnostic code with gcc and run it using Valgrind on your desktop/laptop development machine, which is probably an x86 machine.
    • Of course you can use any other Valgrind-supported architecture/compiler, x86/gcc isn't your only choice.

This way Valgrind will be able to check some of your code, which is better than nothing.

And separating the compiler/chip specific parts of your code will also make it more portable and reusable.

Oh, and this isn't directly related, but you should also consider using a static analysis program like PC-Lint: http://www.gimpel.com/html/index.htm

It checks some things that Valgrind checks, and many things that Valgrind doesn't check. Plus it will check all of your code, not just the non-8051/IAR code.

There are plenty of similar tools out there; PC-Lint is the most popular that I've seen.

like image 200
svec Avatar answered Nov 06 '22 02:11

svec


You should check this page, Valgrind Supported Platforms. 8051 micro-controller instruction set is not supported by Valgrind.

Moreover, you should know Valgrind is an instruction simulator. It means you have to run Valgrind on the system, and it runs your code with OS and base layer of C or other POSIX libraries to simulate your program's memory read/write, or profiling. So 8051 is impossible to run Valgrind.

like image 25
jclin Avatar answered Nov 06 '22 02:11

jclin