What s New in LLDB. Debug your way to fame and glory #WWDC15. Developer Tools. Session 402

Similar documents
Advanced Debugging and the Address Sanitizer

Optimizing Swift Performance Session 409

Finding Bugs Using Xcode Runtime Tools

Implementing UI Designs in Interface Builder

Improving your Existing Apps with Swift

Accessibility on OS X

Thread Sanitizer and Static Analysis

Profiling in Depth. Do you know where your code is? Session 412. Kris Markel Performance Tools Engineer Chad Woolf Performance Tools Engineer

Cocoa Development Tips

What's New in UIKit Dynamics and Visual Effects Session 229

Using and Extending the Xcode Source Editor

Debugging and Profiling

Building Better Apps with Value Types in Swift Session 414

To use Xcode s Continuous Integration service with this Xcode beta, you need OS X with OS X Server 4.0.

What s New in NSCollectionView Session 225

What s New in Swift #WWDC18. Ted Kremenek, Languages & Runtimes Manager Slava Pestov, Swift Compiler Engineer

Understanding Undefined Behavior

ios Application Development Lecture 2: Seminar and Unit 1

Modern User Interaction on ios

Building Faster in Xcode

Enhancing your apps for the next dimension of touch

Xcode & Swift: Introduction

What s New in the LLVM Compiler. Chris Lattner LLVM Chief Architect

Building Watch Apps #WWDC15. Featured. Session 108. Neil Desai watchos Engineer

Monetize and Promote Your App with iad

Introducing Swift Playgrounds

What s New in SpriteKit

Xcode 6 and ios 8 What s New for Software Developers

iphone Application Programming Lab 2: MVC and Delegation + A01 discussion

Introducing On Demand Resources

Adopting Advanced Features of the New UI

Introducing Metal 2. Graphics and Games #WWDC17. Michal Valient, GPU Software Engineer Richard Schreyer, GPU Software Engineer

Extending Your Apps with SiriKit

Building Visually Rich User Experiences

What s New in Notifications

What s New in Cocoa for macos

Seamless Linking to Your App

Enabling Your App for CarPlay

Getting the Most out of Playgrounds in Xcode

Mysteries of Auto Layout, Part 1

Touch Bar Fundamentals

Questions. Exams: no. Get by without own Mac? Why ios? ios vs Android restrictions. Selling in App store how hard to publish? Future of Objective-C?

Swift. Introducing swift. Thomas Woodfin

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

Power, Performance, and Diagnostics

Data Delivery with Drag and Drop

Cocoa Touch Best Practices

Accessibility on ios. Developing for everyone. Frameworks #WWDC14. Session 210 Clare Kasemset ios Accessibility

What s New in Foundation for Swift Session 207

Apple offers a number of resources where you can get Xcode development support:!

Xcode Tricks. ios App Development Fall 2010 Lecture 13

Localizing with Xcode 9

Introducing LLDB for Linux on Arm and AArch64. Omair Javaid

Leveraging Touch Input on ios

What s New in tvos #WWDC16. App Frameworks. Session 206. Hans Kim tvos Engineer

Mastering Xcode for iphone OS Development Part 1. Todd Fernandez Sr. Manager, IDEs

What s New in Core Data?

SWIFT! init(title: String) { self.title = title } // required initializer w/ named parameter

Mastering UIKit on tvos

Introduction to Swift. Dr. Sarah Abraham

WatchKit In-Depth, Part 2

Ruby: Introduction, Basics

Working with Metal Overview

Localization Best Practices on tvos

CSE 351. GDB Introduction

Introductory ios Development

Using Grouped Notifications

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga

What's New in Core Spotlight

Porting Objective-C to Swift. Richard Ekle

What s New in MapKit. App Frameworks #WWDC17. Fredrik Olsson

CSE 431S Type Checking. Washington University Spring 2013

Cocoa. Last Week... Music 3SI: Introduction to Audio/Multimedia App. Programming. Today... Why Cocoa? Wikipedia - Cocoa

