• GDB使用总结


    1. GDB概述

    GNU发布的调试器,可以查看程序如何运行或崩溃时的状态。

    主要功能:

    • 启动程序,可以按照自定义的要求运行程序。 
    • 可让被调试的程序在你所指定的断点处停住。
    • 当程序被停住时,可以检查此时程序中所发生的事。 
    • 动态的改变程序的执行环境。 

    GDB启动程序
    //通过GDB启动/attach一个可程序或打开一个core文件
    gdb [options] [executable-file [core-file or process-id]]
    //为可执行程序指定执行参数
    gdb [options] --args executable-file [inferior-arguments ...]
    //为GDB启动指定扩展脚本
    gdb [options] [--python|-P] script-file [script-arguments ...]

    其他启动参数:
    -tui Text User Interface
    -s file read symbol table from file
    --silent do not print version number

    GDB命令特点:
    命令别名
    自动完成(命令/符号名)
    帮助强大:
    help class
    help all
    help command

    2. 运行控制类命令:
    run(r)
    step(s) [count]
    next(n) [count]
    contine(c) [ignore-count]
    finish(fin)
    until(u) line
    skip file|func
    stepi(si)
    nexti(ni)
    多线程控制命令:
    info thread
    thread thread-id
    thread apply ID1 ID2 command
    thread apply all command 
    set scheduler-locking off|on|step 
    break location thread thread-id

    break location thread thread-id if ...

    3. 程序停止点

    3.1 断点
    break(b) [line]|[function][address]
    break(b) [line]|[function][address] if …
    condition break-num
    command break-num
    tbreak(tb) [line]|[function][address]
    rbreak(rb) regex
    info break [break-num]
    delete(d) break-num
    disable(dis) break-num [count]
    enable(ena) break-num
    ignore break-num count

    3.2 观察点

    watch [-l|-location] expr [thread thread-id]
    rwatch [-l|-location] expr [thread thread-id]
    awatch [-l|-location] expr [thread thread-id]
    info watchpoints
    delete(d) watch-num
    disable(dis) watch-num
    enable(ena) watch-num
    condition watch-num
    command watch-num
    3.3 扑捉点
    catch event [exception][exec][fork][syscall][signal][throw]
    tcatch event

    清除停止点 clear / delete
    保存停止点 save breakpoints [file]


    4. 状态查看类命令:
    list(l) /-tui(Ctrl+x+a切换)
    search/forward-search(fo)/reverse-search(rev)
    print(p) /format expr
    print(p) *array@len
    x/nfu addr
    set print pretty
    set print array on
    set print elements unlimited
    info [locals][variables][float][vtbl][registers]
    whatis / ptype
    display
    4.1 堆栈查看命令
    backtrace(bt)
    info frame(f)
    frame frame-num
    up [frame-num]
    down [frame-num]

    5. 改变程序运行类命令:
    set [var] expr
    jump location
    return [expression]
    call expression

    6.内存转储
    dump [format] memory filename start_addr end_addr 转储内存某地址范围内容到指定文件
    dump [format] value filename expr  转储变量值到指定文件
    append [binary] memory filename start_addr end_addr
    append [binary] value filename expr
    restore filename [binary] bias start end

    generate-core-file(gcore) [file]  生成core文件

  • 相关阅读:
    Win10或Win8下ObjectARX2015 Wizard向导创建项目失败解决方法
    对用友二次开发的初次认识
    我对asp.net管道模型的理解
    wblockCloneObjects 写块克隆的使用
    acedCommand 之使用镜像命令
    MFC之动态调用自己写的类库中的类的成员方法
    objectarx 天正的墙转梁线
    objectarx 之让用户自定义插件命令
    MFC之多字节和宽字节的总结
    MFC之使用blat发送邮件
  • 原文地址:https://www.cnblogs.com/bitkevin/p/6665085.html
Copyright © 2020-2023  润新知