XCode_LLDB_调试锦集


长篇高能

Diy_Commands 来自:https://github.com/facebook/chisel


快捷键cmd+L快速定位至源码文件中指定行

快捷键cmd+k快速清除console中的调试信息。

打印UI Hierarchy
  po [[self view] recursiveDescription]

po [[[[UIApplication sharedApplication] windows] objectAtIndex:0] recursiveDescription]



(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.

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

                       debugger commands.

  disassemble       -- Disassemble bytes in the current function, or elsewhere

                       in the executable program as specified by the user.

  expression        -- Evaluate an expression (ObjC++ or Swift) in the current

                       program context, using user defined variables and

                       variables currently in scope.

  frame             -- A set of commands for operating on the current thread's

                       frames.

  gdb-remote        -- Connect to a remote GDB server.  If no hostname is

                       provided, localhost is assumed.

  gui               -- Switch into the curses based GUI mode.

  help              -- Show a list of all debugger commands, or give details

                       about specific commands.

  kdp-remote        -- Connect to a remote KDP server.  udp port 41139 is the

                       default port number.

  log               -- A set of commands for operating on logs.

  memory            -- A set of commands for operating on memory.

  platform          -- A set of commands to manage and create platforms.

  plugin            -- A set of commands for managing or customizing plugin

                       commands.

  process           -- A set of commands for operating on a process.

  quit              -- Quit out of the LLDB debugger.

  register          -- A set of commands to access thread registers.

  script            -- Pass an expression to the script interpreter for

                       evaluation and return the results. Drop into the

                       interactive interpreter if no expression is given.

  settings          -- A set of commands for manipulating internal settable

                       debugger variables.

  source            -- A set of commands for accessing source file information

  target            -- A set of commands for operating on debugger targets.

  thread            -- A set of commands for operating on one or more threads

                       within a running process.

  type              -- A set of commands for operating on the type system

  version           -- Show version of LLDB debugger.

  watchpoint        -- A set of commands for operating on watchpoints.


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.

  c         -- ('process continue')  Continue execution of all threads in the

               current process.

  call      -- ('expression --')  Evaluate an expression (ObjC++ or Swift) in

               the current program context, using user defined variables and

               variables currently in scope.

  continue  -- ('process continue')  Continue execution of all threads in the

               current process.

  detach    -- ('process detach')  Detach from the current process being

               debugged.

  di        -- ('disassemble')  Disassemble bytes in the current function, or

               elsewhere in the executable program as specified by the user.

  dis       -- ('disassemble')  Disassemble bytes in the current function, or

               elsewhere in the executable program as specified by the user.

  display   -- ('_regexp-display')  Add an expression evaluation stop-hook.

  down      -- ('_regexp-down')  Go down "n"frames in the stack (1 frame by

               default).

  env       -- ('_regexp-env')  Implements a shortcut to viewing and setting

               environment variables.

  exit      -- ('quit')  Quit out of the LLDB debugger.

  f         -- ('frame select')  Select a frame by index from within the

               current thread and make it the current frame.

  file      -- ('target create')  Create a target using the argument as the

               main executable.

  finish    -- ('thread step-out')  Finish executing the function of the

               currently selected frame and return to its call site in

               specified thread (current thread, if none specified).

  image     -- ('target modules')  A set of commands for accessing information

               for one or more target modules.

  j         -- ('_regexp-jump')  Sets the program counter to a new address.

  jump      -- ('_regexp-jump')  Sets the program counter to a new address.

  kill      -- ('process kill')  Terminate the current process being debugged.

  l         -- ('_regexp-list')  Implements the GDB 'list' command in all of

               its forms except FILE:FUNCTION and maps them to the appropriate

               'source list' commands.

  list      -- ('_regexp-list')  Implements the GDB 'list' command in all of

               its forms except FILE:FUNCTION and maps them to the appropriate

               'source list' commands.

  n         -- ('thread step-over')  Source level single step in specified

               thread (current thread, if none specified), stepping over calls.

  next      -- ('thread step-over')  Source level single step in specified

               thread (current thread, if none specified), stepping over calls.

  nexti     -- ('thread step-inst-over')  Single step one instruction in

               specified thread (current thread, if none specified), stepping

               over calls.

  ni        -- ('thread step-inst-over')  Single step one instruction in

               specified thread (current thread, if none specified), stepping

               over calls.

  p         -- ('expression --')  Evaluate an expression (ObjC++ or Swift) in

               the current program context, using user defined variables and

               variables currently in scope.

  po        -- ('expression -O  -- ')  Evaluate an expression (ObjC++ or Swift)

               in the current program context, using user defined variables and

               variables currently in scope.

  print     -- ('expression --')  Evaluate an expression (ObjC++ or Swift) in

               the current program context, using user defined variables and

               variables currently in scope.

  q         -- ('quit')  Quit out of the LLDB debugger.

  r         -- ('process launch -c /bin/sh --')  Launch the executable in the

               debugger.

  rbreak    -- ('breakpoint set -r %1')  Sets a breakpoint or set of

               breakpoints in the executable.

  repl      -- ('expression -r  -- ')  Evaluate an expression (ObjC++ or Swift)

               in the current program context, using user defined variables and

               variables currently in scope.

  run       -- ('process launch -c /bin/sh --')  Launch the executable in the

               debugger.

  s         -- ('thread step-in') Source level single step in specified thread

               (current thread, if none specified).

  si        -- ('thread step-inst')  Single step oneinstruction in specified

               thread (current thread, if none specified).

  step      -- ('thread step-in') Source level single step in specified thread

               (current thread, if none specified).

  stepi     -- ('thread step-inst')  Single step oneinstruction in specified

               thread (current thread, if none specified).

  t         -- ('thread select')  Select a thread as the currently active

               thread.

  tbreak    -- ('_regexp-tbreak')  Set a one shot breakpoint using a regular

               expression to specify the location, where <linenum> is in

               decimal and <address> is in hex.

  undisplay -- ('_regexp-undisplay')  Remove an expression evaluation

               stop-hook.

  up        -- ('_regexp-up')  Go up "n"frames in the stack (1 frame by

               default).

  x         -- ('memory read')  Read from the memory of the process being

               debugged.


Current user-defined commands:


  alamborder   -- For more information run 'help alamborder'

  alamunborder -- For more information run 'help alamunborder'

  binside      -- For more information run 'help binside'

 bmessage     -- For more information run 'help bmessage'

 border       -- For more information run 'help border'

 caflush      -- For more information run 'help caflush'

  dcomponents  -- For more information run 'help dcomponents'

  fa11y        -- For more information run 'help fa11y'

  flicker      -- For more information run 'help flicker'

 fv           -- For more information run 'help fv'

 fvc          -- For more information run 'help fvc'

 hide         -- For more information run 'help hide'

  mask         -- For more information run 'help mask'

  pa11y        -- For more information run 'help pa11y'

  pactions     -- For more information run 'help pactions'

  paltrace     -- For more information run 'help paltrace'

  panim        -- For more information run 'help panim'

  pca          -- For more information run 'help pca'

  pcells       -- For more information run 'help pcells'

 pclass       --打印一个对象的继承关系

  pcomponents  -- For more information run 'help pcomponents'

  pcurl        -- For more information run 'help pcurl'

  pdata        -- For more information run 'help pdata'

 pdocspath    --打印Document全路径

  pinternals   --打印对象内部所有属性

  pinvocation  -- For more information run 'help pinvocation'

  pivar        -- For more information run 'help pivar'

  pjson        -- For more information run 'help pjson'

  pkp          -- For more information run 'help pkp'

 presponder   -- For more information run 'help presponder'

  ptv          -- For more information run 'help ptv'

 pvc          -- For more information run 'help pvc'

 pviews       -- For more information run 'help pviews'

  rcomponents  -- For more information run 'help rcomponents'

 show         -- For more information run 'help show'

  slowanim     -- For more information run 'help slowanim'

  taplog       -- For more information run 'help taplog'

  unborder     -- For more information run 'help unborder'

  unmask       -- For more information run 'help unmask'

  unslowanim   -- For more information run 'help unslowanim'

  visualize    -- For more information run 'help visualize'

  vs           -- For more information run 'help vs'

  wivar        -- For more information run 'help wivar'



There are many commands; here's a few: (Compatibility with iOS/Mac indicated at right)

Command Description iOS OS X
pviews Print the recursive view description for the key window. Yes Yes
pvc Print the recursive view controller description for the key window. Yes No
visualize Open a UIImageCGImageRefUIViewCALayerNSData (of an image),UIColorCIColor, or CGColorRef in Preview.app on your Mac. Yes No
fv Find a view in the hierarchy whose class name matches the provided regex. Yes No
fvc Find a view controller in the hierarchy whose class name matches the provided regex. Yes No
show/hide Show or hide the given view or layer. You don't even have to continue the process to see the changes! Yes Yes
mask/unmask Overlay a view or layer with a transparent rectangle to visualize where it is. Yes No
border/unborder Add a border to a view or layer to visualize where it is. Yes Yes
caflush Flush the render server (equivalent to a "repaint" if no animations are in-flight).) Yes Yes
bmessage Set a symbolic breakpoint on the method of a class or the method of an instance without worrying which class in the hierarchy actually implements the method. Yes Yes
wivar Set a watchpoint on an instance variable of an object. Yes Yes
presponder Print the responder chain starting from the given object. Yes Yes



