Debug Shared Libraries on Linux Real-Time Targets Using Eclipse/GDB

Updated Jan 31, 2018

Reported In

Software

  • LabVIEW Professional
  • LabVIEW Full

Operating System

  • NI Linux Real-Time

Programming Language

  • C
  • C++

Other

Software Tools : Eclipse IDE, GDB Debugger

Issue Details

I created a shared library using the C & C++ Development Tools for NI Linux Real-Time (LinuxRT), Eclipse Edition. How do I debug the shared library on LinuxRT targets using Eclipse/GDB?

Solution

There are two debugging methods you can use to debug your shared library. Both assume that you have built the shared library that is going to be deployed using the practices described in the document Getting Started with C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition. The document is packaged with your install of the C & C++ Development Tools for NI Linux Real-Time (LinuxRT), Eclipse Edition.

You may also import your existing code into C & C++ Development Tools for NI Linux Real-Time (LinuxRT), Eclipse Edition and build using the specified cross compiler path and specific prefix, arm-none-linux-gnueabi-, to allow compatibility with the Linux Real-Time operating system running on the target. 

To allow the GDB in Eclipse to work correctly, you must copy /usr and /usrlib from the target root file system to a directory on the local host, <RootFileSystemDir>. Before you begin, make sure that your project has a Debug configuration that is deployable. 

Before engaging in the following debugging methods, complete the following steps to transfer the shared library .so file to the target:
  1. Go to the file menu bar and click Window»Open Perspective»Other»Remote System Explorer.
  2. Click OK.
  3. Click Define a connection to remote system button to open the New Connection Wizard.

  4. Select SSH Only under the General folder.
  5. Click Next.
  6. Select a profile to contain the remote system connection from the Parent profile pull-down menu.
  7. Enter the hostname or IP Address of your Linux Real-Time target in the Host name text box.
  8. Click Finish.
  9. In the Remote System Explorer window, navigate to the workspace directory and find the .sofile in the Debug folder of the appropriate project.
  10. Copy the .so file over to the /usr/lib directory of the target by expanding Sftp Files under the target and navigate to /usr/lib

    Note: The shared library does not have to placed in this directory. If placed in another directory, the Call Library Node will then have to be supplied the entire path to the shared library.

Debugging Method Using GDB in Eclipse: 
Please note that you will need a .gbdinit file to run the debugging capabilities. This will set your breakpoints in the code. Complete the following steps to create the .gbdinit file:
  1. Navigate to your project path in the Windows explorer.
  2. Right-click the window.
  3. Select New»Text Document»File»Save As.
  4. Select All Files as the Save as type and name it .gdbinit.
  5. Select Save.
  6. In the file, enter on separate lines:
    set breakpoint pending on
    set sysroot <RootFileSystemDir>
Then, follow the instructions in the document, Getting Started with C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition, under Debugging a C/C++ Project. This will set you up to debug your shared library. The new project should be added under the C/C++ Remote Application in the Debug Configurations menu. Complete the following steps to further debug your shared library:
  1. Navigate to Run»Debug Configurations.
  2. In the Debug Configurations window, make sure your project is selected in the Main tab.
  3. In the same tab, go to the Connection option and select your target.
  4. In the same tab, change the Remote Absolute File Path for C/C++ Application to point to the shared library on the target.
  5. In the same tab, next to the Apply button, click Select other.
  6. From the Select Preferred Launcher window, select Standard Remote Create Process Launcher if not already selected.
  7. Click OK.
  8. Navigate to the Debugger tab.
  9. Select Gdbserver Settings.
  10. Take note of the port number that will be in the form xxxx. Normally, this will have a default value of 2345.
  11. Open your operating system command prompt.
  12. Execute the command gdbserver :xxxx ---attach 'pidof lvrt' where xxxx is your port number.
  13. Go back to the Debug Configurations window.
  14. In the Debugger tab, click the Main tab.
  15. Select Browse for the GDB Debugger option.
  16. Navigate to <National Instruments>\Eclipse\toolchain\gcc-4.4-arm\i386\bin\arm-none-linux-gnueabi-gdb.exe.
  17. Click Open.
  18. Select Browse for the GDB command file.
  19. Navigate to your current project's .gdbinit file.
  20. Click Open.
  21. Uncheck Stop on startup.
  22. Select Apply»Debug.
The Debug View should now open up, and, in the bottom portion of Eclipse, in the Console Tab, you should be able to debug your application. Once execution is suspended at a breakpoint in the shared library source code, you will have control of this GDB Console tab.

To stop debugging, you need to have control of the Console. You can stop the program by clicking the pause icon, labelled Suspend. Then, enter the command detach to disassociate the project.

Note: When the shared library is called from the VI running on the target and the execution arrives at a breakpoint, the lvrt process on the target will be suspended. This causes the host to lose connection to the target. Once the debugger is no longer on a breakpoint, the connection to the target will be repaired.

Debugging using the GDB Command Prompt and SSH Client: 
To use this method, you will need an SSH Client. Complete the following steps to debug using the GDB command prompt and SSH client:
  1. Open the command prompt on the local host.
  2. Navigate to the location of the GDB debugger by typing cd C:\Program Files\National Instruments\Eclipse\toolchain\gcc-4.4-arm\i386\bin\.
  3. Type arm-none-linux-gnueabi-gdb.exe to execute the debugger.
  4. Type the following commands:

    set breakpoint pending on
    file C:/<path to the shared object>/ExampleLibrary.so
    set sysroot <RootFileSystemDir>

  5. Enter in any breakpoints in the command prompt here.
  6. Find an open TCP port on the cRIO in the format of xxxx, where xxxx is an open port number on your target. The default value is usually 2345.
  7. Open the SSH client, and enter:
    gdbserver :xxxx --attach 'pidof lvrt'.
  8. Go back to the command prompt and enter:
    target remote <Target Name>:xxxx.
To exit the debugging process, ensure that the GDB is no longer in continue mode, and type detach.

WAS THIS ARTICLE HELPFUL?

Not Helpful