您的位置:首页 > 其它

LLDB之理解LLDB基本命令语法

2016-07-23 12:54 453 查看
    与LLDB进行交互就是在调试区域部分输入相应的命令,每一个LLDB命令都包含着0个或者多个子命令,并且可能具有一个或者多个可选的参数,就像下面一样:

<command> [<subcommand> [<subcommand>...]] <action> [-options [option-value]] [argument [argument...]]

<command>(命令)和<subcommand>(子命令):LLDB调试命令的名称,命令和子命令按层级结构来排列:一个命令对象为跟随其的子命令对象创建一个上下文,子命令又为其子命令创建一个上下文,依此类推。
<action>:在上下文中执行命令的操作
<options>:命令选项,动作的修改者
<arguement>:命令的参数,
根据使用的命令的上下文来表示各种不同的东西
[]:表示命令是可选的,可以有也可以没有

注意:
LLBD命令行的解析操作在执行命令之前完成。上面的这些元素之间通过空格来分割,如果某一元素自身含有空格,则可以使用双引用。而如果元素中又包含双引号,则可以使用反斜杠;或者元素使用单引号。在LLDB中单引号和双引号是等价的,例如:
        (lldb) command [subcommand] -option
"some \"quoted\" string"
        can also be written:
        (lldb) command [subcommand] -option
'some "quoted" string'

举个例子,假设我们给testPerson方法设置一个断点,我们使用下面的命令:
       
breakpoint set -n
testPerson
这个命令对应到上面的语法就是:

command: breakpoint
表示断点命令
action: set
表示设置断点
option: -n表示根据方法name设置断点
arguement: testPerson
表示方法名为testPerson

[b]子命令[/b](Subcommands)

子命令是组织相关操作的分隔标识。一个命令的最终子命令将是一个动词表面将要执行的动作。例如:管理断点的命令由breakpoint开始,然后执行相应命令,breakpoint
list和breakpoint disable,表示列举所有断点和使断点失效,最后一个词义标识很清楚。

参数(Arguments)

一个命令可能要求一个或者多个参数,参数是动作执行的分隔标识。例如:breakpoint disable是要求给与一个参数指明具体失效的断点,向:
breakpoint disable 1,使断点ID为1的断点失效。
   
[b]命令选项[/b](Options)

一个命令当中可能包含一个或者多个命令选项,命令选项使用双虚线(--)开始用于不同的组合来修改执行的动作。有一些命令也使用了单虚线
(-)开始进行操作.例如:当我们需要设置一个断点,在第一次触发的时候删除,可以使用命令为breakpoint
set --one-shot 或者  breakpoint set -o.-o是--one-shot的缩写,所有前后功能是一样的。我们可以在触发断点之后,在console中输入
help br set,我们将可以看到命令功能:
-o ( --one-shot )  The breakpoint
is deleted
the first time
it causes a stop.

[b]命令的格式[/b](Command Forms)

LLDB命令是可以以许多格式显示的,例如:下面3种格式所执行的功能是一样的,都表示打印变量someVariable。

Canonical form(标准样式)   expression --object-description -- someVariable

Abbreviated form(缩写样式) e -O -- someVariable

Alias(别名样式)            po someVariable

上面e就是expression的缩写,-O就是--object-description的缩写,别名就是使用另外名称替代原有功能,这个在console中可以通过help
command alias得到对应的帮助信息。在开发中我们经常使用缩写和别名进行操作,方便,快捷。

[b]学会使用help命令[/b]

LLDB为我们提供了大量的文档,在调试的时候,我们经常可以通过help得到帮助信息,比如:

1:直接输入help,可以得到大量的命令信息

(lldb) help

Debugger commands:

apropos           -- Find a list of debugger commands related to a particular

word/subject.

breakpoint        -- A set of commands
for operating on breakpoints. Also see

_regexp-break.

bugreport         --
Set of commands
for creating domain specific bugreports.

command           -- A set of commands
for managing or customizing the

debugger commands.
....

....

....

For more information on any command, type
'help <command-name>'.

2:对于如何使用对应的子命令,都会有相应的提示,根据提示操作即可,例如:我们想了解与断点相关的信息,就可以help breakpoint,我们将可以看到所有与断点相关的信息。

(lldb) help breakpoint

The following subcommands are supported:

clear   -- Clears a breakpoint or set of breakpoints
in the executable.

command -- A set of commands
for adding, removing and examining bits of

code to be executed when the breakpoint
is hit (breakpoint
'commands').

delete  -- Delete the specified breakpoint(s).  If no breakpoints are

specified, delete them all.

disable -- Disable the specified breakpoint(s) without removing 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    -- A set of 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>'.

3:
同理如果想知道操作断点的具体命令,例如:如何显示当前所有断点,由上可知list是我们需要的指令:


(lldb) help br list
       List some or all breakpoints at configurable levels of detail.

Syntax: breakpoint list <cmd-options> [<breakpt-id>]

Command Options Usage:

  breakpoint list [-Dbi] [<breakpt-id>]
  breakpoint list [-Dfi] [<breakpt-id>]
  breakpoint list [-Div] [<breakpt-id>]
  ...
  This command takes options and free-form arguments.  If your arguments
  resemble option specifiers (i.e., they start with a - or --), you must use
  ' -- ' between the end of the command options and the beginning of the arguments.

这里提供了我们操作的语法和指令,可以由帮助信息进行相应操作:

(lldb) br list
Current breakpoints:

1: file = '/Users/longshihua/Desktop/LLDB调试技巧学习/LLDB调试技巧学习/ViewController.swift', line
= 29, exact_match = 0, locations = 1, resolved = 1, hit count = 1

  1.1: where = LLDB调试技巧学习`LLDB调试技巧学习.ViewController.testPerson
() -> () + 207 at ViewController.swift:30, address = 0x000000010e0b916f, resolved, hit count = 1  
...
...
...

4:尽可能多的使用缩写和别名,方便操作,输入(lldb) help,我们在底部可以看到如下信息:

Current command abbreviations (type 'help command alias' for more info):

  add-dsym  -- ('target symbols add')  Add a debug symbol file to one of the

               target's current modules by specifying a path to a debug symbols

               file, or using the options to specify a module to download

               symbols for.

  attach    -- ('_regexp-attach')  Attach to a process id if in decimal,

               otherwise treat the argument as a process name to attach to.

  b         -- ('_regexp-break')  Set a breakpoint using a regular expression

               to specify the location, where <linenum> is in decimal and

               <address> is in hex.

  bt        -- ('_regexp-bt')  Show a backtrace.  An optional argument is

               accepted; if that argument is a number, it specifies the number

               of frames to display.  If that argument is 'all', full
               backtraces of all threads are displayed.

...
...

...

For more information on any command, type 'help <command-name>'.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: