How to determine where my application crashed on Linux

HI, I was recently in a project in linux written in C. This application has several processes and they share a shared memory block ... When the application starts for about several hours, the process crashed without any traces, so it’s very difficult to find out what is the problem or where can I start viewing codes ... well, maybe the memory is full or the pointer is running ... but I don’t know ... Do you have tools or any methods for detecting problems ... He would be greatly appreciated if it is allowed. thanx for your advice ...

+4
source share
4 answers

Before starting the program, enable core dumps:

ulimit -c unlimited 

(and make sure that the working directory of the process can be written in the process)

After the process crashes, it should leave the core file, which can then be viewed with gdb :

 gdb /some/bin/executable core 

Alternatively, you can start the process under gdb when it starts - gdb will wake up when the process crashes.

+4
source

You can also run gdb on gdb-many-windows if you are using emacs. which give you the best debugging options to explore things like stack, etc. This is very similar to the Visual Studio IDE.

Here is a useful link

 http://emacs-fu.blogspot.com/2009/02/fancy-debugging-with-gdb.html 
+3
source

Valgrind is where you need to go next. Most likely, you have a memory misuse problem, which is benign - while it is not. Run the programs under valgrind and see what it says.

+1
source

I agree with bmargulies - Valgrind is absolutely the best tool for automatically detecting improper memory usage. Almost all Linux distributions should have it, so just emerge valgrind or apt-get install valgrind or whatever your distribution uses.

However, Valgrind is hardly the least cryptic thing, and it usually helps you determine when the program ultimately turned to memory incorrectly - if you saved the wrong array index in a variable and then accessed it later, then you still have to figure it out. However, especially when combined with a powerful debugger such as GDB (the backtrace or bt command is your friend), Valgrind is an incredibly useful tool.

Remember to compile the -g flag (if you are using GCC, at least), or Valgrind and GDB will not be able to tell you where a memory error occurred in the source.

0
source

Source: https://habr.com/ru/post/1299613/


All Articles