gdb exe control

Finish And Until
    'finish' lets the current function execute until it finishes.
    'until <source line> makes gdb continue program execution until the given line is reached.
    Note: 'until' can only be executed if the program already

return
    Sometimes we want a function to terminate prematurely during a debugging session.
    For example:
            A function computes a variable's value wrongly.
            We found this, but still want to debug the rest of the program.
            we can force the function to return immediately with the correct value:
    return 59

 

Conditional Break-Points

    Let us suppose we have a long loop, and we want to start debugging only at the 503rd iteration.
    We do this using conditional break-points:

    Breakpoint 1, func_long_calc (i=5000) at c1.c:5
    5        int j = 5;
    (gdb) list 8,10
    8        for (plastic = 0; plastic < i; ++plastic) {
    9            j += plastic;
    10        }
    (gdb) break 9 if plastic == 503
    Breakpoint 4 at 0x804835a: file c1.c, line 9.
    (gdb) cont
    Continuing.

    Breakpoint 4, func_long_calc (i=5000) at c1.c:9
    9            j += plastic;
    (gdb) print plastic
    $1 = 503

 

Other Break-Point Commands

  表达式匹配断点
    'rbreak <regular expression>' sets break-points for all functions whose name matches the regular expression.
    'disable <number>' disables (but does not delete) the given break-point.
    'enable <number>' re-enables the given (previously disabled) break-point.

  临时断点
    'tbreak' sets a temporary break-point - once it is hit, it is deleted.

 

监测点
Watch-Points
    定义
    A watch-point makes the program stop when an expression is true, regardless of the function in which it happens.
        例1
    A basic example: 'watch a == 1' makes the program stop when variable 'a' has the value... '1'.
        例2
    Checking when my memory gets over-written with a zero byte:
    watch *(char*)0x65476 == 0
    查看
    Watch-points and other break-points are all seen using 'info break' or 'info watch'.
        删除
    use 'delete <watch-point number>' to delete a watch-point, just like with a break-point.

 

Hardware Vs. Software Watch-Points
    By default, gdb attempts to use hardware-assisted break-points.
    These get processed using the hardware, and have a lesser impact on program speed...
    ...relative to software watch-points.
    There are a few other caveats to watch-points regarding multi-threaded programs - we'll see them later.

 

I Want To Do This - Again!
    You can ask gdb to save a "checkpoint": (恢复点)
    checkpoint

reference: http://www.haifux.org/lectures/210/index.html

more time!



    After stepping forward and finding you've gone further then you wanted, switch back to the checkpoint:
    restart <checkpoint id>    (返回恢复点)

    To see the list of active check-points:
    info checkpoints (查看恢复点)

    What a checkpoint does: forks off a copy of the program, so gdb will be able to switch back to it later on.
    To delete checkpoints:
    delete checkpoint <checkpoint id> (删除恢复点)

posted on 2013-07-30 10:23  kwingmei  阅读(295)  评论(0编辑  收藏  举报

导航