GDB debugging __linux of embedded Linux system

Source: Internet
Author: User
Tags bz2 parse error stub
Title: Implementation of remote debugging of GDB in embedded Linux 2008-01-11 11:22:08
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

This article refers to the notification address: http://lionwq.spaces.eepw.com.cn/articles/trackback/item/16810


Cross-gdb Embedded Linux cross-debugging 2009-12-02 0:11

Download GDB source code from HTTP://FTP.GNU.ORG/GNU/GDB--gdb-6.2.1.tar.bz2
1-Compile the GDB client:
#cd gdb-6.2.1
#./configure--target=arm-linux--prefix=/root/arm-gdb-v
#make//Period there may be errors, see above

IWMMXT.C: In the function ' Wmac ':
IWMMXT.C:2117: Error: Invalid left value in assignment operation
IWMMXT.C:2133: Error: Invalid left value in assignment operation
IWMMXT.C: In the function ' Wmadd ':
iwmmxt.c:2169: Error: Invalid left value in assignment operation
IWMMXT.C:2177: Error: Invalid left value in assignment operation
iwmmxt.c:2186: Error: Invalid left value in assignment operation
IWMMXT.C:2191: Error: Invalid left value in assignment operation
IWMMXT.C: In the function ' WSLL ':
iwmmxt.c:2840: Warning: integer constant is too large for ' long ' type
IWMMXT.C: In the function ' Wsra ':
iwmmxt.c:2917: Warning: integer constant is too large for ' long ' type
iwmmxt.c:2917: Warning: integer constant is too large for ' long ' type
iwmmxt.c:2919: Warning: integer constant is too large for ' long ' type
IWMMXT.C: In the function ' WSRL ':
iwmmxt.c:2988: Warning: integer constant is too large for ' long ' type
IWMMXT.C: In the function ' Wunpckeh ':
iwmmxt.c:3290: Warning: integer constant is too large for ' long ' type
IWMMXT.C: In the function ' Wunpckel ':
iwmmxt.c:3357: Warning: integer constant is too large for ' long ' type
IWMMXT.C: In the function ' Fetch_iwmmxt_register ':
iwmmxt.c:3707: Warning: Implicit declaration incompatible with built-in function ' memcpy '
iwmmxt.c:3712: Warning: Implicit declaration incompatible with built-in function ' memcpy '
IWMMXT.C: In the function ' Store_iwmmxt_register ':
iwmmxt.c:3722: Warning: Implicit declaration incompatible with built-in function ' memcpy '
iwmmxt.c:3727: Warning: Implicit declaration incompatible with built-in function ' memcpy '
MAKE[2]: * * * [IWMMXT.O] Error 1
MAKE[2]: Leaving directory '/root/documents/gdb-6.2.1/sim/arm '
MAKE[1]: * * * [ALL] Error 2
MAKE[1]: Leaving directory '/root/documents/gdb-6.2.1/sim '
Make: * * * * [All-sim] Error 2


Locate the wrong file and the line in the file according to the prompts above:
C:2117:error:invalid Lvalue in Assignment
C:2133:error:invalid Lvalue in Assignment
C:2169:error:invalid Lvalue in Assignment
C:2177:error:invalid Lvalue in Assignment
C:2186:error:invalid Lvalue in Assignment
C:2191:error:invalid Lvalue in Assignment

Methods Ibid, are all to change the GDB compressed package file, this time the change is
In the gdb-6.2.1/sim/arm/iwmmxt.c file:

No. 2117, 2133, 2169, 2177, 2186, 2191 lines;

The method is as follows:

The 2117 line (signed long) T + = s;
To (signed long Long) T; t = (signed long long) (t + s);


2133 rows (signed long long) Wr[bits = = (signed long long) T;
Change to {(signed long Long) Wr[bits (12, 15)]; Wr[bits] = (signed long Long) (wr[bits) + t);}


The 2169 line (signed long) S1 = a * b;
Changed to (signed long) S1; S1 = (Signed long) (A * b);


The 2177 Line (signed long) s2 = a * b;
Changed to (signed long) S2; S2 = (signed Long) (A * b);


The 2186 line (unsigned long) S1 = a * b;
Changed to (unsigned long) s1; S1 = (unsigned long) (A * b);


The 2191 line (signed long) s2 = a * b;
Changed to (unsigned long) S2; S2 = (unsigned long) (A * b);



Compile Gdbserver:

Linux-arm-low.c:26:21:error:sys/reg.h:no such file or directory
Make: * * * * [LINUX-ARM-LOW.O] Error 1

According to the LINUX-ARM-LOW.C:
#ifdef HAVE_SYS_REG_H
#include <sys/reg.h>
#endif

The modifications in Gdb/gdbserver/config.h are as follows:
/* Define If you have the <sys/reg.h> header file. */
#define HAVE_SYS_REG_H 1

/* Define If you have the <sys/reg.h> header file. */
#define HAVE_SYS_REG_H 1 omitted


#make Install
#vi ~/.bash_profile Modification: path= $PATH:/root/arm-gdb/bin
#source ~/.bash_profile
#arm-linux-gdb-v

2-Compiling Gdbserver
#cd gdb-6.2.1
#./configure--target=arm-linux--host=arm-linux
#cd Gdb/server
#./configure--target=arm-linux--host=arm-linux
Modified gdb/gdbserver/config.h: #define HAVE_SYS_REG_H 1-->//#define HAVE_SYS_REG_H 1
#make CC=ARM-LINUX-GCC
Copy the Gdbserver from the Gdb/gdbserver directory to the/bin of the Development Board system (embedded Linux)
Instance:
hello.c
#include <stdio.h>
#include <string.h>
int main ()
{
Char *str=null;
strcpy (str, "Hello");
printf ("Str is%s\n", str);
return 0;
}

#arm-linux-gcc-g Hello.c-o Hello
Set host IP address: 192.168.1.10, the Development Board system IP address: 192.168.1.230 (generally only set to the same network segment on the line),
In the Development Board:
#gdbserver 192.168.1.230:1234 Hello
Process test created:pid=80//enables Gdbserver to monitor on port 1234.
In the host:
#arm-linux-gdb
(GDB) Target remote 192.168.1.230:1234//If the link is successful, the serial terminal of the development Board will display the following:
Remote Debugging from Host 192.168.1.10
(gdb) symbol file Hello//Here Hello is the path on the PC
(GDB) List
(GDB) Break 5
(GDB) continuing
(GDB) Step//Prompts for a segment error (usually caused by illegal access to memory)


Commonly used GDB debugging commands: (Some of the only opening letters can be directly replaced with the beginning letter, you can also use the tab to display its full command name)
The file file name loads an executable file in gdb, symbol file Hello
Break N Set Breakpoint breaks 5
Info view various information related to the executable program info Breakpoint delete/disable/enable Breakpoint num
Kill terminates the program being debugged
Print shows the value of a variable or an expression
Set args sets the run parameters of the debugger
Watch set the observation point in the program (if the data changes, will give the situation before and after the change)
Delete a breakpoint or observation point of a setting
Clear deletes a breakpoint or observation point of the setting
Continue continues execution of the program from the breakpoint
List lists the code for executable programs that are loaded in GDB
Run runs an executable program loaded in GDB
Next step to the loaded program
Step stepping, you can go inside the function to see the execution (return to the call by finish)
Whatis view variable or function type
Pype display of data structure definition
Make compiles the program without exiting GDB
Quit Exit GDB

GDB debugging a program with parameters

GdB--args./TESTPRG arg1 arg2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.