<div dir="ltr">We have a big legacy embedded code we need to maintain. Often, we wish to run some functions of the code on the PC with injected input, to test them or to test changes we&#39;ve done to them without loading the code to the device it should run on.<div>
The code is written with C.<br><div>Obviously, this is not an easy task, it is more difficult because, the code is bug ridden, and many times it works by accident (for example, a NULL pointer added a constant and then derefeced, this worked because the memory address was legal).</div>
<div>Since the code is big, our strategy is: compile just the parts you need, debug it enough so that it would run on the PC, and keep the changes. Hopefully, after enough time, all (or most) of the code would be runnable on a PC.</div>
<div>We use gcc+gdb to compile and debug the code. In Visual Studio&#39;s cl.exe there are some <a href="http://msdn.microsoft.com/en-us/library/aa289171(VS.71).aspx">security checks</a> at run time. This can really assist debugging. For example knowing when an unintialized variable was used can save you alot of frustration when trying to figure out why you&#39;re getting a wrong numberic results.</div>
<div>My questions are:</div><div>1) Are there parallel (or better) runtime security checks for gcc/gdb? I found the -fstack-protection stack canary switch, but are there more of this type?</div><div>2) What other tools are there which offer similar protection? Valgrind of course is the first thing that comes to my mind, but I&#39;ll be glad to hear any more ideas.</div>
<div>For example, I would love to be able to get a warning whenever a pointer is dereferenced twice, where the first time the pointer points at the memory address of variable x, and the second time it points to variable y. That way I&#39;ll get a warning for the following bug:</div>
<div>int x[3] = {1,2,3};int y[3] = {4,5,6};</div><div>int *p = x;</div><div>for (int i=0;i&lt;=3;i++,p++) (*p) = (*p)++; // note the &lt;=</div><div>3) We use win32 for regular development, so if anyone knows what is the support for such tests in cygwin/mingw, I&#39;ll be glad to hear about it.</div>
<div><br></div><div>Thanks</div><div>Elazar Leibovich</div></div></div>