Using GDB to debug a core file on Linux
While investigating problems related to a sudden termination of the session, the Support Team could request to run the GDB debugger in the user's environment to examine what happened when the program terminated.
Prerequisite: the system is configured to generate core files.
Many Linux distributions (e.g. RHEL/CentOS) have it disabled by default. Ensure to turn on the creation of core files.
The following instructions should help in most cases, but we recommend to consult the official documentation of your Linux.
Edit the /etc/profile file and change the ulimit line as it follows:
ulimit -c unlimited >/dev/null 2>&1
Edit the /etc/sysctl.conf file and add the following lines to the end of the file:
kernel.core_uses_pid = 1
kernel.core_pattern = /tmp/core-%e--%u-%g-%p-%t
fs.suid_dumpable = 2
Reproduce the problem and proceed to analyze the core dump with GDB as explained below.
Where to find core files
Usually there are two places where core files can be generated:
- A file 'core' in your home directory
- A directory with the name of the crashing process in /var/crash
On Ubuntu, you need to use a tool called apport-unpack to extract the core file from the segmentation fault report.
Format of the command to use that tool is:
apport-unpack report target-directory
For example:
apport-unpack /var/crash/_usr_NX_bin_nxplayer.bin.1000.crash $HOME/nomachine_crash
In the folder $HOME/nomachine_crash you'll find the core file.
How to gather the stacktrace from the core file
1. Install GDB if is it's not already installed: http://www.gnu.org/software/gdb/
2. Verify if a core file has been generated on the remote machine where you are connecting.
If yes, identify which binary created it:
sudo gdb -c PATH_TO_CORE_FILE
The first line of output of command above provides information about the binary, for example:
sudo gdb -c /usr/NX/etc/core.1111
Core was generated by `/usr/NX/bin/nxserver.bin --daemon
In case of NoMachine, the core file can be generated by:
nxnode.bin
nxserver.bin
nxrunner.bin (or nxclient.bin for versions previous to v8)
nxplayer.bin
3. Run GDB as root or as sudo user by specifying the binary that generated it:
gdb -core=<path_to_core_file> -se=/usr/NX/bin/nxnode.bin
or:
gdb -core=<path_to_core_file> -se=/usr/NX/bin/nxserver.bin
or:
gdb -core=<path_to_core_file> -se=/usr/NX/bin/nxrunner.bin
(gdb -core=<path_to_core_file> -se=/usr/NX/bin/nxclient.bin for versions < v8)
or:
gdb -core=<path_to_core_file> -se=/usr/NX/bin/nxplayer.bin
4. in the GDB command line type:
set height 0
set logging file /tmp/NoMachineBacktrace.txt
set logging on
thr apply all bt
5. Send the /tmp/NoMachineBacktrace.txt file to the Support Team.
