This site uses cookies for functional purposes. To continue please read and agree to our Data Privacy.

By closing this message, you consent to our use of cookies on this device.

PLCnext on Instagram  PLCnext on YouTube Github PLCnext CommunityStore PLCnext Community

C++ remote debugging with GDB server

Because the PLCnext Technology does have a GDB server (GNU debug server) directly implemented it is possible to create in an easy and performant way a C++ remote session.

This short manual introduced all necessary steps to establish a remote debug session and connect directly to a running process by using the Eclipse® Neon or Eclipse® Photon IDE.

Software used here:

Note:

  • These instructions are based on the firmware 2019.x of the AXC F 2152. For a PLCnext Control running on firmware 1.x, read this article instead.
  • The task watchdogs must be deactivated (0 ms) during the debug session.
  • The shared library must be created in "Debug"-Build mode.
  • The shared library (.so file) on the Host System (eclipse workspace) and on PLCnext Target must be the same.
  • The overall performance between steps can take a few seconds.
  • For some steps you'll need root or admin user privileges (for admin user, please use the precommand "sudo").

Debug Configuration

  1. Open your program in Eclipse.
  2. Configure the Debugging by "Run" -> "Debug Configurations...":
    Debug Configuration
  3. Create a C/C++ remote application by double-clicking the list item:
    Debug remote application
  4. On the "Main" tab,
    1. Insert the path to the C/C++ application executable, e.g.:
      FW_SVN_XXXX\SDK\sysroots\cortexa9t2hf-neon-pxc-linux-gnueabi\usr\bin\Arp.System.Application
    2. Set the "Build Configuration" drop-down menu to "Debug" (in Eclipse Neon):

    3. Debug Settings
    4. ...or to "Use Active" (in Eclipse Photon):
      EclipsePhoton MainConfig
    5. Click the "Select other" button (same in both Eclipse Neon and Photon).
  5. In the "Select Preferred Launcher" dialog box, choose "GDB (DSF) Manual Remote Debugging Launcher" and close with the "OK" button:
    Manual remote debug launcher
  6. Back in the "Debug Configuration" dialog, switch to the "Debugger" tab.
  7. As the "GDB debugger", choose the "gdb" executable from the PLCnext toolchain, e.g.:
    FW_SVN_XXXX\SDK\sysroots\x86_64-pokysdk-mingw32\usr\bin\arm-pxc-linux-gnueabi\arm-pxc-linux-gnueabi-gdb.exe
  8. Create a "gdbinit.txt" file containing the following handles and add it as the "GDB command file":
    
                handle SIGUSR2 nostop noprint 
                handle SIGILL nostop noprint 
                handle SIGSTOP nostop noprint
            

    Attach to process
  9. On the "Shared Libraries" tab, insert the directory of the shared library to debug.
    Usually, the library of a Eclipse project is saved in the "Debug" or "Debug\lib" subdirectory to a program.
    Shared libraries
  10. On the "Connection" tab, insert a host name or IP address of the remote target; insert the port on which the gdbserver instance is listening:
    Debugger connection

Attach to remote gdbserver

Note:

  • Executing the gdbserver --attach command, the whole PLCnext task will go into Stop mode, so the outports will stand still and the remote connection to PLCnext Engineer will be interrupted.
  • The PLCnext task will stay "stopped" (i.e. detached or disconnected in Eclipse) after debugging and has to be restarted manually:
    /etc/init.d/plcnext restart or restart the controller by pressing the "Reset" button on its housing, or switch the current off and on again.
  • A breakpoint in GDB will stop the cyclic task only, so all other programs will keep running.
  • A breakpoint in PLCnext Engineer prohibits the call of C++ programs, so all tasks controlled by the ESM will stop.
  1. Log into a shell on the remote system.
  2. Determine the process ID of PLCnext Technology process:
    ps | grep Arp.System
  3. Start the gdbserver and attach it to the desired port:
    sudo gdbserver :2345 --attach <your process ID here>
    resulting in this answer if successfully attached:
    Grep Arp System answer

Set the breakpoints and start a debug session

  1. Select the newly created debug configuration by means of the "Debug" menu icon:
    Start Debug
    Note: It might happen that warnings or errors are displayed after starting the debug session. Prevent that by checking "Always launch without asking" or "Remember my decision" in the respective dialog boxes:
    Warnings in Eclipse Neon:
    Failure Debug 1
    Failure Debug 2
    Warning in Eclipse Photon:
    Eclipse Photon Confirm Switch
  2. After the warnings have been acknowledged, the Eclipse debug view appears where you can add breakpoints and step through the code:
    Debug window

For actions in this environment, please refer to the Eclipse Neon Online Help or the Eclipse Photon Online Help.

Comments  

# idzm 2019-05-20 08:46
It also works for Eclipse IDE 2019‑03.