Use DDD + GDB to develop ARMLinux programs

Source: Internet
Author: User
Use DDD + GDB to develop the ARMLinux Program-general Linux technology-Linux programming and kernel information. The following is a detailed description. Since Linux runs on my board, I have been thinking about how to debug future programs. In fact, I am really a layman in Linux development. Today I know what GDB is. I believe that many people have been using LED and printf methods for debugging since Bootloader debugging. When I complete the setup, I will plot a USER partition in MTDBLOCK, then put the compiled program into the file system image, use the Bootloader to go To the NAND through the serial port, and then mount the file for debugging, it takes a lot of time. Today, I have finally found a shortcut to stop coughing!

First, we will introduce DDD and GDB. GDB is a tool used to debug programs in Linux. It can not only debug C/C ++, but also debug many other languages such as Pascal. Let's take an example: assume there is a program named test. c. debug it with GDB. First, add the debug information option "-g" during compilation, for example, # arm-linux-gcc test. c-o test-g; then, because we are not developing local programs, we need to use a server to start the program containing debugging information on the target machine (arm). Of course, there must be a certain data sharing mode (such as nfs) between the local machine and the target machine and a certain communication mode (such as Ethernet or serial port). Finally, start a GDB client on the local machine, you can log on to the server of the target machine to debug the program. There are also many articles on the Internet about how GDB works. You can search for it, but I am a beginner, so I will not go to the content. To make the difference between GDB and DDD clearer, Let's first look at the debugging process of GDB:

I debug through Ethernet, the local IP address 192.168.2.31, the target machine (arm development board IP address 192.168.2.223), the local machine through nfs shared development directory lgraphics.

First, compile on the local machine:
Lxz @ lxzlinux :~ /Lgraphics> arm-linux-gcc lgraphics. c-o lg-g

Switch to the target machine:
[Root @ (none) lgraphics] # gdbserver 192.168.2.31: 2345 lg
Process lg created; pid = 402
Listening on port 2345

Switch to the local machine:
Lxz @ lxzlinux :~ /Lgraphics> arm-linux-gdb lg
GNU gdb 6.6
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.2.223: 2345 lg
Remote debugging using 192.168.2.223: 2345 lg
0x40001290 in _ start () from/lib/ld-linux.so.2

At this time, the target machine will also see:
Remote debugging from host 192.168.2.31

Enter:
(Gdb) B main (set the breakpoint to the main function)
Breakpoint 1 at 0x9c00: file lgraphics. c, line 442.
(Gdb) cont (start execution)
Continuing.
Breakpoint 1, main () at lgraphics. c: 442 (when a Breakpoint is encountered and the Breakpoint program line is displayed)
442 int I, j, B = 0;
(Gdb) step (single-step execution)
445 linitgraph ("/dev/fb0"); (display current program line)

Now, you can see what GDB is and how it is used. I believe that you will be angry with me for being unfriendly to the GDB interface, and think about the development tool in Windows, which debugging method is still text interface. Fortunately, some diligent people have helped us write a lot of GDB graphical front-ends, and we do not need to use GDB like above.

Start with DDD. DDD is a graphical front-end of GDB. It is a graphical interface that helps you enter tedious GDB debugging command tools. Of course, there are also many articles about how inadequate DDD is, replacing it with Insight. In my Suse, DDD exists. I don't care that much about it. I used it first. Let's see how to debug it when using DDD:

Same local Compilation:
Lxz @ lxzlinux :~ /Lgraphics> arm-linux-gcc lgraphics. c-o lg-g

Switch to the target machine:
[Root @ (none) lgraphics] # gdbserver 192.168.2.31: 2345 lg
Process lg created; pid = 402
Listening on port 2345

Switch to the local machine:
Lxz @ lxzlinux :~ /Lgraphics> ddd-debugger arm-linux-gdb lg

Then the graphic interface of DDD will be started. There is a text input box below the window, where the basic gdb of ddd is located. Enter target remote 192.168.2.223: 2345 lg, the prompt information is the same as when we use GDB. The difference is that, except for this command to connect to the target machine, other commands do not need to be input. They can be found on the graphical interface, so I won't talk about it. In addition, commands for connecting to the target machine can also be set in DDD. You can find other articles about DDD without entering them. The following is the graphic interface of DDD. watch is under the toolbar. You can set a breakpoint (red dot) for the code. You can see the single-step position (Green Arrow) and the execution control toolbar on the right, at the bottom is the input and output display of GDB.

Here, just like me, cainiao will surely find out that the Linux program can be so well tuned that there is no difference between it and CE. The following describes how to use GDB + DDD. I didn't set up it from scratch. I don't understand the package dependency. I have to assume that you have installed tools such as GCC and DDD when installing Linux. The GDB source code package gdb-6.6.tar.bz2 can be downloaded from the ftp://gcc.gnu.org, there is also a requirement that you have installed the cross compiler arm-linux-gcc.

After downloading:
# Tar xvjf gdb-6.6.tar.bz2
# Mkdir gdbbuild
# Cd gdbbuild
# ../Gdb-6.6/configure -- target = arm-linux -- prefix =/home/lxz/lxzgdb

Here, the -- prefix parameter is the directory to be installed, and then
# Make
# Make install
In this way, the arm-linux-gdb tool is in/home/lxz/lxzgdb/bin. You can add this PATH to the PATH.

Next, create a gdbserver, under the directory of the upper-level gdbbuild
# Mkdir gdbserverbuild
# Cd gdbserverbuild
# CC = arm-linux-gcc ../gdb-6.6/gdb/gdbserver/configure -- host = arm-linux -- prefix =/home/lxz/lxzgdbserver

The -- prefix parameter is the directory to be installed, and then
# Make
# Make install

Some articles say that debugging information of arm-linux-strip should be removed.
# Cd/home/lxz/lxzgdbserver/bin
# Arm-linux-strip gdbserver

Copy the gdbserver to your Development Board.
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.