[c++] Counter exit code 139 when running, but gdb make it through

My question sounds specific, but I doubt it still can be of a C++ debug issue.

I am using omnet++ which is to simulate wireless network. omnet++ itself is a c++ program.

I encountered a queer phenomena when I run my program (modified inet framework with omnet++ 4.2.2 in Ubuntu 12.04): the program exit with exit code 139 (people say this means memory fragmentation) when touching a certain part of the codes, when I try to debug, gdb doesn't report anything wrong with the 'problematic' codes where the simulation exits previously, actually, the debug goes through this part of codes and output expected results.

gdb version info: GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04

Could anybody tell me why the run fails but debug doesn't?

Many thanks!

This question is related to c++ gdb segmentation-fault undefined-behavior

The answer is


exit code 139 (people say this means memory fragmentation)

No, it means that your program died with signal 11 (SIGSEGV on Linux and most other UNIXes), also known as segmentation fault.

Could anybody tell me why the run fails but debug doesn't?

Your program exhibits undefined behavior, and can do anything (that includes appearing to work correctly sometimes).

Your first step should be running this program under Valgrind, and fixing all errors it reports.

If after doing the above, the program still crashes, then you should let it dump core (ulimit -c unlimited; ./a.out) and then analyze that core dump with GDB: gdb ./a.out core; then use where command.


this error is also caused by null pointer reference. if you are using a pointer who is not initialized then it causes this error.

to check either a pointer is initialized or not you can try something like

Class *pointer = new Class();
if(pointer!=nullptr){
    pointer->myFunction();
}

Examples related to c++

Method Call Chaining; returning a pointer vs a reference? How can I tell if an algorithm is efficient? Difference between opening a file in binary vs text How can compare-and-swap be used for a wait-free mutual exclusion for any shared data structure? Install Qt on Ubuntu #include errors detected in vscode Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio 2017 errors on standard headers How do I check if a Key is pressed on C++

Examples related to gdb

How to install gdb (debugger) in Mac OSX El Capitan? Step out of current function with GDB How do I get the backtrace for all the threads in GDB? Counter exit code 139 when running, but gdb make it through gdb: how to print the current line or find the current line number? How do I pass a command line argument while starting up GDB in Linux? GDB: break if variable equal value How to attach a process in gdb gdb fails with "Unable to find Mach task port for process-id" error gdb: "No symbol table is loaded"

Examples related to segmentation-fault

Command failed due to signal: Segmentation fault: 11 Android Fatal signal 11 (SIGSEGV) at 0x636f7d89 (code=1). How can it be tracked down? Counter exit code 139 when running, but gdb make it through segmentation fault : 11 Segmentation Fault - C What causes a Python segmentation fault? How to return a class object by reference in C++? Login with facebook android sdk app crash API 4 Returning pointer from a function Fixing Segmentation faults in C++

Examples related to undefined-behavior

Counter exit code 139 when running, but gdb make it through Undefined behavior and sequence points What is the strict aliasing rule?