Apple offers a number of resources where you can get Xcode development support:!

What s New in Xcode App Signing

New UIKit Support for International User Interfaces

Designing for Apple Watch

Building for Voice with Siri Shortcuts

ios Accessibility Developing for everyone Session 201 Ian Fisch ios Accessibility

Adapting to the New UI of OS X Yosemite

ECEN 449 Microprocessor System Design. Review of C Programming

Mastering Drag and Drop

PLUX ios Application Programming Interface. Documentation - ios API

App Extension Best Practices

Localizing with Xcode 6

Stanford CS193p. Developing Applications for ios. Winter CS193p. Winter 2017

Creating Complications with ClockKit Session 209

Storyboards and Controllers on OS X

What s New in Cocoa. App Frameworks #WWDC17. Ali Ozer Daphne Larose

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

Richard Mallion. Swift for Admins #TEAMSWIFT

ios: Objective-C Primer

Game Center Techniques, Part 1

Kevin van Vechten Core OS

Fast Introduction to Object Oriented Programming and C++

A Fast Review of C Essentials Part I

Polymorphism COSC346

Fix Bugs Faster Using Activity Tracing

Swift API Design Guidelines

Advanced Scrollviews and Touch Handling Techniques

Transcription:

Developer Tools #WWDC15 What s New in LLDB Debug your way to fame and glory Session 402 Kate Stone Software Behavioralist Sean Callanan Master of Expressions Enrico Granata Data Wizard 2015 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

The Year s Highlights Changes big and small

Since WWDC 2014

Since WWDC 2014 Shipped Swift debugger

Since WWDC 2014 Shipped Swift debugger Shipped Swift REPL

Since WWDC 2014 Shipped Swift debugger Shipped Swift REPL LLDB in disguise

Since WWDC 2014 Shipped Swift debugger Shipped Swift REPL LLDB in disguise Numerous improvements

Since WWDC 2014 Shipped Swift debugger Shipped Swift REPL LLDB in disguise Numerous improvements Swift types show inherited Objective-C fields

Since WWDC 2014 Shipped Swift debugger Shipped Swift REPL LLDB in disguise Numerous improvements Swift types Help includes command aliases

Since WWDC 2014 Shipped Swift debugger Shipped Swift REPL LLDB in disguise Numerous improvements Swift types help Help includes command aliases

Since WWDC 2014 Shipped Swift debugger Shipped Swift REPL LLDB in disguise Numerous improvements Swift types help Help includes command aliases

Since WWDC 2014 Shipped Swift debugger Shipped Swift REPL LLDB in disguise Numerous improvements Swift types help Help includes command aliases expression -O --

Since WWDC 2014 Shipped Swift debugger Shipped Swift REPL LLDB in disguise Numerous improvements Swift types help Help includes command aliases expression -O -- po

Since WWDC 2014 Shipped Swift debugger Shipped Swift REPL LLDB in disguise Numerous improvements Swift types help Help includes command aliases Improved data formatting expression -O -- po

Since WWDC 2014 Shipped Swift debugger Shipped Swift REPL LLDB in disguise Numerous improvements Swift types help Help includes command aliases Improved data formatting expression -O -- po - Set<T>, NSIndexPath

Since WWDC 2014 Shipped Swift debugger Shipped Swift REPL LLDB in disguise Numerous improvements Swift types help Help includes command aliases Improved data formatting expression -O -- po - Set<T>, NSIndexPath printf() prototype for expressions

Since WWDC 2014 Shipped Swift debugger Shipped Swift REPL LLDB in disguise Numerous improvements Swift types help Help includes command aliases Improved data formatting expression -O -- po - Set<T>, NSIndexPath printf() prototype for expressions Improved disassembly

Recent Breakpoint Enhancements Named breakpoints Multiple non-unique names allowed Other breakpoint commands take names

Recent Breakpoint Enhancements Named breakpoints breakpoint set -N name Multiple non-unique names allowed Other breakpoint commands take names

