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

Debugging sharp weapon GDB (part I)

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Debugging sharp weapon GDB (part one) 1.1 GDB first acquaintance 1.1.1 what is GDB?

GDB is the gnu debuger in the GNU project, which can follow the execution of the program and restore the state of the program before it crashed.

1.1.2 Why do I need GDB?

The research and development process of software products must be accompanied by bug, which is an indispensable technology in software development (debugging tools are very important).

1.1.3 DBG and binutils

1.2 General use of GDB

1. The custom program gets started (specify the parameters that affect the running of the program)

two。 Set conditional breakpoints (program pauses execution when conditions are met)

3. Backtracking check causes the program to end abnormally (core dump)

4. Dynamically change the execution flow of the program (an auxiliary way to locate the problem)

1.3Boot mode of GDB

 starts directly:

Gdbgdb test.outgdb test.out core

 dynamic link

Gdb test.out pid

1.4 Application example of GDB

Example 1:

Dbg / / start file test.out / / load the target program set args arg1 arg2 / / set command line parameters run / / execute the target program Note: gdb + file test.out = = gdb test.out

Example 2:

Gdb / / start attach pid / / link to the target process. After the link is successful, the target program will stop executing continue / / resume execution Note: gdb + attach pid = = gdb test.out pid1.5 breakpoint debugging 1.5.1 breakpoint type software breakpoint: implemented by illegal instruction exception (software implementation) The program is located at the hardware breakpoint in ram through interrupts: implemented by hardware features (limited in number) the program is located at data breakpoints in flash (read-only): implemented by hardware features (limited in number), monitors memory and triggers 1.5.2 software breakpoint-related operations when memory is rewritten

Set the breakpoint through the function name:

Break func_name [if var = value] tbreak func_name [if var = value]

Set the breakpoint by line number:

Break file_name:line_num [if var = value] break file_name:line_num [if var = value]

The breakpoint set by Tbreak takes effect only once.

1.5.3 related actions during debugging

1.5.4 hardware breakpoints and their operations

When the code is in the read-only register (flash), it can only be debugged through hardware breakpoints.

Hardware breakpoints need hardware support, and the number is limited.

GDB supports hardware breakpoints through the hbreak command, which is exactly the same as the use of break

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

Servers

Wechat

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

12
Report