gdb所有调试技术_所有关于调试的技巧

gdb所有调试技术

For any software project, debugging is considered to be an essential yet demanding task. Developers must enter a continuous cycle of testing, debugging, and deploying to make sure their product is up to date and functioning correctly across all targeted platforms.

对于任何软件项目,调试都被认为是必不可少但要求很高的任务。 开发人员必须进入一个连续的测试,调试和部署周期,以确保其产品是最新的并且可以在所有目标平台上正常运行。

Usually, this is how the process goes: Once the developers finalize a program’s codebase for a product, this codebase is then sent to a tester. Testers run the codebase against well-defined input tests to check if the program gives the expected outputs. During testing, the testers observe the relationship between the input and output of the program. If one of the test cases produces the wrong results, the test reports that back to the original developers.

通常,这就是过程的过程:开发人员完成产品的程序代码库后,该代码库将发送给测试人员。 测试人员针对定义明确的输入测试运行代码库,以检查程序是否提供了预期的输出。 在测试期间,测试人员会观察程序输入和输出之间的关系。 如果其中一个测试用例产生了错误的结果,则该测试将报告给原始开发人员。

A program malfunction means that the codebase contains a bug, but that doesn’t give us any further information about the location of that bug. In other words, testing reveals the presence and effects of errors — not the cause of errors. The developers must then go through a debugging process to identify the causes and fix the bugs causing them.

程序故障意味着代码库包含一个错误,但是并没有为我们提供有关该错误位置的任何进一步信息。 换句话说,测试表明存在 错误的后果-不是错误的原因 。 然后,开发人员必须通过调试过程来找出原因并修复导致它们的错误。

Although there is no fixed procedure to fix all bugs, there are several techniques that can reduce your debugging efforts. A significant (if not the entire) part of this process is spent finding the location of the bug.

尽管没有修复所有错误的固定过程,但是有几种技术可以减少调试工作。 此过程的大部分(如果不是全部)花费在查找错误的位置上。

In this article, we will discuss the three most known and used techniques:

在本文中,我们将讨论三种最常用和最常用的技术:

  • Trace-based debugging

    基于跟踪的调试
  • Spectrum-based debugging

    基于频谱的调试
  • Delta debugging

    台达调试

Different techniques are better suited to different cases. There is no precise best method. It all depends on the type of codebase you’re testing and your preferences. Nevertheless, it is suitable for developers to have knowledge of and experience with all of these approaches. Sometimes, a combination of one or more of these approaches will lead you to the location of the bug.

不同的技术更适合于不同的情况。 没有精确的最佳方法。 这完全取决于您正在测试的代码库的类型以及您的偏好。 但是,适合开发人员了解和体验所有这些方法。 有时,将这些方法中的一种或多种结合使用,将带您找到错误的位置。

So, let’s get debugging.

因此,让我们进行调试。

基于跟踪的调试 (Trace-Based Debugging)

Image for post
Canva) Canva制作 )

Trace-based debugging is traditional and the most common debugging technique used in most debugging tools today. Trace-based debugging is predicated on the concept of breakpoints.

基于跟踪的调试是传统的,并且是当今大多数调试工具中使用的最常见的调试技术。 基于跟踪的调试基于断点的概念。

A breakpoint is a pausing or stopping point added to the program to examine the state of program execution up until that point. After rectifying the current bug, the developer usually sets the next breakpoint and repeats the same process until all the bugs are corrected.

断点是添加到程序的暂停或停止点,用于检查直到该点之前的程序执行状态。 在纠正了当前错误之后,开发人员通常会设置下一个断点,并重复相同的过程,直到所有错误都得到纠正。

Traced-based debugging has four sub-techniques

基于跟踪的调试具有四个子技术

  1. Trace debugging (TD)

    跟踪调试(TD)
  2. Omniscient debugging (OD)

    全能调试(OD)
  3. Algorithmic debugging (AD)

    算法调试(AD)
  4. Hybrid debugging (HD)

    混合调试(HD)

All of these sub-techniques are based around the same concept: program slicing.

所有这些子技术都基于相同的概念:程序切片。

切片 (Slicing)

Program slicing is a technique used in computer science to simplify big programs by focusing on a smaller, selected section of them. The process of slicing deletes parts of the program that have no or little effect on the aspect being tested or the overall output of the program. In 1981, Mark Weiser, computer scientist and Chief Technology Officer at Xerox PARC, defined a program slice as:

程序切片是计算机科学中使用的一种技术,它通过专注于较小的选定部分来简化大型程序。 切片过程将删除对测试的方面或程序的整体输出没有影响或影响很小的程序部分。 1981年,施乐PARC的计算机科学家兼首席技术官Mark Weiser将程序片段定义为:

“The mental abstraction people make when they are debugging a program.”

“人们在调试程序时会产生思维上的抽象。”

Program slicing is used in many applications in computer science:

程序切片用于计算机科学的许多应用程序中:

  1. Debugging.

    调试。
  2. Reverse-engineering a program.

    对程序进行逆向工程。
  3. Measuring a program’s coverage, overlap, or clustering.

    测量程序的覆盖范围,重叠或聚类。
  4. To gain a deeper understanding of the inner workings of a program.

    深入了解程序的内部工作原理。