1、brew安装命令【ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"】



2、通过brew安装chisel【brew install chisel


3、创建~/.lldbinit
cd ~/

touch .lldbinit

open ~/.lldbinit

4、Add the following line to ~/.lldbinit to load chisel when Xcode launches:

  command script import /usr/local/opt/chisel/libexec/fblldb.py


重启XCode,开始调试之旅吧

- (IBAction)checkBtnAction:(id)sender 触发断点

(lldb)po sender

<UIButton: 0x8231d10; frame = (175 20; 60 40); opaque = NO; autoresize = RM+BM; tag = 2; layer = <CALayer: 0x8231e00>>

(lldb)pviews sender

<UIButton: 0x8231d10; frame = (175 20; 60 40); opaque = NO; autoresize = RM+BM; tag = 2; layer = <CALayer: 0x8231e00>>

   | <UIImageView: 0x820c070; frame = (8 13; 13.5 13.5); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x820c920>>

   | <UIButtonLabel: 0x8205a00; frame = (21.5 11; 30 18); text = ''; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8205c40>>

(lldb)pvc                    效果同:IOS8中UIViewController 的一个私有方法[UIViewController _printHierarchy] 

<KLTabBarController: 0x1bb32b0; view = <UILayoutContainerView; 0x8278540>; frame = (0, 0; 320, 480)>

   | <KLNavigationController: 0x1bb3830; view = <UILayoutContainerView; 0x1be8e70>; frame = (0, 0; 320, 480)>

   |   | <EduHomePageViewController: 0x1bb6be0; view = <UIView; 0x1b9b960>; frame = (0, 0; 320, 480)>

   |   | <StudentCircleTabViewController: 0x82ce240; view = <UIView; 0x82c9ac0>; frame = (0, 64; 320, 416)>

   |   | <AddTopicViewController: 0x82e8570; view = <UIView; 0x821d400>; frame = (0, 64; 320, 416)>

   | <KLNavigationController: 0x1bbc260; view not loaded>

   |   | <ContactMainListViewController: 0x1bba470; view not loaded>

   | <KLNavigationController: 0x1b69a90; view not loaded>

   |   | <DynamicTabViewController: 0x1b62140; view not loaded>

   | <KLNavigationController: 0x1b96cd0; view not loaded>

   |   | <MineViewController: 0x1b96e80; view not loaded>



(lldb) visualize image

XCode_LLDB_调试锦集_第1张图片

fv   fvc通过类名搜索当前内存中存在的view和viewController实例的命令,支持正则搜索。

(lldb)fv UIButton

0x8231d10 UIButton

0x8205a00 UIButtonLabel

0x8206ee0 UIButtonLabel

0x8232d00 UIButton

0x820da20 UIButtonLabel

0x82302b0 UIButton

0x8230600 UIButton

0x821f030 UIButtonLabel

0x8231b70 UIButton

(lldb) fv label

0x821fe90 UILabel

0x8205a00 UIButtonLabel

0x8206ee0 UIButtonLabel

0x821e560 UITextFieldLabel

0x820da20 UIButtonLabel

0x82e88c0 UILabel

0x821f030 UIButtonLabel

0x821ce60 UILabel

0x1b99050 UITabBarButtonLabel

0x1bea750 UITabBarButtonLabel

0x1b4e310 UITabBarButtonLabel

0x1b4b510 UITabBarButtonLabel

///////////////////////////////////////////////////////////////////////////////////////

(lldb) fv scrollView

0x821fa80 UIScrollView

(lldb) fvc viewc

0x1bb6be0 EduHomePageViewController

0x82ce240 StudentCircleTabViewController

0x82e8570 AddTopicViewController

0x1bba470 ContactMainListViewController

0x1b62140 DynamicTabViewController

0x1b96e80 MineViewController

///////////////////////////////////////////////////////////////////////////////////////

实时显示和隐藏一个指定的 UIView 

(lldb) hide sender

(lldb) show sender


///////////////////////////////////////////////////////////////////////////////////////

(lldb) border sender

(lldb) unborder sender

(lldb) mask sender

(lldb) unmask sender


(lldb) p sender

(UIButton *) $132 = 0x0824e1c0

(lldb) border sender

border命令还可以指定添加的边框颜色Color边框宽度Width

border0x0824e1c0 -c purple -w 2

(lldb) border 0x0824e1c0 -c purple -w 2

(lldb) unborder sender



///////////////////////////////////////////////////////////////////////////////////////

caflush 相当于执行了 [CATransaction flush] 方法,要注意如果在动画过程中执行这个命令,就直接渲染出动画结束的效果。

当调试界面颜色、坐标之类的时候,可以直接在控制台修改属性,然后caflush就可以看到效果


(lldb) po sender

<UIButton: 0x8232d00; frame = (88 20; 60 40); opaque = NO; autoresize = RM+BM; tag = 1; layer = <CALayer: 0x82319e0>>


(lldb) p sender

(UIButton *) $277 = 0x08232d00

(lldb) e (void)[$277 setBackgroundColor:[UIColor greenColor]]

(lldb) caflush



///////////////////////////////////////////////////////////////////////////////////////

 bmessage

欲在 [BeyondCtrl viewWillAppear:] 里打断点,但若 BeyondCtrl并没有实现viewWillAppear: 方法时:

 (lldb)bmessage -[MyViewController viewWillAppear:] 

他会在其父类的 viewWillAppear: 方法中打断点,并添加上了条件:[self isKindOfClass:[BeyondCtrl class]]


///////////////////////////////////////////////////////////////////////////////////////

Print the responder chain starting from the given object.

(lldb) presponder sender

<UIButton: 0x8232d00; frame = (88 20; 60 40); opaque = NO; autoresize = RM+BM; tag = 1; layer = <CALayer: 0x82319e0>>

   | <UIScrollView: 0x821fa80; frame = (-10 -12; 340 358); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x821d710>; layer = <CALayer: 0x821fa50>; contentOffset: {0, 0}>

   |    | <UIView: 0x821d400; frame = (0 64; 320 416); autoresize = W+H; layer = <CALayer: 0x821d3d0>>

   |    |    | <AddTopicViewController: 0x82e8570>

   |    |    |    | <UIViewControllerWrapperView: 0x82a29b0; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x82a25b0>>

   |    |    |    |    | <UINavigationTransitionView: 0x827a000; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x827a120>>

   |    |    |    |    |    | <UILayoutContainerView: 0x1be8e70; frame = (0 0; 320 480); autoresize = W+H; gestureRecognizers = <NSArray: 0x827dae0>; layer = <CALayer: 0x82791e0>>

   |    |    |    |    |    |    | <KLNavigationController: 0x1bb3830>

   |    |    |    |    |    |    |    | <UIViewControllerWrapperView: 0x827dd00; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x827ddf0>>

   |    |    |    |    |    |    |    |    | <UITransitionView: 0x82783f0; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x8278780>>

   |    |    |    |    |    |    |    |    |    | <UILayoutContainerView: 0x8278540; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x8277ee0>>

   |    |    |    |    |    |    |    |    |    |    | <KLTabBarController: 0x1bb32b0>

   |    |    |    |    |    |    |    |    |    |    |    | <UIWindow: 0x1be8a70; frame = (0 0; 320 480); autoresize = W+H; gestureRecognizers = <NSArray: 0x1b70350>; layer = <UIWindowLayer: 0x1bb3bf0>>

   |    |    |    |    |    |    |    |    |    |    |    |    | <UIApplication: 0x1b881e0>

   |    |    |    |    |    |    |    |    |    |    |    |    |    | <AppDelegate: 0x1b89a10>


