Backtrace due to Sigsegv 11 signal - c++

I am running a multi-threaded C++ program in a Linux system which has android on it. I am getting a crash due to SIGSEGV 11 (segmentation fault). A backtrace generated shows .so file followed by heap with some address.
How to check where exactly the segmentation fault has occurred? How to debug the address which gets printed in the backtrace?

Use adb logcat to get the logs. The extra info (callstack, registry) there should help you identify the issue.
To translate addresses in source line use addr2line available in NDK

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.

Debug huge C++ project on linux

I developed a project on Mac using C++. It works perfectly. However when I try to launch it from a Linux server, I get a bad alloc error:
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted
I don't know how to debug the whole project because I have absolutely no idea of where the issue come from. Why is it working on my Mac and not on Linux? All articles and questions about that only ask for single file program but not 40+ files project.
Is there a way to get the file or line that causes the bad alloc?
Build your program with the -g compiler option to get meaningful stack traces.
Then run the program in a debugger, e.g. gdb:
gdb --args [executable] [arguments...]
When gdb has loaded, enter the command run and you program will be run. As soon as the exception is thrown and not caught by your program, gdb will show you a stack trace showing you from where the exception was thrown.
std::bad_alloc means that your program wasn't able to allocate any more memory, probably because the OS either ran out of memory or you hit an explicit memory limit imposed by the system.

Get stacktrace for crash, without running the app in a debugger

I normally use GDB (in Linux, with the Qt Creator debugger GUI) to debug. But right now I have a crash that refuses to ever happen when running under the debugger, yet happens easily when running outside of it.
How do I get a stack trace of my crash, in these circumstances?
A linux-specific solution is OK.
Note: I'm talking about running a debug build only, even when it's run outside the debugger.
The easiest way to be sure you can obtain a stacktrace after a crash is to run
ulimit -c unlimited
In your shell before starting the program.
This will ensure that the kernel is allowed to produce a "core dump" of unlimited size (for many distros the default size is 0) when a program crashes.
That core file can then be loaded into gdb as gdb programfile corefile and then the command thread apply all bt will give you stack traces for all threads for that specific crash (use just bt if you only care about the crashing thread).
You can also use the pstack program to get a stacktrace from a running program.

Debugging segmentation faults (core dumped) for big projects

I tried to run this code [the-git-link] (https://github.com/DropIn/SequentialTextReading), but I experience a "Segmentation fault (core dumped)". Do you have any idea about this error? I am running it on Ubuntu 14.4 and
the code is too big to use traditional debug methods on it like using gdb.
Any idea how to solve this problem or what tools should i use to solve it knowing that there are many files and main in the project?
You can also load your coredump to gdb and find the root cause, after your program crashed.
You may benefit from reading How to generate core dump file in Ubuntu, and How to analyze a program's core dump file with gdb?

How to debug runtime crash (not segmentation fault) in Linux

I develop complex server program for Linux. It uses thousands of parallel SSL connections and implements custom protocol that serves client applications.
The problem is that this program sometimes crashes. It shows Terminated message in terminal and stops to work. I enabled automatic core dump to get crash report and analyze it with GDB. However, for any reason Linux (CentOS) doesn't create core dump. It looks like it creates core dump for segmentation fault only (I run ulimit -c unlimited, and when I provoke segmentation fault, dump is created).
Why Linux doesn't create core dump when software stops to work and shows Terminated message, and how to debug such issues if they exist in production enviroment only and never appear in test computer?