Introduction to GDB
GDB is a powerful program debugging tool under UNIX released by the GNU open source organization.
GDB porting
method 1:
If ubuntu has installed a cross compiler (normally it must be installed), then it has integrated its own gdb, just copy gdbserver to the specified directory /bin/ of the development board file system
Test gdb related information
Method 2:
This is more troublesome, you need to obtain the source code of gdb and gdbserver from the official website, the path address: Download GDB (sourceware.org)
Unzip and compile steps:
tar -vxzf gdb-9.1.tar.gz //Generate gdb-9.1 after decompression cd gdb-9.1 mkdir build //You need to create a new build directory under gdb cd build ../configure --target=arm-linux-gnueabihf --prefix=/home/l17/tool/gdb make //compile make install //Install
Problems may arise:
gdb-9.1/missing: makeinfo: not found ... Makefile:490: recipe for target 'gdb.info' failed make[4]: *** [gdb.info] Error 127 ... Makefile:2006: recipe for target 'subdir_do' failed make[3]: *** [subdir_do] Error 1 ... Makefile:851: recipe for target 'all' failed make: *** [all] Error 2
Solution:
sudo apt install texinfo
Cross-compile gdbserver. After executing the following command, gdbserver will be generated. Copy gdbserver to the specified directory /bin/ of the development board file system (recommended method 1)
cd gdb-9.1/gdb/gdbserver //Go to the gdbserver directory ./configure --target=arm-linux-gnueabihf --host=arm-linux-gnueabihf make CC=arm-linux-gnueabihf-gcc //Cross compile gdbserver
add environment variable
After the configuration is complete, you need to enter ubuntu's /etc/profile to modify the environment variables
Method 1: Because the toolchain is installed, no modification is usually required export PATH=/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin:$PATH Method 2: Determine the current export PATH=/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin:/home/ l17/tool/gdb/bin:$PATH
debug test
Write a simple application
/**************************************Start of file************************************/ /*-------------------------------------------------------------------------------------- Includes */ #include <stdio.h> #include <unistd.h> int main(int argc, char *argv[]) { unsigned int timerCnt = 0; while(1) { printf("system runing times:%d\r\n", timerCnt); timerCnt++; sleep(1); } } /****************************************End of file************************************/
- ubuntu cross compile gdbApp.c output executable file
arm-linux-gnueabihf-gcc gdbApp.c -o gdbApp -g
- Copy the executable file to the development board (file system nfs)
cp gdbApp /home/l17/nfs/rootfs/
- Start the development board and execute the gdb service command (enter the debugging host, which is the ubuntu ip address)
gdbserver 192.168.0.67:2001 gdbApp //Start gdbserver on the development board
- ubuntu starts gdb to debug the specified code
arm-linux-gnueabihf-gdb gdbApp
- Enter the following command in the gdb window to connect to the debugging device (you need to know the ip address of the debugging device)
target remote 192.168.0.50:2001
Use gdb related commands to perform debugging work (specifically, Baidu)
- l command, wipe the source code
- b command, set debug breakpoints
- c command, execute the next breakpoint
- q command to quit debugging
Debugging based on VSCode interface
- New folder: .vscode, New file: launch.json
- Run -> Add configuration Select: c/c++:(gdb) to start, the configuration information will be automatically generated (if you need to know the meaning of the red font, point the mouse to it, there will be a prompt message, vscode yyds)
- Modify the generated configuration information as follows:
{ "configurations": [ { "name": "gdbApp", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/gdbApp", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gdb", "miDebuggerServerAddress": "192.168.0.50:2001" "setupCommands": [ { "description": "for gdb Enable neat printing", "text": "-enable-pretty-printing", "ignoreFailures": true }, { "description": "Set disassembly style to Intel", "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } ] } ] }
Run and debug
- Start the development board and execute the gdb service command (enter the debug host, which is the ubuntu ip address)
gdbserver 192.168.0.67:2001 gdbApp //Start gdbserver on the development board
- run -> start debugging
This can be used like keil iar ccs vs and other ide tools