Yocto Project gdb cross debug
Background
- When working with embedded systems like BMCs, limited memory often means that full debugging tools like GDB aren’t available on the target image. Fortunately, there are two practical approaches for debugging in a Yocto-based environment: using gdbserver for live debugging, or analyzing core dump files offline. This article walks you through how to set up both.
- 當程式有錯誤的時候可以使用兩種方式去除錯,使用gdbserver進行cross debugging 或是使用產生的coredump file進行除錯
Example
- Let's start with a very basic example. We have a service called hello-recipe, which encounters a segmentation fault due to dereferencing a null pointer.
- 假設有一個service叫做hello-recipe,其main.cpp有Dereferencing a null pointer 造成的 segmentation fault:
- we can checkout log using systemctl
- 檢查service
- Serivce Setting
- demo-hello/hello-recipe.bb
- build image
bitbake obmc-phosphor-image
- generate sdk
bitbake -c populate_sdk obmc-phosphor-image
- download sdk
/build/tmp/deploy/sdk$ ./oecore-obmc-phosphor-image-x86_64-armv7ahf-vfpv4d16-ums120-toolchain-nodistro.0.sh
- setup environment
. /usr/local/oecore-x86_64/environment-setup-armv7ahf-vfpv4d16-openbmc-linux-gnueabi
Cross Debugging
option 1: remote debug
- In remote embedded chips e.g. bmc
- open gdbserver
- gdbserver :1234 /usr/bin/hello
- enter gdb
build/tmp/deploy/sdk$ arm-openbmc-linux-gnueabi-gdb
- setup sysroot and code entry
- connect to remote
target remote $REMOTE_IP:1234
- debug step by step 單步執行除錯
option 2 using coredump coredump
- at earlier systemctl log, we can know that process 490 has problem. 從systemctl可知是 process 490有錯
- find coredump file in remote 在遠端裝置查看core file 位置
- download binary and core file to host. 下載binary及core file到host除錯
- decompress core file 解壓縮core file
- using gdb to debug 用gdb進行除錯
- setup sysroot and code entry 設定 sysroot 及 code位置