lldb調試命令一

1.什麼是LLDB

         LLDB是英文Low Lever Debug的縮寫,是XCode內置的爲我們開發者提供的調試工具;方便開發者對開發問題進行快速有效的解決;

2.LLDB 斷點設置

新建一個Object-C工程,寫了下方代碼,給一個 OC 方法下斷點,運行工程,就可以進入LLDB調試環境


1、使用LLDB中“breakpoint set -n 函數名 ”下斷點


1.在lldb 中輸入給demo1方法下斷點

 breakpoint set -n demo1  
 
輸出:
​​​​Breakpoint 2: where = LLDB調試`-[ViewController demo1] at ViewController.m:27, address = 0x000000010d8e1be0

表示斷點下入成功

其中:

Breakpoint 2: 表示這是全局的第二個斷點
where = LLDB調試`-[ViewController demo1] at ViewController.m:27,:標示斷點位置和方法名稱
address = 0x000000010d8e1be0:斷點所表示的內存地址


2.給函數下斷點
breakpoint set -n "[ViewController douYinClick:]"
Breakpoint 3: where = LLDB調試`-[ViewController douYinClick:] at ViewController.m:34, address = 0x000000010d8e1c10

2、breakpoint set -l 行數 -f 文件名


輸入:
breakpoint set -l 23 -f ViewController.m
輸出:
Breakpoint 4: where = LLDB調試`-[ViewController touchesBegan:withEvent:] + 77 at ViewController.m:23:5, address = 0x000000010d8e1b8d

3.使用breakpoint set -a 16位的物理地址

這裏我們首先找到16爲物理地址,xcode工具欄Debug  ->Debug WorkFlow -> Alawys Show Disassembly進入棧調試找到物理地址0x10d8e1b97;

輸入:
breakpoint set -a 0x10d8e1b97
輸出:
Breakpoint 5: where = LLDB調試`-[ViewController touchesBegan:withEvent:] + 87 at ViewController.m:24:6, address = 0x000000010d8e1b97

4、使用函數全部名稱設置斷點

breakpoint set -F 函數全名

輸入:
breakpoint set -F kuaiShouClick:

5.使用函數局部名稱進行設置斷點

輸入:
 breakpoint set -r touchBegan
輸出:
Breakpoint 9: 5 locations.

這個說明是第9組下了斷點,共下了5處斷點,但是我們項目只有一個處實現了,說明給底層函數中也可以使用這種方式下斷點,我們可以使用 breakpoint list進行驗證

輸入:
breakpoint list
輸出:
Current breakpoints:
1: file = '/Users/a1/Desktop/GitHub/iOSLearn/LLDB/LLDB調試/LLDB調試/ViewController.m', line = 21, exact_match = 0, locations = 1, resolved = 1, hit count = 5

  1.1: where = LLDB調試`-[ViewController touchesBegan:withEvent:] at ViewController.m:21, address = 0x000000010d8e1b40, resolved, hit count = 5 

2: name = 'demo1', locations = 1, resolved = 1, hit count = 4
  2.1: where = LLDB調試`-[ViewController demo1] at ViewController.m:27, address = 0x000000010d8e1be0, resolved, hit count = 4 

3: names = {'[ViewController douYinClick:]', '[ViewController douYinClick:]'}, locations = 1, resolved = 1, hit count = 0
  3.1: where = LLDB調試`-[ViewController douYinClick:] at ViewController.m:34, address = 0x000000010d8e1c10, resolved, hit count = 0 

4: file = 'ViewController.m', line = 23, exact_match = 0, locations = 1, resolved = 1, hit count = 3
  4.1: where = LLDB調試`-[ViewController touchesBegan:withEvent:] + 77 at ViewController.m:23:5, address = 0x000000010d8e1b8d, resolved, hit count = 3 

5: address = LLDB調試[0x0000000100001b97], locations = 1, resolved = 1, hit count = 3
  5.1: where = LLDB調試`-[ViewController touchesBegan:withEvent:] + 87 at ViewController.m:24:6, address = 0x000000010d8e1b97, resolved, hit count = 3 

6: name = 'kuaiShouClick', locations = 0 (pending)

7: name = 'kuaiShouClick', locations = 0 (pending)

8: name = 'kuaiShouClick:', locations = 1, resolved = 1, hit count = 0
  8.1: where = LLDB調試`-[ViewController kuaiShouClick:] at ViewController.m:37, address = 0x000000010d8e1c60, resolved, hit count = 0 

9: regex = 'touchBegan', locations = 5, resolved = 5, hit count = 0
  9.1: where = UIKitCore`-[_UIFocusFastScrollingRecognizer focusEnginePanGesture:touchBeganAtDigitizerLocation:], address = 0x00007fff47371559, resolved, hit count = 0 
  9.2: where = UIKitCore`-[UIKeyboardMenuView showAsHUDFromLocation:withInputView:touchBegan:], address = 0x00007fff4750b652, resolved, hit count = 0 
  9.3: where = UIKitCore`-[_UITextDocumentInterface _setInputModeList:touchBegan:fromLocation:updatePoint:], address = 0x00007fff47518923, resolved, hit count = 0 
  9.4: where = UIKitCore`-[_UIInputViewControllerOutput setInputModeList:touchBegan:fromLocation:updatePoint:], address = 0x00007fff475196ce, resolved, hit count = 0 
  9.5: where = MapKit`-[MKActionRowItemView _touchBegan], address = 0x00007fff2768f2d6, resolved, hit count = 0 

