"Process finished with exit code 139" in CLion IDE while the program is running fine in the terminal

Viewed 3485

I am working on a software project, which can be build by invoking cmake, make and make install. The IDE I am using is JetBrains' CLion.

The thing that I do not understand is that when I run the program in CLion, I get this feedback:

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

However, when I run the program in a terminal, it works flawlessly. When I use the CLion debugger, Assembly code is presented to me and I don't know why (see screenshot below). enter image description here

I don't know how I should debug this issue. Apologies if my issue is a duplicate, in this case I'd be happy if one could show me the "original".

I should also mention that (although feeling quite comfortable with my Ubuntu 20.04) I am still fairly new to Linux/Unix in general and also not a master of the C language.

Thanks in advance for any hints, help or pushes in the right direction! Have a nice day!

1 Answers

I managed to figure it out.

I added the line set( CMAKE_BUILD_TYPE Debug ) to the CMakeLists.txt file at the root level of the project. By doing to, I enabled the debug functionality of CLion. Hence, I was able to break at the point where the segmentation fault happens and to successfully debug it.

(In case someone is interested: What caused the segmentation fault was that a strrchr(const char *str, int c) function was called with str being NULL. str was holding the file name that the program would read. The reason the program worked on the terminal was that I navigated to the folder containing the file and executed the program. In the CLion configuration, I added the path in "global form". By providing a path relative to the executable file inside the CLion project solved the issue for me.)

Related