LLExec Linux Plugins Debug

From Axel Public Wiki
Jump to navigation Jump to search

Prerequisites

This page will show you how to debug LLExec plugins for the Linux platform. You need:

  • A developer Linux Machine, or a Virtual Machine, with the target toolchain already installed.
  • A target board running Linux and LLExec, with or without realtime extensions.


We suggest to use a free IDE called CodeLite, to debug the plugin.

Setup CodeLite

We assume you are using Linux Machine based on Ubuntu or debian. Please installa CodeLite from this website:
https://downloads.codelite.org/

Setup your environment

You have to export some environment variables in a login script,
ie ~/.profile, this is an example, correct with your toolchain settings:

export MY_SDK_PATH="/opt/sysroots"
export PATH="$MY_SDK_PATH/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi:$PATH"
export CCPREFIX="arm-poky-linux-gnueabi-"
export CCDEFINES="ALPLC_P_ARM9 -DALPLC_C_GCCARM9"
export CCFLAGS="-march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/dvdk/toolchain_xeno_1.0/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi -fno-delete-null-pointer-checks "
export GDB_FULL_PATH="$MY_SDK_PATH/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/$CCPREFIX"gdb
export SYSROOT_FULL_PATH="$MY_SDK_PATH/cortexa7hf-vfp-neon-poky-linux-gnueabi"



Open Codelite.
Click on the menu "Settings" --> "GDB Settings..."
A window will appear.
In the field "Debugger path" insert the full path of your toolchain debugger, ie:

/opt/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gdb

Click on the menu "Settings" --> "Build Settings"
Click on button "Add compiler" then give it the name "CrossCompile gcc" Define the following fields:

C++ Compiler         = $(CCPREFIX)g++
C Compiler           = $(CCPREFIX)gcc
Assembler Name       = $(CCPREFIX)as
Linker               = $(CCPREFIX)g++
Shared Object Linker = $(CCPREFIX)g++ -shared -fPIC
Archive              = ar rcus
Resurce Compiler     = windres
Make                 = make -j 3

Compile Plugin Example

Click on the menu "Project" --> "Create Workspace", right click on the project node,
and then click on "Add an Existing Project".
Add the project "LLPlugin_EXAMPLE.project" under LLExec's plugin headers.
Click on the menu "Build" --> "Configuration manager" and select "LINUX_debug for the project.
Copy the file LLXPlugin_EXAMPLE.so, you can find under the directory TestProgram,
copy it in your target board, where LLExec is installed.
Then edit the file LLExecLinux.conf to add the reference to the new plugin:

<plugins>
  <plugin filename="./LLModbusTCP.so"/>
  <plugin filename="./LLModbusRTU.so"/>
  <plugin filename="./LLXPlugin_Database.so"/>
  <plugin filename="./LLXPlugin_ModbusSlave.so"/>
  <plugin filename="./LLXPlugin_FileSystem.so"/>
  <plugin filename="./LLXPlugin_Recipes.so"/>
  <plugin filename="./LLXPlugin_Alarms.so"/>
  <plugin filename="./LLXPlugin_EXEMPLE.so"/>
</plugins>

Debug plugin

The first thing to do, to debug the plugin, is to copy all so files and LLExec executable from the target directory /data/plc to the plugin headers directory on the developing machine, under directory ~/LLExec/TestProgram.

On the target kill all the LLExec instances:

~# killall -9 LLExec

From the /data/plc/ directory launch gdbserver:

/data/plc# gdbserver :8888 ./LLExec
 Process ./LLExec created; pid = 3864
 Listening on port 8888

On codelite right click on the LLXPlugin_EXAMPLE project and select Settings.
Un the new window, on the pane on the right select Debugger.
Check the option Debugging a remote target and insert IP address of the target and the port 8888.
On a terminal on the developer machine please check if is defined the environment variable SYSROOT_FULL_PATH:

echo $SYSROOT_FULL_PATH

If this variable is defined, open again the debugger settings for the project, switch to the TAB Startup commands and insert the command

set sysroot /apath/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi

where the path is the content of your SYSROOT_FULL_PATH variable.


In the CodeLite IDE open the file LLXPlugin_EXAMPLE.cpp and set a breakpoint in the function

LLXPLG_INITIALIZEPLUGIN
{
   m_plcApi = *api; // <= press F9 to insert a breakpoint here
   return TRUE;
}

Now you can start debugging by pressing F5,
the program counter will stop on the breakpoint.

Stop debugger

In order to stop the debugger and restart a new debugging session you have to stop the debugger in the CodeLide IDE, by pressing shift F5
Please log in into the Target and give the command

killall -9 LLExec gdbserver