zoukankan      html  css  js  c++  java
  • gdb常用命令

    1. GDB Tutorial

        (1). 编译时加 -g 选项生成gdb所需的调试信息:

            gcc [other flags] -g <source files> -o <output file>

        (2). 显示代码信息

    $gdb program
    (gdb) list                        #向后显示源码信息
    (gdb) list -                      #向前显示源码信息
    (gdb) set listsize                #设置一次显示源代码的行数
    (gdb) show listsize               #显示一次显示源代码的行数

        (3). gdb 常用命令

    $gdb program  
    (gdb) dir code_directory        #open a directory to load code
    (gdb) b file1.c:6 if i>=5       #set a conditional breakpoint
    (gdb) dis 1                     #disable a specified breakpoint
    (gdb) en  1                     #enable a specified breakpoint
    (gdb) del 1                     #delete a specified breakpoint
    (gdb) n                         #next
    (gdb) s                         #step
    (gdb) bt                        #backtrace - produces a stack trace
    (gdb) watch var                 #watch variable
    (gdb) info b                    #shows information about all declared breakpoints
    (gdb) print s.var               #see a particular field “var” of a object “s”
    (gdb) printf “run1,run2=[%d,%d)
    ", rule->numRun1, rule->numRun2
    (gdb) focus src                 #focus set to SRC window.
    (gdb) focus cmd                 #focus set to CMD window.
    (gdb) define pc                 #define a gdb command.
    > p var1
    > p var2
    > end
    (gdb) p array[10]@100           #print 100 element starting from index 10.
    (gdb) dir /path/of/your/code
    (gdb) set var=n    #set the value of var
    (gdb) dump mem data.txt str_array[0] str_array[1000]
    (gdb) attach pid   #attach to a program after starting gdb
    (gdb) …...

        (4). ~/.gdbinit: gdb启动时会自动加载的配置脚本文件. 示例:

    set print pretty on
    set print elements 200
    set breakpoint pending on
    winheight CMD +20
    focus cmd
    
    define pxy
        printf "index=%d xy=%f %f 
    ", index, x, y
        p $arg0 * x
        p $arg1 * y
    end
    
    b test.cc:125

    (5)堆栈的调试 

    $gdb program
    (gdb) bt -3                     #打印栈底下3层的栈信息
    (gdb) f 0                       #查看栈顶信息
    (gdb) down n                    #向栈顶移动n层
    (gdb) up n                      #向栈低移动n层
    (gdb) info f                    #查看当前栈层信息
    (gdb) info args                 #查看当前栈层参数信息
    (gdb) info locals               #查看当前栈层局部变量信息

    2 打印容器:.gdbinit中添加

    python
    import sys 
    sys.path.insert(0, '/usr/share/gcc-4.8.5/python')
    from libstdcxx.v6.printers import register_libstdcxx_printers
    register_libstdcxx_printers (None)
    end
  • 相关阅读:
    百度云推送
    web请求报出 “超过了最大请求长度” 【注意:重启IIS】
    页面多个Jquery版本共存的冲突问题,解决方法!
    Web Api 中使用 PCM TO WAV 的语音操作
    Web Api 如何做上传文件的单元测试
    那些年收集的前端学习资源
    原创: 做一款属于自己风格的音乐播放器 (HTML5的Audio新特性)
    Web Api 接口文档制作
    如何在Asp.Net WebApi接口中,验证请求参数中是否携带token标识!
    JavaScript 面试题,给大家补补基础,加加油,埋埋坑!
  • 原文地址:https://www.cnblogs.com/yyqng/p/14696329.html
Copyright © 2011-2022 走看看