gdb

1. gcc ... -omain -g
    -g : The function and variable names will be saved.
2. start gdb
    gdb appName
    set args xxx xxx xxx
        Pass arguments to the app

3. l command:
    l : show source code, and type "enter" to continue show source code.
    show listsize : Number of source lines gdb will list by default is 10
    set listsize 20: set it 20
    l 5 : show line 5
    l insert_sort.c:5 : show line 5 of insert_sort.c
    l insert_sort.c:func : show the code of a func
    l main.c:main : show the code of a func
4. breakpoint operations:
    b 14 : set breakpoint in line 14
    b 17 : set breakpoint in line 17
    i b : show all the breakpoints
    d 1 : delete the first breakpoint
    d 2 3 : delete two breakpoints at the same time
    d 4-7 : delete breakpoints the fourth to seventh
    dis 2 : disable the second breakpoint
    ena 2 : enable the second breakpoint
    r : running
    p i : show the value of i
    b 17 if i==10 : set condition breakpoint
        set the breakpoint and it will be hit when i==10
5. debug operations
    r : run app and stop at the first breakpoint
    p i : show the value of i
    p array[i] : show value of the ith element
    ptype i : show the type of i
    n : go by one step
    display i : display i in every step
    i(info) display : show all display
    undisplay i(the ith one) : Contrary to the display
    step : get into a func
    finish : get out of a func,but you must delete all breakpoints in the func.
    c(continue) : continue to debug and stop at next breakpoint
5. other operations
    q(quit) : quit gdb
    set var i=5 : set the value of i
    until : Jump out of the loop,but you must delete all breakpoints in the loop
    start : run a line and then stop,used after starting gdb
    r : run to the first breakpoint and then stop
    
    
    
 

posted on 2018-09-17 06:42  langjitianyadaolao  阅读(90)  评论(0编辑  收藏  举报

导航