///////////////////////////////////////////////////////////////////////////////////////

(lldb) pcells

<__NSArrayI 0x821bd60>(

<TopicTableViewCell: 0x82eb890; baseClass = UITableViewCell; frame = (0 0.00999832; 320 100); autoresize = W; layer = <CALayer: 0x824e8e0>>,

<TopicTableViewCell: 0x82f7060; baseClass = UITableViewCell; frame = (0 100.01; 320 100); autoresize = W; layer = <CALayer: 0x826eca0>>,

<TopicTableViewCell: 0x82644f0; baseClass = UITableViewCell; frame = (0 200.01; 320 100); autoresize = W; layer = <CALayer: 0x8264900>>,

<TopicTableViewCell: 0x82413d0; baseClass = UITableViewCell; frame = (0 300.01; 320 100); autoresize = W; layer = <CALayer: 0x8241570>>

)




然后重启Xcode




GDB and LLDB Command Examples

The tables in this chapter list commonly used GDB commands and present equivalent LLDB commands and alternative forms. Also listed are the built-in GDB compatibility aliases in LLDB.

Notice that full LLDB command names can be matched by unique short forms, which can be used instead. For example, instead ofbreakpoint setbr se can be used.

Execution Commands

GDB

LLDB

Launch a process with no arguments.

(gdb) run

(gdb) r

(lldb)process launch

(lldb)run

(lldb)r

Launch a process with arguments <args>.

(gdb) run <args>

(gdb) r <args>

(lldb) process launch -- <args>

(lldb) r <args>

Launch process a.out with arguments 1 2 3 without having to supply the args every time.

% gdb --args a.out 1 2 3

(gdb) run

...

(gdb) run

...