Recent Breakpoint Enhancements Named breakpoints breakpoint set -N name Multiple non-unique names allowed Other breakpoint commands take names breakpoint enable name breakpoint disable name breakpoint delete name

Recent Breakpoint Enhancements Named breakpoints breakpoint set -N name Multiple non-unique names allowed Other breakpoint commands take names breakpoint enable name Breakpoints in ~/.lldbinit Create default breakpoints when LLDB starts Inherited by all debug targets breakpoint disable name breakpoint delete name

Recent Breakpoint Enhancements Named breakpoints breakpoint set -N name Multiple non-unique names allowed Other breakpoint commands take names breakpoint enable name Breakpoints in ~/.lldbinit Create default breakpoints when LLDB starts Inherited by all debug targets breakpoint disable name breakpoint delete name breakpoint set -n malloc -N memory breakpoint set -n free -N memory breakpoint disable memory

Xcode 7

Xcode 7 Improvements in expression evaluation Swift 2 support Objective-C module support

Xcode 7 Improvements in expression evaluation Swift 2 support Objective-C module support Improved data formatters Vector types in Objective-C and Swift Custom data formatters written in Swift

Xcode 7 Improvements in expression evaluation Swift 2 support Objective-C module support Improved data formatters Vector types in Objective-C and Swift Custom data formatters written in Swift Address Sanitizer integration

Xcode 7 Improvements in expression evaluation memory history Swift 2 support Objective-C module support memory read Improved data formatters Vector types in Objective-C and Swift Custom data formatters written in Swift memory write memory find Address Sanitizer integration

Xcode 7 Improvements in expression evaluation memory history Swift 2 support Objective-C module support memory read Improved data formatters Vector types in Objective-C and Swift Custom data formatters written in Swift memory write memory find Address Sanitizer integration Type lookup command Built-in type documentation

Type Lookup

Type Lookup (lldb)

Type Lookup (lldb) type lookup ErrorType protocol ErrorType { var _domain: Swift.String { get } var _code: Swift.Int { get } } (lldb)

Type Lookup (lldb) type lookup ErrorType protocol ErrorType { var _domain: Swift.String { get } var _code: Swift.Int { get } } (lldb) type lookup Comparable protocol Comparable : _Comparable, Equatable { func <=(lhs: Self, rhs: Self) -> Swift.Bool func >=(lhs: Self, rhs: Self) -> Swift.Bool func >(lhs: Self, rhs: Self) -> Swift.Bool }

Type Lookup (lldb) type lookup ErrorType protocol ErrorType { var _domain: Swift.String { get } type lookup var _code: Swift.Int { get } } (lldb) type lookup Comparable protocol Comparable : _Comparable, Equatable { func <=(lhs: Self, rhs: Self) -> Swift.Bool func >=(lhs: Self, rhs: Self) -> Swift.Bool func >(lhs: Self, rhs: Self) -> Swift.Bool }

Compilers in LLDB Making Swift and Objective-C better and easier to debug

Overview Objective-C expression improvements Swift error-handling support

Overview Objective-C expression improvements Swift error-handling support

Objective-C and Swift in LLDB Obj-C

Objective-C and Swift in LLDB Obj-C

Objective-C and Swift in LLDB Obj-C

Objective-C and Swift in LLDB Obj-C

How Swift Works in LLDB (lldb)

How Swift Works in LLDB (lldb) p for i in (0..<5) { print(i) }

How Swift Works in LLDB (lldb) p for i in (0..<5) { print(i) } expression -- p

How Swift Works in LLDB (lldb) p for i in (0..<5) { print(i) } 0 1 2 3 4 expression -- p

How Swift Works in LLDB LLDB Your Program (lldb) p for i in (0..<5) { print(i) } 0 1 2 3 4 expression -- p

How Swift Works in LLDB Swift LLDB Your Program (lldb) p for i in (0..<5) { print(i) } 0 1 2 3 4 expression -- p

