xcode 如何在 self.view 的属性上设置 lldb 观察点?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13976219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I set an lldb watchpoint on a property of self.view?
提问by DenverCoder9
I want to trace when something changes the size of self.view. What's the correct format?
我想跟踪什么时候改变 self.view 的大小。什么是正确的格式?
(lldb) po self.view
(UIView *) = 0x0a8aba20 <UIView: 0xa8aba20; frame = (0 0; 480 864); autoresize = W+TM+BM; layer = <CALayer: 0xa8aba50>>
(lldb) watch set variable self.view.frame.size.width
error: "self" is a pointer and . was used to attempt to access "view". Did you mean "self->view.frame.size.width"?
(lldb) watch set variable self->view
error: "view" is not a member of "(PlayViewController *) self"
(lldb) watch set variable self->view.frame.size.width
error: "view" is not a member of "(PlayViewController *) self"
I've tried the documentation and other lldb watchpoint questions but can't find anything for this specific case.
我已经尝试了文档和其他 lldb 观察点问题,但找不到针对此特定情况的任何内容。
Thanks for your help.
谢谢你的帮助。
回答by rob mayoff
The view controller references its view from its _view
instance variable.
视图控制器从它的_view
实例变量中引用它的视图。
The view doesn't store its frame directly. It just returns its layer's `frame'.
视图不直接存储其框架。它只是返回其图层的“框架”。
The view references its layer from its _layer
instance variable.
视图从它的_layer
实例变量引用它的层。
The layer doesn't store the frame either. It computes its frame from its bounds
, position
, anchorPoint
, and transform
. The size is part of bounds
.
该层也不存储帧。它从计算它的框架bounds
,position
,anchorPoint
,和transform
。大小是 的一部分bounds
。
The layer doesn't store its bounds directly in an instance variable. Instead, its layer
instance variable references an instance of a private C++ class, CA::Layer
. The member layout of this class is undocumented.
该层不直接将其边界存储在实例变量中。相反,它的layer
实例变量引用了一个私有 C++ 类的实例,CA::Layer
. 此类的成员布局未记录。
In other words, you can go self->_view->_layer->layer
to get to the CA::Layer
instance, but then you're stuck because you don't know where in the CA::Layer
to find the bounds.
换句话说,你可以self->_view->_layer->layer
去的CA::Layer
实例,但随后你就完蛋了,因为你不知道在哪里的CA::Layer
寻找范围。
So, trying to use a watchpoint to detect changes to the view's size is rather difficult.
因此,尝试使用观察点来检测视图大小的变化是相当困难的。
It is easier to put a breakpoint on -[CALayer setBounds:]
.
在 上放置断点更容易-[CALayer setBounds:]
。
On the simulator
在模拟器上
Remember to use the layer addressin the breakpoint condition, notthe view address.
切记在断点条件下使用层地址,而不是视图地址。
(lldb) po self.view
(UIView *) = 0x0a034690 <UIView: 0xa034690; frame = (0 20; 768 1004); autoresize = W+H; layer = <CALayer: 0xa034780>>
(lldb) break set -F '-[CALayer setBounds:]' -c '((int*)$esp)[1] == 0xa034780'
Breakpoint created: 2: name = '-[CALayer setBounds:]', locations = 1, resolved = 1
When the breakpoint is hit, the CALayer
instance is referenced by ((int *)$esp)[1]
, and the new bounds is *(CGRect *)($esp+12)
:
当断点被击中时,CALayer
实例被 引用((int *)$esp)[1]
,新的边界是*(CGRect *)($esp+12)
:
(lldb) po ((int*)$esp)[1]
(int) = 167987072 <CALayer:0xa034780; position = CGPoint (384 480); bounds = CGRect (0 0; 768 1004); delegate = <UIView: 0xa034690; frame = (0 -22; 768 1004); autoresize = W+H; layer = <CALayer: 0xa034780>>; sublayers = (<CALayer: 0xa033010>); backgroundColor = <CGColor 0xa034960> [<CGColorSpace 0xa02b3b0> (kCGColorSpaceDeviceRGB)] ( 1 1 1 1 )>
(lldb) p *(CGRect*)($esp+12)
(CGRect) = origin=(x=0, y=0) size=(width=768, height=960)
(lldb) finish
(lldb) po 0xa034780
(int) = 167987072 <CALayer:0xa034780; position = CGPoint (384 480); bounds = CGRect (0 0; 768 960); delegate = <UIView: 0xa034690; frame = (0 0; 768 960); autoresize = W+H; layer = <CALayer: 0xa034780>>; sublayers = (<CALayer: 0xa033010>); backgroundColor = <CGColor 0xa034960> [<CGColorSpace 0xa02b3b0> (kCGColorSpaceDeviceRGB)] ( 1 1 1 1 )>
On the device
在设备上
Remember to use the layer addressin the breakpoint condition, notthe view address.
切记在断点条件下使用层地址,而不是视图地址。
(lldb) po self.view
(UIView *) (lldb) po $r0
(unsigned int) = 520297216 <CALayer:0x1f031b00; position = CGPoint (384 480); bounds = CGRect (0 0; 768 1004); delegate = <UIView: 0x1f031a10; frame = (0 -22; 768 1004); autoresize = W+H; layer = <CALayer: 0x1f031b00>>; sublayers = (<CALayer: 0x1f030840>); backgroundColor = <CGColor 0x1f031ce0> [<CGColorSpace 0x1e530ad0> (kCGColorSpaceDeviceRGB)] ( 1 1 1 1 )>
(lldb) p/f $r2
(unsigned int) = 0
(lldb) p/f $r3
(unsigned int) = 0
(lldb) p *(CGSize *)$sp
(CGSize) = (width=768, height=960)
(lldb) finish
(lldb) po 0x1f031b00
(int) = 520297216 <CALayer:0x1f031b00; position = CGPoint (384 480); bounds = CGRect (0 0; 768 960); delegate = <UIView: 0x1f031a10; frame = (0 0; 768 960); autoresize = W+H; layer = <CALayer: 0x1f031b00>>; sublayers = (<CALayer: 0x1f030840>); backgroundColor = <CGColor 0x1f031ce0> [<CGColorSpace 0x1e530ad0> (kCGColorSpaceDeviceRGB)] ( 1 1 1 1 )>
= 0x1f031a10 <UIView: 0x1f031a10; frame = (0 20; 768 1004); autoresize = W+H; layer = <CALayer: 0x1f031b00>>
(lldb) break set -F '-[CALayer setBounds:]' -c '$r0 == 0x1f031b00'
Breakpoint created: 2: name = '-[CALayer setBounds:]', locations = 1, resolved = 1
When the breakpoint is hit, the CALayer
instance is referenced by $r0
, the new X origin is in $r2
, the new Y origin is in $r3
, and the new size is *(CGSize *)$sp
:
当断点被击中时,CALayer
实例被 引用$r0
,新的 X 原点在$r2
,新的 Y 原点在$r3
,新的大小是*(CGSize *)$sp
:
break set -F '-[CALayer setBounds:]' -c '$rdi == 0x...'
回答by user8030
On 64 bit simulators the break command should be:
在 64 位模拟器上,break 命令应该是:
##代码##