I have such setup. I need to program on some embedded device which in spec says to run Linux (although when you turn on the device, clearly the display doesn't show anything linux related - small display). The embedded device has its own SDK. Now, I thought using valgrind to check for memory management/allocation. Can I use valgrind to check a program written for my device? The problem I see is that the program might contain some device specific SDK calls, hence the program might not run on ordinary fedora linux that I run on my desktop for example. What are my options?
2 Answers
Running valgrind on embedded devices can be quite challenging, if not impossible.
What you can do is to create unit tests, and execute them using valgrind on the host platform. That is a way to at least check memory problems of part of the code.
Other option is to use platform emulation, and run programs in emulators (again on the host system). QEMU is quite famous open source emulator.

- 62,405
- 41
- 173
- 273
-
Which platform do you mean by "host"? With the links you provided this doesn't seem easy task... Are there maybe some good static checker programs? For checking for memory leaks? This one I could run just on code. – Mar 19 '14 at 08:35
-
@dmcr_code Under "host", I mean the computer where you write and compile programs. What you asked is quite complex topic. Static checkers help up to some extend, but valgrind is much better. – BЈовић Mar 19 '14 at 08:38
-
Yes but like I said I can't run all code on my host computer right? Because some part of code may contain calls to device SDK hence on my computer they won't run? – Mar 19 '14 at 08:39
-
@dmcr_code No, you can not. This is the easiest and simplest way to check at least (unit tested) part of the code. – BЈовић Mar 19 '14 at 10:07
-
so you recommending me testing that part of code using valgrind and my computer which do not contain device specific SDK calls right? – Mar 19 '14 at 10:17
-
@dmcr_code Yes. You could also cross compile unit and functional tests and valgrind for your target, and execute them there. There you can use platform specific sdk. – BЈовић Mar 19 '14 at 10:33
-
I am not sure I fully understood your last comment.. :( though testing some part of code which does not rely on device SDK is also not bad idea – Mar 19 '14 at 10:44
-
@dmcr_code Write unit tests and functional tests. Cross compile them, and execute on your target. It all depends on what you are doing – BЈовић Mar 19 '14 at 10:53
-
maybe due to my inexperience with these tools (functional etc.) I am not fully following you. You can also see my response to unwind. I'll either have to follow c safely memory handling practices, or try to avoid dynamic memory – Mar 19 '14 at 10:59
Perhaps.
Make sure you really run Linux, of course.
Figure out the hardware platform; Valgrind supports quite a few platforms but not all.
Consider whether your platform has resources (memory and CPU speed) to spare; running Valgrind is quite costly.
If all of those check out ok, then you should be able to run Valgrind, assuming of course you can get it onto the target machine. You might need to build and install it yourself, of course.
I assume you have some form of terminal/console access, i.e. over serial port, telnet, or something that you can use to run programs on the target.
UPDATE: Based on feedback in comments, I'm starting to doubt the possibility for you to run Valgrind on your particular device.

- 391,730
- 64
- 469
- 606
-
I am a bit confused. The device is similar to this: http://p.globalsources.com/IMAGES/PDT/B1054670876/POS-Terminal.jpg. Hardware says: Dual CPU 32bit ARM9 CPU. Clearly when you run this device (due to small screen size) you can hardly see numbers and letters... So I am really curious how can I run valgrind on this device? Where will I see the output? – Mar 19 '14 at 08:13
-
[See this question regarding "ARM9"](http://stackoverflow.com/questions/6378152/valgrind-on-the-arm9), it seems you need more precision. – unwind Mar 19 '14 at 08:17
-
this is some spec on device: http://s30.postimg.org/6ftarwgz5/2012051115061359.jpg. I can't see Cortex there? But even if there was support for valgrind, how would I run valgrind on this device? Where would I see the output? (I have already shown you how the device looks physically) – Mar 19 '14 at 08:32
-
How do you run code on the device? Do you have any form of terminal access, over a serial port or network? The device seems to have plenty of I/O ports that could be used for this. – unwind Mar 19 '14 at 08:35
-
No, I usually download an executable I have to the device using some download tool. Then when you launch device executable gets executed. I didn't use terminal to access the device yet ... – Mar 19 '14 at 08:37
-
what is your opinion on using static checker for memory management related problems? is there a good tool for this? I could use a static checker right? – Mar 19 '14 at 08:45
-
Not sure about static checkers, simply because I haven't had any experience with them. Of course, all checking is better than no checking, typically. :) Also consider refactoring code not to use heap allocations, it's often more possible than you might think. – unwind Mar 19 '14 at 08:50
-
thank you for advice about refactoring. But the code might need to deal with stuff like: en.wikipedia.org/wiki/Type-length-value So I thought the "Value" field there needed to be dynamic array, isn't it? Plus I am not sure yet about stack and heap size of the device – Mar 19 '14 at 09:02