How Swift Works in LLDB Swift LLDB Added Code Your Program (lldb) p for i in (0..<5) { print(i) } 0 1 2 3 4 expression -- p

How Swift Works with Your Variables Swift LLDB Added Code Your Program (lldb)

How Swift Works with Your Variables Swift LLDB Added Code Your Program (lldb) p for i in (0..<3) { print(names[i]) }

How Swift Works with Your Variables Swift LLDB Added Code Your Program (lldb) p for i in (0..<3) { print(names[i]) } Kate Sean Enrico

How Swift Works with Your Variables Swift Added Code Data LLDB Your Program (lldb) p for i in (0..<3) { print( names[i]) } Kate Sean Enrico

How Swift Works with the SDK Swift Added Code Data LLDB Your Program (lldb)

How Swift Works with the SDK Swift Added Code Data LLDB Your Program (lldb) p NSApplication.sharedApplication()

How Swift Works with the SDK Swift Added Code Data LLDB Your Program (lldb) p NSApplication.sharedApplication() (NSApplication) $R1 = 0x0000600000100240 { AppKit.NSResponder = { NSObject = { isa = NSApplication } _nextresponder = nil } }

How Swift Works with the SDK Swift Added Code Data LLDB Your Program SDK Module (lldb) p NSApplication.sharedApplication() (NSApplication) $R1 = 0x0000600000100240 { AppKit.NSResponder = { NSObject = { isa = NSApplication } _nextresponder = nil } }

How Swift Works with the SDK Swift Added Code Data Class LLDB Your Program SDK Module (lldb) p NSApplication.sharedApplication() (NSApplication) $R1 = 0x0000600000100240 { AppKit.NSResponder = { NSObject = { isa = NSApplication } _nextresponder = nil } }

It s All Automatic!

It s All Automatic! in Swift

Let s Try the Same Thing in Objective-C! (lldb)

Let s Try the Same Thing in Objective-C! (lldb) p NSLog(@ %d, i)

Let s Try the Same Thing in Objective-C! (lldb) p NSLog(@ %d, i) error: 'NSLog' has unknown return type; cast the call to its declared return type error: 1 errors parsing expression

Let s Try the Same Thing in Objective-C! (lldb) p NSLog(@ %d, i) error: 'NSLog' has unknown return type; cast the call to its declared return type error: 1 errors parsing expression How it s defined What LLDB sees void NSLog(NSString *format,...)??? NSLog(...)

Let s Try the Same Thing in Objective-C! (lldb) p NSLog(@ %d, i) 2015-05-14 21:50:41.852 DemoApp[58380:1079308] 0

Let s Try the Same Thing in Objective-C! (lldb)

Let s Try the Same Thing in Objective-C! (lldb) p NSMakeRect(0, 0, 10, 10)

Let s Try the Same Thing in Objective-C! (lldb) p NSMakeRect(0, 0, 10, 10) error: use of undeclared identifier NSMakeRect error: 1 errors parsing expression

Let s Try the Same Thing in Objective-C! (lldb) p NSMakeRect(0, 0, 10, 10) error: use of undeclared identifier NSMakeRect error: 1 errors parsing expression NS_INLINE NSRect NSMakeRect( How it s defined CGFloat, CGFloat, CGFloat, CGFloat) What LLDB sees

Let s Try the Same Thing in Objective-C! (lldb) p NSMakeRect(0, 0, 10, 10) (NSRect) $0 = (origin = (x = 0, y = 0), size = (width = 10, height = 10))

Let s Try the Same Thing in Objective-C! (lldb)

Let s Try the Same Thing in Objective-C! (lldb) p [NSApplication sharedapplication].undomanager

Let s Try the Same Thing in Objective-C! (lldb) p [NSApplication sharedapplication].undomanager error: property undomanager not found on object of type id error: 1 errors parsing expression

Let s Try the Same Thing in Objective-C! (lldb) p [NSApplication sharedapplication].undomanager error: property undomanager not found on object of type id error: 1 errors parsing expression How it s defined What LLDB sees -(NSApplication*)sharedApplication -(id)sharedapplication

