Implementation of remote debugging of GDB in embedded Linux
Author:vicky
The remote debugging environment consists of host GDB and the target debug stub, both through a serial port or a TCP connection. Use the GDB standard Remote serial protocol to work together to realize the monitoring and debugging function of the system kernel and upper layer application on the target machine. The debug stub is a piece of code in an embedded system that exists as a medium between the host GDB and the target debugger.
For now, embedded Linux system, there are three kinds of remote debugging methods, respectively, suitable for different occasions debugging work: With ROM Monitor debugging target machine program, with KGDB Debug system kernel and debug user space program with Gdbserver. The difference of these three debugging methods mainly lies in the difference of the existence form of the remote debugging stub of the target machine, and the design idea and the realization method are basically the same. And our most common use is to debug the application. is to use the Gdb+gdbserver way to debug. In many cases, users need to repeatedly debug an application, especially complex programs. Using the GdB method debugging, because of the limited resources of embedded system, it can not be debugged directly on the target system, which is usually debugged by Gdb+gdbserver. Gdbserver is running on the target system and GDB is running on the host.
To perform GDB debugging, the target system must include the Gdbserver program, and the host must also install the GDB program. General Linux distributions have a running GDB, but developers can not directly use the release of GDB to do remote debugging, but to obtain GDB source code package for the arm platform for a simple configuration, recompile to the corresponding gdb. The GDB source code package can be from
http://ftp.cs.pu.edu.tw/Linux/sourceware/gdb/releases/downloads, the latest version is gdb-6.4. Download to a directory, the author downloads to their own user directory:/home/vicky. After downloading, enter the/home/vicky directory, configure the compilation steps as follows: #tar JXVF gdb-6.4-tar-bz2 #cd gdb-6.4 #./configure--target=arm-linux--prefix=/usr/local/arm-gdb-v #make (This step may have a problem, the hint of a function (specific function name do not remember) Parse error, is unsigned the front of more than one "}", you use VI to enter that line to delete it on the line. ) #make Install #export path= $PATH:/usr/local/arm-gdb Enter Gdbserver directory: #./configure--target=arm-linux–host=arm-linux #make CC=/USR/LOCAL/ARM/2.95.3/BIN/ARM-LINUX-GCC (This step is to specify the position of ARM-LINUX-GCC, may not be the same as yours) Make the Gdbserver executable file in the Gdbserver directory without error, burn it to the root file system partition of Flash, or mount it via NFS. Just make sure Gdbserver can run on the Development Board. The following can be used Gdb+gdbserver debug our Development Board program. Running Gdbserver on the target board is actually under the minicom of the host, and my Red Hat Linux is installed under VMware. I did it after minicom #mount 192.168.2.100://tmp (where parameter-o nolock can be done without this step, but faster), Hello and Gdbserver are all located in the Linux root directory, Hang the host root directory in the/TMP directory on the Development Board. To perform GDB debugging, first start the Gdbserver service on the target system. Enter the command in the directory where the Gdbserver resides: (Under Minicom) #cd/tmp #./gdbserver 192.168.2.100:2345 Hello 192.168.2.100 for host IP, a debug process is opened on the 2345 port of the target system, hello for the program to be debugged. Prompt appears: Process/tmp/hello created:pid=80 Listening on port 2345
(under another terminal) #cd/ #export path= $PATH:/usr/local/arm-gdb/bin #arm-linux-gdb Hello (GDB) Target remote 192.168.2.223:2345 (192.168.2.223 for Development Board IP) Prompt appears: Remote Debugging using 192.168.2.223:2345 [New Thread 80] [Switching to Thread 80] 0x40002a90 in?? () At the same time under the minicom hint: Remote Debugging from Host 192.168.2.100 (GDB) Connection is successful, this time you can enter a variety of GDB commands such as list, run, Next, step, break, and so on program debugging.
Above for NFS mount and TFTP through the way, can only be debugged on the host after the download to the Development Board to run, if there are errors to repeat this process, cumbersome not to say, some programs can only be debugged on the Development Board. So the author uses the Gdbserver remote debugging mode. I hope it's useful for you to debug your program.
From Hua Heng Technical Support forum embedded Technology Garden |