Slide 1

Slide 1 text

These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 412 Debugging in Xcode Ken Orr Xcode Debugger UI Manager

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Control Flow Correctness

Slide 5

Slide 5 text

Breakpoints Variables

Slide 6

Slide 6 text

Breakpoints and Breakpoint Actions

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

NSLog(@"%ld", foo);

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Creating and Deleting Breakpoints

Slide 11

Slide 11 text

Creating and Deleting Breakpoints

Slide 12

Slide 12 text

Creating and Deleting Breakpoints ⌘\ Add Or Remove Breakpoint At Current Line

Slide 13

Slide 13 text

Creating and Deleting Breakpoints

Slide 14

Slide 14 text

Managing Your Breakpoints

Slide 15

Slide 15 text

Managing Your Breakpoints

Slide 16

Slide 16 text

Managing Your Breakpoints ⌘6 Breakpoint Navigator

Slide 17

Slide 17 text

Managing Your Breakpoints

Slide 18

Slide 18 text

Managing Your Breakpoints Change a Breakpoint Group Control-click a breakpoint to move it to a different group

Slide 19

Slide 19 text

Managing Your Breakpoints

Slide 20

Slide 20 text

Managing Your Breakpoints Project Breakpoint Group Contains breakpoints that belong to the listed project

Slide 21

Slide 21 text

Managing Your Breakpoints Project Breakpoint Group Contains breakpoints that belong to the listed project

Slide 22

Slide 22 text

Managing Your Breakpoints

Slide 23

Slide 23 text

Managing Your Breakpoints Shared Breakpoint Group Shared breakpoints are available to all users who open the project

Slide 24

Slide 24 text

Managing Your Breakpoints

Slide 25

Slide 25 text

Managing Your Breakpoints

Slide 26

Slide 26 text

Managing Your Breakpoints User Breakpoint Group User breakpoints are available from all of your projects and workspaces

Slide 27

Slide 27 text

Exception and Symbolic Breakpoints

Slide 28

Slide 28 text

Exception and Symbolic Breakpoints Add Breakpoint Allows you to add an exception or symbolic breakpoint

Slide 29

Slide 29 text

Exception and Symbolic Breakpoints Add Breakpoint Allows you to add an exception or symbolic breakpoint

Slide 30

Slide 30 text

Exception and Symbolic Breakpoints

Slide 31

Slide 31 text

Exception and Symbolic Breakpoints Type of Exception Breakpoint Allows you to stop on all exceptions, Objective-C exceptions, or C++ exceptions

Slide 32

Slide 32 text

Exception and Symbolic Breakpoints When to Break Allows you to specify whether you want to break on catch or throw

Slide 33

Slide 33 text

Exception and Symbolic Breakpoints

Slide 34

Slide 34 text

Exception and Symbolic Breakpoints Symbol Name Execution will pause when a symbol with this name is called

Slide 35

Slide 35 text

Exception and Symbolic Breakpoints Module Name Lets you restrict what libraries with the specified symbol name should result in a pause

Slide 36

Slide 36 text

Editing Breakpoints

Slide 37

Slide 37 text

Editing Breakpoints Edit Breakpoint ⌥⌘

Slide 38

Slide 38 text

Editing Breakpoints Condition to Evaluate An expression to evaluate in order to determine if the breakpoint should be stopped at

Slide 39

Slide 39 text

Editing Breakpoints Ignore Count The number of times to ignore the breakpoint before stopping

Slide 40

Slide 40 text

Editing Breakpoints Automatically Continue Continues program execution after all of the breakpoint’s actions have completed

Slide 41

Slide 41 text

Breakpoint Actions

Slide 42

Slide 42 text

Breakpoint Actions

Slide 43

Slide 43 text

Breakpoint Actions

Slide 44

Slide 44 text

Breakpoint Actions

Slide 45

Slide 45 text

Breakpoint Actions

Slide 46

Slide 46 text

Debugger Command Breakpoint Action

Slide 47

Slide 47 text

Debugger Command Breakpoint Action po myVariable

Slide 48

Slide 48 text

Debugger Command Breakpoint Action po myVariable expr (void)NSLog(@“%f“, myVariable)

Slide 49

Slide 49 text

Debugger Command Breakpoint Action po myVariable breakpoint set -f SKTWindowController.m -l 100 expr (void)NSLog(@“%f“, myVariable)

Slide 50

Slide 50 text