There are several possible approaches to slicing a program, such as static slicing, dynamic slicing, conditional slicing, and amorphous slicing.

切片程序有几种可能的方法,例如静态切片,动态切片,条件切片和无定形切片。

  • Static slicing: Static slices are constructed for a subset of the program’s variables without any assumptions about the input of the program. After picking a slice’s variable set, we can construct one of two types of slices: a backward slice or a forward slice. A backward slice contains the sections of the program that could affect the slice’s variables, while a forward slice contains those sections that are affected by the slice’s variables.

    静态切片: 静态切片是为程序变量的子集构造的,无需对程序输入进行任何假设。 选择切片的变量集后,我们可以构造两种切片中的一种:后向切片或前向切片 片。 落后 slice包含程序中可能影响slice变量的部分,而正向 切片包含受影响的部分 通过切片的变量。

  • Dynamic slicing: Dynamic slices are formed based on the variable set and the point in the code we want to inspect in addition to the sequence of input values for which the program produced an error. This information is called the dynamic slicing criterion.

    动态切片:动态切片是根据变量集和我们要检查的代码点(除了程序会产生错误的输入值的顺序)形成的。 此信息称为动态切片标准。
Image for post
Canva) Canva制作 )
  • Conditional slicing: In static slicing, we provide nothing about the input. In dynamic slicing, we construct it based on a specific input. Conditional slicing lays somewhere in the middle. In a conditional slice, we can provide information to the slicing tool about the input without being so specific about precise values.

    条件切片:在静态切片中,我们不提供任何内容 关于输入。 在动态切片中,我们基于特定的 输入。 有条件的切片位于中间的某个位置。 在条件切片中,我们可以提供信息 到切片工具关于输入没有 对精确值如此具体。

  • Amorphous slicing: All previous slicing discussed so far represents syntax preserving. These approaches are constructed by deleting the statements that don’t affect the set of variables in question. However, amorphous slices are constructed using any program transformation, which simplifies the program while preserving the functionality of the overall program.

    非晶切片:到目前为止讨论的所有先前切片都表示语法保留。 通过删除不影响相关变量集的语句来构造这些方法。 但是,可使用任何程序转换来构造无定形切片,从而简化了程序,同时保留了整个程序的功能。

Among those four types, dynamic slicing is the most used technique in debugging. That is because when we debug, we have a specific test case that produced the error, so we can use that test case as an input to construct our slices.

在这四种类型中,动态切片是调试中最常用的技术。 那是因为当我们调试时,我们有一个产生错误的特定测试用例,因此我们可以将该测试用例用作构建切片的输入。

跟踪调试 (Trace Debugging)

Image for post
Canva) Canva制作 )

In trace debugging (TD), the debugger can set a breakpoint, and when a breakpoint is reached during program execution, the program is suspended. Then, the programmer can examine the program state by running it line by line. The debugger takes control over the interpreter only, and hence the scalability of TD is the same as that of the interpreter. During the process of finding the location of a bug, if a bug is found before the breakpoint, then the debugging process needs to restart to catch it.

在跟踪调试(TD)中,调试器可以设置一个断点,并且在程序执行过程中达到断点时,程序将被挂起。 然后,程序员可以通过逐行运行程序来检查程序状态。 调试器仅控制解释器,因此TD的可伸缩性与解释器的可伸缩性相同。 在查找错误的位置的过程中,如果在断点之前发现了错误,则调试过程需要重新启动以捕获它。

全能调试 (Omniscient debugging)

In omniscient debugging (OD), also known as back-in-time debugging, the debugger can trace the computations of the program both backward and forward. In this type of debugging, execution traces are enormous, and storing them is a challenging task, so the scalability of OD is quite tricky.

在全知式调试(OD)(也称为即时调试)中,调试器可以向后和向前跟踪程序的计算。 在这种类型的调试中,执行跟踪非常庞大,并且存储它们是一项具有挑战性的任务,因此OD的可伸缩性非常棘手。

算法调试 (Algorithmic debugging)

Image for post
Canva) Canva制作 )

Algorithmic debugging (AD) is a semi-automatic debugging technique that produces a dialog between the debugger and the developer to find bugs. So, there is no need to see the code to perform the actual debugging. That’s why the level of abstraction of AD is high. AD is done in two phases: First, it builds the execution tree of the given program. Then, the execution tree made is explored in full detail.

算法调试(AD)是一种半自动调试技术,可在调试器和开发人员之间产生对话框以查找错误。 因此,无需查看代码即可执行实际的调试。 这就是为什么AD的抽象水平很高的原因。 AD分两个阶段完成:首先,它构建给定程序的执行树。 然后,将详细探讨制作的执行树。

混合调试 (Hybrid debugging)

Hybrid debugging (HD) is a debugging technique that combines trace debugging, omniscient debugging, and algorithmic debugging. First, it uses trace debugging to find out the part of the program where the error occurs. Then, it uses algorithmic debugging on only that part of the program and produces its execution tree. Afterward, it applies omniscient debugging to a single method where algorithmic debugging identified a bug.

