Build a cross-debugging environment: Arm-Linux-GDB and gdbserver

Source: Internet
Author: User

Build a cross-debugging environment: Arm-Linux-GDB and gdbserver
2013-01-10 09:19:34

Classification: embedded

Operating System: ubuntu9.04

Development Board: botron 2410 s

Cross-compilation tool: arm-linux-gcc-4.1.1

GDB + gdbserver is a common method for debugging the target board.

The network environment is as follows: Host 192.168.1.123 target: 192.168.1.21

NFS shared directory: Mount-T nfs-O intr, nolock, rsize = 1024, wsize = 1024 192.168.1.123:/home/lingd/arm2410s/tmp

Sky Blue: Command

Purple: Command running result

RED: Notes



1. Preparations

Create an installation directory and modify directory permissions
Lingd @ Ubuntu :~ $ Sudo mkdir-P/opt/crosstool/ARM-GDB

Lingd @ Ubuntu :~ $ Sudo chown-r lingd/opt/crosstool/ARM-GDB

Download gdb-6.5.tar.bz2 (or the latest version of GDB)
Lingd @ Ubuntu :~ $ CD downloads


2. Compile arm-Linux-GDB

The gdb-6.5 uses Autoconf/automake. Therefore, you can easily port the -- target, -- host, and -- prefix parameters of the configure script to other platforms. -- Target specifies the target machine environment to be debugged, usually set to the prefix of the cross compiler, such as -- target = arm-Linux, -- target = MIPS-Linux, -- target = armv5-linux-uclibc, -- target's default value is the i386-linux, that is, the i386pc -- Host specifies the runtime environment of the compiled file, the value can be the prefix of the i386-linux or cross compiler, by default, the i386-linux -- prefix specifies the directory to be installed.
Lingd @ Ubuntu :~ /Downloads $ tar jxvf gdb-6.5.tar.bz2

Lingd @ Ubuntu :~ /Downloads $ CD gdb-6.5

Lingd @ Ubuntu :~ /Downloads/gdb-6.5 $./configure -- target = arm-Linux -- prefix =/opt/crosstool/ARM-GDB

Lingd @ Ubuntu :~ /Downloads/gdb-6.5 $ make

Lingd @ Ubuntu :~ /Downloads/gdb-6.5 $ sudo make install

Lingd @ Ubuntu :~ /Downloads/gdb-6.5 $ ls/opt/crosstool/ARM-GDB/bin
Arm-Linux-GDB arm-Linux-gdbtui arm-Linux-run
After installation, You can see arm-Linux-GDB, arm-Linux-run, and so on in/opt/crosstool/ARM-GDB/bin.

Configure Environment Variables
Lingd @ Ubuntu :~ /Downloads/gdb-6.5 $ VI ~ /. Bashrc

Add
If [-D/opt/crosstool/ARM-GDB/bin]; then

Path =/opt/crosstool/ARM-GDB/bin: $ path

Fi
Make the configured environment variables take effect
Lingd @ Ubuntu :~ /Downloads/gdb-6.5 $ source ~ /. Bashrc


3. Compile gdbserver
Lingd @ Ubuntu :~ /Downloads/gdb-6.5 $ CD ../gdb-6.5/GDB/gdbserver

Lingd @ Ubuntu :~ /Downloads/gdb-6.5/GDB/gdbserver $./configure -- target = arm-Linux -- Host = arm-Linux

Lingd @ Ubuntu :~ /Downloads/gdb-6.5/GDB/gdbserver $ make cc =/opt/crosstool/gcc-4.1.1-glibc-2.3.2/ARM-Linux/bin/ARM-Linux-GCC # Here is the path of the Cross Compiler

Lingd @ Ubuntu :~ /Downloads/gdb-6.5/GDB/gdbserver $ ls

The generated gdbserver is copied to the NFS shared directory, because gdbserver runs on the target machine.
Lingd @ Ubuntu :~ // Downloads/gdb-6.5/GDB/gdbserver $ CP gdbserver ~ /Arm2410s


4. Copy the libthread Library (if this step is not done, an error will occur when running gdbserver !)
Lingd @ Ubuntu :~ /Downloads/gdb-6.5/GDB/gdbserver $ CD/opt/crosstool/gcc-4.1.1-glibc-2.3.2/ARM-Linux/lib

Lingd @ Ubuntu:/opt/crosstool/gcc-4.1.1-glibc-2.3.2/ARM-Linux/Lib $ LS-l libthread_db *
-Rwxr-XR-x 1 lingd 28092 libthread_db-1.0.so

Lrwxrwxrwx 1 lingd 17 2009-12-29 18:51 libthread_db.so-> libthread_db.so.1

Lrwxrwxrwx 1 lingd 19 2009-12-29 18:51 libthread_db.so.1-> libthread_db-1.0.so

Copy the libthread_db-1.0.so to the NFS shared directory, which is ~ /Arm2410s ,~ /Arm2410s/lib is my external inventory location (my file system is cramfs and cannot be directly copied to/lib of the Target Board)
Lingd @ Ubuntu:/opt/crosstool/gcc-4.1.1-glibc-2.3.2/ARM-Linux/Lib $ mkdir ~ /Arm2410s/lib