這裏我們可以看到第九組共有5出斷點,都是底層使用的方法,並且都包含touchBegan 字段方法名稱

3.LLDB斷點配置

    其實斷點配置還有很多,這裏只是簡單的列舉幾個:

  • -i <count> (--ignore -count <count>)
輸入:
breakpoint set -F wangZheClick: -i 3
  • -o <boolean>只斷住一次
輸入:
 breakpoint set -F wangZheClick: -o yes
  • -N 給斷點添加別名

輸入:
breakpoint set -F douYinClick: -N douyinBreakPoint
輸出:
Current breakpoints:
1: file = '/Users/a1/Desktop/GitHub/iOSLearn/LLDB/LLDB調試/LLDB調試/ViewController.m', line = 21, exact_match = 0, locations = 1, resolved = 1, hit count = 2

  1.1: where = LLDB調試`-[ViewController touchesBegan:withEvent:] at ViewController.m:21, address = 0x0000000105105b40, resolved, hit count = 2 

3: name = 'douYinClick:', locations = 1, resolved = 1, hit count = 0
  Names:
    douyinBreakPoint

  3.1: where = LLDB調試`-[ViewController douYinClick:] at ViewController.m:34, address = 0x0000000105105c10, resolved, hit count = 0 
  • -N 給斷點添加別名
輸入:
breakpoint set -n demo1 -c "i==10"

4.斷點的禁用與啓用和刪除

  • 查看斷點列表:breakpoint list 
輸入:
breakpoint list 
輸出:
Current breakpoints:
1: file = '/Users/a1/Desktop/GitHub/iOSLearn/LLDB/LLDB調試/LLDB調試/ViewController.m', line = 21, exact_match = 0, locations = 1, resolved = 1, hit count = 6

  1.1: where = LLDB調試`-[ViewController touchesBegan:withEvent:] at ViewController.m:21, address = 0x00000001094e2b30, resolved, hit count = 6 

2: name = 'demo1', locations = 1, resolved = 1, hit count = 5
Condition: i==10

  2.1: where = LLDB調試`-[ViewController demo1] at ViewController.m:29, address = 0x00000001094e2be0, resolved, hit count = 5 
  • 禁用第二組斷點
輸入:
breakpoint disable 2
輸出:
1 breakpoints disabled.
查看下斷點列表,說明第二組斷點還在裏面,只是沒有啓用
Current breakpoints:
1: file = '/Users/a1/Desktop/GitHub/iOSLearn/LLDB/LLDB調試/LLDB調試/ViewController.m', line = 21, exact_match = 0, locations = 1, resolved = 1, hit count = 8

  1.1: where = LLDB調試`-[ViewController touchesBegan:withEvent:] at ViewController.m:21, address = 0x00000001094e2b30, resolved, hit count = 8 

2: name = 'demo1', locations = 1 Options: disabled 
Condition: i==10

  2.1: where = LLDB調試`-[ViewController demo1] at ViewController.m:29, address = 0x00000001094e2be0, unresolved, hit count = 5 
  • 啓用第二組斷點
輸入:
breakpoint enable 2

注意:我在這裏操作的時候都是以組爲單位進行禁用斷點和啓用斷點,因爲一般情況下我們下斷點一組都是隻有一個斷點;
如果是如下情況,我們使用:breakpoint set -r touchBegan,下斷點後,共5處斷點

breakpoint list
Current breakpoints:
1: file = '/Users/a1/Desktop/GitHub/iOSLearn/LLDB/LLDB調試/LLDB調試/ViewController.m', line = 21, exact_match = 0, locations = 1, resolved = 1, hit count = 8

  1.1: where = LLDB調試`-[ViewController touchesBegan:withEvent:] at ViewController.m:21, address = 0x00000001094e2b30, resolved, hit count = 8 

2: name = 'demo1', locations = 1, resolved = 1, hit count = 5
Condition: i==10

  2.1: where = LLDB調試`-[ViewController demo1] at ViewController.m:29, address = 0x00000001094e2be0, resolved, hit count = 5 

