Debugging GDB for JiCity Encapsulation Code

Debugging GDB for JiCity Encapsulation Code

Debugging GDB for JiCity Encapsulation Code

A few days ago, I participated in the algorithm competition on the JiCity platform, which focused on image recognition, behavior recognition, image segmentation, and other areas. The documentation and various tutorials are quite comprehensive, and there are sample codes and video explanations to help you get started. Additionally, there are mentors available in the WeChat group to assist, so I won’t go into detail about the basic content. You can refer to:

https://www.cvmart.net/community/detail/6724https://cvmart.net/community/detail/6753https://cvmart.net/community/detail/6457

After completing the model training and during the algorithm encapsulation, I encountered some issues. Since the encapsulation framework is primarily based on C++, I installed GDB for debugging to pinpoint the problems. Here I share the debugging process of the JiCity encapsulation code using GDB.

GDB Installation】

I downloaded the latest version:

https://ftp.gnu.org/gnu/gdb/gdb-12.1.tar.gztar -xzvf gdb-12.1.tar.gzmkdir buildcd build../configure

Before running make, you need to install texinfo. Since the JiCity platform’s source is Aliyun, you need to change it to Tsinghua’s source to use apt, as it seems that only Tsinghua’s source has this package.

cp /etc/apt/sources.list /etc/apt/sources.list.bakvim /etc/apt/sources.list
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricteddeb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricteddeb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universedeb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universedeb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiversedeb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiversedeb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiversedeb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricteddeb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universedeb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse
apt-get updateapt-get upgradeapt-get install texinfo

You also need to apt install libgmp-dev to resolve the configure: error: GMP is missing or unusable issue. Then you can continue installing gdb.

make -j8make install

The documentation defaults to directly build:

mkdir -p /usr/local/ev_sdk/buildcd /usr/local/ev_sdk/buildcmake ..make installmkdir -p /usr/local/ev_sdk/test/buildcd /usr/local/ev_sdk/test/buildcmake ..make install

By default, no additional debugging information is included, which may result in errors like No symbol table is loaded. Here you need to modify two files: the CMakeLists.txt files in the ev_sdk and test directories.

The CMakeLists.txt in the test directory only pertains to the related code of test-ji-api, including test.cpp, Algo.cpp, etc. Since this is just test code, you only need to add set(CMAKE_BUILD_TYPE DEBUG) in the CMakeLists.txt.

In the CMakeLists.txt under ev_sdk, in addition to adding set(CMAKE_BUILD_TYPE DEBUG), you also need to comment out SET(CMAKE_BUILD_TYPE “Release”) to debug the src under SampleAlgorithm.cpp, SampleDetector.cpp, etc.

【Using GDB for Debugging】

After completing the above steps, you can start debugging with gdb. The images presented at the beginning of this article are displayed. You can perform single-line debugging using commands. Typically, you might attach a process for debugging, but since there is developed test code here, it is more convenient to start debugging directly from it.

gdb ../bin/test-ji-api

Then you can set breakpoints at positions you notice while reading the code, for example:

br Algo.cpp:205br SampleAlgorithm.cpp:93

Next, you can start debugging:

run -f 1 -i../data/111.jpg  -o result.jpg

Here, run can also be replaced with start, which is equivalent to automatically adding a breakpoint at the entry point. Common commands during debugging include:

n(next): step over s(:one step in): step into finish(:to the return): execute to return p var_(:print variable): print parameter until line(:go to line): execute to a specified line backtrace: view the call stack info args: view current function parameters info locals: view local variables

For other gdb commands, you can refer to:

https://gitee.com/saaavsaaa/saaavsaaa.github.io/blob/master/aaa/gdb.md

Debugging GDB for JiCity Encapsulation Code

Leave a Comment