(% lldb -- a.out 1 2 3

(lldb) run

...

(lldb) run

...

Launch a process with arguments in a new terminal window (OS X only).

 —

(lldb) process launch --tty -- <args>

(lldb) pro la -t -- <args>

Launch a process with arguments in an existing Terminal window, /dev/ttys006 (OS X only).

 —

(lldb) process launch --tty=/dev/ttys006 -- <args>

(lldb) pro la -t/dev/ttys006 -- <args>

Set environment variables for process before launching.

(gdb) set env DEBUG 1

(lldb) settings set target.env-vars DEBUG=1

(lldb) set se target.env-vars DEBUG=1

Set environment variables for process and launch process in one command.

 

(lldb) process launch -v DEBUG=1

Attach to the process with process ID 123.

(gdb) attach 123

(lldb)process attach --pid 123

(lldb) attach -p 123

Attach to a process named a.out.

(gdb) attach a.out

(lldb) process attach --name a.out

(lldb) pro at -n a.out

Wait for a process named a.out to launch and attach.

(gdb) attach -waitfor a.out

(lldb) process attach --name a.out --waitfor

(lldb) pro at -n a.out -w

Attach to a remote GDB protocol server running on the system eorgadd, port 8000.

(gdb) target remote eorgadd:8000

(lldb) gdb-remote eorgadd:8000

Attach to a remote GDB protocol server running on the local system, port 8000.

(gdb) target remote localhost:8000

(lldb) gdb-remote 8000

Attach to a Darwin kernel in kdp mode on the system eorgadd.

(gdb) kdp-reattach eorgadd

(lldb) kdp-remote eorgadd

Do a source-level single step in the currently selected thread.代码级

(gdb) step

(gdb) s

(lldb) thread step-in

(lldb)step

(lldb)s

Do a source-level single step over in the currently selected thread.【代码级

(gdb) next

(gdb) n

(lldb) thread step-over

(lldb)next

(lldb)n

Do an instruction-level single step in the currently selected thread.汇编级

(gdb) stepi

(gdb) si

(lldb) thread step-inst

(lldb)si

Do an instruction-level single step over in the currently selected thread.汇编级

(gdb) nexti

(gdb) ni

(lldb) thread step-inst-over

(lldb)ni

Step out of the currently selected frame.【重要

(gdb) finish

(lldb) thread step-out

(lldb)finish

Backtrace and disassemble every time you stop.牛逼

 —

(lldb)target stop-hook add

Enter your stop hook command(s). Type 'DONE' to end.

> bt

register read

> disassemble --pc

>DONE

Stop hook #1 added.

Breakpoint Commands

GDB

LLDB

Set a breakpoint at all functions named main.

(gdb) break main

(lldb) breakpoint set --name main

(lldb) br s -n main

(lldb) b main

Set a breakpoint in file test.c at line 12.

(gdb) break test.c:12

(lldb) breakpoint set --file test.c --line 12

(lldb) br s -f test.c -l 12

(lldb) b test.c:12

Set a breakpoint at all C++ methods whose basename is main.

(gdb) break main

(Note: This will break on any C functions namedmain.)

(lldb) breakpoint set --method main

(lldb) br s -M main

Set a breakpoint at an Objective-C function: -[NSString stringWithFormat:].【十分重要】适合于不能断下来的方法

(gdb) break -[NSString stringWithFormat:]

(lldb) breakpoint set --name "-[NSString stringWithFormat:]"

(lldb)b -[NSString stringWithFormat:]

【提示attempt to insert nil,但是断不下来】

使用LLDB命令,在提示的方法上面,下内存断点
(LLDB) b -[__NSPlaceholderDictionary initWithObjects:forKeys:count:];
即可断下来,原来是:请求的dict中lastGetTime是从缓存中取的,第一次是nil



第2个解决的问题:
              NSLog打印一个长度为0的数组
              报错:NSRangeException> -[__NSCFString deleteCharactersInRange:]:
               Range or index out of bounds
解决办法:
             由于没有step into的概念,所以一直没有找到问题
             最后,打了一个内存断点,才找到问题所在,
             b -[__NSCFString deleteCharactersInRange:]
             原来是,用了一个NSArray的分类,美化打印效果,结果在打印的时候,没有对空数组作验证导致崩溃

Set a breakpoint at all Objective-C methods whose selector is count.

(gdb) break count

(Note: This will break on any C or C++ functions named count.)

(lldb) breakpoint set --selector count

(lldb) br s -S count

Set a breakpoint by a regular expression on a function name.

(gdb) rbreak regular-expression

(lldb) breakpoint set --regex regular-expression

(lldb) br s -r regular-expression

Set a breakpoint by a regular expression on a source file’s contents.

(gdb) shell grep -e -n pattern source-file

(gdb) break source-file:CopyLineNumbers

(lldb) breakpoint set --source-pattern regular-expression --file SourceFile

(lldb) br s -p regular-expression -f file

List all breakpoints.

(gdb) info break

(lldb) breakpoint list

(lldb) br l

Delete a breakpoint.

(gdb) delete 1

(lldb) breakpoint delete 1

(lldb) br del 1

Watchpoint Commands

GDB

LLDB

Set a watchpoint on a variable when it is written to.

(gdb) watch global_var

(lldb) watchpoint set variable global_var

(lldb) wa s v global_var

Set a watchpoint on a memory location when it is written to.

(gdb) watch -location g_char_ptr

(lldb) watchpoint set expression -- my_ptr

(lldb) wa s e -- my_ptr

 

Note: The size of the region to watch for defaults to the pointer size if no -x byte_size is specified. This command takes “raw” input, evaluated as an expression returning an unsigned integer pointing to the start of the region, after the option terminator (--).

Set a condition on a watchpoint.

 —

(lldb) watch set var global

(lldb) watchpoint modify -c '(global==5)'

(lldb) c

...

(lldb) bt

* thread #1: tid = 0x1c03, 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16, stop reason = watchpoint 1

frame #0: 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16

frame #1: 0x0000000100000eac a.out`main + 108 at main.cpp:25

frame #2: 0x00007fff8ac9c7e1 libdyld.dylib`start + 1

(int32_t) global = 5

List all watchpoints.

(gdb) info break

(lldb) watchpoint list

(lldb) watch l

Delete a watchpoint.

(gdb) delete 1

(lldb) watchpoint delete 1

(lldb) watch del 1

Examining Variables

GDB

LLDB

Show the arguments and local variables for the current frame.

(gdb) info args

and

(gdb) info locals

(lldb) frame variable

(lldb) fr v

Show the local variables for the current frame.

(gdb) info locals

(lldb) frame variable --no-args

(lldb) fr v -a

Show the contents of the local variable bar.

(gdb) p bar

(lldb) frame variable bar

(lldb) fr v bar

(lldb) p bar

Show the contents of the local variable bar formatted as hex.

(gdb) p/x bar

(lldb) frame variable --format x bar

(lldb) fr v -f x bar

Show the contents of the global variable baz.

(gdb) p baz

(lldb) target variable baz

(lldb) ta v baz

Show the global/static variables defined in the current source file.

 —

(lldb) target variable

(lldb) ta v

Display the variables argc and argv every time you stop.

(gdb) display argc

(gdb) display argv

(lldb) target stop-hook add --one-liner "frame variable argc argv"

(lldb) ta st a -o "fr v argc argv"

(lldb) display argc

(lldb) display argv

Display the variables argc and argv only when you stop in the function named main.

 —

 

(lldb) target stop-hook add --name main --one-liner "frame variable argc argv"

(lldb) ta st a -n main -o "fr v argc argv"

Display the variable *this only when you stop in the C class named MyClass.

 —

 

(lldb) target stop-hook add --classname MyClass --one-liner "frame variable *this"

(lldb) ta st a -c MyClass -o "fr v *this"

Evaluating Expressions

GDB

LLDB

Evaluate a generalized expression in the current frame.

(gdb) print (int) printf ("Print nine: %d.", 4 + 5)

 

Or if you don’t want to see void returns:

(gdb) call (int) printf ("Print nine: %d.", 4 + 5)

(lldb) expr (int) printf ("Print nine: %d.", 4 + 5)

 

Or use the print alias:

(lldb) print (int) printf ("Print nine: %d.", 4 + 5)

Create and assign a value to a convenience variable.

(gdb) set $foo = 5

(gdb) set variable $foo = 5

 

Or use the print command:

(gdb) print $foo = 5

 

Or use the call command:

(gdb) call $foo = 5

 

To specify the type of the variable:

(gdb) set $foo = (unsigned int) 5

LLDB evaluates a variable declaration expression as you would write it in C:

(lldb) expr unsigned int $foo = 5

Print the Objective-C description of an object.

(gdb) po [SomeClass returnAnObject]

(lldb) expr -O -- [SomeClass returnAnObject]

 

Or use the po alias:

(lldb) po [SomeClass returnAnObject]

Print the dynamic type of the result of an expression.

(gdb) set print object 1

(gdb) p someCPPObjectPtrOrReference

 

Note: Only for C++ objects.

(lldb) expr -d run-target -- [SomeClass returnAnObject]

(lldb) expr -d run-target -- someCPPObjectPtrOrReference

 

Or set dynamic type printing as default:

(lldb) settings set target.prefer-dynamic run-target

Call a function to stop at a breakpoint in the function.

(gdb) set unwindonsignal 0

(gdb) p function_with_a_breakpoint()

(lldb) expr -u 0 -- function_with_a_breakpoint()

Examining Thread State

GDB

LLDB

Show the stack backtrace for the current thread.

(gdb) bt

(lldb)thread backtrace

(lldb)bt

Show the stack backtraces for all threads.

(gdb) thread apply all bt

(lldb)thread backtrace all

(lldb)bt all

Backtrace the first five frames of the current thread.

(gdb) bt 5

(lldb)thread backtrace -c 5

(lldb)bt 5 (lldb-169 and later)

(lldb)bt -c 5 (lldb-168 and earlier)

Select a different stack frame by index for the current thread.【重要

(gdb) frame 12

(lldb)frame select 12

(lldb)fr s 12

(lldb)f 12

List information about the currently selected frame in the current thread.

 —

(lldb)frame info

Select the stack frame that called the current stack frame.【重要

(gdb) up

(lldb)up

(lldb) frame select --relative=1

Select the stack frame that is called by the current stack frame.重要

(gdb) down

(lldb)down

(lldb) frame select --relative=-1

(lldb) fr s -r-1

Select a different stack frame using a relative offset.

(gdb) up 2

(gdb) down 3

(lldb) frame select --relative 2

(lldb)fr s -r2

 

(lldb) frame select --relative -3

(lldb)fr s -r-3

Show the general-purpose registers for the current thread.

(gdb) info registers

(lldb)register read

Write a new decimal value 123 to the current thread register rax.

(gdb) p $rax = 123

(lldb)register write rax 123

Skip 8 bytes ahead of the current program counter (instruction pointer).

(gdb) jump *$pc+8

(lldb) register write pc `$pc+8`

 

The LLDB command uses backticks to evaluate an expression and insert the scalar result.

Show the general-purpose registers for the current thread formatted as signed decimal.

 —

(lldb)register read --format i

(lldb)re r -f i

 

LLDB now supports the GDB shorthand format syntax, but no space is permitted after the command:

(lldb)register read/d

 

Note: LLDB tries to use the same format characters as printf(3) when possible. Type help format to see the full list of format specifiers.

Show all registers in all register sets for the current thread.

(gdb) info all-registers

(lldb)register read --all

(lldb)re r -a

Show the values for the registers named raxrsp and rbp in the current thread.

(gdb) info all-registers rax rsp rbp

(lldb)register read rax rsp rbp

Show the values for the register named rax in the current thread formatted as binary.

(gdb) p/t $rax

(lldb)register read --format binary rax

(lldb)re r -f b rax

 

LLDB now supports the GDB shorthand format syntax, but no space is permitted after the command:

(lldb)register read/t rax

(lldb)p/t $rax

Read memory from address 0xbffff3c0 and show four hex uint32_t values.

(gdb) x/4xw 0xbffff3c0

(lldb)memory read --size 4 --format x --count 4 0xbffff3c0

(lldb) me r -s4 -fx -c4 0xbffff3c0

(lldb) x -s4 -fx -c4 0xbffff3c0

 

LLDB now supports the GDB shorthand format syntax, but no space is permitted after the command:

(lldb)memory read/4xw 0xbffff3c0

(lldb) x/4xw 0xbffff3c0

(lldb) memory read --gdb-format 4xw 0xbffff3c0

Read memory starting at the expression argv[0].

(gdb) x argv[0]

(lldb) memory read `argv[0]`

 

Note that any command can inline a scalar expression result (as long as the target is stopped) using backticks around any expression:

(lldb) memory read --size `sizeof(int)` `argv[0]`

Read 512 bytes of memory from address 0xbffff3c0 and save results to a local file as text.

(gdb) set logging on

(gdb) set logging file /tmp/mem.txt

(gdb) x/512bx 0xbffff3c0

(gdb) set logging off

(lldb) memory read --outfile /tmp/mem.txt --count 512 0xbffff3c0

(lldb) me r -o/tmp/mem.txt -c512 0xbffff3c0

(lldb) x/512bx -o/tmp/mem.txt 0xbffff3c0

Save binary memory data to a file starting at 0x1000 and ending at 0x2000.

(gdb) dump memory /tmp/mem.bin 0x1000 0x2000

(lldb) memory read --outfile /tmp/mem.bin --binary 0x1000 0x1200

(lldb) me r -o /tmp/mem.bin -b 0x1000 0x1200

Disassemble the current function for the current frame.

(gdb) disassemble

(lldb)disassemble --frame

(lldb) di -f

Disassemble any functions named main.

(gdb) disassemble main

(lldb)disassemble --name main

(例如) disassemble --name checkBtnAction:

(lldb)di -n main

Disassemble an address range.

(gdb) disassemble 0x1eb8 0x1ec3

(lldb)disassemble --start-address 0x1eb8--end-address 0x1ec3

(lldb)di -s 0x1eb8-e 0x1ec3

Disassemble 20 instructions from a given address.

(gdb) x/20i 0x1eb8

(lldb)disassemble --start-address 0x1eb8--count 20

(lldb)di -s 0x1eb8-c 20

Show mixed source and disassembly for the current function for the current frame.

 —

(lldb)disassemble --frame --mixed

(lldb) di -f -m

Disassemble the current function for the current frame and show the opcode bytes.

 —

(lldb)disassemble --frame --bytes

(lldb) di -f -b

Disassemble the current source line for the current frame.

 —

(lldb)disassemble --line

(lldb) di -l

Executable and Shared Library Query Commands

GDB

LLDB

List the main executable and all dependent shared libraries.

(gdb) info shared

(lldb)image list

Look up information for a raw address in the executable or any shared libraries.

(gdb) info symbol 0x1ec4

(lldb)image lookup --address 0x1ec4

(lldb)im loo -a 0x1ec4

Look up functions matching a regular expression in a binary.

(gdb) info function <FUNC_REGEX>

This one finds debug symbols:(区分大小写)

(lldb)image lookup -r -n <FUNC_REGEX>

  例如:image lookup -r -n snapshotView

 

This one finds non-debug symbols:

(lldb)image lookup -r -s <FUNC_REGEX>

 

Provide a list of binaries as arguments to limit the search.

Look up information for an address in a.out only.

 —

(lldb)image lookup --address 0x1ec4 a.out

(lldb)im loo -a 0x1ec4 a.out

Look up information for a type Point by name.

(gdb) ptype Point

(lldb)image lookup --type Point

例如   image lookup --type Rect

(lldb)im loo -t Point

Dump all sections from the main executable and any shared libraries.

(gdb) maintenance info sections

(lldb)image dump sections

Dump all sections in the a.out module.

 —

(lldb) image dump sections a.out

Dump all symbols from the main executable and any shared libraries.

 —

(lldb)image dump symtab

Dump all symbols in a.out and liba.so.

 —

(lldb) image dump symtab a.out liba.so

Miscellaneous

GDB

LLDB

Echo text to the screen.

(gdb) echo Here is some text\n

(lldb)script print "Here is some text"

Remap source file pathnames for the debug session.

(gdb) set pathname-substitutions /buildbot/path /my/path

(lldb) settings set target.source-map /buildbot/path /my/path

 

Note: If your source files are no longer located in the same location as when the program was built—maybe the program was built on a different computer—you need to tell the debugger how to find the sources at the local file path instead of the build system file path.

Supply a catchall directory to search for source files in.

(gdb) directory /my/path

(No equivalent command yet.)

例如:

(lldb) image lookup -r -n snapshotView

11 matches found in /Users/pzh/Library/Developer/Xcode/iOS DeviceSupport/7.1.2 (11D257)/Symbols/System/Library/Frameworks/UIKit.framework/UIKit:

        Address: UIKit[0x2fcf8410] (UIKit.__TEXT.__text + 522912)

        Summary: UIKit`-[UIView snapshotView]        Address: UIKit[0x2fd4447c] (UIKit.__TEXT.__text + 834316)

        Summary: UIKit`-[UIInputViewTransition snapshotView]        Address: UIKit[0x2fd44524] (UIKit.__TEXT.__text + 834484)

        Summary: UIKit`-[UIInputViewTransition snapshotViewBeginFrame]        Address: UIKit[0x2fd458b8] (UIKit.__TEXT.__text + 839496)

        Summary: UIKit`-[UIInputViewTransition snapshotViewEndFrame]        Address: UIKit[0x2ff17c70] (UIKit.__TEXT.__text + 2749184)

        Summary: UIKit`-[UIView snapshotViewAfterScreenUpdates:]        Address: UIKit[0x2ff51e54] (UIKit.__TEXT.__text + 2987236)

        Summary: UIKit`-[UINavigationController _snapshotView]        Address: UIKit[0x2ffcde2c] (UIKit.__TEXT.__text + 3495100)

        Summary: UIKit`-[UIScreen(UISnapshotting) snapshotViewAfterScreenUpdates:]        Address: UIKit[0x2ffcdf80] (UIKit.__TEXT.__text + 3495440)

        Summary: UIKit`__59-[UIScreen(UISnapshotting) snapshotViewAfterScreenUpdates:]_block_invoke        Address: UIKit[0x2ffce038] (UIKit.__TEXT.__text + 3495624)

        Summary: UIKit`__59-[UIScreen(UISnapshotting) snapshotViewAfterScreenUpdates:]_block_invoke_2        Address: UIKit[0x2ffce6d0] (UIKit.__TEXT.__text + 3497312)

        Summary: UIKit`-[UIScreen(UISnapshotting) snapshotView]        Address: UIKit[0x300fc480] (UIKit.__TEXT.__text + 4733712)

        Summary: UIKit`-[UISnapshotView _snapshotView]

2 matches found in /Users/pzh/Library/Developer/Xcode/iOS DeviceSupport/7.1.2 (11D257)/Symbols/System/Library/Frameworks/QuickLook.framework/QuickLook:

        Address: QuickLook[0x2fa6d698] (QuickLook.__TEXT.__text + 205824)

        Summary: QuickLook`-[QLPreviewViewController snapshotView]        Address: QuickLook[0x2fa6f86c] (QuickLook.__TEXT.__text + 214484)

        Summary: QuickLook`-[QLPreviewContentController snapshotView]

1 match found in /Users/pzh/Library/Developer/Xcode/iOS DeviceSupport/7.1.2 (11D257)/Symbols/System/Library/PrivateFrameworks/iTunesStoreUI.framework/iTunesStoreUI:

        Address: iTunesStoreUI[0x364fb6d8] (iTunesStoreUI.__TEXT.__text + 728568)

        Summary: iTunesStoreUI`-[SUSnapshotView snapshotView:usingIOSurface:]



(lldb)image lookup --type Rect

Best match found in /Users/pzh/Library/Developer/Xcode/DerivedData/JZH-bzgkjnlsuwbivkexxhazkliasuuu/Build/Products/Debug-iphoneos/JZH.app/JZH:

id = {0x00ce1117}, name = "Rect", byte-size = 8, decl = MacTypes.h:546, clang_type = "typedef Rect"

     typedef 'Rect': id = {0x00ce1123}, name = "Rect", byte-size = 8, decl = MacTypes.h:540, clang_type = "struct Rect {

    short top;

    short left;

    short bottom;

    short right;

}"



