Target Debugging with Yocto - cu-ecen-aeld/yocto-assignments-base GitHub Wiki

Motivation:

While I was implementing the socket application, I ran in to segfault issue. As per the wiki page, there was no gdb support added to the yocto build. For projects involving socket communication, linked lists and other data structures, there are good chances students will run into a segmentation fault.

Implementation:

The changes can be made in build.sh which can be found here and tested with raspberry pi 3b+

Gdb

The following lines are added in local.conf file

  1. To add gdb in the image, IMAGE_INSTALL:append = gdb
  2. To add debug tools support in the yocto build, IMAGE_FEATURES += tools-debug
  3. Now run build.sh to add the gdb support

RemoteGdb

  1. To add gdb server in the image, add IMAGE_INSTALL:append = gdb gdbserver
  2. To add debug & profiling, tools support and in the yocto build. We also need to add all the source and debug packages for remote debugging to work. IMAGE_FEATURES += tools-debug src-pkgs dbg-pkgs in the image

Valgrind

  1. To add valgrind support in the image,IMAGE_INSTALL:append = valgrind
  2. To add the debug and profiling tools, IMAGE_FEATURES += tools-debug tools-profile eclipse-debug

Verification:

Gdb

  1. After booting, we will run an executable that has a segfault issue and the other code without a segfault issue. Do to the executable directory and type gdb . You can give r for run command and bt for backtrace. The below image is a segfault program where the IP address is not provided with a client which resulted in a segfault. gdbsupportsegfault

  2. In the second image, the code does not have a segfault issue. codewithnosegfault

RemoteGdb

  1. The remote gdb support is verified using two raspberry pi. One acting as the target and the other one acting as a host. In the target Rpi with Ip address 10.0.0.35, the executable is run through gdbserver with the following command. gdbserver :PORTNUMBER "executable path" In the image, the command given is gdbserver :1234 /usr/bin/client where 1234 is the port number

remotegdbclienttarget

  1. From host Rpi we will debug an application in the target raspberry pi. We need to enter gdb mode in host Rpi. As you can see in the below image, the host Rpi (10.0.0.38) is connected to target Rpi(10.0.0.38) by the command target remote <hostRpi IP address:PORTNUMBER>. In this example the command given is target remote 10.0.0.35:1234

  2. The required object files are read from the target Rpi. We have to give run and continue commands to debug the target application remotegdbclienthost

Valgrind

  1. After bootup of Rpi, the valgrind functionality can be checked by giving the following command valgrind --leak-check=full -v "executable path". In the following image, I have tested the client application through Valgrind. valgrind1

  2. The memory leak information is provided at the end valgrind2

References:

  1. https://mikeframpo.net/notes/2021/06/20/yocto-debugging-gdb.html
  2. https://www.oreilly.com/library/view/mastering-embedded-linux/9781787283282/25b6d1c4-80e9-46da-b0be-8bd333631c7d.xhtml