Project build failed in release mode, runs fine in debug mode - gdb

I have a big project solution that I am trying to execute, it builds perfectly fine in both release as well as debug mode. The problem is when I try to execute it the debug one is fine but release mode creates segmentation fault and creates a core dump.
Now can anyone help me about how to find out the line number in the code that might have caused the segmentation fault. I tried using gdb but couldn't do much.

Now can anyone help me about how to find out the line number in the code that might have caused the segmentation fault.
Not with the information you've provided (which is insufficient).
You should read GDB documentation. Here is a good place to start.
You should load the executable and core into GDB, and use where command to fund out which function you are crashing in.
Since the crash only happens in "release mode", you'll need to figure out how to add -g flag to your release mode build. Once you've done that, GDB will tell you the file and line number where the crash happens.

Related

Debugging gdb: exit code 139 in VSCode

I am working on a large codebase and trying to debug the same using gdb(C/C++) extension on VSCode.
On running a particular configuration, I get an error with exit code 139. I know this is a segmentation fault, but am unable to exactly pinpoint where the seg fault is occurring. Is there any way I can monitor that?
Probably some file that I am missing where the details are being captured?
I can debug segfault using gdb from the terminal. But since the code requires certain configurations and is spread over hundreds of files, I am not sure how to do that.

GDB Exits/Crashes while Trying to Debug TensorFlow C++ Code

Whenever I try to debug TensorFlow's C++ code with Eclipse + GDB, I get GDB crashing, or actually exiting with: error code = -1.
As long as I don't set a breakpoint in TensorFlow's C++ code, the program runs just fine. But when I do, and when the debugger gets to the breakpoint, it crashes after a few seconds with error code -1. There is nothing meaningful in the GDB traces which can explain this behavior.
The GDB version I am using is 7.7.1, running with Eclipse Neon under Ubuntu 14.04.
TensorFlow is compiled in debug mode. I don't think that Eclipse is missing the debug symbols for it, as it is not complaining that those are missing (and also, occasionally, the debugger is able to step through a few steps in the code before it crashes).
An easy way to reproduce is to try and debug the label_image example:
https://www.tensorflow.org/versions/r0.11/tutorials/image_recognition/index.html
Compile it and then create a 'C/C++ Application' debug configuration in Eclipse, directing it to the compiled binary of the label_image app.
I've encountered the same problem with GDB on macOS. But, I finally succeeded to debug tf with lldb. And I also found that using VisualStudio Code + lldb makes it easy for debugging.
Here is my way of debugging. Maybe you can give it a try.

Netbeans v7 C++ debugger bug

I have a program that I have written in C++ under linux (Ubuntu 10.10).
The programming and debugging worked perfectly until the moment I added the following lines to the code:
mapfile = fopen(map_filename,"wb");
fwrite(map_header,1,20,mapfile); // <-- this is the problem line
fclose(mapfile);
After I added those, the program compiles ok, but the debugger now won't start. It immediately fails with this message:
Program completed, Exit code 0x177
error while loading shared libraries: unexpected PLT reloc type 0xcc
And if I remove the line with the "fwrite", the debugger will start normally.
This problem only happends inside Netbeans.
When I debug it using the command-line "gdb" it also works ok without any problems.
Anyone have idea why its happening and how to fix it?
P.S: Those problems started recently so I assume maybe it has to do something with system updates, I'm not sure.
Found the problem:
Not long ago, I removed some old C++ projects from netbeans. It figures out that netbeans (at least v7.0) remembers all the breakpoints that I put on old projects that don't even exist in the IDE anymore.
I found this by looking at the Debugger Console (Window->Debugging->Debugging Console) and seeing that when "gdb" starts, it tries to setup all these breakpoints from other projects or from projects that do not exists (this is a bug in netbeans, btw)
The solution: I simply cleaned all the breakpoints (inside Window->Debugging->Breakpoints) and now the program can be debugged properly.
Hope this will help to anyone out there who has the similar problem.

Visual Studio 2012 Release only error

There are a number of errors going on here but I'm sure they are all linked, so first off I'm getting Access violation reading location exceptions at locations (generally near 0x00000000)
but I only get these exceptions in release and not in debug, even if i setup debugging to do so. Also I found where the error happens but when I step over that it goes in to a complete unrelated function that is not called in the line or in any of the functions in that line of code. But when similar code is called it still goes to this unrelated function but doesn't fail. This all only happens in release versions. I know which piece of code is causing the error as if I comment it out its all fine. Also in the watch window in release all the numbers are wrong most of the time, which has never been a problem but it could help also a added some code to it to output the values of variables to a file and the variables are all fine, the pointers are sensible, but when the exception happens it always says their 0x00000020 but when I look at the log they are fine. This is in 32 bit , but on 64 bit windows 7 in c++. Please any help would be good!
Visual Studio's debugger will cause the program to use a debug heap that can hide uninitialized memory if you use the option "Start with Debugging" to start your program, in release or debug. You can try to run your program built in the Debug configuration without the debugger attached, and then use the Attach to Process... option in the debug menu to attach to your executable.
If this doesn't help, I recommend using windbg to debug your program. For help getting started with windbg, take a look at the answers on this question.
Once windbg is configured and symbol paths are set up, you can use the "!analyze -v" option once the program crashes to get a lot of information about the crash automatically.

Release build not working when run without debugging in VS2010

I encountered following problem:
I write program in c++ using VS2010. Debug build works properly when run with/without debugging in VS. When I launch built executable directly it also works.
Release build works when run with debugging in VS and alsp when I launch build executable directly.
Unfortunately, program does not work when I run release build in VS -without debugging-. Window is created and then program crashes quickly (without any error message). Since it crashes when run without debugging I don't know how to identify what causes the problem.
Any ideas what might be causing this? Thanks :)
It seems most likely you have some sort of memory error/corruption that just happens to work ok in the debugger.
You can try using couts to isolate how far/where it dies, or try a tool like Purify (or valgrind for free if you can port to Linux).