iOS開(kāi)發(fā)LLDB終端命令

Clang

Clang: a C language family frontend for LLVM
LLVM的C語(yǔ)言家族前端

英文版 中文版
clang編譯器提供的指令

編譯可執(zhí)行文件

clang HelloWorld.m -o HelloWorld -framework Foundation

將OC代碼轉(zhuǎn)換成C++代碼

將OC代碼轉(zhuǎn)換成C++代碼來(lái)剖析具體的底層實(shí)現(xiàn)直焙。

$ xcrun -sdk iphoneos clang -arch arm64 -rewrite-objc main.m -o main-arm64.cpp

上面命令將main.m文件轉(zhuǎn)換成iOS系統(tǒng)下64位架構(gòu)(以下討論均在64位架構(gòu)基礎(chǔ)上進(jìn)行)的C++代碼沽损。

xcrun 命令

xcode安裝的時(shí)候順帶安裝了xcrun命令,xcrun命令在clang的基礎(chǔ)上進(jìn)行了一些封裝换淆,要更好用一些。

##### 在模擬器下編譯
xcrun -sdk iphonesimulator clang -rewrite-objc main.m

#在真機(jī)下編譯
xcrun -sdk iphoneos clang -rewrite-objc main.m

Debugger commands

在xcode的console中輸入help可查看所有自帶命令

常用命令:

1. po

po --Evaluate an expression on the current thread. Displays any returned value with formatting controlled by the type's author.
在當(dāng)前線程上求一個(gè)表達(dá)式。顯示任何返回值,其格式由類(lèi)型的創(chuàng)作者控制

2. p & print

p -- Evaluate an expression on the current thread. Displays any returned value with LLDB's default formatting.
print -- Evaluate an expression on the current thread. Displays any returned value with LLDB's default formatting.
在當(dāng)前線程上求一個(gè)表達(dá)式簇爆。以LLDB的默認(rèn)格式顯示任何返回的值

p的隱藏功能

//默認(rèn)打印為10進(jìn)制
(lldb) p 100
(int) $8 = 100
//轉(zhuǎn)16進(jìn)制
(lldb) p/x 100
(int) $9 = 0x00000064
//轉(zhuǎn)8進(jìn)制
(lldb) p/o 100
(int) $10 = 0144
//轉(zhuǎn)二進(jìn)制
(lldb) p/t 100
(int) $2 = 0b00000000000000000000000001100100
//字符轉(zhuǎn)10進(jìn)制數(shù)字
(lldb) p/d 'A'
(char) $7 = 65
//10進(jìn)制數(shù)字轉(zhuǎn)字符
(lldb) p/c 66
(int) $10 = B\0\0\0
3. x

x -- Read from the memory of the current target process.
從當(dāng)前目標(biāo)進(jìn)程的內(nèi)存中讀取。

        GLPerson *p = [GLPerson alloc];
        p.height = 180;
        p.name = @"loong";
        p.char1 = 'g';
        p.char2 = 'n';
        p.weight = 150;
--- 上面是代碼
(lldb) x p
0x600003c5ff60: 18 17 3b 06 01 00 00 00 67 6e 00 00 b4 00 00 00  ..;.....gn......
0x600003c5ff70: 96 00 00 00 00 00 00 00 40 f0 3a 06 01 00 00 00  ........@.:.....
x打印內(nèi)存.png

幾組數(shù)據(jù)

  • 數(shù)字4代表輸出4組數(shù)據(jù)

輸出格式

  • x :代表16進(jìn)制
  • f :代表浮點(diǎn)數(shù)
  • d :代表10進(jìn)制

字節(jié)大小

  • b :byte 代表1個(gè)字節(jié)
  • h :half word 代表2個(gè)字節(jié)
  • w :word 代表4個(gè)字節(jié)
  • g :giant word 代表8個(gè)字節(jié)

4. bt