3: regex = 'touchBegan', locations = 5, resolved = 5, hit count = 0
  3.1: where = UIKitCore`-[_UIFocusFastScrollingRecognizer focusEnginePanGesture:touchBeganAtDigitizerLocation:], address = 0x00007fff47371559, resolved, hit count = 0 
  3.2: where = UIKitCore`-[UIKeyboardMenuView showAsHUDFromLocation:withInputView:touchBegan:], address = 0x00007fff4750b652, resolved, hit count = 0 
  3.3: where = UIKitCore`-[_UITextDocumentInterface _setInputModeList:touchBegan:fromLocation:updatePoint:], address = 0x00007fff47518923, resolved, hit count = 0 
  3.4: where = UIKitCore`-[_UIInputViewControllerOutput setInputModeList:touchBegan:fromLocation:updatePoint:], address = 0x00007fff475196ce, resolved, hit count = 0 
  3.5: where = MapKit`-[MKActionRowItemView _touchBegan], address = 0x00007fff2768f2d6, resolved, hit count = 0 

我們只想給其中某一個方法下,可以找到它的編號:例如給[UIKeyboardMenuView showAsHUDFromLocation:withInputView:touchBegan:]這個方法下斷點;

禁用輸入:
breakpoint disable 3.3
啓用輸入:
breakpoint enable 3.3
  • 刪除斷點

        1.刪除所有斷點

輸入:
breakpoint delete
輸出:
About to delete all breakpoints, do you want to do that?: [Y/n] 
詢問是否刪除 Y
All breakpoints removed. (2 breakpoints)

查看breakpoint list
輸出:No breakpoints currently set.



        2.刪除組斷點

輸入:
breakpoint delete 2
輸出:
1 breakpoints deleted; 0 breakpoint locations disabled.

查看breakpoint list

Current breakpoints:
1: file = '/Users/a1/Desktop/GitHub/iOSLearn/LLDB/LLDB調試/LLDB調試/ViewController.m', line = 21, exact_match = 0, locations = 1, resolved = 1, hit count = 8

  1.1: where = LLDB調試`-[ViewController touchesBegan:withEvent:] at ViewController.m:21, address = 0x00000001094e2b30, resolved, hit count = 8 

3: regex = 'touchBegan', locations = 5, resolved = 5, hit count = 0
  3.1: where = UIKitCore`-[_UIFocusFastScrollingRecognizer focusEnginePanGesture:touchBeganAtDigitizerLocation:], address = 0x00007fff47371559, resolved, hit count = 0 
  3.2: where = UIKitCore`-[UIKeyboardMenuView showAsHUDFromLocation:withInputView:touchBegan:], address = 0x00007fff4750b652, resolved, hit count = 0 
  3.3: where = UIKitCore`-[_UITextDocumentInterface _setInputModeList:touchBegan:fromLocation:updatePoint:], address = 0x00007fff47518923, resolved, hit count = 0 
  3.4: where = UIKitCore`-[_UIInputViewControllerOutput setInputModeList:touchBegan:fromLocation:updatePoint:], address = 0x00007fff475196ce, resolved, hit count = 0 
  3.5: where = MapKit`-[MKActionRowItemView _touchBegan], address = 0x00007fff2768f2d6, resolved, hit count = 0 

       2.刪除組內斷點

輸入:
breakpoint delete 3.4
輸出:
0 breakpoints deleted; 1 breakpoint locations disabled.

查看Breakpoint list 
Current breakpoints:
1: file = '/Users/a1/Desktop/GitHub/iOSLearn/LLDB/LLDB調試/LLDB調試/ViewController.m', line = 21, exact_match = 0, locations = 1, resolved = 1, hit count = 8

  1.1: where = LLDB調試`-[ViewController touchesBegan:withEvent:] at ViewController.m:21, address = 0x00000001094e2b30, resolved, hit count = 8 

3: regex = 'touchBegan', locations = 5, resolved = 4, hit count = 0
  3.1: where = UIKitCore`-[_UIFocusFastScrollingRecognizer focusEnginePanGesture:touchBeganAtDigitizerLocation:], address = 0x00007fff47371559, resolved, hit count = 0 
  3.2: where = UIKitCore`-[UIKeyboardMenuView showAsHUDFromLocation:withInputView:touchBegan:], address = 0x00007fff4750b652, resolved, hit count = 0 
  3.3: where = UIKitCore`-[_UITextDocumentInterface _setInputModeList:touchBegan:fromLocation:updatePoint:], address = 0x00007fff47518923, resolved, hit count = 0 
  3.4: where = UIKitCore`-[_UIInputViewControllerOutput setInputModeList:touchBegan:fromLocation:updatePoint:], address = 0x00007fff475196ce, unresolved, hit count = 0  Options: disabled 
  3.5: where = MapKit`-[MKActionRowItemView _touchBegan], address = 0x00007fff2768f2d6, resolved, hit count = 0 

刪除組內斷點的時候,失敗了,查詢後發下組內斷點還是存在的,說明刪除斷點的時候只能按照組進行刪除,

5.查看 LLDB 的其他指令

  直接在LLDB 上 輸入 :help 就可以查看其他的指令了,這裏太多了,就不貼過來了;

    可以搜索部分比如:help breakpoint,就是查看 breakpoint下的所有指令。

輸入:
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
      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>'.

 6.斷點的簡寫

  b -f ViewController.m -r Clicked: 等同於:breakpoint set --file ViewController.m -r Clicked:

  • b :breakpoint set
  • -f--file
  • -n--name

 但是 breakpoint list 、breakpoint disable 等只能簡寫成 break libreak dis ,因爲簡寫的 b 後面默認會帶上 set 的。

這一篇文章主要描述一下LLDB中我們經常使用的斷點調試方式,下一篇文章講下LLDB的進階用法。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章