(lldb) thread backtrace

* thread #1: tid = 0x1e3f, 0x0011c08a JZH`-[AddTopicViewController checkBtnAction:](self=0x07c91880, _cmd=0x00bf7d95, sender=0x07ca0060) + 50 at AddTopicViewController.m:371, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1

  * frame #0: 0x0011c08a JZH`-[AddTopicViewController checkBtnAction:](self=0x07c91880, _cmd=0x00bf7d95, sender=0x07ca0060) + 50 at AddTopicViewController.m:371

    frame #1: 0x309a5036 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 90

    frame #2: 0x309a4fd6 UIKit`-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 30

    frame #3: 0x309a4fb0 UIKit`-[UIControl sendAction:to:forEvent:] + 44

    frame #4: 0x30990716 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 374

    frame #5: 0x309a4a2e UIKit`-[UIControl touchesEnded:withEvent:] + 590

    frame #6: 0x30967f12 UIKit`_UIGestureRecognizerUpdate + 5522

    frame #7: 0x3099fd48 UIKit`-[UIWindow _sendGesturesForEvent:] + 772

    frame #8: 0x3099f66e UIKit`-[UIWindow sendEvent:] + 666

    frame #9: 0x309748cc UIKit`-[UIApplication sendEvent:] + 196

    frame #10: 0x30972f76 UIKit`_UIApplicationHandleEventQueue + 7102

    frame #11: 0x2e11e20a CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14

    frame #12: 0x2e11d6da CoreFoundation`__CFRunLoopDoSources0 + 206

    frame #13: 0x2e11bece CoreFoundation`__CFRunLoopRun + 622

    frame #14: 0x2e086ebe CoreFoundation`CFRunLoopRunSpecific + 522

    frame #15: 0x2e086ca2 CoreFoundation`CFRunLoopRunInMode + 106

    frame #16: 0x32f8c662 GraphicsServices`GSEventRunModal + 138

    frame #17: 0x309d314c UIKit`UIApplicationMain + 1136

    frame #18: 0x00063490 JZH`main(argc=1, argv=0x27dffc88) + 108 at main.m:15


(lldb) thread backtrace -c 5

* thread #1: tid = 0x1e3f, 0x0011c08a JZH`-[AddTopicViewController checkBtnAction:](self=0x07c91880, _cmd=0x00bf7d95, sender=0x07ca0060) + 50 at AddTopicViewController.m:371, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1

  * frame #0: 0x0011c08a JZH`-[AddTopicViewController checkBtnAction:](self=0x07c91880, _cmd=0x00bf7d95, sender=0x07ca0060) + 50 at AddTopicViewController.m:371

    frame #1: 0x309a5036 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 90

    frame #2: 0x309a4fd6 UIKit`-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 30

    frame #3: 0x309a4fb0 UIKit`-[UIControl sendAction:to:forEvent:] + 44

    frame #4: 0x30990716 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 374



