programm hangs up and stops in screen how to figure out root cause

thomasfischer25

New Member
Credits
14
Hi,

i run one of my c programs in screen, to access in from different pcs via ssh.

It seems like my program has an issue and stops working once in a while. Maybe memory access issue or similar. Problem is, that I do not see the last output in console, since screen will end once the program which stops due to an error ends.

how can I still get the output of the program stored in some kind of logfile etc. to get the last messages which will give me some information about the error reason.

Thank you!
 


JasKinasis

Well-Known Member
Credits
5,050
Maybe try adding some logging capabilities to your program?
That might help you to track down and diagnose any problems.

You could perhaps also use conditional compilation to only build the logging capabilities into debug builds of your program, without affecting release builds.

Running your program through a debugger like gdb will also help to determine if there are any problems in your program itself.

If it's only crashing inside screen, then perhaps try downloading the debug symbols for screen.
Then you can do the following:
1. Run screen in one terminal
2. Open another terminal window and attach gdb to the running screen process.
3. Go back to the terminal containing your screen session and run your program.
4. When screen crashes take a look at the terminal running gdb - you should be able to perform a back-trace and examine the stack to see what caused screen to crash. In turn it might yield some clues about what is causing your program to crash.

Also running a couple of code analysers over your code might also pick up potential problems.
E.g. splint to check for general problems and valgrind/cachegrind to check for any memory leaks / memory management related problems.

Other things that might help in your code:
- Use debug assertions
If you have any points in your program where a particular condition should always be true, stick in an assertion.
That way, when running a debug build of your program, if any of your assertions fails, the program will exit with an error, telling you which assertion failed. When you know which assertion failed, you should have a rough idea where to set some breakpoints, before debugging.
- sanitise and range check ALL user input
- Beware of dangling/stray pointers
Always check pointers are valid before dereferencing them.
Unused pointers should be initialised to NULL when they are not in use.
- Avoid memory leaks by cleaning up/freeing any memory that is dynamically allocated using malloc etc.
 
Last edited:

Members online


Latest posts

Top