Monday, September 1, 2008

segmentation fault in linux/unix

A wired error happened today when I am trying to run a gcc complied application.
"Segmentation fault" happened in the least expected place (at least according to cout, it paused), so I tried very hard to
modify this bit of code in many ways. I couldn't solve the problem until I tried gdb.
After reading wikipedia for the simplest way of using gdb, and few other articles on the web, I start to debug the code.
I find that the application had a bug in one line, which is way below the code that I was messing around. 
How stupid I am... I should know that the application is still running and cout just haven't finish printing.....
I should have turn to debugging straight away because this is c++, not c#.

Conclusion: Never trust manual debug using cout.

1 comment:

Noahcarl said...

This is such a relatable debugging experience. Segmentation faults can be incredibly misleading, especially when the crash appears to happen near a specific output like cout, making you focus on the wrong section of code. It’s a great reminder of how powerful tools like gdb are in tracing the real source of the issue instead of guessing and modifying random sections. Honestly, moments like this are part of every developer’s journey. It also reflects a broader lesson about precision and clarity, similar to defining clear dissertation objectives in research, if you don’t pinpoint the exact problem or goal, you can easily spend time fixing the wrong thing. Debugging really teaches patience and structured thinking.