美文网首页
开始学习LLDB命令(第二章:Help & Apropo

开始学习LLDB命令(第二章:Help & Apropo

作者: 股金杂谈 | 来源:发表于2017-05-21 19:20 被阅读129次

    跟其他的开发工具一样,LLDB也有大量健全的文档.知道如何通过一些比较模糊的命令标志在这些文档中导航, 是掌握LLDB必不可少的技能.
    LLDB官方文档

    help 命令

    打开一个终端窗口键入lldb. LLDB会迅速出来.在那里简单的键入help命令:

    (lldb) help
    

    这将会显示出所有可以用的命令, 包括从~/.lldbinit加载出来的自定义的命令, 但是可能晚一点显示出来

    page32image6336.png

    这里有相当多的LLDB命令可以用.
    然而, 许多命令包含着几个子命令, 这些子命令又有自己相关的文档.
    breakpoint命令为例. 通过键入下面的指令来查看breakpoint命令的文档:

    (lldb) help breakpoint
    

    你会看到下面这些输出:

    Commands for operating on breakpoints (see 'help b' for shorthand.)
    Syntax: breakpoint <subcommand> [<command-options>]
    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
          set     -- Sets a breakpoint or set of breakpoints in the
    executable.
    For more help on any particular subcommand, type 'help <command>
    <subcommand>'.
    

    在这里你可以看到几个支持的子命令. 要查看breakpoint name命令的文档, 可以输入下面的内容:

    (lldb) help 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, 别担心你将很快就会理解breakpoints和后面所有的命令.从现在开始, help是你要记住的最重要的命令.

    apropos命令

    有时你并不知道你要搜索的命令的名字, 但是你知道它包含的关键词或者短语可以给你指出正确的方向.apropos就是为你做这件事的. 这有点像在web上用搜索引擎找东西.
    apropos是不区分大小写的,并且将返回LLDB文档中匹配的任何结果.例如搜索任何与Swift有关内容:

    (lldb) apropos swift
    

    你将会看到下面这些输出:

    The following built-in commands may relate to 'swift':
      breakpoint set          -- Sets a breakpoint or set of breakpoints in
    the executable.
      expression              -- Evaluate an expression (ObjC++ or Swift) in
    the current program context, using user defined variables and variables
                                 currently in scope.
      language swift          -- A set of commands for operating on the Swift
    Language Runtime.
      language swift demangle -- Demangle a Swift mangled name
      language swift 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去搜索一个特定的句子.例如, 如果你要搜索与reference counting相关的内容, 你可以使用下面的命令:

    (lldb) apropos "reference count"
    The following built-in commands may relate to 'reference count':
      language swift refcount -- Inspect the reference count data for a Swift
    object
      target modules list     -- List current executable and dependent shared
    library images.
    

    注意爱用双引号包裹着单词"reference count",.apropos只会接收一个搜索的参数, 因此双引号可以让它们作为一个单独的参数是必要的.
    感觉不够整洁?apropos是一个用来查询的方便的工具.它不像现代互联网搜索引擎那么复杂, 然而在平常的练习中你可以找到你想要的.
    我们为什么要学这些?
    我们很容易就会忘记我们将要学习的大量的LLDB命令, 但是只要把helpapropos这两个命令记在心中.这些是查询命令信息的基础, 在调试只路上你会不停的用到他们.

    相关文章

      网友评论

          本文标题:开始学习LLDB命令(第二章:Help & Apropo

          本文链接:https://www.haomeiwen.com/subject/kszmxxtx.html