混合调试(HD)是一种结合了跟踪调试,全能调试和算法调试的调试技术。 首先,它使用跟踪调试来找出程序中发生错误的部分。 然后,它仅对程序的那部分使用算法调试,并生成其执行树。 之后,它将无所不知的调试应用于单个方法,在该方法中,算法调试确定了一个错误。

基于频谱的调试 (Spectrum-Based Debugging)

Image for post
Canva) Canva制作 )

In spectrum-based debugging, also known as spectrum-based fault localization (SFL), the debugging process is done by monitoring the statements included in a particular execution tree. This is achieved by using the program spectrum to identify the active part of the program during its run. The program spectrum is a collection of runtime information that gives a view of the dynamic behavior of the program. It includes some flags corresponding to different parts of the program. Different types of program spectra exist, such as block hit/miss and function hit/miss. These spectra are used to pinpoint the exact sections of the code running for specific or abstract input.

在基于频谱的调试(也称为基于频谱的故障定位(SFL))中,调试过程是通过监视特定执行树中包含的语句来完成的。 这是通过使用程序范围来标识程序运行期间的活动部分来实现的。 节目范围是 运行时信息的集合 给出了程序动态行为的视图。 它包括一些与程序的不同部分相对应的标志。 存在不同类型的程序频谱,例如block hit/missfunction hit/miss 。 这些频谱用于查明为特定或抽象输入运行的代码的确切部分。

Delta调试 (Delta Debugging)

Image for post
Canva) Canva制作 )

The process of delta debugging (DD) is to minimize automated test cases. It takes test cases that may cause the error and prepares an error report. From that error report, minimal test cases are selected based on their high probability of producing the error. The minimum test cases will regenerate the same error and thus help the developer locate the bug behind it.

增量调试(DD)的过程是最大程度地减少自动化测试用例。 它使用可能导致错误的测试用例,并准备一个错误报告。 从该错误报告中, 根据产生错误的高可能性选择最少的测试用例。 最少的测试用例将重新生成相同的错误,从而帮助开发人员找到其背后的错误。

结论 (Conclusion)

There are a number of other strategies that can be used to help the developer locate bugs existing in the code. As a developer, I always remind myself of a few things:

还有许多其他策略可用于帮助开发人员查找代码中存在的错误。 作为开发人员,我总是想起一些事情:

  • The bug may not be where you’re looking for it. Sometimes when a developer looks for a bug, they spend a long time inspecting a specific section of the code just to find out that the bug is elsewhere.

    该错误可能不在您要查找的地方。 有时,当开发人员寻找错误时,他们会花很长时间检查代码的特定部分,以发现错误在其他地方。

  • Looking at the problem from another angle gives a different perspective. And by pointing out the parts of the code that are bug-free, we can reveal where the bug really is.

    从另一个角度看问题会给出不同的观点。 通过指出代码中没有错误的部分,我们可以揭示错误的真正位置。
  • Inspect the input data and test details. Sometimes, the test case may be broken. So, it’s always a good idea to go through it and make sure everything is on point.

    检查输入数据和测试详细信息。 有时,测试用例可能会损坏。 因此,始终仔细检查并确保一切都正确是一个好主意。

All of the above are techniques used to locate bugs errors, but then what?

以上所有都是用于定位错误的技术,但那又是什么呢?

Once a bug has been identified, errors must be corrected. In some cases, this can be trivial. At other times, it’s going to be straightforward. Developers must think thoroughly about how a specific fix is going to affect the remainder of the code. They need to ensure that the repair will not cause other parts of the code to break. Bugs that represent conceptual errors in the code are without a doubt the most difficult to fix. That’s why developers must rethink not just the fix but also the logic of the program.

一旦发现错误,就必须纠正错误。 在某些情况下,这可能是微不足道的。 在其他时候,这将很简单。 开发人员必须仔细考虑特定的修复程序将如何影响其余的代码。 他们需要确保修复不会引起代码其他部分的破坏。 毫无疑问,代表代码中概念错误的错误最难修复。 这就是为什么开发人员不仅要重新考虑修补程序,还要重新考虑程序的逻辑。

This is the second article in a series discussing everything about debugging and debuggers. The first article was:

这是该系列的第二篇文章,讨论了有关调试和调试器的所有内容。 第一篇文章是:

Upcoming articles will be:

即将发表的文章将是:

  • All About Debugging: Special Systems. I will discuss debugging special systems such as large-scale debugging, parallel system debugging, and more.

    关于调试的所有信息:特殊系统。 我将讨论调试特殊系统,例如大规模调试,并行系统调试等。
  • All About Debugging: Advanced Approaches. I will discuss unanswered questions about debuggers, visual debuggers, and the latest debugging research.

    有关调试的所有信息:高级方法。 我将讨论有关调试器,可视调试器和最新调试研究的未解答问题。

翻译自: https://medium.com/better-programming/all-about-debugging-the-techniques-920b06d61a9e

gdb所有调试技术

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值