Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use gdb and gdbserver to build online debugging environment in Linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces how to use gdb and gdbserver to build an online debugging environment in Linux. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

1. Introduction

Single-chip microcomputer generally use Jlink to debug online through SWD or JTAG interface directly, Linux applications usually add printf output log to debug, this way is simple, but some hidden programs bug only by adding print information is not so easy to locate, at this time can be similar to single-chip microcomputer debugging gdb debugging to achieve, this article introduces the construction of online debugging environment in linux environment, hope to help you.

GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes-- or what another program was doing at the moment it crashed.

two。 Environment introduction

2.1. Hardware

1) A NUC972 development board made by a third party on the Internet:

Friends who are interested in buying can go to their Taobao store to buy:

Https://s.click.taobao.com/X8mza8w

2.2. Software

1) Uboot continues to use what was used in the previous article without change.

2) Kernel does not need to be changed on the basis of the previous article.

3) based on the previous article generated by Buildroot, Rootfs needs to make some changes to generate gdbserver.

3.Buildroot configuration

Buildroot needs to be configured to generate gdb and gdbserver. The steps are as follows:

1) confirm whether Toolchain | Build cross gdb for the host is selected. This is checked by default.

The function of this is: Build a cross gdb that runs on the host machine and debugs programs running on the target. It requires' gdbserver' installed on the target.

2) Select the Thread library debugging under Toolchain, and be sure to select this first, otherwise the third step cannot be performed.

3) Select Target packages | Debugging, profiling and benchmark- > gdb and gdbserver

The above functions are:

This option allows to build gdbserver and/or the gdb debugger for the target.For embedded development, the most common solution is to build only 'gdbserver' for the target, and use a cross-gdb on the host.

4) Save and compile.

The generated gdb is located at: / home/topsemic/nuc972/buildroot/NUC970_Buildroot/output/host/usr/bin

In the directory

The generated gdbserver is located at:

/ home/topsemic/nuc972/buildroot/NUC970_Buildroot/output/target/usr/bin directory

5) put the above gdbserver directly into the / usr/bin directory of the board, and then log in to the board and enter gdbserver. You can see the following information, indicating that the gdbserver of the board has been built.

4. Create a new test program

1) create a new test program gdbtest.c

# include int main () {char s [64] = "Welcome to www.topsemic.com"; int a = 1; int c = axi2; int * ptr = NULL; printf ("s is:% s", s); printf ("c is:% d", c); * ptr = 20; printf ("% d", * ptr); return 0;}

2) Cross compilation

Topsemic@topsemic-virtual-machine:~/nuc972/examples/gdbserver$ arm-linux-gcc gdbtest.c-o gdbtest-g

Note: arm-linux-gcc gdbtest.c-o gdbtest-g where the "- g" parameter indicates GDB compilation.

The result of running this program on the board is as follows:

Let's use the following online debugging method to see what causes Segmentation fault

5. On-line debugging

Before debugging, connect the board and PC through the network cable, the steps are as follows:

1) in the directory where the executable on the development board is located, execute the following command to start gdbserver:

Command format: gdbserver:

192.168.0.80 is the IP address of Ubuntu and 1234 is the port number of the connection

Note: you need to configure the IP of the virtual machine Ubuntu to a fixed 192.168.0.80. This setting method is described in "Linux Learning Series 8: operating Network Ports".

2) start gdb debugging under Ubuntu with the command format:

Topsemic@topsemic-virtual-machine:~/nuc972/examples/gdbserver$ / home/topsemic/nuc972/buildroot/NUC970_Buildroot/output/host/usr/bin/arm-linux-gdb gdbtest

3) enter the following command after the pop-up dialog box (gdb) to connect the development board

(gdb) target remote 192.168.0.100 purl 1234

Where 192.168.0.100 is the IP address of the development board

4) after that, you can enter the following GDB debugging commands. For detailed usage of other debugging commands, please enter "help command name" to check.

Command: l, see the code.

Command: B main, set the breakpoint at main.

Command: B6, set a breakpoint on line 6.

Command: C, continue.

Command: n, step by step.

Command: Q, exit gdb.

Type c until the end of the program.

Step through debugging while viewing the information printed on the board

You can see that the execution process of the board subroutine is consistent with the progress of the breakpoints added on the Ubuntu. In addition, you can

It is found that the Segmentation fault is caused by line 10, which locates the problem.

On how to use gdb and gdbserver in Linux to build an online debugging environment is shared here. I hope the above content can be of some help and can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report