Question

I am using KDevelop for C++ development and debugging. Looks like I am dereferencing an NULL pointer somewhere, because I get:

*** Program received signal SIGSEGV (Segmentation fault) ***

How can I figure out where it happened? I would like KDevelop to break on these kind of signals and unhandled exceptions.

Was it helpful?

Solution

You have to run the application inside the debugger. Press the Debug button in KDevelop in case you already have a proper launch configuration.

In KDevelop, this will open the Debug area view and run the application in GDB. After the crash, press the Frame Stack tool view on the bottom bar.

There you go.

OTHER TIPS

Unlike interpreted languages, such as Python, and languages which do not allow explicit memory management and use automatic garbage collection, like Java and C#, what you are asking is essentially impossible for C++ with any editor. The reason for this is that when a pointer is created, it is just that -- a pointer to a memory address. It is impossible to check whether the memory at the pointed address has been allocated properly and is accessible until one actually tries to access the memory via the pointer. In general, there are three main categories of errors:

1) syntax (these are also a subclass of the second below)

2) compile time

3) run time.

In the first case, most modern IDEs will be able to catch the error even before you try to compile. These are errors that arise from incorrect syntax.

In the second case, these errors can be caught and compile time (these are usually also those that arise from incorrect syntax, but not only; for example, accessing a static array out of range will produce this error).

In the third case, these are errors that can only be caught during the run time of the program. What you are asking about is of this type in C++.

So, the best thing to do would be to run the program in debug mode. The debugger that is included with KDevelop is a very capable one. You'll be able to track memory allocation/deletion explicitly. For more information, see here: http://userbase.kde.org/KDevelop4/Manual/Debugging_programs

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