Let s Try the Same Thing in Objective-C! (lldb) p [NSApplication sharedapplication].undomanager (NSUndoManager * nullable) $1 = nil

The Information Is Right There!

The Information Is Right There! Your Code names, MyFunc(), MyView

The Information Is Right There! Your Code names, MyFunc(), MyView SDK Functions NSLog, NSMakeRect

The Information Is Right There! Your Code names, MyFunc(), MyView SDK Functions NSLog, NSMakeRect SDK Classes NSView, NSApplication *

The Information Is Right There! Your Code names, MyFunc(), MyView SDK Functions NSLog, NSMakeRect SDK Classes NSView, NSApplication * SDK Constants NSASCIIStringEncoding

The Information Is Right There! Your Code names, MyFunc(), MyView SDK Functions NSLog, NSMakeRect SDK Classes NSView, NSApplication * SDK Constants NSASCIIStringEncoding Macros INT_MAX, MAX()

The Information Is Right There! Your Code names, MyFunc(), MyView SDK Functions NSLog, NSMakeRect SDK Classes NSView, NSApplication * SDK Constants NSASCIIStringEncoding Macros INT_MAX, MAX()

The Information Is Right There! Your Code names, MyFunc(), MyView SDK Functions NSLog, NSMakeRect SDK Classes NSView, NSApplication SDK Constants NSASCIIStringEncoding Macros INT_MAX, MAX()

expr @import AppKit

expr @import UIKit

Overview Objective-C expression improvements Swift error-handling support

Handling Errors in Swift Expressions

Handling Errors in Swift Expressions Expressions can handle Swift errors

Handling Errors in Swift Expressions Expressions can handle Swift errors No need to try in LLDB

Handling Errors in Swift Expressions Expressions can handle Swift errors No need to try in LLDB (lldb)

Handling Errors in Swift Expressions Expressions can handle Swift errors No need to try in LLDB (lldb) expr ThisFunctionThrows()

Handling Errors in Swift Expressions Expressions can handle Swift errors No need to try in LLDB (lldb) expr ThisFunctionThrows() (a.enumerror) $E0 = SeriousError

Handling Errors in Swift Expressions Expressions can handle Swift errors No need to try in LLDB (lldb) expr ThisFunctionThrows() (a.enumerror) $E0 = SeriousError Works in the REPL, too!

Handling Errors in Swift Expressions Expressions can handle Swift errors No need to try in LLDB (lldb) expr ThisFunctionThrows() (a.enumerror) $E0 = SeriousError Works in the REPL, too! 1>

Handling Errors in Swift Expressions Expressions can handle Swift errors No need to try in LLDB (lldb) expr ThisFunctionThrows() (a.enumerror) $E0 = SeriousError Works in the REPL, too! 1> ThisFunctionThrows()

Handling Errors in Swift Expressions Expressions can handle Swift errors No need to try in LLDB (lldb) expr ThisFunctionThrows() (a.enumerror) $E0 = SeriousError Works in the REPL, too! 1> ThisFunctionThrows() $E0: EnumError = MyError

Stopping When Swift Errors Occur

Stopping When Swift Errors Occur Use breakpoints

Stopping When Swift Errors Occur Use breakpoints On Objective-C exceptions

Stopping When Swift Errors Occur Use breakpoints On Objective-C exceptions (lldb)

Stopping When Swift Errors Occur Use breakpoints On Objective-C exceptions (lldb) br s -E objc

Stopping When Swift Errors Occur Use breakpoints On Objective-C exceptions breakpoint set -E language (lldb) br s -E objc

Stopping When Swift Errors Occur Use breakpoints On Objective-C exceptions breakpoint set -E language (lldb) br s -E objc Breakpoint 1: where = libobjc.a.dylib`objc_exception_throw, address = 0x00007fff9046bd18

Stopping When Swift Errors Occur Use breakpoints On Objective-C exceptions breakpoint set -E language (lldb) br s -E objc Breakpoint 1: where = libobjc.a.dylib`objc_exception_throw, address = 0x00007fff9046bd18 On Swift errors

