第二章:Help 和 Apropos

2018-01-24  本文已影响0人  KarenLoo

就像其他大型开发者工具一样,LLDB 提供了大量的文档。 知道如何浏览这个文档 —— 包括一些比较晦涩的命令标志 —— 对于掌握 LLDB 是非常重要的。

“help”命令

打开终端窗口并输入 lldb。 LLDB 提示符将出现。 然后只需输入 help 命令:

(lldb) help

这将显示出所有可用的命令,包括从 ~/.lldbinit 中加载的自定义命令 —— 稍后会更多。

Help & Apropos-1.png

LLDB 可以使用相当多的命令。

但是,许多命令有大量子命令,而子命令又有子命令,这些命令也有自己的相关文档。 我告诉过你这是一个庞大的文件量!

以 breakpoint 命令为例。 通过输入以下内容运行 breakpoint 文档:

(lldb) help breakpoint

你会看到下面的输出:

 Commands for operating on breakpoints (see 'help b' for shorthand.)

Syntax: breakpoint

The following subcommands are supported:

  clear   -- Delete or disable breakpoints matching the specified
             source file and line.
  command -- Commands for adding, removing and listing LLDB commands
             executed when a breakpoint is hit.
  delete  -- Delete the specified breakpoint(s).  If no breakpoints are
             specified, delete them all.
  disable -- Disable the specified breakpoint(s) without deleting them.
             If none are specified, disable all breakpoints.
  enable  -- Enable the specified disabled breakpoint(s). If no
             breakpoints are specified, enable all of them.
  list    -- List some or all breakpoints at configurable levels of
             detail.
  modify  -- Modify the options on a breakpoint or set of breakpoints
             in the executable.  If no breakpoint is specified, acts on
             the last created breakpoint.  With the exception of -e, -d
             and -i, passing an empty argument clears the modification.
  name    -- Commands to manage name tags for breakpoints
  read    -- Read and set the breakpoints previously saved to a file
             with "breakpoint write".
  set     -- Sets a breakpoint or set of breakpoints in the executable.
  write   -- Write the breakpoints listed to a file that can be read in
             with "breakpoint read".  If given no arguments, writes all
             breakpoints.

For more help on any particular subcommand, type 'help <command> <subcommand>'.

你可以在这里看到几个支持的子命令。 通过输入以下内容查找 breakpoint name 的文档:

(lldb) help breakpoint name

你会看到下面的输出:

   Commands to manage name tags for breakpoints

Syntax: breakpoint name

The following subcommands are supported:

      add    -- Add a name to the breakpoints provided.
      delete -- Delete a name from the breakpoints provided.
      list   -- List either the names for a breakpoint or the breakpoints for a given name.

For more help on any particular subcommand, type 'help <command> <subcommand>'.

如果你目前不了解 breakpoint name,不要担心 —— 你很快就会熟悉断点和所有其子命令。 现在,help 命令是你要记住的最重要的命令。

“apropos”命令

有时你不知道你正在搜索的命令的名字,但你知道某个单词或短语可能会指引你正确的方向。 apropos 命令可以为你做这个,这有点像使用搜索引擎在网上找东西。

apropos 将根据 LLDB 文档对任何单词或字符串进行不区分大小写的搜索,并返回匹配的结果。 例如,尝试搜索有关 Swift 的任何内容:

(lldb) apropos swift

你会看到下面的输出:

The following commands may relate to 'swift':
  swift    -- A set of commands for operating on the Swift Language Runtime.
  demangle -- Demangle a Swift mangled name
  refcount -- Inspect the reference count data for a Swift object

The following settings variables may relate to 'swift':


  target.swift-framework-search-paths -- List of directories to be searched when locating frameworks for Swift.
  target.swift-module-search-paths -- List of directories to be searched when locating modules for Swift.
  target.use-all-compiler-flags -- Try to use compiler flags for all modules when setting up the Swift expression parser, not just the main executable.

这显示了与 Swift 这个单词有关的所有内容:首先是命令,然后是 LLDB 设置,这些设置可以用来控制 LLDB 的运行方式。

你也可以使用 apropos 来搜索特定的句子。 例如,如果你正在寻找引用计数的相关内容,则可以尝试以下操作:

(lldb) apropos "reference count"
The following commands may relate to 'reference count':
  refcount -- Inspect the reference count data for a Swift object

注意包裹“reference count”的引号。 apropos 只接受一个参数来搜索,所以引号是必要的,把输入作为一个单一的参数。

灵活吧?apropos 是一个方便查询的工具。 它不像现代的互联网搜索引擎那么复杂,不过,你尝试几次,通常能找到你要找的内容。

接下来?

很容易忘记即将到来的大量 LLDB 命令的猛攻,但尽量把 help 和 apropos 这两个命令记在心里。 它们是查询命令信息的基础,而且在你掌握调试的时候,你会一直使用它们。

上一篇 下一篇

猜你喜欢

热点阅读