bt -- Show the current thread's call stack. Any numeric argument displays at most that many frames. The argument 'all' displays all threads.
顯示當(dāng)前線程的調(diào)用堆棧爽撒。任何數(shù)字參數(shù)最多顯示多少幀冕碟。參數(shù)“ all”顯示所有線程

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 2.1
  * frame #0: 0x0000000100000b81 KCObjc`main(argc=1, argv=0x00007ffeefbff578) at main.m:27:27 [opt]
    frame #1: 0x00007fff6acf2cc9 libdyld.dylib`start + 1
    frame #2: 0x00007fff6acf2cc9 libdyld.dylib`start + 1

命令一覽

Debugger commands:
  apropos           -- List debugger commands related to a word or subject.
  breakpoint        -- Commands for operating on breakpoints (see 'help b' for
                       shorthand.)
  bugreport         -- Commands for creating domain-specific bug reports.
 
  command           -- Commands for managing custom LLDB commands.

  disassemble       -- Disassemble specified instructions in the current
                       target.  Defaults to the current function for the
                       current thread and stack frame.
  expression        -- Evaluate an expression on the current thread.  Displays
                       any returned value with LLDB's default formatting.
  frame             -- Commands for selecting and examing the current thread's
                       stack frames.
  gdb-remote        -- Connect to a process via remote GDB server.  If no host
                       is specifed, localhost is assumed.
  gui               -- Switch into the curses based GUI mode.
  help              -- Show a list of all debugger commands, or give details
                       about a specific command.
  kdp-remote        -- Connect to a process via remote KDP server.  If no UDP
                       port is specified, port 41139 is assumed.
  language          -- Commands specific to a source language.
  log               -- Commands controlling LLDB internal logging.
  memory            -- Commands for operating on memory in the current target
                       process.
  platform          -- Commands to manage and create platforms.
  plugin            -- Commands for managing LLDB plugins.
  process           -- Commands for interacting with processes on the current
                       platform.
  quit              -- Quit the LLDB debugger.
  register          -- Commands to access registers for the current thread and
                       stack frame.
  reproducer        -- Commands for manipulating reproducers. Reproducers make
                       it possible to capture full debug sessions with all its
                       dependencies. The resulting reproducer is used to replay
                       the debug session while debugging the debugger.
                       Because reproducers need the whole the debug session
                       from beginning to end, you need to launch the debugger
                       in capture or replay mode, commonly though the command
                       line driver.
                       Reproducers are unrelated record-replay debugging, as
                       you cannot interact with the debugger during replay.
  script            -- Invoke the script interpreter with provided code and
                       display any results.  Start the interactive interpreter
                       if no code is supplied.
  settings          -- Commands for managing LLDB settings.
  source            -- Commands for examining source code described by debug
                       information for the current target process.
  statistics        -- Print statistics about a debugging session
  target            -- Commands for operating on debugger targets.
  thread            -- Commands for operating on one or more threads in the
                       current process.
  type              -- Commands for operating on the type system.
  version           -- Show the LLDB debugger version.
  watchpoint        -- Commands for operating on watchpoints.