Stopping When Swift Errors Occur Use breakpoints On Objective-C exceptions breakpoint set -E language (lldb) br s -E objc Breakpoint 1: where = libobjc.a.dylib`objc_exception_throw, address = 0x00007fff9046bd18 On Swift errors (lldb)

Stopping When Swift Errors Occur Use breakpoints On Objective-C exceptions breakpoint set -E language (lldb) br s -E objc Breakpoint 1: where = libobjc.a.dylib`objc_exception_throw, address = 0x00007fff9046bd18 On Swift errors (lldb) br s -E swift

Stopping When Swift Errors Occur Use breakpoints On Objective-C exceptions breakpoint set -E language (lldb) br s -E objc Breakpoint 1: where = libobjc.a.dylib`objc_exception_throw, address = 0x00007fff9046bd18 On Swift errors (lldb) br s -E swift Breakpoint 1: where = libswiftcore.dylib`swift_willthrow, address = 0x00000001001f71e0

Stopping on Specific Errors

Stopping on Specific Errors Supported for Swift

Stopping on Specific Errors Supported for Swift (lldb)

Stopping on Specific Errors Supported for Swift (lldb) br s -E swift -O EnumError Breakpoint 1: where = libswiftcore.dylib`swift_willthrow, (lldb) address = 0x00000001001f71e0

Stopping on Specific Errors Supported for Swift (lldb) br s -E swift -O EnumError Breakpoint 1: where = libswiftcore.dylib`swift_willthrow, (lldb) address = 0x00000001001f71e0 breakpoint set -E language -O type-name