(lldb) f 0

frame #0: 0x0011c08a JZH`-[AddTopicViewController checkBtnAction:](self=0x07c91880, _cmd=0x00bf7d95, sender=0x07ca0060) + 50 at AddTopicViewController.m:371

   368 

   369 - (IBAction)checkBtnAction:(id)sender {

   370 

-> 371     if (sender == self.privateBtn) {

   372         self.checkIndex = 1;

   373         UIImage *image = [UIImage imageNamed:@"radio_buttons_p"];

   374         [self.privateBtn setImage:image forState:UIControlStateNormal];

(lldb) f 1

frame #1: 0x309a5036 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 90

UIKit`-[UIApplication sendAction:to:from:forEvent:]:

    0x309a5036 <+90>: cmp    r4, #0x0

    0x309a5038 <+92>: it     ne

    0x309a503a <+94>: movne  r4, #0x1

    0x309a503c <+96>: mov    r0, r4

(lldb) f 3

frame #3: 0x309a4fb0 UIKit`-[UIControl sendAction:to:forEvent:] + 44

UIKit`-[UIControl sendAction:to:forEvent:]:

    0x309a4fb0 <+44>: add    sp, #0x8

    0x309a4fb2 <+46>: pop    {r4, r5, r7, pc}

    0x309a4fb4 <+48>: mov    r8, r8

    0x309a4fb6 <+50>: mov    r8, r8


(lldb) f 0

frame #0: 0x0011c08a JZH`-[AddTopicViewController checkBtnAction:](self=0x07c91880, _cmd=0x00bf7d95, sender=0x07ca0060) + 50 at AddTopicViewController.m:371

   368 

   369 - (IBAction)checkBtnAction:(id)sender {

   370 

-> 371     if (sender == self.privateBtn) {

   372         self.checkIndex = 1;

   373         UIImage *image = [UIImage imageNamed:@"radio_buttons_p"];

   374         [self.privateBtn setImage:image forState:UIControlStateNormal];

(lldb) frame info

frame #0: 0x0011c08a JZH`-[AddTopicViewController checkBtnAction:](self=0x07c91880, _cmd=0x00bf7d95, sender=0x07ca0060) + 50 at AddTopicViewController.m:371

(lldb) f 1

frame #1: 0x309a5036 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 90

UIKit`-[UIApplication sendAction:to:from:forEvent:]:

    0x309a5036 <+90>: cmp    r4, #0x0

    0x309a5038 <+92>: it     ne

    0x309a503a <+94>: movne  r4, #0x1

    0x309a503c <+96>: mov    r0, r4

(lldb) frame info

frame #1: 0x309a5036 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 90



(lldb) register read

General Purpose Registers:

        r0 = 0x3890d621  libobjc.A.dylib`objc_msgSend + 1

        r1 = 0x00d98210  "privateBtn"

        r2 = 0x0000002a

        r3 = 0x00000000

        r4 = 0x07c91880

        r5 = 0x00bf7d95  "checkBtnAction:"

        r6 = 0x07ca0060

        r7 = 0x27dfdf88

        r8 = 0x01b9db00

        r9 = 0x00000002

       r10 = 0x07cb7330

       r11 = 0x00000000

       r12 = 0x07ca0094

        sp = 0x27dfdef4

        lr = 0x0011c075  JZH`-[AddTopicViewController checkBtnAction:] + 29 at AddTopicViewController.m:369

        pc = 0x0011c08a  JZH`-[AddTopicViewController checkBtnAction:] + 50 at AddTopicViewController.m:371

      cpsr = 0x60000030

(lldb)   register write r6 9

(lldb) register read

General Purpose Registers:

        r0 = 0x3890d621  libobjc.A.dylib`objc_msgSend + 1

        r1 = 0x00d98210  "privateBtn"

        r2 = 0x0000002a

        r3 = 0x00000000

        r4 = 0x07c91880

        r5 = 0x00bf7d95  "checkBtnAction:"

        r6 = 0x00000009

        r7 = 0x27dfdf88

        r8 = 0x01b9db00

        r9 = 0x00000002

       r10 = 0x07cb7330

       r11 = 0x00000000

       r12 = 0x07ca0094

        sp = 0x27dfdef4

        lr = 0x0011c075  JZH`-[AddTopicViewController checkBtnAction:] + 29 at AddTopicViewController.m:369

        pc = 0x0011c08a  JZH`-[AddTopicViewController checkBtnAction:] + 50 at AddTopicViewController.m:371

      cpsr = 0x60000030


(lldb) register read --format i

General Purpose Registers:

        r0 = invalid target  libobjc.A.dylib`objc_msgSend + 1

        r1 = invalid target  "privateBtn"

        r2 = invalid target

        r3 = invalid target

        r4 = invalid target

        r5 = invalid target  "checkBtnAction:"

        r6 = invalid target

        r7 = invalid target

        r8 = invalid target

        r9 = invalid target

       r10 = invalid target

       r11 = invalid target

       r12 = invalid target

        sp = invalid target

        lr = invalid target  JZH`-[AddTopicViewController checkBtnAction:] + 29 at AddTopicViewController.m:369

        pc = invalid target  JZH`-[AddTopicViewController checkBtnAction:] + 50 at AddTopicViewController.m:371

      cpsr = invalid target

(lldb)register read/d

General Purpose Registers:

        r0 = 949016097  libobjc.A.dylib`objc_msgSend + 1

        r1 = 14254608  "privateBtn"

        r2 = 42

        r3 = 0

        r4 = 130619520

        r5 = 12549525  "checkBtnAction:"

        r6 = 130581728

        r7 = 668983176

        r8 = 130195872

        r9 = 2

       r10 = 130367088

       r11 = 0

       r12 = 130581780

        sp = 668983028

        lr = 1163381  JZH`-[AddTopicViewController checkBtnAction:] + 29 at AddTopicViewController.m:369

        pc = 1163402  JZH`-[AddTopicViewController checkBtnAction:] + 50 at AddTopicViewController.m:371

      cpsr = 1610612784

(lldb)register read --all

General Purpose Registers:

        r0 = 0x3890d621  libobjc.A.dylib`objc_msgSend + 1

        r1 = 0x00d98210  "privateBtn"

        r2 = 0x0000002a

        r3 = 0x00000000

        r4 = 0x07c91880

        r5 = 0x00bf7d95  "checkBtnAction:"

        r6 = 0x07c884e0

        r7 = 0x27dfdf88

        r8 = 0x07c2a1a0

        r9 = 0x00000002

       r10 = 0x07c53e70

       r11 = 0x00000000

       r12 = 0x07c88514

        sp = 0x27dfdef4

        lr = 0x0011c075  JZH`-[AddTopicViewController checkBtnAction:] + 29 at AddTopicViewController.m:369

        pc = 0x0011c08a  JZH`-[AddTopicViewController checkBtnAction:] + 50 at AddTopicViewController.m:371

      cpsr = 0x60000030


Floating Point Registers:

        s0 = 0

        s1 = 0

        s2 = 0

        s3 = 0

        s4 = 0

        s5 = 0

        s6 = 0

        s7 = 0

        s8 = 0

        s9 = 0

       s10 = 0

       s11 = 0

       s12 = 0

       s13 = 0

       s14 = 0

       s15 = 0

       s16 = 0

       s17 = 0

       s18 = 0

       s19 = 0

       s20 = 0

       s21 = 0

       s22 = 0

       s23 = 0

       s24 = 0

       s25 = 0

       s26 = 0

       s27 = 0

       s28 = 0

       s29 = 0

       s30 = 0

       s31 = 0

        d0 = 0

        d1 = 0

        d2 = 0

        d3 = 0

        d4 = 0

        d5 = 0

        d6 = 1

        d7 = 1

        d8 = 0

        d9 = 0

       d10 = 0

       d11 = 0

       d12 = 0

       d13 = 0

       d14 = 0

       d15 = 0

       d16 = 18.3

       d17 = 18.3

       d18 = 2176.00148808956

       d19 = 2176.00148808956

       d20 = 0

       d21 = 0

       d22 = 0

       d23 = 0

       d24 = -72

       d25 = -72

       d26 = -0

       d27 = -0

       d28 = 0

       d29 = 0

       d30 = 1

       d31 = 1

        q0 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}

        q1 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}

        q2 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x8c 0xc2 0x00 0x00 0x00 0x00}

        q3 = {0x00 0x00 0x00 0x00 0x00 0x00 0xf0 0x3f 0x00 0x00 0x8c 0xc2 0x00 0x00 0xf0 0x3f}

        q4 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}

        q5 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}

        q6 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x34 0x00 0x00 0x00 0x34}

        q7 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}

        q8 = {0xcd 0xcc 0xcc 0xcc 0xcc 0x4c 0x32 0x40 0x00 0x00 0x8c 0xc2 0x00 0x00 0x8c 0xc2}

        q9 = {0x00 0x00 0x0c 0xc3 0x00 0x00 0xa1 0x40 0x00 0x00 0x00 0x00 0x00 0x00 0xf0 0x3f}

       q10 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}

       q11 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xf0 0x3f}

       q12 = {0x00 0x00 0x00 0x00 0x00 0x00 0x52 0xc0 0x00 0x00 0x00 0x00 0x00 0x00 0xf0 0x3f}

       q13 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}

       q14 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}

       q15 = {0x00 0x00 0x00 0x00 0x00 0x00 0xf0 0x3f 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}

     fpscr = 0x8b000095

  exception = 0x00000000

       fsr = 0x00000000

       far = 0x00000000


