NI Linux Real-Time Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Debug a shared library called by a CLFN on NI RT Linux using VS Code

Solved!
Go to solution

Hello LabVIEW Community,

 

I am currently trying to debug a shared library using VS Code on NI RT Linux.

 

Situation is as follows:

I have cross-compiled the shared library according to NI’s tutorial (see: https://nilrt-docs.ni.com/cross_compile/build_shared_library.html) (local OS: Windows, remote: NI RT Linux).

 

I can debug the library when using the library through an executable (this is the way NI proposes in their tutorial: https://nilrt-docs.ni.com/cross_compile/call_shared_library.html). This works fine, I can step into the library and see what is going on (debug info is present at the library).

 

However, I want to call the library’s functions from within LabVIEW using CallLibrary Function Nodes (CLFNs) and not from an executable. Especially I want to see what is going on inside of the shared library when I am calling the functions from CLFNs. Challenge is that in this case I do not have an executable compiled by myself that I can configure for “program” in my launch.json (see last link), but instead must attach to the process which has loaded the shared library (as to my understanding this is the “lvrt” process). I think on the remote system I have to start the gdbserver in attach mode (“gdbserver -attach :9092 $(pidof lvrt)”) and then connect to it from within VS Code (how do I configure the launch.json?)

 

I would like to achieve something like this: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000YGvGCAW&l=de-DE where NI describes how to debug a CLFN call in a shared library using Eclipse. However, NI nowadays recommends to not use the Eclipse way for new projects, but instead use the modernized toolchain (using VS Code).

 

Question is: How can I do this with VS Code?

 

(for sake of discussion: let’s assume the library is the library from the tutorial (myLib.so) and in a CLFN the function add(x, y) is called)

Please let me now if you need additional information.

0 Kudos
Message 1 of 2
(779 Views)
Solution
Accepted by topic author _MariusG

Hello LabVIEW Community,

 

as it turned out I was able to find the solution by myself.

 

In case someone encounters this challenge as well, here is the solution:

 

On your remote system (running LabVIEW Realtime):

start the GDB server: “gdbserver :9092 --attach $(pidof lvrt)”

 

On your local system:

Copy the lvrt executable to your sysroots directory:

Location on the remote system: /usr/local/natinst/labview/lvrt

Location on (my) local system: C:/build/23.0/x64/sysroots/core2-64-nilrt-linux/usr/local/natinst/labview/lvrt

 

Configure your launch.json:

{

    "version": "0.2.0",

    "configurations": [

      {

        "name": "x64 (gdb) Attach",

        "type": "cppdbg",

        "request": "attach",

        "program": "C:/build/23.0/x64/sysroots/core2-64-nilrt-linux/usr/local/natinst/labview/lvrt",

        "useExtendedRemote": true,

        //"processId":,

        "showDisplayString": true,

        "MIMode": "gdb",

        "miDebuggerPath": "C:/build/23.0/x64/sysroots/x86_64-w64-mingw32/usr/bin/x86_64-nilrt-linux/x86_64-nilrt-linux-gdb.exe",

        "miDebuggerServerAddress": "X.X.X.X:9092"   (IPv4 of your remote system OR Name of your remote System)

      }

    ]

  }

 

Make sure that you set: “useExtendedRemote” to true!

I highly recommend to not configure the processId and let it default to “${command:pickProcess}”. VS Code will prompt you to select the process from the remote system when you start the debugging (select the “lvrt” process).

 

If you find that you have found a better solution or a way to optimize my solution, please let me know.

0 Kudos
Message 2 of 2
(709 Views)