Using GDB for embedded remote debugging

Source: Internet
Author: User

PC Host: Ubuntu 10.4

Target board: TQ2440 Development Board, Linux kernel 2.6.30

Note: To use GDB for debugging, it is highly recommended to use NFS services, otherwise debugging can be cumbersome.

Use the NFS service to refer to: S3C2440 Mount NFS File system

1. Overview

The so-called remote debugging, is the development Board to build a GDB server, while the program to be debugged is also located in the Development Board, and then on the PC using GDB to initiate a remote connection to debug. That is, the program on the PC-side debugging the Development Board. Note that it is necessary to include the symbolic debug information (symbolic Debug information) of the debugged program on the PC side, so it is highly recommended to use NFS, otherwise it will require two debug applications, one for GDB and another for gdbserver.

2. Installing the GDB Service

Download the GDB installation package: http://ftp.gnu.org/gnu/gdb/

The 7.4 is used here.

Unpack the installation package:

[Email protected]:~/work_yj423$ tar-xvf gdb-7.4/

[Email protected]:~/work_yj423/gdb-7.4$ pwd
/home/yj423/work_yj423/gdb-7.4

Before you start compiling, you must know the name of your cross compiler. My cross compiler is ARM-UNKNOWN-LINUX-GNUEABI-GCC, and the name will be used below.

First compile the Gdbserver, which runs on the Development Board.

Execute the following command:

[Email protected]:~/work_yj423/gdb-7.4$ cd gdb/gdbserver/
[Email protected]:~/work_yj423/gdb-7.4/gdb/gdbserver$./configure--host=arm-unknown-linux-gnueabi--target= Arm-unknown-linux-gnueab
[Email protected]:~/work_yj423/gdb-7.4/gdb/gdbserver$ make

After make, the executable file Gdbserver is generated in the current directory.

Then the GDB is compiled and the program runs on the PC.

Execute the following command:

[Email protected]:~/work_yj423/gdb-7.4/gdb/gdbserver$ CD. /.. /
[Email protected]:~/work_yj423/gdb-7.4$ sudo./configure--targe=arm-unknown-linux-gnueabi
[Email protected]:~/work_yj423/gdb-7.4$ make

Note the directory where the command is executed. After execution, the executable file gdb is generated under gdb-7.4/gdb/. I changed gdb to Armgdb.

3. Debugging with GDB

The test procedure is hello.c and the program is as follows:

[CPP]View PlainCopy
    1. #include <stdio.h>
    2. void Main ()
    3. {
    4. printf ("Hello world\n");
    5. printf ("Hello world\n");
    6. }

Compile the file using the cross compiler, and use the-G parameter to generate hello. Copy gdbserver and hello to the mount point of NFS, my mount point is/home/yj423/nfswork.

[Email protected]:~/nfswork$ ls
Bin Dev Gdbserver home linuxrc proc Sbin tmp var
Boot etc hello lib mnt root sys usr welcome

You can see Gdbserver and hello.

Next, use NFS on the Development Board:
[[email protected]/] #mount-o nolock 192.168.1.103:/home/yj423/nfswork/mnt/nfs
[[email protected]/] #cd/mnt/nfs
[[Email Protected] NFS] #ls
Bin Dev Gdbserver home linuxrc proc Sbin tmp var
Boot etc hello lib mnt root sys usr welcome

Then execute the gdbserver:

[Email protected] nfs]#./gdbserver localhost:2001 Hello
Process Hello created; PID = 948
Listening on Port 2001

2001 is the port number, and Hello indicates the program to debug. At this point gdbserver wait for the PC to link.

To execute GDB on a PC:

[Email protected]:~$./armgdb-q/home/yj423/nfswork/hello

Reading symbols From/home/yj423/nfswork/hello...done.

To perform a remote link:

(GDB) Target remote 192.168.1.6:2001
Remote Debugging using 192.168.1.6:2001
Warning:unable to find dynamic linker breakpoint function.
GDB would be unable to debug shared library initializers
and track explicitly loaded dynamic code.
0x400007b0 in?? ()
(GDB)

The 192.168.1.6 here is the IP address of the Development Board.

At this point the PC-side gdb and the gdbserver of the Development Board have been connected and can then be debugged.

(GDB) B main
Cannot access memory at address 0x0
Breakpoint 1 at 0x83e0:file hello.c, line 5.
(GDB) C
Continuing.
Warning: '/lib/libc.so.6 ': Shared Library architecture unknown is not compatible with target architecture arm.
Warning:could not load shared library symbols for/lib/ld-linux.so.3.
Does you need "set Solib-search-path" or "Set Sysroot"?
Breakpoint 1, Main () at Hello.c:5
5 printf ("Hello world\n");
(GDB) n
6 printf ("Hello world\n");
(GDB) n
7}

Here is just a simple debug. There will be shared library debugging and multi-process debugging, please look forward to!

To be continued ~~~~~~~~~

Using GDB for embedded remote debugging

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.