Post Go back to editing

Step into the “libiio” functions to observe the detailed workflow and understand the software-hardware interaction

Category: Hardware

I deployed my cross-compiled file onto the Pluto SDR to run it as a standalone application. The Pluto SDR and libiio are both quite intriguing, and I'm eager to gain a deeper understanding of their operation and explore them further, and step into the libiio functions to see the actual working flow. 

I understand that libiio is organized as a shared library. In my project, I include the iio.h header file to utilize libiio. The header file provides the necessary api, and everything work well.

However, after cross-compiling my code and deploying it onto the Pluto SDR, I encountered an issue while trying to use gdbserver/gdb to trace the detailed execution flow. For example, I set a breakpoint in the iio_buffer_push() function, but when I attempt to step into this function to inspect its internal workings, I'm unable to do so, only get the information:
Single stepping until exit from function iio_buffer_push, which has no line number information.

To address this, I tried building libiio with debug information by running cmake .. -DCMAKE_BUILD_TYPE=Debug and cross-compiled my code with debug information with the lowest optimization level (-O0), using the following flags: -std=gnu99 -O0 -g -fno-inline -o mycode mycode.c -lpthread -liio -lm -Wall -Wextra -lrt. Despite these efforts, I still cannot step into the iio_buffer_push() function.

Could you please give me any suggestions? Thanks !!!



update more information
[edited by: pointer at 9:23 AM (GMT -4) on 21 Aug 2024]
  • Few questions:

    1. With respect to debugging such a library function you need to make sure that its actually using the library built with the debug symbols

    2. What are you trying to understand inside libiio itself? You really shouldn't need to dig into the library.

    3. Can you debug from the remote contexts and not on the device?

    -Travis

  • Hi Travis. Thank you for your timely reply and helpful suggestions.

    1. Debug Symbols: I cross-compiled my code with debug information at the lowest optimization level. However, I noticed that the /usr/bin directory on the Pluto SDR contains the libiio.so shared library, which I believe was generated when the firmware was flashed. This on-board shared library likely does not include debug information and may not be compiled with the lowest optimization level. As a result, when I attempted to use GDB/GDBserver to debug the deployed file on the board, I was unable to step into the functions within this library. If I understand correctly, I may need to modify the firmware to enable debugging. I also tried to cross-compile libiio.so with debug information and replace the on-board version, but I was unable to get it to work.

    2. What I want to explore: I want to step into the internal functions and see the actual software-hardware working flows. I am attempting to step into the iio_buffer_push() function to understand the entire process of pushing samples to the hardware, including how the software interacts with the hardware. If possible, I would like to further explore this library in more detail.

    3. Debugging: While my currently deployed code works well, I am curious if it’s possible to step into the internal functions of libiio, such as iio_buffer_push(), in the context of remote debugging. I would follow your nice suggestion and try to see how it works.

    Thank you for your nice suggestions. If possible, could you please give me any additional suggestions?

    -- Bruce

  • Libiio implements a C API for the linux IIO framework.

    Debugging the library should work as long as you compile with debug symbols and make gdb aware of the location of the source files.

    Use ldd to check what library your application links to. You can also use LD_LIBRARY_PATH or LD_PRELOAD env vars to force the loading of your debug library.

    -Adrian

  • Hi Adrian. Thank you so much for your prompt reply and the very helpful suggestions. I will follow your advice and try to make it work.

    I'll check which libraries my application is currently linked to and cross-compile the required libraries on my local computer, ensuring they include debug information and are compiled with the lowest optimization level, then deploy the generated libraries onto the Pluto device and use environment variables to ensure that the debug versions are loaded. 

    Thanks!

    -Bruce