gdb命令小抄

来源:互联网 发布:淘宝淘口令在哪里 编辑:程序博客网 时间:2024/04/29 19:15
本文转自:http://blog.chinaunix.net/u/28499/showart_1154662.html
作者:gawk

在精华区看到gdb的文章,
http://www.chinaunix.net/index.p ... read.php?tid=150524
内容太多,我做了一个小抄
欢迎大家补充

1.按TAB键两次会将命令或者函数名补齐

2.设置断点
  break function
  break linenum
  break +offset  当前行号前offset行
  break -offset  当前行号后offset行
  break *address 运行内存地址处停止
  break          下一行
  break ... if condition ...可以是上述参数

3.设置观察点
  watch  expr     变量有变化停止
  rwatch expr     变量被读停止
  awatch expr     变量被读写时停止

4.设置捕捉点
  catch event
  event有如下:
  throw  catch  exec  fork vfork load unload

[Copy to clipboard] [ - ]
CODE:
Raised signals may be caught:
        catch signal              - all signals
        catch signal <signame>    - a particular signal
Raised exceptions may be caught:
        catch throw               - all exceptions, when thrown
        catch throw <exceptname>  - a particular exception, when thrown
        catch catch               - all exceptions, when caught
        catch catch <exceptname>  - a particular exception, when caught
Thread or process events may be caught:
        catch thread_start        - any threads, just after creation
        catch thread_exit         - any threads, just before expiration
        catch thread_join         - any threads, just after joins
Process events may be caught:
        catch start               - any processes, just after creation
        catch exit                - any processes, just before expiration
        catch fork                - calls to fork()
        catch vfork               - calls to vfork()
        catch exec                - calls to exec()
Dynamically-linked library events may be caught:
        catch load                - loads of any library
        catch load <libname>      - loads of a particular library
        catch unload              - unloads of any library
        catch unload <libname>    - unloads of a particular library
The act of your program's execution stopping may also be caught:
        catch stop
C++ exceptions may be caught:
        catch throw               - all exceptions, when thrown
        catch catch               - all exceptions, when caught

4.停止条件维护
  可以用condition命令来修改断点的条件,目前只有break watch支持if
  condition <bnum> <expression>
  condition <bnum> 清除停止条件

5.为停止点设定运行命令
  可以用commands命令来设置
  commands <bnum>
  .....
  end

6.其他有用的指令
  finish 运行程序,直到当前函数完成
  until或u运行程序直到退出循环体,用在for或者while上,比较方便
x命令增加如下

[Copy to clipboard] [ - ]
CODE:
Examine memory: x/FMT ADDRESS.
ADDRESS is an expression for the memory address to examine.
FMT is a repeat count followed by a format letter and a size letter.
Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),
  t(binary), f(float), a(address), i(instruction), c(char) and s(string).
Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).
The specified number of objects of the specified size are printed
according to the format.

Defaults for format and size letters are those previously used.
Default count is 1.  Default address is following last thing printed
with this command or "print".

-----------------------------------------------------------------------
参考资料:
gdb help
http://bbs.chinaunix.net/thread-150524-1-1.html