In the embedded development, sometimes need to do the source level debugging, can set breakpoints, step execution, compared to each step printing printf or printk, more friendly. This debugging method is described below.
GDB cross-debugging is similar to a Web browser, the local PC for the client, the remote Development Board for the server side, both sides to compile the tool chain uniformly, the version is best consistent.
--TARGET Specifies the target cross compiler prefix, such as--target=arm-linux, with the default value of I386-linux
--HOST specifies where the compiled program needs to run, for example,--host=arm-linux
--PREFIX Specifies the directory to install
Therefore, when compiling the arm-linux-gdb, you do not need to specify host, because it is running on the local PC, when compiling gdbserver, you need to specify the host as Arm-linux, because, Gdbserver is running on the arm platform. Both need to specify the same target.
Compiling arm-linux-gdb
Create a new arm-gdb in the gdb-7.8 directory to store the compiled build file.
./configure--target=arm-linux--prefix=/-gdb/
Then make && makes install, you can find arm-linux-gdb under the arn-gdb/bin/directory,
If necessary, you can add this execution path to the system environment variable.
Compiling gdbserver
In the gdb-7.8 directory, switch to the Gdb/gdbserver directory,
./configure--target=arm-linux--host=arm-linux
Then make CC=/OPT/GCC-3.4.5-GLIBC-2.3.6/BIN/ARM-LINUX-GCC, you can then generate Gdbserver in the current directory.
It is important to note that running Gdbserver also requires the libthread_db library, and if you do not have this library in your own file system, you need to copy the libthread_db* from the local cross-compilation tool into the board.
sudo cp/opt/gcc-3.4.5-glibc-2.3.6/arm-linux/lib/libthread_db*/home/hao/nfs/lib/–d
Use the-D option to copy the past along with the link relationship when copying.
How to use
Copy the generated gdbserver to the Development Board, communicate between PC and Development Board via NFS file system, Development Board ip:192.168.0.200, local host ip:192.168.0.104
On the local machine, compile an application with Arm-linux-gcc–g, and on the Development Board, execute
Gpbserver How to use: Gpbserver Development Board IP address: Communication port (optional) program "command line arguments" to debug
Then on the local machine, start the ARM-LINUX-GDB, the operation is as follows:
Once the connection is successful, the board will display:
The GDB command can then be executed on the local PC, and the debug output
Note: After the target remote is executed, the program above the board is already running, and the Run command cannot be used locally and can be used with the Continue command.
The debug command is input locally and the debug output is output on the Development Board.
Introduction, the Gdbserver on the Development Board will start a sub-process, and then use the test program to replace the child process, itself as a parent process, receive from the PC arm-ling-gdb debug command input,
Let the program in the crash when the core dump file, using the Arm-linux-gdb on the PC to analyze the file, to determine the location of crashes.
1. Generate a core dump file
The Linux system defaults to not producing a core dump file (Ulimit–c yields a result of 0, the program does not produce), setting the Ulimit–c Unlimited, without limiting the core dump output size.
2. Execute the program under test, generate the core dump file, the default name is core
3. Debug the core file using Arm-linux-gdb
On the local PC machine, execute the arm-linux-gdb./test_debug./core file to find the address that generated the segment error.
Such debugging, looks very complex, if you really want to debug, and CPU processing speed is fast enough, direct porting of the lower version of GDB to the Board on the line.
GDB Cross-Debugging RELATED links:
tiny4412 android GDB debugging problem, cannot break point (resolved)
Problems with remote debugging using Gdbserver
Gdb+gdbserver Cross-compiling
Technorati Tags: gdbserver,linux
Setting up cross-debugging environment Arm-linux-gdb cooperating Gdbserver