The GDB debugging tool for Linux Learning

Source: Internet
Author: User

GDB1.GDB Introduction

This chapter introduces a very powerful debugging tool gdb , you can completely control the operation of the program, so that the program is like a toy in your hand, let it go, call it to stop, and at any time can view all the internal state of the program, such as the values of the variables, The arguments passed to the function, the line of code currently executing, and so on.

With GDB, even if the debugging means enriched, the basic idea of debugging is still "analysis of the phenomenon------------ hypothesis error causes new phenomena to verify the hypothesis " such a cycle, based on how the phenomenon assumes the cause of the error, and how to design new phenomena to verify the hypothesis, This requires very rigorous analysis and thinking, if you have a powerful tool in the hands of abuse and neglect of the analysis process, often will not cure the local bug, resulting in a wrong phenomenon disappears but the bug still exists, even the more the program is wrong

Common commands for 2.gdb
    • Help (h) ——— List command classes by module
    • Help class--view specific commands for a particular type
    • List (l) ——— View Code, can follow line number and function name
    • Quit (q) ——— exit GDB
    • Run (R) ———-running the program at full speed
    • Start ——— – step through, run the program, stop at the first line to execute the statement
    • Next (N) ——— step over process
    • Step (s) executes ———-by-statement, encounters a function, jumps inside a function
    • BackTrace (BT) – View stack frames and hierarchical relationships for function calls
    • info (i) ——— view the value of the local variable inside GDB, info breakpoints the stack frame of the toggle function.
    • Finish ———-end the current function and return to the function call point
    • Set ————-sets the value of a variable set var n = 100
    • Run argv[1] argv[2]– command-line arguments when debugging
    • Print (p)--– printing variables and addresses
    • Break (b)--– set breakpoints, which can be based on line number and function name
    • Delete (d) ——-Remove breakpoint D breakpoints NUM
    • Display ——— setting watch variables
    • Undisplay ——-Canceling observation variables
    • Continue (c) – Continue running the remaining code at full speed
    • Enable breakpoints ——-enabling breakpoints
    • Disable Breakpoints ——-disabling breakpoints
    • X ————— – View memory X/20xw display 20 units, 16 binary, 4 bytes per unit
    • Watch ———— The variable that is set to the observer is changed, the printed display

    • I watch ———-show observation points

    • Core file ——— ulimit-c 1024 to open the core file, while debugging GDB a.out core
3.gdb Debug Mode
    • Run running at full speed
    • Start single-Step commissioning
    • Set Follow-fork-mode Child#makefile project management. Sets the tracking mode to track parent or child processes.

The GDB debugging tool for Linux Learning

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.