[ios] LLDB (Swift) : 원시 주소를 사용 가능한 유형으로 캐스팅

원시 주소를 사용 가능한 Swift 클래스로 캐스팅 할 수있는 LLDB 명령이 있습니까?

예를 들면 :

(lldb) po 0x7df67c50 as MKPinAnnotationView

이 주소가 MKPinAnnotationView를 가리키는 것을 알고 있지만 선택할 수있는 프레임이 아닙니다. 그러나 속성을 검사 할 수 있도록 원시 주소를 MKPinAnnotationView로 캐스팅하고 싶습니다. 이게 가능해?



답변

Xcode 8.2.1 및 Swift 3에서 lldb 명령 po 또는 p 는 입력 된 변수와 함께 작동하지 않습니다. 유형이 지정된 개체 인스턴스의 속성을 검사하려면 빠른 명령 print 를 사용해야합니다 . ( cbowns의 답변에 감사드립니다 !) 예 :

expr -l Swift -- import UIKit
expr -l Swift -- let $pin = unsafeBitCast(0x7df67c50, to: MKPinAnnotationView.self)
expr -l Swift -- print($pin.alpha)


답변

Swift의 unsafeBitCast함수를 사용 하여 주소를 객체 인스턴스로 캐스팅 할 수 있습니다 .

(lldb) e let $pin = unsafeBitCast(0x7df67c50, MKPinAnnotationView.self)
(lldb) po $pin

그런 다음 $pin평소 와 같이 작업 할 수 있습니다. 속성 액세스, 메서드 호출 등.

자세한 내용은이 기사를 확인하십시오 : Swift Memory Dumping .


답변

의 lldb 형식 expression은 Xcode 7.3에서 변경된 것 같습니다. 다음으로 시작했습니다.

(lldb) expr -l Swift -- import UIKit
(lldb) expr -l Swift -- let $view = unsafeBitCast(0x7fb75d8349c0, UIView.self)


답변

커스텀 클래스의 경우 프로젝트를 가져와야합니다.

expr -l Swift -- import MyTestProject
expr -l Swift --  let $vc = unsafeBitCast(0x7fad22c066d0, ViewController.self)
expr -l Swift -- print($vc.view)


답변

Xcode 8 / Swift 3에서 저에게 효과적이었습니다. (이것은 @sfaxon의 답변을 기반으로합니다 .)

(lldb) expr -l Swift -- import UIKit
(lldb) expr -l Swift -- let $nav = unsafeBitCast(0x1030ff000, to: UINavigationController.self)


답변

위의 모든 답변 덕분에 unsafeBitCast 는 Xcode 8.3.2 / Swift 3 / macOS / Cocoa Application에서도 잘 작동합니다.

현재 인스턴스의 주소를 기억

(lldb) p tabView.controlTint
(NSControlTint) $R10 = defaultControlTint

(lldb) p self
(LearningStoryboard.NSTabViewController) $R11 = 0x00006080000e2280 {
.....

나중에 그들을 조사하십시오

(lldb) p unsafeBitCast(0x00006080000e2280, to: NSTabViewController.self).tabView.controlTint
(NSControlTint) $R20 = graphiteControlTint

(lldb) p $R11.tabView.controlTint
(NSControlTint) $R21 = graphiteControlTint

이런 일이 생기면

(lldb) p unsafeBitCast(0x00006080000e2280, to: NSTabViewController.self).tabView.controlTint
error: use of undeclared identifier 'to'

(lldb) p $R11.tabView.controlTint
error: use of undeclared identifier '$R11'

어셈블러가 아닌 Swift 소스 코드의 스택 프레임 중 하나를 선택해야합니다.

일시 중지 버튼 을 클릭하여 응용 프로그램을 일시 중지 했거나 예외와 함께 중지했을 때 발생할 수 있습니다. 그에 따라 스택 프레임을 선택하여 lldb 가 적절한 프로그래밍 언어를 추론하도록합니다.


답변

Objective-C 버전

po ((MKPinAnnotationView *)0x7df67c50).alpha