Lingd @ Ubuntu:/opt/crosstool/gcc-4.1.1-glibc-2.3.2/ARM-Linux/Lib $ CP libthread_db-1.0.so ~ /Arm2410s/lib

Lingd @ Ubuntu:/opt/crosstool/gcc-4.1.1-glibc-2.3.2/ARM-Linux/Lib $ Cd ~ /Arm2410s/lib

Lingd @ Ubuntu :~ /Arm2410s/Lib $ ln-s libthread_db-1.0.so libthread_db.so.1

Lingd @ Ubuntu :~ /Arm2410s/Lib $ ln-s libthread_db-1.0.so libthread_db.so

Before Running gdbserver on the development board, set the library file search path ld_libraray_path.

Under minicom
Root @ lingd-arm2410s:/# Mount-T nfs-O intr, nolock, rsize = 1024, wsize = 1024 192.168.1.123:/home/lingd/arm2410s/tmp

Root @ lingd-arm2410s:/# export ld_libraray_path =$ {ld_libraray_path}:/tmp/lib

If the root file system is not a read-only file system, you can directly copy the libthread_db-1.0.so to the/lib or/usr/lib of the development board, and then establish the corresponding matching Link


4. Test

Write a program, compile it with arm-Linux-gcc-G, and put it in the NFS shared directory/home/lingd/arm2410s. The program name is GPRS.

Under minicom
Root @ lingd-arm2410s:/# cd/tmp

Root @ lingd-arm2410s:/tmp #./gdbserver 192.168.1.123: 6666 GPRS
Process GPRS created; pid = 825

Listening on port 6666

Gpbserver usage: gpbserver Host IP Address: the command line parameters of the program [Program command line parameters] To be debugged on the communication port are optional.

Start a terminal and run the following command
Lingd @ Ubuntu :~ $ CD arm2410s/

Lingd @ Ubuntu :~ /Arm2410s $ arm-Linux-GDB GPRS
Gnu gdb 6.5

Copyright (c) 2006 Free Software Foundation, Inc.

GDB is free software, covered by the GNU General Public License, and you are

Welcome to change it and/or distribute copies of it under certain conditions.

Type "show copying" to see the conditions.

There is absolutely no warranty for GDB. Type "show warranty" for details.

This GDB was configured as "-- Host = i686-pc-linux-gnu -- target = arm-Linux "...
(GDB) target remote 192.168.1.21: 6666 # connection target: target remote Development Board IP Address: Communication Port
Remote debugging using 192.168.1.21: 6666

0x40001330 in ?? ()
(GDB)


At this point, the Development Board terminal can see the response information remote debugging from host 192.168.1.123
Root @ lingd-arm2410s:/tmp # gdbserver 192.168.1.123: 6666 GPRS
Process GPRS created; pid = 825

Listening on port 6666

Remote debugging from host 192.168.1.123


Now you can view the program source code through L, and then set the breakpoint B. Run the command C.

5. Common gdb commands:

Load: load a program

Symbol-file: loads the symbol library file, which can be an executable file compiled with the-G parameter.

F (ILE): Specifies an executable file for debugging. GDB reads the debugging messages of some files, such as f a.exe.

L (IST): The column program outputs the source file.

R (un): After loading the executable file to be debugged, you can run the executable file using the Run Command.

B (reak): sets a breakpoint (break point). For example, B 25 sets a breakpoint in line 2 of the source program. When the program is executed to line 2, it will interrupt; you can also use B funcname and funcname as the function name,


When the program stops running at the breakpoint,
C (ontinue): The C command can be executed on another interrupted program until the next breakpoint or program ends.

P (RINT): Enter the value of a variable. If the program defines an int A, p a will output the current value of AA.

N (EXT): the execution is interrupted when the program is executed to the breakpoint. You can use N commands for one-step execution.

S (TEP): the execution is interrupted when the program is executed to the breakpoint. You can use the S command to execute a single step into a function.

Q (uit): Exit GDB


The effects of simplified commands, such as l, are the same as that of the complete command list.
6. Notes 1). If the simplified command F is not always usable, GDB will prompt
(GDB) f GPRS
No symbol table is loaded. Use the "file" command.

Use the complete command file instead of (GDB) file GPRS
Reading symbols from/home/lingd/arm2410s/GPRS... done.


2) during staggered debugging, we do not use R (un) to execute the program. Because after executing the target remote command, the target board program is already running, and you should use the continue command instead of the Run Command. If you choose to re-run the program, GDB will prompt that you do not know how to run the program, because the gpbserver on the Development Board has exited "killing inferior.
(GDB) r
The program being debugged has been started already.

Start it from the beginning? (Y or N) y


Starting program:/home/lingd/arm2410s/GPRS

Don't know how to run. Try "help target ".


Reference: establishing the cross-Debugger GDB and gdbserverhttp: // blog.csdn.net/hansel/archive/2007/10/18/1830543.aspxgdb1_gdbserver on the ARM platform is a common method for debugging the target board.

Http://blog.csdn.net/dllbl/archive/2008/09/14/2830813.aspx

Original article: http://blog.csdn.net/unbutun/article/details/6105790

Related Article

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.