Hacker News new | ask | show | jobs
by pixelp3 3886 days ago
I think it is very important that computer science students learn C early on. Learning concepts like memory management and word alignment (which he mentions) is very critical imo.

For other majors which have require some programming it is best if they stick to something like Python, etc.

But the author does make a lot of good points regarding how many holes there are in these languages, and how much of a time sink they can. In fact I spent the last few days trying to track down this obscure bug where an object being allocated in C++ was randomly being free'd (according to gdb a valid address would become 0x1 all of a sudden) and I couldn't figure it out. I implemented some nasty WAR which makes the program run now...

1 comments

A small aside, would be interested to hear how you tracked down the bug? Obviously after you have solved the root cause.

In the embedded world, I would put a breakpoint on a write operation for that address. Once the breakpoint is triggered, I would inspect the trace.

This is in the embedded world, unfortunately the gdb for this platform is rather limited and watch breakpoints don't work as expected.

Essentially here is what was happening: -Create C++ object -Try to point some reference to this object, but object address is suddenly 0x1 (just by doing one step in gdb) when trying to access one of it's properties. -Tried to run it with valgrind, and it works fine with valgrind, which leads me to believe it is some memory allocation issue with C++ on the heap -I modified the C++ class to have a uint64_t variable before the variable declaration. Now program works fine!

I believe the issue is probably with heap corruption at some point, when something overwrites certain addresses.Having that extra unneeded 64-bit int in the heap makes it still be valid.

> This is in the embedded world, unfortunately the gdb for this platform is rather limited and watch breakpoints don't work as expected.

Thanks for sharing. There is nothing like a JTAG debugger with this kind of bugs. Good luck that it does not resurface later on.