Current command abbreviations (type 'help command alias' for more info):
  add-dsym  -- 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    -- Attach to process by ID or name.
  b         -- Set a breakpoint using one of several shorthand formats.
  bt        -- Show the current thread's call stack.  Any numeric argument
               displays at most that many frames.  The argument 'all' displays
               all threads.
  c         -- Continue execution of all threads in the current process.
  call      -- Evaluate an expression on the current thread.  Displays any
               returned value with LLDB's default formatting.
  continue  -- Continue execution of all threads in the current process.
  detach    -- Detach from the current target process.
  di        -- Disassemble specified instructions in the current target. 
               Defaults to the current function for the current thread and
               stack frame.
  dis       -- Disassemble specified instructions in the current target. 
               Defaults to the current function for the current thread and
               stack frame.
  display   -- Evaluate an expression at every stop (see 'help target
               stop-hook'.)
  down      -- Select a newer stack frame.  Defaults to moving one frame, a
               numeric argument can specify an arbitrary number.
  env       -- Shorthand for viewing and setting environment variables.
  exit      -- Quit the LLDB debugger.
  f         -- Select the current stack frame by index from within the current
               thread (see 'thread backtrace'.)
  file      -- Create a target using the argument as the main executable.
  finish    -- Finish executing the current stack frame and stop after
               returning.  Defaults to current thread unless specified.
  image     -- Commands for accessing information for one or more target
               modules.
  j         -- Set the program counter to a new address.
  jump      -- Set the program counter to a new address.
  kill      -- Terminate the current target process.
  l         -- List relevant source code using one of several shorthand formats.
  list      -- List relevant source code using one of several shorthand formats.
  n         -- Source level single step, stepping over calls.  Defaults to
               current thread unless specified.
  next      -- Source level single step, stepping over calls.  Defaults to
               current thread unless specified.
  nexti     -- Instruction level single step, stepping over calls.  Defaults to
               current thread unless specified.
  ni        -- Instruction level single step, stepping over calls.  Defaults to
               current thread unless specified.
  p         -- Evaluate an expression on the current thread.  Displays any
               returned value with LLDB's default formatting.
  parray    -- Evaluate an expression on the current thread.  Displays any
               returned value with LLDB's default formatting.
  po        -- Evaluate an expression on the current thread.  Displays any
               returned value with formatting controlled by the type's author.
  poarray   -- Evaluate an expression on the current thread.  Displays any
               returned value with LLDB's default formatting.
  print     -- Evaluate an expression on the current thread.  Displays any
               returned value with LLDB's default formatting.
  q         -- Quit the LLDB debugger.
  r         -- Launch the executable in the debugger.
  rbreak    -- Sets a breakpoint or set of breakpoints in the executable.
  re        -- Commands to access registers for the current thread and stack
               frame.
  repl      -- Evaluate an expression on the current thread.  Displays any
               returned value with LLDB's default formatting.
  run       -- Launch the executable in the debugger.
  s         -- Source level single step, stepping into calls.  Defaults to
               current thread unless specified.
  si        -- Instruction level single step, stepping into calls.  Defaults to
               current thread unless specified.
  sif       -- Step through the current block, stopping if you step directly
               into a function whose name matches the TargetFunctionName.
  step      -- Source level single step, stepping into calls.  Defaults to
               current thread unless specified.
  stepi     -- Instruction level single step, stepping into calls.  Defaults to
               current thread unless specified.
  t         -- Change the currently selected thread.
  tbreak    -- Set a one-shot breakpoint using one of several shorthand formats.
  undisplay -- Stop displaying expression at every stop (specified by stop-hook
               index.)
  up        -- Select an older stack frame.  Defaults to moving one frame, a
               numeric argument can specify an arbitrary number.
  v         -- Show variables for the current stack frame. Defaults to all
               arguments and local variables in scope. Names of argument,
               local, file static and file global variables can be specified.
               Children of aggregate variables can be specified such as
               'var->child.x'.  The -> and [] operators in 'frame variable' do
               not invoke operator overloads if they exist, but directly access
               the specified element.  If you want to trigger operator
               overloads use the expression command to print the variable
               instead.
               It is worth noting that except for overloaded operators, when
               printing local variables 'expr local_var' and 'frame var
               local_var' produce the same results.  However, 'frame variable'
               is more efficient, since it uses debug information and memory
               reads directly, rather than parsing and evaluating an
               expression, which may even involve JITing and running code in
               the target program.
  var       -- Show variables for the current stack frame. Defaults to all
               arguments and local variables in scope. Names of argument,
               local, file static and file global variables can be specified.
               Children of aggregate variables can be specified such as
               'var->child.x'.  The -> and [] operators in 'frame variable' do
               not invoke operator overloads if they exist, but directly access
               the specified element.  If you want to trigger operator
               overloads use the expression command to print the variable
               instead.
               It is worth noting that except for overloaded operators, when
               printing local variables 'expr local_var' and 'frame var
               local_var' produce the same results.  However, 'frame variable'
               is more efficient, since it uses debug information and memory
               reads directly, rather than parsing and evaluating an
               expression, which may even involve JITing and running code in
               the target program.
  vo        -- Show variables for the current stack frame. Defaults to all
               arguments and local variables in scope. Names of argument,
               local, file static and file global variables can be specified.
               Children of aggregate variables can be specified such as
               'var->child.x'.  The -> and [] operators in 'frame variable' do
               not invoke operator overloads if they exist, but directly access
               the specified element.  If you want to trigger operator
               overloads use the expression command to print the variable
               instead.
               It is worth noting that except for overloaded operators, when
               printing local variables 'expr local_var' and 'frame var
               local_var' produce the same results.  However, 'frame variable'
               is more efficient, since it uses debug information and memory
               reads directly, rather than parsing and evaluating an
               expression, which may even involve JITing and running code in
               the target program.
  x         -- Read from the memory of the current target process.
For more information on any command, type 'help <command-name>'.
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市匆浙,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌厕妖,老刑警劉巖首尼,帶你破解...
    沈念sama閱讀 212,884評(píng)論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異幻件,居然都是意外死亡同云,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,755評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門(mén)别威,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)查排,“玉大人凳枝,你說(shuō)我怎么就攤上這事“虾耍” “怎么了岖瑰?”我有些...
    開(kāi)封第一講書(shū)人閱讀 158,369評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)砂代。 經(jīng)常有香客問(wèn)我蹋订,道長(zhǎng),這世上最難降的妖魔是什么刻伊? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,799評(píng)論 1 285
  • 正文 為了忘掉前任露戒,我火速辦了婚禮,結(jié)果婚禮上捶箱,老公的妹妹穿的比我還像新娘智什。我一直安慰自己,他們只是感情好丁屎,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,910評(píng)論 6 386
  • 文/花漫 我一把揭開(kāi)白布荠锭。 她就那樣靜靜地躺著,像睡著了一般悦屏。 火紅的嫁衣襯著肌膚如雪节沦。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 50,096評(píng)論 1 291
  • 那天础爬,我揣著相機(jī)與錄音甫贯,去河邊找鬼。 笑死看蚜,一個(gè)胖子當(dāng)著我的面吹牛叫搁,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播供炎,決...
    沈念sama閱讀 39,159評(píng)論 3 411
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼渴逻,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了音诫?” 一聲冷哼從身側(cè)響起惨奕,我...
    開(kāi)封第一講書(shū)人閱讀 37,917評(píng)論 0 268
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎竭钝,沒(méi)想到半個(gè)月后梨撞,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體雹洗,經(jīng)...
    沈念sama閱讀 44,360評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,673評(píng)論 2 327
  • 正文 我和宋清朗相戀三年卧波,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了时肿。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,814評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡港粱,死狀恐怖螃成,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情查坪,我是刑警寧澤寸宏,帶...
    沈念sama閱讀 34,509評(píng)論 4 334
  • 正文 年R本政府宣布,位于F島的核電站咪惠,受9級(jí)特大地震影響击吱,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜遥昧,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,156評(píng)論 3 317
  • 文/蒙蒙 一覆醇、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧炭臭,春花似錦永脓、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,882評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至威创,卻和暖如春落午,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背肚豺。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,123評(píng)論 1 267
  • 我被黑心中介騙來(lái)泰國(guó)打工溃斋, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人吸申。 一個(gè)月前我還...
    沈念sama閱讀 46,641評(píng)論 2 362
  • 正文 我出身青樓梗劫,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親截碴。 傳聞我的和親對(duì)象是個(gè)殘疾皇子梳侨,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,728評(píng)論 2 351