Fixing Segmentation faults in C++

Compile your application with -g, then you’ll have debug symbols in the binary file. Use gdb to open the gdb console. Use file and pass it your application’s binary file in the console. Use run and pass in any arguments your application needs to start. Do something to cause a Segmentation Fault. Type bt in the gdb console to get a stack trace of the Segmentation Fault.

Undefined reference to class constructor, including .cpp file fixes

The undefined reference error indicates that the definition of a function/method (i.e constructor here) was not found by the linker. And the reason that adding the following line: fixes the issue, is it brings in the implementation as part of the main.cpp whereas your actual implementation is in StaticObject.cpp. This is an incorrect way to fix this problem. I haven’t used Netbeans … Read more

R debugging: “only 0’s may be mixed with negative subscripts”

The problem: actionlist$RPos[1000] has a value of 21. n1 ranges from -31 to 0. When you add them you get a vector with a mix of positive and negative values, which isn’t allowed in subsetting. How I got there: First check traceback(): This tells me the problem is in actionlist$RPos[i] + n1 most likely. Then I just added a simple print(i) statement to tell … Read more

Valgrind complains with “Invalid write of size 8”

This looks wrong: Should probably be: (spaces added for convenience). EDIT: Some additional explanation: When you say return_data[i]=… you are trying to write something into return_data[i]. Now, return_data is char**, so return_data[i] is char*. So you are writing a pointer into some location in memory. It looks like your pointers are 8 bytes long (which is fine), but you’ve only allocated 6 bytes: MAX_SOURCE_STRING+1. So … Read more

Eclipse java debugging: source not found

Eclipse debugging works with the class actually loaded by the program. The symptoms you describe sounds like the class in question was not found in the project, but in a distribution jar without debug info found before the project you are working with. This can happen for several reasons but have a look at the location where the classes … Read more

What is the purpose of the vshost.exe file?

The vshost.exe feature was introduced with Visual Studio 2005 (to answer your comment). The purpose of it is mostly to make debugging launch quicker – basically there’s already a process with the framework running, just ready to load your application as soon as you want it to. See this MSDN article and this blog post for more information.

What’s the difference between nexti and stepi in gdb?

stepi is more detailed than nexti. if you call sum() from main() function then doing stepi reaches you inside the sum() function, but nexti doesn’t. Below is the screenshot when you call stepi when you were at call of sum() instruction (i.e., => 0x08048403 <+40>: call 0x8048419 <sum>). The stepi instuction routes you inside the … Read more