(lldb) register read r5

      r5 = 0x00bf7d95  "checkBtnAction:"

(lldb) register read --format binary r5

      r5 = 0b00000000101111110111110110010101  "checkBtnAction:"

(lldb) register read/t r5

      r5 = 0b00000000101111110111110110010101  "checkBtnAction:"


(lldb) disassemble --name checkBtnAction:

JZH`-[AddTopicViewController checkBtnAction:]:

    0x11c058 <+0>:   push   {r7, lr}

    0x11c05a <+2>:   mov    r7, sp

    0x11c05c <+4>:   sub    sp, #0x94

    0x11c05e <+6>:   add    r3, sp, #0x88

    0x11c060 <+8>:   movw   r9, #0x0

    0x11c064 <+12>:  str    r0, [sp, #0x90]

    0x11c066 <+14>:  str    r1, [sp, #0x8c]

    0x11c068 <+16>:  str.w  r9, [sp, #0x88]

    0x11c06c <+20>:  mov    r0, r3

    0x11c06e <+22>:  mov    r1, r2

    0x11c070 <+24>:  blx    0xb29fc8                  ; symbol stub for: objc_storeStrong

(lldb) disassemble --start-address0x11c058--count 20

JZH`-[AddTopicViewController checkBtnAction:]:

    0x11c058 <+0>:  push   {r7, lr}

    0x11c05a <+2>:  mov    r7, sp

    0x11c05c <+4>:  sub    sp, #0x94

    0x11c05e <+6>:  add    r3, sp, #0x88

    0x11c060 <+8>:  movw   r9, #0x0

    0x11c064 <+12>: str    r0, [sp, #0x90]

    0x11c066 <+14>: str    r1, [sp, #0x8c]

    0x11c068 <+16>: str.w  r9, [sp, #0x88]

    0x11c06c <+20>: mov    r0, r3

    0x11c06e <+22>: mov    r1, r2

    0x11c070 <+24>: blx    0xb29fc8                  ; symbol stub for: objc_storeStrong

    0x11c074 <+28>: movw   r0, #0x3f88

    0x11c078 <+32>: movt   r0, #0xbb

    0x11c07c <+36>: add    r0, pc

    0x11c07e <+38>: ldr    r0, [r0]

    0x11c080 <+40>: movw   r1, #0xc184

    0x11c084 <+44>: movt   r1, #0xc7

    0x11c088 <+48>: add    r1, pc

->  0x11c08a <+50>: ldr    r2, [sp, #0x88]

    0x11c08c <+52>: ldr    r3, [sp, #0x90]

(lldb) disassemble --frame --mixed

JZH`-[AddTopicViewController checkBtnAction:] at AddTopicViewController.m:369

   368 

   369 - (IBAction)checkBtnAction:(id)sender {

   370 

JZH`-[AddTopicViewController checkBtnAction:]:

    0x11c058 <+0>:   push   {r7, lr}

    0x11c05a <+2>:   mov    r7, sp

    0x11c05c <+4>:   sub    sp, #0x94

    0x11c05e <+6>:   add    r3, sp, #0x88

    0x11c060 <+8>:   movw   r9, #0x0

    0x11c064 <+12>:  str    r0, [sp, #0x90]

    0x11c066 <+14>:  str    r1, [sp, #0x8c]

    0x11c068 <+16>:  str.w  r9, [sp, #0x88]

    0x11c06c <+20>:  mov    r0, r3

    0x11c06e <+22>:  mov    r1, r2

    0x11c070 <+24>:  blx    0xb29fc8                  ; symbol stub for: objc_storeStrong

    0x11c074 <+28>:  movw   r0, #0x3f88

    0x11c078 <+32>:  movt   r0, #0xbb

    0x11c07c <+36>:  add    r0, pc

    0x11c07e <+38>:  ldr    r0, [r0]

    0x11c080 <+40>:  movw   r1, #0xc184

    0x11c084 <+44>:  movt   r1, #0xc7

    0x11c088 <+48>:  add    r1, pc

JZH`-[AddTopicViewController checkBtnAction:] + 50 at AddTopicViewController.m:371

   370 

-> 371     if (sender == self.privateBtn) {

   372         self.checkIndex = 1;

->  0x11c08a <+50>:  ldr    r2, [sp, #0x88]

    0x11c08c <+52>:  ldr    r3, [sp, #0x90]

    0x11c08e <+54>:  ldr    r1, [r1]

    0x11c090 <+56>:  str    r0, [sp, #0x74]

    0x11c092 <+58>:  mov    r0, r3

    0x11c094 <+60>:  ldr    r3, [sp, #0x74]

    0x11c096 <+62>:  str    r2, [sp, #0x70]

    0x11c098 <+64>:  blx    r3

    0x11c09a <+66>:  mov    r7, r7

    0x11c09c <+68>:  blx    0xb29f58                  ; symbol stub for: objc_retainAutoreleasedReturnValue

    0x11c0a0 <+72>:  mov    r1, r0

    0x11c0a2 <+74>:  str    r1, [sp, #0x6c]

    0x11c0a4 <+76>:  blx    0xb29f18                  ; symbol stub for: objc_release

    0x11c0a8 <+80>:  ldr    r0, [sp, #0x70]

    0x11c0aa <+82>:  ldr    r1, [sp, #0x6c]

    0x11c0ac <+84>:  cmp    r0, r1

    0x11c0ae <+86>:  bne.w  0x11c22c                  ; <+468> at AddTopicViewController.m:379

    0x11c0b2 <+90>:  movs   r2, #0x1

    0x11c0b4 <+92>:  movw   r0, #0x3f48

    0x11c0b8 <+96>:  movt   r0, #0xbb

    0x11c0bc <+100>: add    r0, pc

    0x11c0be <+102>: ldr    r0, [r0]

    0x11c0c0 <+104>: movw   r1, #0xc174

    0x11c0c4 <+108>: movt   r1, #0xc7

    0x11c0c8 <+112>: add    r1, pc

JZH`-[AddTopicViewController checkBtnAction:] + 114 at AddTopicViewController.m:372

   371     if (sender == self.privateBtn) {

   372         self.checkIndex = 1;

   373         UIImage *image = [UIImage imageNamed:@"radio_buttons_p"];

    0x11c0ca <+114>: ldr    r3, [sp, #0x90]

    0x11c0cc <+116>: ldr    r1, [r1]

    0x11c0ce <+118>: str    r0, [sp, #0x68]

    0x11c0d0 <+120>: mov    r0, r3

    0x11c0d2 <+122>: ldr    r3, [sp, #0x68]

    0x11c0d4 <+124>: blx    r3

    0x11c0d6 <+126>: movw   r0, #0xf53a

    0x11c0da <+130>: movt   r0, #0xbd

    0x11c0de <+134>: add    r0, pc

    0x11c0e0 <+136>: movw   r1, #0x3f1c

    0x11c0e4 <+140>: movt   r1, #0xbb

    0x11c0e8 <+144>: add    r1, pc

    0x11c0ea <+146>: ldr    r1, [r1]

    0x11c0ec <+148>: movw   r2, #0xa6c8

    0x11c0f0 <+152>: movt   r2, #0xc7

    0x11c0f4 <+156>: add    r2, pc

    0x11c0f6 <+158>: movw   r3, #0x33d6

    0x11c0fa <+162>: movt   r3, #0xc8

    0x11c0fe <+166>: add    r3, pc

(lldb) disassemble --line

JZH`-[AddTopicViewController checkBtnAction:] + 50 at AddTopicViewController.m:371

   370 

-> 371     if (sender == self.privateBtn) {

   372         self.checkIndex = 1;

JZH`-[AddTopicViewController checkBtnAction:]:

->  0x11c08a <+50>:  ldr    r2, [sp, #0x88]

    0x11c08c <+52>:  ldr    r3, [sp, #0x90]

    0x11c08e <+54>:  ldr    r1, [r1]

    0x11c090 <+56>:  str    r0, [sp, #0x74]

    0x11c092 <+58>:  mov    r0, r3

    0x11c094 <+60>:  ldr    r3, [sp, #0x74]

    0x11c096 <+62>:  str    r2, [sp, #0x70]

    0x11c098 <+64>:  blx    r3

    0x11c09a <+66>:  mov    r7, r7

    0x11c09c <+68>:  blx    0xb29f58                  ; symbol stub for: objc_retainAutoreleasedReturnValue

    0x11c0a0 <+72>:  mov    r1, r0

    0x11c0a2 <+74>:  str    r1, [sp, #0x6c]

    0x11c0a4 <+76>:  blx    0xb29f18                  ; symbol stub for: objc_release

    0x11c0a8 <+80>:  ldr    r0, [sp, #0x70]

    0x11c0aa <+82>:  ldr    r1, [sp, #0x6c]

    0x11c0ac <+84>:  cmp    r0, r1

    0x11c0ae <+86>:  bne.w  0x11c22c                  ; <+468> at AddTopicViewController.m:379

    0x11c0b2 <+90>:  movs   r2, #0x1

    0x11c0b4 <+92>:  movw   r0, #0x3f48

    0x11c0b8 <+96>:  movt   r0, #0xbb

    0x11c0bc <+100>: add    r0, pc

    0x11c0be <+102>: ldr    r0, [r0]

    0x11c0c0 <+104>: movw   r1, #0xc174

    0x11c0c4 <+108>: movt   r1, #0xc7

    0x11c0c8 <+112>: add    r1, pc









(lldb) pinternals sender

(UIButton) $48 = {

  UIControl = {

    UIView = {

      UIResponder = {

        NSObject = {

          isa = UIButton

        }

      }

      _layer = 0x08458300

      _gestureInfo = nil

      _gestureRecognizers = nil

      _subviewCache = 0x08402d30 @"2 objects"

      _charge = 0

      _tag = 2

      _viewDelegate = nil

      _backgroundColorSystemColorName = nil

      _countOfMotionEffectsInSubtree = 0

      _countOfTraitChangeRespondersInDirectSubtree = 3239186440

      _viewFlags = {

        userInteractionDisabled = 0

        implementsDrawRect = 0

        implementsDidScroll = 0

        implementsMouseTracking = 1

        implementsIntrinsicContentSize = 0

        hasBackgroundColor = 0

        isOpaque = 0

        becomeFirstResponderWhenCapable = 0

        interceptMouseEvent = 0

        deallocating = 0

        debugFlash = 0

        debugSkippedSetNeedsDisplay = 0

        debugScheduledDisplayIsRequired = 1

        isInAWindow = 0

        isAncestorOfFirstResponder = 0

        dontAutoresizeSubviews = 0

        autoresizeMask = 18

        patternBackground = 0

        fixedBackgroundPattern = 0

        dontAnimate = 1

        superLayerIsView = 0

        layerKitPatternDrawing = 0

        multipleTouchEnabled = 0

        exclusiveTouch = 0

        hasViewController = 0

        needsDidAppearOrDisappear = 1

        gesturesEnabled = 1

        deliversTouchesForGesturesToSuperview = 0

        chargeEnabled = 0

        skipsSubviewEnumeration = 0

        needsDisplayOnBoundsChange = 0

        hasTiledLayer = 0

        hasLargeContent = 0

        unused = 0

        traversalMark = 0

        appearanceIsInvalid = 0

        monitorsSubtree = 0

        hostsAutolayoutEngine = 1

        constraintsAreClean = 1

        subviewLayoutConstraintsAreClean = 1

        intrinsicContentSizeConstraintsAreClean = 0

        potentiallyHasDanglyConstraints = 1

        doesNotTranslateAutoresizingMaskIntoConstraints = 0

        autolayoutIsClean = 0

        layoutFlushingDisabled = 0

        layingOutFromConstraints = 0

        wantsAutolayout = 1

        subviewWantsAutolayout = 0

        isApplyingValuesFromEngine = 0

        isInAutolayout = 0

        isSubviewUpdatingAutoresizingConstraints = 0

        isUpdatingConstraints = 0

        isHostingUpdateConstraintsPassDuringLayout = 0

        isRunningEngineLevelConstraintsPass = 0

        isUnsatisfiableConstraintsLoggingSuspended = 0

        systemLayoutFittingSizeNeedsUpdate = 0

        systemLayoutFittingSizeNeedsUpdateInWholeSubtree = 0

        isCalculatingSystemLayoutFittingSize = 0

        stayHiddenAwaitingReuse = 0

        stayHiddenAfterReuse = 0

        skippedLayoutWhileHiddenForReuse = 0

        hasMaskView = 0

        hasVisualAltitude = 0

        hasBackdropMaskViews = 0

        backdropMaskViewFlags = 0

        delaysTouchesForSystemGestures = 0

        subclassShouldDelayTouchForSystemGestures = 0

        hasMotionEffects = 1

        backdropOverlayMode = 0

        tintAdjustmentMode = 0

        isReferenceView = 0

        hasUserInterfaceIdiom = 0

        userInterfaceIdiom = 0

        ancestorDefinesTintColor = 0

        ancestorDefinesTintAdjustmentMode = 0

        needsTraitCollectionDidChange = 0

        coloredViewBounds = 0

        coloredAlignmentRects = 0

        coloredHighlightItems = 0

        preservesSuperviewMargins = 0

        hasGeometryObservers = 0

        wantsGeometryChanges = 0

        hasTraitStorageList = 0

        dontUpdateInferredLayoutMargins = 0

      }

    }

    _targetActions = nil

    _previousPoint = (x = 0, y = 0)

    _downTime = 2001-01-01 08:00:00 CST

    _controlFlags = {

      disabled = 0

      tracking = 0

      touchInside = 0

      touchDragged = 0

      requiresDisplayOnTracking = 0

      highlighted = 0

      dontHighlightOnTouchDown = 0

      delayActions = 0

      allowActionsToQueue = 0

      pendingUnhighlight = 0

      selected = 0

      verticalAlignment = 0

      horizontalAlignment = 0

      wasLastHighlightSuccessful = 0

      touchHasHighlighted = 0

    }

  }

}

(lldb)pclass sender

UIButton

   | UIControl

   |    | UIView

   |    |    | UIResponder

   |    |    |    | NSObject


(lldb)pdocspath

/var/mobile/Applications/4E6E3F37-BE80-420D-9B6C-D332A314BEF6/Documents



(lldb) helpvs

Interactively search for a view by walking the hierarchy.


Arguments:

  <view>; Type: UIView*; The view to border.


Syntax: vs <view>


This command is implemented as FBViewSearchCommand in /usr/local/Cellar/chisel/1.3.0/libexec/commands/FBFlickerCommands.py.


(LLDB adds the next line, sorry...)

Syntax: vs

(lldb) vs sender


Use the following and (q) to quit.

(w) move to superview

(s) move to first subview

(a) move to previous sibling

(d) move to next sibling

(p) print the hierarchy


<UIButton: 0x824e1c0; frame = (175 20; 60 40); opaque = NO; autoresize = RM+BM; tag = 2; layer = <CALayer: 0x824fe50>>


w

<UIScrollView: 0x822fa40; frame = (-10 -12; 340 358); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x822d6b0>; layer = <CALayer: 0x822fa10>; contentOffset: {0, 0}>


q


I hope 0x0822fa40 was what you were looking for. I put it on your clipboard.







《未完待续》














你可能感兴趣的:(ios,xcode,调试,lldb)