Log Message Breakpoint Action

Slide 51

Slide 51 text

Log Message Breakpoint Action myVariable = @myVariable@, hit %H times

Slide 52

Slide 52 text

Shell Command Breakpoint Action

Slide 53

Slide 53 text

Shell Command Breakpoint Action screencapture Command: /tmp/screenShot.png Arguments:

Slide 54

Slide 54 text

Sound Breakpoint Action

Slide 55

Slide 55 text

Sound Breakpoint Action ~/Library/Sounds Sounds put in your home directory show up in Xcode

Slide 56

Slide 56 text

AppleScript Breakpoint Action

Slide 57

Slide 57 text

AppleScript Breakpoint Action tell application "Mail" set myMessage to make new outgoing message with properties {visible:false, subject:"Test Failed", content:"The test failed"} tell myMessage make new to recipient at end of to recipients with properties {name:"Ken Orr", address:"[email protected]"} myMessage send end tell end tell

Slide 58

Slide 58 text

Demo Breakpoints and breakpoint actions Alex Raftis Xcode Debugger UI Engineer

Slide 59

Slide 59 text

The Variables View

Slide 60

Slide 60 text

Viewing Your Variables

Slide 61

Slide 61 text

Viewing Your Variables

Slide 62

Slide 62 text

Viewing Your Variables Viewing Mode Auto - variables around the line of code you’re paused at Local - all variables in local scope All - all variables including globals and registers

Slide 63

Slide 63 text

Viewing Your Variables Variable Kind Local Variable Argument Static Variable Global Variable Register Instance Variable Expression

Slide 64

Slide 64 text

Viewing Your Variables Variable Name The name of the variable as it appears in your code

Slide 65

Slide 65 text

Viewing Your Variables Dynamic Type Runtime type of the variable

Slide 66

Slide 66 text

Viewing Your Variables Variable Value Current value of the variable

Slide 67

Slide 67 text

Viewing Your Variables Variable Summary Summary for the variable, if there is one

Slide 68

Slide 68 text

Return Value When Stepping Out - (void)updateLabel { [_textField setStringValue:[self currentProcessNameString]]; } - (NSString *)currentProcessNameString { return [NSString stringWithFormat:@"Current process is %@", [[NSProcessInfo processInfo] processName]]; }

Slide 69

Slide 69 text

Return Value When Stepping Out - (void)updateLabel { [_textField setStringValue:[self currentProcessNameString]]; } - (NSString *)currentProcessNameString { return [NSString stringWithFormat:@"Current process is %@", [[NSProcessInfo processInfo] processName]]; }

Slide 70

Slide 70 text

Return Value When Stepping Out - (void)updateLabel { [_textField setStringValue:[self currentProcessNameString]]; } - (NSString *)currentProcessNameString { return [NSString stringWithFormat:@"Current process is %@", [[NSProcessInfo processInfo] processName]]; } return [NSString stringWithFormat:@"Current process is %@", [[NSProcessInfo processInfo] processName]];

Slide 71

Slide 71 text

Return Value When Stepping Out - (void)updateLabel { [_textField setStringValue:[self currentProcessNameString]]; } - (NSString *)currentProcessNameString { return [NSString stringWithFormat:@"Current process is %@", [[NSProcessInfo processInfo] processName]]; } return [NSString stringWithFormat:@"Current process is %@", [[NSProcessInfo processInfo] processName]];

Slide 72

Slide 72 text

Return Value When Stepping Out - (void)updateLabel { [_textField setStringValue:[self currentProcessNameString]]; } - (NSString *)currentProcessNameString { return [NSString stringWithFormat:@"Current process is %@", [[NSProcessInfo processInfo] processName]]; } [_textField setStringValue:[self currentProcessNameString]];

Slide 73

Slide 73 text

Return Value When Stepping Out - (void)updateLabel { [_textField setStringValue:[self currentProcessNameString]]; } - (NSString *)currentProcessNameString { return [NSString stringWithFormat:@"Current process is %@", [[NSProcessInfo processInfo] processName]]; } [_textField setStringValue:[self currentProcessNameString]];

Slide 74

Slide 74 text

A Bit About Variable Summaries title = (__NSCFString *) 0x1234 @”WWDC12”

Slide 75

Slide 75 text

A Bit About Variable Summaries title = (__NSCFString *) 0x1234 @”WWDC12” [title description] Previously implemented with expressions:

