GDB basic commands-from opening the file to debugging

Source: Internet
Author: User

GDB basic commands-from opening the file to debugging

 

  • Prerequisites
    1 gcc-g-o: Compile the original file into a target file that can be debugged by GDB.
    2 GDB open the target file to be debugged
    3 set ARGs Parameters
    Or run.
    4. See parameters for show args.
    5 show environment view environment
    5 unset env clear all environment variables
    6 set environment to set an environment variable var1
    Set/delete breakpoints
    1 info sources or list to view the file. Otherwise, you do not know where to set the breakpoint.
    2. view the breakpoint info breakpoints
    3 break
    4 tbreak: sets a temporary breakpoint and is automatically deleted upon arrival
    5 enable
    Enable Delete
    Enable once
    6 disable
    7 delete breakpoints delete a breakpoint
    Or delete all breakpoints by using delete without adding all parameters.
    -> Breakpoint advanced
    1 break test. C: 5 set the breakpoint to the specified file
    2. Break is paused at a certain position in the memory.
    3 break if to set the condition breakpoint
    4 condition attach conditions to an existing breakpoint
    5. The command can be set at the nth disconnection point.
    Start debugging
    0. Run the program.
    1 step or s single step execution
    2 next or N non-entry single-step execution, that is, when other functions are called, they do not enter the function.
    3 finish until the function returns
    4 until run to a certain row of the Function
    5. Execute continue or cont until the next breakpoint or program ends.
    6 RETURN modify the program process, directly end the current function, and return the specified value
    Set Variables
    Set
    1 set I = 5 modify the value of a variable in the program
    2 set $ I = 5 to set a variable in the PDB environment. This variable is independent from the program, that is, only GDB knows
    Get program information
    1. Monitoring Variables
    Print/FMT print information
    FMT Format:
    ------------------------------
    X hexadecimal
    ------------------------------
    D decimal
    ------------------------------
    U unsigned count
    ------------------------------
    O octal
    ------------------------------
    T binary
    ------------------------------
    A hexadecimal print
    ------------------------------
    C character format
    ------------------------------
    F floating point number
    ------------------------------
    2. Tracking Variables
    Watch trail assigned action eg. I = 4;
    Rwatch follows the read Action eg. B = I;
    Awatch tracks all actions
    Del watchpoint.
    Info display
    Display
    Show display
    Del display
    3 monitoring memory
    X/
    Address can be a memory address or pointer, such as 0x8799f000, P, & VaR
    FMT consists of three parts: NFU. N indicates the length to be viewed. U indicates the format, which is divided into bhwg, indicating byte, half word, word, and double word respectively.
    .
    Eg.
    (GDB) x argv [0]
    0xbfffff61: 0x6d6f682f
    (GDB) x/10cb argv [0]
    0xbfffff61: 47 '/'000000' H '000000' 104 'M' 111 'E' 47'/'67 'C' 109 'H'
    0xbfffff69: 97 'A' 114 'R'
    (GDB) X/10 TB
    12
    0 x bfffff6b: 01101100 01100101 01110011 00101111
    01110111 01101111 01110010 01101011
    0xbfff73: 01110000 01101100
    (GDB) x/10th
    0xbfffff7f:
    0110101101101111 0111010000101111 0110000100000000
    01100010000000110001100000000 0110010000000000 0110010100000000 0110011000000000
    0xbfffff8f: 0110011100000000 0101011000000000
    (GDB)
    4. view the total frame information
    Backtrace or BT
    Note: frame is the stack generated when a function is called. It stores information about the function being called.
    5. Select the frame to be viewed.
    Frame
  • 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.