Stopping on Specific Errors Supported for Swift (lldb) br s -E swift -O EnumError Breakpoint 1: where = libswiftcore.dylib`swift_willthrow, (lldb) address = 0x00000001001f71e0 continue 25 if input > 100 26 { -> 27 throw EnumError.ImportantError 28 } 29 else if input > 10 30 { breakpoint set -E language -O type-name

Of Course, You Can Still Catch Them 1>

Of Course, You Can Still Catch Them 1> import Foundation 2>

Of Course, You Can Still Catch Them 1> import Foundation 2> do { throw NSError(domain: My domain, code: 0, userinfo:nil) } catch let x { print(x) }

Of Course, You Can Still Catch Them 1> import Foundation 2> do { throw NSError(domain: My domain, code: 0, userinfo:nil) } catch let x { print(x) } Error Domain=My domain Code=0 The operation couldn t be completed. (My domain error 0.)

Presentation Is Everything Formatted data is comprehended data

Examining Data

Examining Data frame variable

Examining Data frame variable expression --

Examining Data frame variable expression -- p

Examining Data frame variable expression -- p expression -O --

Examining Data frame variable expression -- p expression -O -- po

The Frame Variable Command

The Frame Variable Command frame variable

The Frame Variable Command (lldb) frame variable (Int, String) mytuple = (0 = 12, 1 = Hello World ) (Int) theyear = 1984 frame variable

The Frame Variable Command (lldb) frame variable (Int, String) mytuple = (0 = 12, 1 = Hello World ) (Int) theyear = 1984 (lldb) frame variable theyear (Int) theyear = 1984 frame variable

The Frame Variable Command (lldb) frame variable (Int, String) mytuple = (0 = 12, 1 = Hello World ) (Int) theyear = 1984 (lldb) frame variable theyear (Int) theyear = 1984 frame variable (lldb) frame variable -format hex theyear (Int) theyear = 0x00000000000007c0

The Frame Variable Command (lldb) frame variable (Int, String) mytuple = (0 = 12, 1 = Hello World ) (Int) theyear = 1984 children (lldb) frame variable theyear (Int) theyear = 1984 frame variable (lldb) frame variable -format hex theyear (Int) theyear = 0x00000000000007c0

The Expression Command

The Expression Command expression -- p

The Expression Command (lldb) p theyear + 1 (Int) $R0 = 1985 expression -- p

The Expression Command (lldb) p theyear + 1 (Int) $R0 = 1985 (lldb) p String($R0 + 1) (String) $R1 = 1986 expression -- p

The Expression Command (lldb) p theyear + 1 (Int) $R0 = 1985 (lldb) p String($R0 + 1) (String) $R1 = 1986 expression -- p (lldb) expr -format hex - [1,2,3] ([Int]) $R0 = 3 values { [0] = 0x0000000000000001 [1] = 0x0000000000000002 [2] = 0x0000000000000003 }

The Expression Command (lldb) p theyear + 1 (Int) $R0 = 1985 (lldb) p String($R0 + 1) (String) $R1 = 1986 expression -- p (lldb) expr -format hex - [1,2,3] ([Int]) $R0 = 3 values { [0] = 0x0000000000000001 [1] = 0x0000000000000002 [2] = 0x0000000000000003 } children

The po Command

The po Command expression -O -- po

The po Command (lldb) po [[MyView alloc] initwithframe: myframe] <MyView: 0x101405110> expression -O -- po

The po Command (lldb) po [[MyView alloc] initwithframe: myframe] <MyView: 0x101405110> (lldb) po @[@1, @2, @3] < NSArrayI 0x10050b2a0>( 1, 2, 3 ) expression -O -- po

The po Command (lldb) po [[MyView alloc] initwithframe: myframe] <MyView: 0x101405110> (lldb) po @[@1, @2, @3] < NSArrayI 0x10050b2a0>( 1, 2, 3 ) expression -O -- po (lldb) po @ Hello World Hello World

Formatting Models

Formatting Models frame variable expression -- p expression -O -- po does not run code runs your code runs your code uses LLDB formatters uses LLDB formatters + code to format object

Formatting Models frame variable expression -- p expression -O -- po does not run code runs your code runs your code uses LLDB formatters uses LLDB formatters + code to format object

Formatting Models frame variable expression -- p expression -O -- po does not run code runs your code runs your code uses LLDB formatters uses LLDB formatters + code to format object

Formatting Models

Formatting Models Out-of-process formatting Data and formatter are separate Easy access to debugger s object model Easier to keep program state intact

Formatting Models Out-of-process formatting Data and formatter are separate Easy access to debugger s object model Easier to keep program state intact In-process formatting Data and formatter live together Easy access to your object model Care required to keep program state intact

In-Process Swift Formatting

In-Process Swift Formatting Powers playgrounds since day one

In-Process Swift Formatting Powers playgrounds since day one Now Public API Also powers LLDB po command

In-Process Swift Formatting

In-Process Swift Formatting Four Swift protocols

In-Process Swift Formatting Four Swift protocols CustomStringConvertible CustomDebugStringConvertible CustomPlaygroundQuickLookable CustomReflectable

In-Process Swift Formatting Four Swift protocols CustomStringConvertible CustomDebugStringConvertible CustomPlaygroundQuickLookable CustomReflectable Partial opt-in possible

CustomStringConvertible String representation of the object Used by the print() function, and string interpolation

CustomStringConvertible String representation of the object Used by the print() function, and string interpolation struct BottlesOfBeer : CustomStringConvertible { var Count: Int var description: String { return \(Count) bottles of beer on the wall } }

CustomDebugStringConvertible Debugger-specific String representation of the object Used by debugprint() (and print() if necessary)

CustomDebugStringConvertible Debugger-specific String representation of the object Used by debugprint() (and print() if necessary) extension BottlesOfBeer : CustomDebugStringConvertible { var debugdescription: String { return \(Count) bottles of stout on the wall. } }

CustomPlaygroundQuickLookable Graphical representation for display in playgrounds

CustomPlaygroundQuickLookable

CustomReflectable

CustomReflectable Allows vending an entirely custom children hierarchy

CustomReflectable Allows vending an entirely custom children hierarchy Returns a Mirror for an object Representation of an object s structure

Temperature Data

Temperature Data struct Timestamp { var Hour: Int var Minute: Int } struct TemperatureData { var Time: Timestamp var Temperature: Float }

Temperature Data struct Timestamp { var Hour: Int var Minute: Int } struct TemperatureData { var Time: Timestamp var Temperature: Float } let Temps = [ TemperatureData(Time: Timestamp(Hour: 6, Minute: 30), Temperature: 10), TemperatureData(Time: Timestamp(Hour: 18, Minute: 30), Temperature: 34) ]

Temperature Data

Temperature Data (lldb) po Temps

Temperature Data (lldb) po Temps 2 elements [0] : TemperatureData Time : Timestamp - Hour : 6 - Minute : 30 - Temperature : 10 [1] : TemperatureData Time : Timestamp - Hour : 18 - Minute : 30 - Temperature : 34

Temperature Data (lldb) po Temps 2 elements [0] : TemperatureData Time : Timestamp - Hour : 6 - Minute : 30 - Temperature : 10 [1] : TemperatureData Time : Timestamp - Hour : 18 - Minute : 30 - Temperature : 34 Time on one line, AM/PM format

Temperature Data (lldb) po Temps 2 elements [0] : TemperatureData Time : Timestamp - Hour : 6 - Minute : 30 - Temperature : 10 [1] : TemperatureData Time : Timestamp - Hour : 18 - Minute : 30 - Temperature : 34 Temperature in F Time on one line, AM/PM format

Step 1: Time on One Line

Step 1: Time on One Line extension Timestamp : CustomStringConvertible { var description: String { let formatter = NSDateFormatter() formatter.datestyle = NSDateFormatterStyle.NoStyle formatter.timestyle = NSDateFormatterStyle.ShortStyle formatter.timezone = NSTimeZone(forSecondsFromGMT: 0) let date = NSDate(timeIntervalSince1970: NSTimeInterval(60 * (Minute + (60*Hour)))) return formatter.stringfromdate(date) } }

Step 2: Fahrenheit Degrees

Step 2: Fahrenheit Degrees extension TemperatureData : CustomReflectable { func custommirror() -> Mirror { return Mirror(self, children: [ Time : \(Time), Temp C : Temperature, Temp F : 1.8*Temperature+32 } } ])

Step 2: Fahrenheit Degrees extension TemperatureData : CustomReflectable { func custommirror() -> Mirror { return Mirror(self, children: [ Time : \(Time), CustomStringConvertible from previous slide Temp C : Temperature, Temp F : 1.8*Temperature+32 } } ])

Temperature Data

Temperature Data (lldb) po Temps

Temperature Data (lldb) po Temps 2 elements [0] : TemperatureData - Time : 6:30 AM - Temp C : 10 - Temp F : 50 [1] : TemperatureData - Time : 6:30 PM - Temp C : 34 - Temp F : 93.2

Temperature Data (lldb) po Temps 2 elements [0] : TemperatureData - Time : 6:30 AM - Temp C : 10 - Temp F : 50 [1] : TemperatureData - Time : 6:30 PM - Temp C : 34 - Temp F : 93.2 That s hot!

At Runtime Too! Conformances can also be added while debugging

At Runtime Too! Conformances can also be added while debugging but not changed

At Runtime Too! Conformances can also be added while debugging but not changed They can also be added in the REPL

And in Playgrounds!

And in Playgrounds!

Summary

Summary More information available more often

Summary More information available more often Objective-C runtime

Summary More information available more often Objective-C runtime SDK modules

Summary More information available more often Objective-C runtime SDK modules In-process formatting

More Information LLDB Documentation http://lldb.llvm.org Swift Language Documentation http://developer.apple.com/swift Apple Developer Forums http://developer.apple.com/forums Stefan Lesser Developer Tools Evangelist slesser@apple.com

Related Sessions Authoring Rich Playgrounds Presidio Wednesday 10:00AM Advanced Debugging and the Address Sanitizer Mission Friday 9:00AM