Very Strange behavior: My c++ program suddenly exit but it run flawlessly o the end in debug mode in Eclipse CDT

StackOverflow https://stackoverflow.com/questions/22972410

Question

I have my own c++ program in Eclipse CDT in ubuntu 64-bit which use an external encoding detection library. As you might guess, I use gcc to compile my program and GDB for debug. Now the most strange behavior I have seen in my programming life: While I debug my program using "Debug As" in Eclipse, it works perfectly to the end but when I select "Run As" it will terminate in the middle of the program suddenly without showing any error or exception message in console!!!

Does someone have any idea about this strange problem?

Was it helpful?

Solution

Knowing how to debug is very important. If your debugger fails to do so, you can try commenting out certain lines of code until the program works. If that doesn't work, your program might be suffering from a heisenbug in which I would suggest you to print out variables in console while running to analyze them. You should also review your code. Sometimes it can be a really silly error.

OTHER TIPS

What really helped me is to find the UB behaviour, as suggested by @PaulMcKenzie. For clang/gcc you can add -fsanitize=undefined to see what can cause the problem. In other words compile and run something like this: clang -fsanitize=undefined -o myprogram myprogram.c -O3 and then fix the problems that are printed into your console.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top