Slide 76

Slide 76 text

A Bit About Variable Summaries NSCFString *) 0x1234 @”WWDC12” [title description] with expressions:

Slide 77

Slide 77 text

A Bit About Variable Summaries

Slide 78

Slide 78 text

A Bit About Variable Summaries Can change the state of your program

Slide 79

Slide 79 text

A Bit About Variable Summaries Can change the state of your program May not always work

Slide 80

Slide 80 text

A Bit About Variable Summaries LLDB Block of memory representing __NSCFString

Slide 81

Slide 81 text

A Bit About Variable Summaries LLDB Block of memory representing __NSCFString Character Data LLDB looks inside the object and reads the memory of the specific data it wants

Slide 82

Slide 82 text

Creating Custom Summaries import lldb LLDB

Slide 83

Slide 83 text

Creating Custom Summaries import lldb LLDB

Slide 84

Slide 84 text

Creating Custom Summaries import lldb LLDB

Slide 85

Slide 85 text

Creating Custom Summaries import lldb def circle_summary(valueObject, dictionary): LLDB

Slide 86

Slide 86 text

Creating Custom Summaries import lldb def circle_summary(valueObject, dictionary): # grab the bounds of the SKTCircle. bounds = valueObject.GetChildMemberWithName('_bounds') size = bounds.GetChildMemberWithName('size') … return 'Major Radius = ' + majorRadiusAsString + ', Minor Radius = ' + minorRadiusAsString + ', Area = ' + areaAsString LLDB

Slide 87

Slide 87 text

Creating Custom Summaries import lldb def circle_summary(valueObject, dictionary): SBValue # grab the bounds of the SKTCircle. bounds = valueObject.GetChildMemberWithName('_bounds') size = bounds.GetChildMemberWithName('size') … return 'Major Radius = ' + majorRadiusAsString + ', Minor Radius = ' + minorRadiusAsString + ', Area = ' + areaAsString LLDB

Slide 88

Slide 88 text

Creating Custom Summaries import lldb def circle_summary(valueObject, dictionary): Don’t use this parameter # grab the bounds of the SKTCircle. bounds = valueObject.GetChildMemberWithName('_bounds') size = bounds.GetChildMemberWithName('size') … return 'Major Radius = ' + majorRadiusAsString + ', Minor Radius = ' + minorRadiusAsString + ', Area = ' + areaAsString LLDB

Slide 89

Slide 89 text

Creating Custom Summaries import lldb def circle_summary(valueObject, dictionary): # grab the bounds of the SKTCircle. bounds = valueObject.GetChildMemberWithName('_bounds') size = bounds.GetChildMemberWithName('size') … return 'Major Radius = ' + majorRadiusAsString + ', Minor Radius = ' + minorRadiusAsString + ', Area = ' + areaAsString LLDB

Slide 90

Slide 90 text

Demo Variables view and custom LLDB summaries Troy Koelling Xcode Debugger UI Engineer

Slide 91

Slide 91 text

Advanced Debugging

Slide 92

Slide 92 text

Debugging as Root

Slide 93

Slide 93 text

Debugging as Root Edit Scheme ⌘<

Slide 94

Slide 94 text

Debugging as Root

Slide 95

Slide 95 text

What Is an XPC Service Privileged Bits Your App Process App Logic Crashy Bits

Slide 96

Slide 96 text

What Is an XPC Service Crashy Bits Privileged Bits Your App Process App Logic XPC Services (separate processes)

Slide 97

Slide 97 text

Demo Advanced debugging Han Ming Ong Xcode Debugger UI Engineer

Slide 98

Slide 98 text

More Information Michael Jurewitz Developer Tools Evangelist [email protected] Documentation LLDB Custom Summaries http://lldb.llvm.org/varformats.html Documentation LLDB Scripting http://lldb.llvm.org/scripting.html Apple Developer Forums http://devforums.apple.com

Slide 99

Slide 99 text

Related Sessions Debugging with LLDB Presidio Friday 10:15AM Cocoa Interprocess Communication with XPC Russian Hill Thursday 4:30PM OpenGL ES Tools and Techniques Pacific Heights Wednesday 3:15PM Learning Instruments Presidio Wednesday 4:30PM

Slide 100

Slide 100 text

Labs Xcode Lab Developer Tools Lab B Ongoing LLDB Lab Developer Tools Lab C Friday 11:30AM

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No content