How to setup a debugging environment for NX 3.x and use Valgrind to detect possible memory problems
Customers with valid subscriptions can receive un-stripped versions of NX binaries and libraries as well as patched versions of the components. In this case, a debugging environment should be set up.
Customers should open a support enquiry via the support center with details of the issue so that the team can evaluate what the next steps should be.
A typical case is to setup an environment which allows to run nxagent with Valgrind, a tool to detect possible memory-management problems, aimed at C and C++ programs.
Steps below are referring to set-up a debugging environment for user nxdebug. All the commands with the '#' prefix are intended to be run from xterm or similar by using the sudo utility or by the root user.
Retrieve binaries and libraries for debug purposes
In general, NoMachine provides the un-stripped binaries and libraries and the patched versions by means of compressed tar archives. Extract the provided archive to a temporary directory, for example:
# tar zxvf nxdebugArchive.tar.gz
This will create the directory nxdebugArchive containing the NX binaries and libraries needed to setup the debugging environment.
Create a system account for user nxdebug
Use the NX Server facilities to add user nxdebug to the system:
# nxserver --useradd nxdebug --system
This will create the user nxdebug on the system and also its home directory ("e.g. /home/nxdebug") and it will prompt asking for the password for this user. Enter the password and use it when logging with user "nxdebug" with the NX Client.
Create a copy of the NX Node configuration file to personalize it
Copy the node.cfg file to customize the access parameters of the user nxdebug:
# cp /usr/NX/etc/node.cfg /usr/NX/etc/nxdebug.node.cfg
More information about how to specify alternative NX binaries and libraries is available at: AR02H00553
Create the debug directories
Create the directories for debug purposes and copy there the NX binaries and libraries from the original installation of NX.
A personal NX Node configuration file will ensure that these will be used only by the nxdebug user:
# cp -a /usr/NX/bin /usr/NX/nxdebug.bin
# cp -a /usr/NX/lib /usr/NX/nxdebug.lib
Put in place the NX binaries and libraries for debug
Copy the NX binaries and libraries provided for debug purposes with the nxdebugArchive.tar.gz to the debug directories.
Create the script to run nxagent
Create the nxagent-valgrind.sh script in the /usr/NX/nxdebug.bin directory. This script lets the agent start with Valgrind seeking for memory problems.
To detect memory corruption, the nxagent-valgrind.sh script can be:
#!/bin/bash
exec valgrind -v --tool=memcheck --error-limit=no
--log-file=valgrind-log.%p /usr/NX/nxdebug.bin/nxagent "$@"
To detect memory leaks, the nxagent-valgrind.sh script can be:
#!/bin/bash
exec valgrind -v --tool=memcheck --error-limit=no --leak-check=full
--leak-resolution=high --num-callers=40 --show-reachable=yes
--error-limit=no --log-file=valgrind-log.%p
/usr/NX/nxdebug.bin/nxagent "$@"
Ensure that the nxagent-valgrind.sh script is executable
In case, modify the permission of the file "nxagent-valgrid.sh" to let it be executable:
# chmod 0755 /usr/NX/nxdebug.bin/nxagent-valgrind.sh
Customize the NX Node configuration file for user nxdebug
Add the following lines in the file "/usr/NX/etc/nxdebug.node.cfg". These keys will ensure that user nxdebug uses the NX binaries and libraries for debug and the the nxagent is started with Valgrind:
PathBin = "/usr/NX/nxdebug.bin"
PathLib = "/usr/NX/nxdebug.lib"
CommandNXAgent = "/usr/NX/nxdebug.bin/nxagent-valgrind.sh"
Run the NX session as user debug
Start a session by NX Client using "nxdebug" as username.
It will use the settings stored in the file "/usr/NX/etc/nxdebug.node.cfg" and thus will scan for memory problems using valgrind.
Retrieve the Valgrind log
The logfile created in the /usr/NX/nxdebug.bin directory will be valgrind-log.PID where PID is the PID of the nxagent process.
