Finding Bugs Using Xcode Runtime Tools

Size: px
Start display at page:

Download "Finding Bugs Using Xcode Runtime Tools"

Transcription

1 Session Developer Tools #WWDC17 Finding Bugs Using Xcode Runtime Tools 406 Kuba Mracek, Program Analysis Engineer Vedant Kumar, Compiler Engineer 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

2 Improvements in Runtime Checking

3 Improvements in Runtime Checking

4 Improvements in Runtime Checking

5 Improvements in Runtime Checking

6 Improvements in Runtime Checking

7 Improvements in Runtime Checking Runtime Issues

8

9

10

11

12 4

13 4

14 4

15

16

17

18 Address Sanitizer Thread Sanitizer Undefined Behavior Sanitizer Main Thread Checker

19 Main Thread Checker Address Sanitizer Thread Sanitizer Undefined Behavior Sanitizer Using Runtime Tools Effectively

20 Main Thread Checker New Address Sanitizer Thread Sanitizer Undefined Behavior Sanitizer Using Runtime Tools Effectively

21 Main Thread Checker New Address Sanitizer Thread Sanitizer Undefined Behavior Sanitizer New Using Runtime Tools Effectively

22 NEW Main Thread Checker Detects misuses of common APIs

23 UI Updates and Threads Some APIs must only be used from the main thread

24 UI Updates and Threads Main Thread Background Thread

25 UI Updates and Threads Main Thread Background Thread AppKit.framework UIKit.framework

26 UI Updates and Threads Main Thread AppKit.framework UIKit.framework Background Thread

27 UI Updates and Threads Main Thread AppKit.framework UIKit.framework Background Thread File downloads Image processing

28 UI Updates and Threads Main Thread AppKit.framework UIKit.framework Background Thread File downloads Image processing

29 UI Updates and Threads Main Thread AppKit.framework UIKit.framework Background Thread File downloads Image processing UI update

30 UI Updates and Threads Main Thread AppKit.framework UIKit.framework! Background Thread File downloads Image processing UI update

31 UI Updates and Threads Main Thread AppKit.framework UIKit.framework Background Thread File downloads Image processing UI update Missed UI updates Visual defects Data corruptions Crashes

32 UI Updates and Threads Main Thread AppKit.framework UIKit.framework UI update Background Thread File downloads Image processing

33 Demo Main Thread Checker

34

35

36

37 Common Places for Mistakes Networking callbacks Creating and destroying NSView and UIView objects Designing asynchronous APIs

38 Designing Asynchronous APIs Let API user specify callback queue

39 Designing Asynchronous APIs Let API user specify callback queue DeepThought.asyncComputeAnswer(to: thequestion) { reply in }

40 Designing Asynchronous APIs Let API user specify callback queue DeepThought.asyncComputeAnswer(to: thequestion, completionqueue: queue) { reply in }

41 Main Thread Checker NEW Detects violations of API threading rules AppKit, UIKit and WebKit APIs Swift and C languages No recompilation Enabled by default in the Xcode debugger

42 Address Sanitizer Detects memory issues

43 Finding Memory Issues Security critical bugs Use-after-free and buffer overflows Diagnoses hard-to-reproduce crashes Advanced Debugging and the Address Sanitizer WWDC 2015

44

45

46

47

48

49

50

51

52

53

54 Address Sanitizer in Xcode 9 NEW Detects use-after-scope Detects use-after-return (opt-in) Compatible with Malloc Scribble

55 // Use of Stack Memory Out of Scope int *integer_pointer = NULL; if (is_some_condition_true()) { int value = calculate_value(); integer_pointer = &value; } *integer_pointer = 42;

56 // Use of Stack Memory Out of Scope int *integer_pointer = NULL; if (is_some_condition_true()) { int value = calculate_value(); integer_pointer = &value; } *integer_pointer = 42;

57 // Use of Stack Memory Out of Scope int *integer_pointer = NULL; if (is_some_condition_true()) { int value = calculate_value(); integer_pointer = &value; } *integer_pointer = 42;

58 // Use of Stack Memory Out of Scope int *integer_pointer = NULL; if (is_some_condition_true()) { int value = calculate_value(); integer_pointer = &value; } *integer_pointer = 42;

59 // Use of Stack Memory Out of Scope int *integer_pointer = NULL; if (is_some_condition_true()) { int value = calculate_value(); integer_pointer = &value; } *integer_pointer = 42; Use of out of scope stack memory

60 // Use of Stack Memory after Return int *returns_address_of_stack() { int a = 42; return &a; } int *integer_pointer = returns_address_of_stack(); *integer_pointer = 43;

61 // Use of Stack Memory after Return int *returns_address_of_stack() { int a = 42; return &a; } int *integer_pointer = returns_address_of_stack(); *integer_pointer = 43;

62 // Use of Stack Memory after Return int *returns_address_of_stack() { int a = 42; return &a; } int *integer_pointer = returns_address_of_stack(); *integer_pointer = 43;

63 // Use of Stack Memory after Return int *returns_address_of_stack() { int a = 42; return &a; } int *integer_pointer = returns_address_of_stack(); *integer_pointer = 43;

64 // Use of Stack Memory after Return int *returns_address_of_stack() { int a = 42; return &a; } int *integer_pointer = returns_address_of_stack(); *integer_pointer = 43; Use of stack memory after return

65 Address Sanitizer and Swift Swift is a much safer language Mixed projects Unsafe pointer types are not memory safe

66 // Use-after-free Bug Using UnsafePointer let string = "Hello, World!" var firstbytepointer: UnsafePointer<CChar> string.withcstring { pointertocstring in firstbytepointer = pointertocstring } let firstbyte = firstbytepointer.pointee print(firstbyte)

67 // Use-after-free Bug Using UnsafePointer let string = "Hello, World!" var firstbytepointer: UnsafePointer<CChar> string.withcstring { pointertocstring in firstbytepointer = pointertocstring } let firstbyte = firstbytepointer.pointee print(firstbyte)

68 // Use-after-free Bug Using UnsafePointer let string = "Hello, World!" var firstbytepointer: UnsafePointer<CChar> string.withcstring { pointertocstring in firstbytepointer = pointertocstring } let firstbyte = firstbytepointer.pointee print(firstbyte)

69 // Use-after-free Bug Using UnsafePointer let string = "Hello, World!" var firstbytepointer: UnsafePointer<CChar> string.withcstring { pointertocstring in firstbytepointer = pointertocstring } let firstbyte = firstbytepointer.pointee print(firstbyte)

70 // Use-after-free Bug Using UnsafePointer let string = "Hello, World!" var firstbytepointer: UnsafePointer<CChar> string.withcstring { pointertocstring in firstbytepointer = pointertocstring } let firstbyte = firstbytepointer.pointee print(firstbyte)

71 // Use-after-free Bug Using UnsafePointer let string = "Hello, World!" var firstbytepointer: UnsafePointer<CChar> string.withcstring { pointertocstring in firstbytepointer = pointertocstring } let firstbyte = firstbytepointer.pointee print(firstbyte)

72 // Use-after-free Bug Using UnsafePointer let string = "Hello, World!" var firstbytepointer: UnsafePointer<CChar> string.withcstring { pointertocstring in firstbytepointer = pointertocstring } let firstbyte = firstbytepointer.pointee print(firstbyte) Use of deallocated memory

73 // Use UnsafePointer Only Inside the Closure let string = "Hello, World!" var firstbytepointer: UnsafePointer<CChar> string.withcstring { pointertocstring in firstbytepointer = pointertocstring } let firstbyte = firstbytepointer.pointee print(firstbyte)

74 // Use UnsafePointer Only Inside the Closure let string = "Hello, World!" string.withcstring { pointertocstring in var firstbytepointer: UnsafePointer<CChar> firstbytepointer = pointertocstring let firstbyte = firstbytepointer.pointee print(firstbyte) }

75 // Use UnsafePointer Only Inside the Closure let string = "Hello, World!" string.withcstring { pointertocstring in var firstbytepointer: UnsafePointer<CChar> firstbytepointer = pointertocstring let firstbyte = firstbytepointer.pointee print(firstbyte) }

76 // Use UnsafePointer Only Inside the Closure let string = "Hello, World!" string.withcstring { pointertocstring in var firstbytepointer: UnsafePointer<CChar> firstbytepointer = pointertocstring let firstbyte = firstbytepointer.pointee print(firstbyte) }

77 // Use UnsafePointer Only Inside the Closure let string = "Hello, World!" string.withcstring { pointertocstring in let firstbyte = pointertocstring.pointee print(firstbyte) }

78 Better Debugging Experience Makes debugging easier Allocation and deallocation backtraces Shows valid and invalid bytes of memory

79

80

81

82

83

84

85

86

87

88

89

90 memory history <expression>

91 memory history 0x cd0

92 memory history 0x cd0 thread..., name = 'Memory deallocated by Thread 1' frame #0: 0x1000fba26 wrap_free frame #1: 0x100001c04 deallocate(p=<unavailable>) at main.m:8 frame #2: 0x100001ce8 perform_heap_operations at main.m:15 frame #3: 0x100001d1a main(argc=<unavailable>, argv=<unavailable>) at main.m thread..., name = 'Memory allocated by Thread 1' frame #0: 0x1000fb85c wrap_malloc frame #1: 0x100001bdf allocate at main.m:4 frame #2: 0x100001c1c perform_heap_operations at main.m:12 frame #3: 0x100001d1a main(argc=<unavailable>, argv=<unavailable>) at main.m

93 When to Use Address Sanitizer C languages and Swift Memory corruptions and crashes General debugging

94 Thread Sanitizer Detects multithreading problems

95 What is Thread Sanitizer Multithreading issues Finds races even if they did not manifest 64-bit macos, 64-bit simulators Thread Sanitizer and Static Analysis WWDC 2016

96 Data Races Unsynchronized accesses to shared mutable variables Lead to data races Memory corruptions and crashes All of these problems apply to Swift!

97 // Swift Data Race Example class EventLog { private var lasteventsource: LogSource? } func log(source: LogSource, message: String) { print(message) lasteventsource = source }

98 // Swift Data Race Example class EventLog { private var lasteventsource: LogSource? } func log(source: LogSource, message: String) { print(message) lasteventsource = source }

99 // Swift Data Race Example class EventLog { private var lasteventsource: LogSource? } func log(source: LogSource, message: String) { print(message) lasteventsource = source }

100 // Swift Data Race Example class EventLog { private var lasteventsource: LogSource? } func log(source: LogSource, message: String) { print(message) lasteventsource = source }

101 // Swift Data Race Example class EventLog { private var lasteventsource: LogSource? } func log(source: LogSource, message: String) { print(message) lasteventsource = source }

102 // Swift Data Race Example class EventLog { private var lasteventsource: LogSource? } func log(source: LogSource, message: String) { print(message) lasteventsource = source } // Thread 1 eventlog.log(source: networkingsubsystem, message: "Download finished") // Thread 2 eventlog.log(source: databasesubsystem, message: "Query complete")

103 // Swift Data Race Example class EventLog { private var lasteventsource: LogSource? } func log(source: LogSource, message: String) { print(message) lasteventsource = source } // Thread 1 eventlog.log(source: networkingsubsystem, message: "Download finished") // Thread 2 eventlog.log(source: databasesubsystem, message: "Query complete")

104 // Swift Data Race Example class EventLog { private var lasteventsource: LogSource? } func log(source: LogSource, message: String) { print(message) lasteventsource = source } Thread 2: Data race in EventLog.log(source:message:) // Thread 1 eventlog.log(source: networkingsubsystem, message: "Download finished") // Thread 2 eventlog.log(source: databasesubsystem, message: "Query complete")

105 // Use DispatchQueue to Synchronize Access class EventLog { private var lasteventsource: LogSource? } func log(source: LogSource, message: String) { print(message) lasteventsource = source }

106 // Use DispatchQueue to Synchronize Access class EventLog { private var lasteventsource: LogSource? private var queue = DispatchQueue(label: "com.example.eventlog.queue") } func log(source: LogSource, message: String) { print(message) lasteventsource = source }

107 // Use DispatchQueue to Synchronize Access class EventLog { private var lasteventsource: LogSource? private var queue = DispatchQueue(label: "com.example.eventlog.queue") } func log(source: LogSource, message: String) { print(message) lasteventsource = source }

108 // Use DispatchQueue to Synchronize Access class EventLog { private var lasteventsource: LogSource? private var queue = DispatchQueue(label: "com.example.eventlog.queue") } func log(source: LogSource, message: String) { queue.async { print(message) lasteventsource = source } }

109 // Use DispatchQueue to Synchronize Access class EventLog { private var lasteventsource: LogSource? private var queue = DispatchQueue(label: "com.example.eventlog.queue") } func log(source: LogSource, message: String) { queue.async { print(message) lasteventsource = source } }

110 // Use DispatchQueue to Synchronize Access class EventLog { private var lasteventsource: LogSource? private var queue = DispatchQueue(label: "com.example.eventlog.queue") } func log(source: LogSource, message: String) { queue.async { print(message) lasteventsource = source } }

111 Dispatch Queues Grand Central Dispatch should be your first choice of synchronization Lightweight, convenient, simple Associate your data with serial dispatch queues Concurrent Programming With GCD in Swift 3 WWDC 2016

112 New in Thread Sanitizer in Xcode 9 NEW Races on collections Swift access races

113 Races on Collections Previously, only reported races on raw memory accesses Synchronization required for larger data structures

114 Races on Collections Previously, only reported races on raw memory accesses Synchronization required for larger data structures NSMutableDictionary *d = [NSMutableDictionary new]; // Thread 1 BOOL found = [d objectforkey:@"answer"]!= nil; // Thread 2 [d setobject:@42 forkey:@"answer"];

115 Races on Collections Previously, only reported races on raw memory accesses Synchronization required for larger data structures NSMutableDictionary *d = [NSMutableDictionary new]; // Thread 1 BOOL found = [d objectforkey:@"answer"]!= nil; // Thread 2 [d setobject:@42 forkey:@"answer"]; Thread 1: Previous access on NSMutableDictionary Thread 2: Race on NSMutableDictionary

116 Races on Collections NEW Races on collections in Objective-C and Swift NSMutableArray, NSMutableDictionary Swift Array and Dictionary

117 Demo Thread Sanitizer and race on NSMutableArray

118 // Race on Swift Array var usernames: [String] = ["alice", "bob"]

119 // Race on Swift Array var usernames: [String] = ["alice", "bob"] // Thread 1 found = usernames.contains("alice") if found { } // Thread 2 usernames.append("carol")

120 // Race on Swift Array var usernames: [String] = ["alice", "bob"] // Thread 1 found = usernames.contains("alice") if found { } Thread 1: Previous access // Thread 2 usernames.append("carol") Thread 2: Swift access race

121 // Use DispatchQueue to Synchronize Accesses var usernames: [String] = ["alice", "bob"] // Thread 1 found = usernames.contains("alice") if found { } // Thread 2 usernames.append("carol")

122 // Use DispatchQueue to Synchronize Accesses var usernames: [String] = ["alice", "bob"] var queue = DispatchQueue(label: "com.example.usernames.queue") // Thread 1 found = usernames.contains("alice") if found { } // Thread 2 usernames.append("carol")

123 // Use DispatchQueue to Synchronize Accesses var usernames: [String] = ["alice", "bob"] var queue = DispatchQueue(label: "com.example.usernames.queue") // Thread 1 found = usernames.contains("alice") if found { } // Thread 2 usernames.append("carol")

124 // Use DispatchQueue to Synchronize Accesses var usernames: [String] = ["alice", "bob"] var queue = DispatchQueue(label: "com.example.usernames.queue") // Thread 1 found = usernames.contains("alice") if found { } // Thread 2 usernames.append("carol")

125 // Use DispatchQueue to Synchronize Accesses var usernames: [String] = ["alice", "bob"] var queue = DispatchQueue(label: "com.example.usernames.queue") // Thread 1 queue.sync { found = usernames.contains("alice") } if found { } // Thread 2 queue.async { usernames.append("carol") }

126 // Use DispatchQueue to Synchronize Accesses var usernames: [String] = ["alice", "bob"] var queue = DispatchQueue(label: "com.example.usernames.queue") // Thread 1 queue.sync { found = usernames.contains("alice") } if found { } // Thread 2 queue.async { usernames.append("carol") }

127 Swift Access Races NEW Applies to all structs Mutating methods require exclusive access to the whole struct Methods on classes require exclusive access to stored properties they change What's New in Swift Tuesday 1:50PM

128 // Swift Access Race with Mutating Methods struct BluePoliceBoxLocation { private var x, y, z: Int private var time: Int }

129 // Swift Access Race with Mutating Methods struct BluePoliceBoxLocation { private var x, y, z: Int private var time: Int } mutating func teleport(toplanet: String) { } mutating func fly(tocity: String) { } mutating func traveltoendoftime() { }

130 // Swift Access Race with Mutating Methods struct BluePoliceBoxLocation { private var x, y, z: Int private var time: Int } mutating func teleport(toplanet: String) { } mutating func fly(tocity: String) { } mutating func traveltoendoftime() { }

131 // Swift Access Race with Mutating Methods struct BluePoliceBoxLocation { private var x, y, z: Int private var time: Int } mutating func teleport(toplanet: String) { } mutating func fly(tocity: String) { } mutating func traveltoendoftime() { } // Thread 1 location.teleport(toplanet: "Mars") // Thread 2 location.traveltoendoftime()

132 // Swift Access Race with Mutating Methods struct BluePoliceBoxLocation { private var x, y, z: Int private var time: Int } mutating func teleport(toplanet: String) { } mutating func fly(tocity: String) { } mutating func traveltoendoftime() { } // Thread 1 location.teleport(toplanet: "Mars") Thread 1: Previous access // Thread 2 location.traveltoendoftime() Thread 2: Swift access race

133 // Swift Access Race with Mutating Methods struct BluePoliceBoxLocation { private var x, y, z: Int private var time: Int } mutating func teleport(toplanet: String) { } mutating func fly(tocity: String) { } mutating func traveltoendoftime() { } // Thread 1 location.teleport(toplanet: "Mars") Thread 1: Previous access // Thread 2 changes x, y, z location.traveltoendoftime() Thread 2: Swift access race changes time

134 // Swift Access Race with Mutating Methods struct BluePoliceBoxLocation { private var x, y, z: Int private var time: Int } mutating func teleport(toplanet: String) { } mutating func fly(tocity: String) { } mutating func traveltoendoftime() { } // Thread 1 location.teleport(toplanet: "Mars") Thread 1: Previous access // Thread 2 location.traveltoendoftime() Thread 2: Swift access race

135 // Incorrect Synchronization Inside a Struct struct BluePoliceBoxLocation { private var x, y, z: Int private var time: Int } mutating func teleport(toplanet: String) { } mutating func fly(tocity: String) { } mutating func traveltoendoftime() { }

136 // Incorrect Synchronization Inside a Struct struct BluePoliceBoxLocation { private var x, y, z: Int private var time: Int private var queue: DispatchQueue = } mutating func teleport(toplanet: String) { queue.sync { } } mutating func fly(tocity: String) { queue.sync { } } mutating func traveltoendoftime() { queue.sync { } }

137 // Incorrect Synchronization Inside a Struct struct BluePoliceBoxLocation { private var x, y, z: Int private var time: Int private var queue: DispatchQueue = } mutating func teleport(toplanet: String) { queue.sync { } } mutating func fly(tocity: String) { queue.sync { } } mutating func traveltoendoftime() { queue.sync { } }

138 // Incorrect Synchronization Inside a Struct struct BluePoliceBoxLocation { private var x, y, z: Int private var time: Int private var queue: DispatchQueue = } mutating func teleport(toplanet: String) { queue.sync { } } mutating func fly(tocity: String) { queue.sync { } } mutating func traveltoendoftime() { queue.sync { } }

139 // Synchronize Calls to Mutating Methods struct BluePoliceBoxLocation { }

140 // Synchronize Calls to Mutating Methods struct BluePoliceBoxLocation { } class BluePoliceBox { private var location: BluePoliceBoxLocation private var queue: DispatchQueue = }

141 // Synchronize Calls to Mutating Methods struct BluePoliceBoxLocation { } class BluePoliceBox { private var location: BluePoliceBoxLocation private var queue: DispatchQueue = func goonrescuemission() { queue.sync { location.teleport(toplanet: "Mars") } } func gotowrongplaceagain() { queue.sync { } } }

142 Find and Fix Your Races Use GCD to synchronize access to data Associate your shared data with a serial queue Thread Sanitizer is invaluable for finding races

143 NEW Undefined Behavior Sanitizer Vedant Kumar, Compiler Engineer

144 What is Undefined Behavior Sanitizer? Runtime bug finder Checks unsafe constructs in the C language family Compatible with other runtime tools Understanding Undefined Behavior Executive Ballroom Thursday 9:00AM

145

146 C++ Dynamic Type Violation Invalid Float Cast Nonnull Return Value Violation Integer Overflow Invalid Shift Exponent Alignment Violation Invalid Boolean Invalid Variable-Length Array Invalid Enum Integer Division by Zero Invalid Integer Cast Reached Unreachable Code Invalid Shift Base Missing Return Value Invalid Object Size Null Dereference Nonnull Assignment Violation Nonnull Parameter Violation Out-of-Bounds Array Access

147 Integer Overflow Alignment Violation Nonnull Return Value Violation

148 Integer Overflow Arithmetic result too big Unsafe in indexing expressions (INT_MAX + 1) INT_MAX Opt-in check for unsigned overflow

149 Demo Undefined Behavior Sanitizer and integer overflow

150 Alignment Violation Unaligned load or store Causes crashes in Release builds Common in (de)serialization code

151 // Serializing Packets for a Custom Network Protocol struct Packet { int magic; int payloadlength; char payload[]; };

152 // Serializing Packets for a Custom Network Protocol struct Packet { int magic; int payloadlength; char payload[]; }; // Sender

153 // Serializing Packets for a Custom Network Protocol struct Packet { int magic; int payloadlength; char payload[]; }; // Sender

154 // Serializing Packets for a Custom Network Protocol struct Packet { int magic; int payloadlength; char payload[]; }; // Sender

155 // Serializing Packets for a Custom Network Protocol struct Packet { int magic; int payloadlength; char payload[]; }; // Sender H e y K u b a!

156 // Serializing Packets for a Custom Network Protocol struct Packet { int magic; int payloadlength; char payload[]; }; // Sender H e y K u b a! // Receiver // Read from stream Packet *P = (Packet *)bytestream; if (P->magic!= )

157 // Serializing Packets for a Custom Network Protocol struct Packet { int magic; int payloadlength; char payload[]; }; // Sender H e y K u b a! // Receiver // Read from stream Packet *P = (Packet *)bytestream; if (P->magic!= )

158 // Serializing Packets for a Custom Network Protocol struct Packet { int magic; int payloadlength; char payload[]; }; // Sender H e y K u b a!

159 // Serializing Packets for a Custom Network Protocol struct Packet { int magic; int payloadlength; char payload[]; }; // Sender H e y K u b a!

160 // Serializing Packets for a Custom Network Protocol struct Packet { int magic; int payloadlength; char payload[]; }; // Sender H e y K u b a!

161 // Serializing Packets for a Custom Network Protocol struct Packet { int magic; int payloadlength; char payload[]; }; // Sender H e y K u b a! H o w s i t g o i n g?

162 // Serializing Packets for a Custom Network Protocol struct Packet { int magic; int payloadlength; char payload[]; }; // Sender H e y K u b a! H o w s i t g o i n g? // Receiver // Read from stream Packet *P = (Packet *)(bytestream + 17); if (P->magic!= )

163 // Serializing Packets for a Custom Network Protocol struct Packet { int magic; int payloadlength; char payload[]; }; // Sender H e y K u b a! H o w s i t g o i n g? // Receiver // Read from stream Packet *P = (Packet *)(bytestream + 17); if (P->magic!= )

164 // Serializing Packets for a Custom Network Protocol struct Packet { int magic; int payloadlength; char payload[]; }; // Sender H e y K u b a! // Receiver // Read from stream Packet *P = (Packet *)(bytestream + 17); if (P->magic!= ) Load of misaligned address

165 // Serializing Packets for a Custom Network Protocol struct Packet { int magic; int payloadlength; char payload[]; }; // Sender H e y K u b a! // Receiver // Read from stream Packet *P = (Packet *)(bytestream + 17); if (P->magic!= ) Load of misaligned address

166 // Use Structure Packing to Decrease Expected Alignment struct Packet { int magic; int payloadlength; char payload[]; } attribute ((packed)); // Read from stream Packet *P = (Packet *)bytestream; if (P->magic!= )

167 // Use Structure Packing to Decrease Expected Alignment struct Packet { int magic; // Member alignment changes to 1 int payloadlength; char payload[]; } attribute ((packed)); // Read from stream Packet *P = (Packet *)bytestream; if (P->magic!= )

168 // Use Structure Packing to Decrease Expected Alignment struct Packet { int magic; // Member alignment changes to 1 int payloadlength; char payload[]; } attribute ((packed)); // Read from stream Packet *P = (Packet *)bytestream; if (P->magic!= ) // The load is aligned

169 // Use Structure Packing to Decrease Expected Alignment struct Packet { int magic; // Member alignment changes to 1 int payloadlength; char payload[]; } attribute ((packed)); // This can change structure layout and performance // Read from stream Packet *P = (Packet *)bytestream; if (P->magic!= ) // The load is aligned

170 // Use memcpy() to Perform Unaligned Accesses struct Packet { int magic; int payloadlength; char payload[]; }; // Read from stream int magic; memcpy(&magic, bytestream + offsetof(struct Packet, magic), sizeof(int)); if (magic!= )

171 // Use memcpy() to Perform Unaligned Accesses struct Packet { int magic; int payloadlength; char payload[]; }; // Read from stream int magic; memcpy(&magic, bytestream + offsetof(struct Packet, magic), sizeof(int)); if (magic!= )

172 Nonnull Return Value Violation Return value annotated nonnull Function returns nil anyway Can cause crashes in mixed C and Swift code Recommended to opt in to the check

173 // Nonnull Return Value SolarSystem + (nonnull NSDictionary *)planetmoons @"Styx"] }; } - (nonnull NSArray *)moonsofplanet:(nonnull NSString *)planet { return [[self class] planetmoons][planet];

174 // Nonnull Return Value SolarSystem + (nonnull NSDictionary *)planetmoons @"Styx"] }; } - (nonnull NSArray *)moonsofplanet:(nonnull NSString *)planet { return [[self class] planetmoons][planet];

175 // Nonnull Return Value SolarSystem + (nonnull NSDictionary *)planetmoons // }; } - (nonnull NSArray *)moonsofplanet:(nonnull NSString *)planet { return [[self class] planetmoons][planet];

176 // Nonnull Return Value SolarSystem + (nonnull NSDictionary *)planetmoons // }; } - (nonnull NSArray *)moonsofplanet:(nonnull NSString *)planet { return [[self class] planetmoons][planet];

177 // Nonnull Return Value SolarSystem + (nonnull NSDictionary *)planetmoons // }; } - (nonnull NSArray *)moonsofplanet:(nonnull NSString *)planet { return [[self class] planetmoons][planet]; // Find the biggest moon for each planet NSMutableArray *biggestmoons = [NSMutableArray new]; [biggestmoons addobject:[solarsystem moonsofplanet:@"pluto"][0]];

178 // Nonnull Return Value SolarSystem + (nonnull NSDictionary *)planetmoons // }; } - (nonnull NSArray *)moonsofplanet:(nonnull NSString *)planet { return [[self class] planetmoons][planet]; Null pointer returned from function declared to never return null // Find the biggest moon for each planet NSMutableArray *biggestmoons = [NSMutableArray new]; [biggestmoons addobject:[solarsystem moonsofplanet:@"pluto"][0]];

179

180

181 Using Runtime Tools Effectively

182 How to Use Runtime Tools Effectively Exercise more code Use the tools together

183 Exercise More Code Can only catch issues in code that is run Use runtime tools for daily development Use them before every release Avoid spreading bugs to users

184 Use Continuous Integration Simplifies testing with runtime tools Ensures that bugs are caught quickly Helps track code coverage Continuous Integration and Code Coverage in Xcode WWDC 2015

185 Use Runtime Tools Together Find more issues Most runtime tools can be used together Address Sanitizer and Thread Sanitizer are not compatible Product Scheme Edit Scheme Diagnostics

186 Runtime Tool Overhead Execution overhead Memory overhead Main Thread Checker 1.02x negligible Undefined Behavior Sanitizer 1.2x negligible Address Sanitizer 2 3x 2x Thread Sanitizer 5 10x 4x

187 Summary Xcode 9 enables you to catch critical issues Use runtime tools early and often Save time, keep users safe!

188 Summary Xcode 9 enables you to catch critical issues Use runtime tools early and often Save time, keep users safe!

189 More Information

190 Related Sessions What's New in Swift Debugging with Xcode 9 Modernizing Grand Central Dispatch Usage Tuesday 1:50PM Wednesday 10:00AM Wednesday 11:00AM Understanding Undefined Behavior Executive Ballroom Thursday 9:00AM What s New in Testing Hall 2 Thursday 3:10PM What's New in LLVM Hall 2 Thursday 4:10PM

191 Labs Performance Profiling and Runtime Analysis Tools Lab Technology Lab K Thu 1:00PM 4:10PM LLVM Compiler, Objective-C, and C++ Lab Technology Lab E Fri 9:00AM 11:00AM

192

Understanding Undefined Behavior

Understanding Undefined Behavior Session Developer Tools #WWDC17 Understanding Undefined Behavior 407 Fred Riss, Clang Team Ryan Govostes, Security Engineering and Architecture Team Anna Zaks, Program Analysis Team 2017 Apple Inc. All

More information

Thread Sanitizer and Static Analysis

Thread Sanitizer and Static Analysis Developer Tools #WWDC16 Thread Sanitizer and Static Analysis Help with finding bugs in your code Session 412 Anna Zaks Manager, Program Analysis Team Devin Coughlin Engineer, Program Analysis Team 2016

More information

Advanced Debugging and the Address Sanitizer

Advanced Debugging and the Address Sanitizer Developer Tools #WWDC15 Advanced Debugging and the Address Sanitizer Finding your undocumented features Session 413 Mike Swingler Xcode UI Infrastructure Anna Zaks LLVM Program Analysis 2015 Apple Inc.

More information

Using and Extending the Xcode Source Editor

Using and Extending the Xcode Source Editor Developer Tools #WWDC16 Using and Extending the Xcode Source Editor Session 414 Mike Swingler Xcode Infrastructure and Editors Chris Hanson Xcode Infrastructure and Editors 2016 Apple Inc. All rights reserved.

More information

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

What s New in LLDB. Debug your way to fame and glory #WWDC15. Developer Tools. Session 402 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.

More information

Optimizing Swift Performance Session 409

Optimizing Swift Performance Session 409 Developer Tools #WWDC15 Optimizing Swift Performance Session 409 Nadav Rotem Manager, Swift Performance Team Michael Gottesman Engineer, Swift Performance Team Joe Grzywacz Engineer, Performance Tools

More information

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

What s New in Swift #WWDC18. Ted Kremenek, Languages & Runtimes Manager Slava Pestov, Swift Compiler Engineer Session #WWDC18 What s New in Swift 401 Ted Kremenek, Languages & Runtimes Manager Slava Pestov, Swift Compiler Engineer 2018 Apple Inc. All rights reserved. Redistribution or public display not permitted

More information

Chapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.

Chapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC. hapter 1 INTRODUTION SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Objectives You will learn: Java features. Java and its associated components. Features of a Java application and applet. Java data types. Java

More information

Building Faster in Xcode

Building Faster in Xcode #WWDC18 Building Faster in Xcode Session 408 David Owens, Xcode Engineer Jordan Rose, Swift Engineer 2018 Apple Inc. All rights reserved. Redistribution or public display not permitted without written

More information

What s New in Xcode App Signing

What s New in Xcode App Signing Developer Tools #WWDC16 What s New in Xcode App Signing Developing and distributing Session 401 Joshua Pennington Tools Engineering Manager Itai Rom Tools Engineer 2016 Apple Inc. All rights reserved.

More information

Kevin van Vechten Core OS

Kevin van Vechten Core OS Kevin van Vechten Core OS 2 3 Bill Bumgarner 4 (lambda (a) (add a d)) 10 timesrepeat:[pen turn:d; draw] z.each { val puts(val + d.to_s)} repeat(10, ^{ putc('0'+ d); }); 5 6 7 8 ^ 9 [myset objectspassingtest:

More information

Introducing the Modern WebKit API

Introducing the Modern WebKit API Frameworks #WWDC14 Introducing the Modern WebKit API Session 206 Anders Carlsson Safari and WebKit Engineer 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written

More information

Extending Your Apps with SiriKit

Extending Your Apps with SiriKit App Frameworks #WWDC16 Extending Your Apps with SiriKit Session 225 Vineet Khosla SiriKit Engineering Diana Huang SiriKit Engineering Scott Andrus SiriKit Engineering 2016 Apple Inc. All rights reserved.

More information

What s New in watchos

What s New in watchos Session App Frameworks #WWDC17 What s New in watchos 205 Ian Parks, watchos Engineering 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from

More information

Implementing UI Designs in Interface Builder

Implementing UI Designs in Interface Builder Developer Tools #WWDC15 Implementing UI Designs in Interface Builder Session 407 Kevin Cathey Interface Builder Engineer Tony Ricciardi Interface Builder Engineer 2015 Apple Inc. All rights reserved. Redistribution

More information

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

SWIFT! init(title: String) { self.title = title } // required initializer w/ named parameter SWIFT! class Session { let title: String // constant non-optional field: can never be null and can never be changed var instruktør: Person? // variable optional field: null is permitted var attendees:

More information

Programming in C. Lecture 9: Tooling. Dr Neel Krishnaswami. Michaelmas Term

Programming in C. Lecture 9: Tooling. Dr Neel Krishnaswami. Michaelmas Term Programming in C Lecture 9: Tooling Dr Neel Krishnaswami Michaelmas Term 2017-2018 1 / 24 Undefined and Unspecified Behaviour 2 / 24 Undefined and Unspecified Behaviour We have seen that C is an unsafe

More information

Pointers, Dynamic Data, and Reference Types

Pointers, Dynamic Data, and Reference Types Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple

More information

Accessibility on OS X

Accessibility on OS X Frameworks #WWDC14 Accessibility on OS X New Accessibility API Session 207 Patti Hoa Accessibility Engineer! Chris Dolan Accessibility Engineer 2014 Apple Inc. All rights reserved. Redistribution or public

More information

ios: Objective-C Primer

ios: Objective-C Primer ios: Objective-C Primer Jp LaFond Jp.LaFond+e76@gmail.com TF, CS76 Announcements n-puzzle feedback this week (if not already returned) ios Setup project released Android Student Choice project due Tonight

More information

COMP26120: Linked List in C (2018/19) Lucas Cordeiro

COMP26120: Linked List in C (2018/19) Lucas Cordeiro COMP26120: Linked List in C (2018/19) Lucas Cordeiro lucas.cordeiro@manchester.ac.uk Linked List Lucas Cordeiro (Formal Methods Group) lucas.cordeiro@manchester.ac.uk Office: 2.28 Office hours: 10-11 Tuesday,

More information

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc. Chapter 1 GETTING STARTED SYS-ED/ Computer Education Techniques, Inc. Objectives You will learn: Java platform. Applets and applications. Java programming language: facilities and foundation. Memory management

More information

ITP 342 Mobile App Development. Data Persistence

ITP 342 Mobile App Development. Data Persistence ITP 342 Mobile App Development Data Persistence Persistent Storage Want our app to save its data to persistent storage Any form of nonvolatile storage that survives a restart of the device Want a user

More information

Review! * follows a pointer to its value! & gets the address of a variable! Pearce, Summer 2010 UCB! ! int x = 1000; Pearce, Summer 2010 UCB!

Review! * follows a pointer to its value! & gets the address of a variable! Pearce, Summer 2010 UCB! ! int x = 1000; Pearce, Summer 2010 UCB! CS61C L03 Introduction to C (pt 2) (1)! inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 3 Introduction to C (pt 2) 2010-06-23!!!Instructor Paul Pearce! The typical! development cycle!

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 3 Introduction to C (pt 2) 2010-06-23! C help session: Tonight 7:00-9:00pm @ 306 Soda!!!Instructor Paul Pearce! The typical! development

More information

Lecture 07 Debugging Programs with GDB

Lecture 07 Debugging Programs with GDB Lecture 07 Debugging Programs with GDB In this lecture What is debugging Most Common Type of errors Process of debugging Examples Further readings Exercises What is Debugging Debugging is the process of

More information

lecture 11 Advanced Swift

lecture 11 Advanced Swift lecture 11 Advanced Swift cs198-001 : spring 2018 1 Attendances Will be posting sheet on Piazza this week Check that we ve accounted for all of your attendances! Make a private piazza post if there is

More information

Media and Gaming Accessibility

Media and Gaming Accessibility Session System Frameworks #WWDC17 Media and Gaming Accessibility 217 Greg Hughes, Software Engineering Manager Charlotte Hill, Software Engineer 2017 Apple Inc. All rights reserved. Redistribution or public

More information

CSC C69: OPERATING SYSTEMS

CSC C69: OPERATING SYSTEMS CSC C69: OPERATING SYSTEMS Tutorial 1 Thursday, Jan 17, 2013 TA: Ioan Stefanovici (ioan@cs.toronto.edu) HOW DO YOU SUCCEED IN THIS COURSE? Show up to lectures & tutorials (way too much material) Work on

More information

A program execution is memory safe so long as memory access errors never occur:

A program execution is memory safe so long as memory access errors never occur: A program execution is memory safe so long as memory access errors never occur: Buffer overflows, null pointer dereference, use after free, use of uninitialized memory, illegal free Memory safety categories

More information

Data Representation and Storage. Some definitions (in C)

Data Representation and Storage. Some definitions (in C) Data Representation and Storage Learning Objectives Define the following terms (with respect to C): Object Declaration Definition Alias Fundamental type Derived type Use pointer arithmetic correctly Explain

More information

Power, Performance, and Diagnostics

Power, Performance, and Diagnostics Core OS #WWDC14 Power, Performance, and Diagnostics What's new in GCD and XPC Session 716 Daniel Steffen Darwin Runtime Engineer 2014 Apple Inc. All rights reserved. Redistribution or public display not

More information

Porting Objective-C to Swift. Richard Ekle

Porting Objective-C to Swift. Richard Ekle Porting Objective-C to Swift Richard Ekle rick@ekle.org Why do we need this? 1.2 million apps in the ios App Store http://www.statista.com/statistics/276623/numberof-apps-available-in-leading-app-stores/

More information

Modern User Interaction on ios

Modern User Interaction on ios App Frameworks #WWDC17 Modern User Interaction on ios Mastering the UIKit UIGesture System Session 219 Dominik Wagner, UIKit Engineer Michael Turner, UIKit Engineer Glen Low, UIKit Engineer 2017 Apple

More information

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309 A Arithmetic operation floating-point arithmetic, 11 12 integer numbers, 9 11 Arrays, 97 copying, 59 60 creation, 48 elements, 48 empty arrays and vectors, 57 58 executable program, 49 expressions, 48

More information

Your Apps and the Future of macos Security

Your Apps and the Future of macos Security #WWDC18 Your Apps and the Future of macos Security Pierre-Olivier Martel, Security Engineering Manager Kelly Yancey, OS Security Garrett Jacobson, Trusted Execution 2018 Apple Inc. All rights reserved.

More information

Homework #3 CS2255 Fall 2012

Homework #3 CS2255 Fall 2012 Homework #3 CS2255 Fall 2012 MULTIPLE CHOICE 1. The, also known as the address operator, returns the memory address of a variable. a. asterisk ( * ) b. ampersand ( & ) c. percent sign (%) d. exclamation

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Introducing the Photos Frameworks

Introducing the Photos Frameworks Media #WWDC14 Introducing the Photos Frameworks Session 511 Adam Swift ios Photos Frameworks 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

What s New in Core Data?

What s New in Core Data? Session App Frameworks #WWDC17 What s New in Core? Persisting since 2004 210 Melissa Turner, Core Engineer Rishi Verma, Core Engineer 2017 Apple Inc. All rights reserved. Redistribution or public display

More information

CS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

CS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/ CS61C Machine Structures Lecture 4 C Pointers and Arrays 1/25/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L04 C Pointers (1) Common C Error There is a difference

More information

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

CSci 4061 Introduction to Operating Systems. Programs in C/Unix CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,

More information

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?

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? 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? Grading: Lab/homework: 40%, project: 40%, individual report:

More information

Cocoa Development Tips

Cocoa Development Tips Session App Frameworks #WWDC17 Cocoa Development Tips Twenty-nine things you may not know about Cocoa 236 Rachel Goldeen, Cocoa Engineer Vincent Hittson, Cocoa Engineer 2017 Apple Inc. All rights reserved.

More information

Data Delivery with Drag and Drop

Data Delivery with Drag and Drop Session App Frameworks #WWDC17 Data Delivery with Drag and Drop 227 Dave Rahardja, UIKit Tanu Singhal, UIKit 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without

More information

C++ Undefined Behavior What is it, and why should I care?

C++ Undefined Behavior What is it, and why should I care? C++ Undefined Behavior What is it, and why should I care? Marshall Clow Qualcomm marshall@idio.com http://cplusplusmusings.wordpress.com (intermittent) Twitter: @mclow ACCU 2014 April 2014 What is Undefined

More information

Recitation #11 Malloc Lab. November 7th, 2017

Recitation #11 Malloc Lab. November 7th, 2017 18-600 Recitation #11 Malloc Lab November 7th, 2017 1 2 Important Notes about Malloc Lab Malloc lab has been updated from previous years Supports a full 64 bit address space rather than 32 bit Encourages

More information

Verification & Validation of Open Source

Verification & Validation of Open Source Verification & Validation of Open Source 2011 WORKSHOP ON SPACECRAFT FLIGHT SOFTWARE Gordon Uchenick Coverity, Inc Open Source is Ubiquitous Most commercial and proprietary software systems have some open

More information

Static Analysis in C/C++ code with Polyspace

Static Analysis in C/C++ code with Polyspace 1 Static Analysis in C/C++ code with Polyspace Yongchool Ryu Application Engineer gary.ryu@mathworks.com 2016 The MathWorks, Inc. 2 Agenda Efficient way to find problems in Software Category of Static

More information

C++ Undefined Behavior

C++ Undefined Behavior C++ Undefined Behavior What is it, and why should I care? A presentation originally by Marshal Clow Original: https://www.youtube.com/watch?v=uhclkb1vkay Original Slides: https://github.com/boostcon/cppnow_presentations_2014/blob/master/files/undefined-behavior.pdf

More information

What s New in Foundation for Swift Session 207

What s New in Foundation for Swift Session 207 App Frameworks #WWDC16 What s New in Foundation for Swift Session 207 Tony Parker Foundation, Apple Michael LeHew Foundation, Apple 2016 Apple Inc. All rights reserved. Redistribution or public display

More information

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

What s New in MapKit. App Frameworks #WWDC17. Fredrik Olsson Session App Frameworks #WWDC17 What s New in MapKit 237 Fredrik Olsson 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. MKMapView.mapType.standard

More information

Localizing with Xcode 9

Localizing with Xcode 9 Session Developer Tools #WWDC17 Localizing with Xcode 9 401 Sara Radi, Software Engineer Aya Siblini, Software Engineer Chris Hanson, Software Engineer 2017 Apple Inc. All rights reserved. Redistribution

More information

Malloc Lab & Midterm Solutions. Recitation 11: Tuesday: 11/08/2016

Malloc Lab & Midterm Solutions. Recitation 11: Tuesday: 11/08/2016 Malloc Lab & Midterm Solutions Recitation 11: Tuesday: 11/08/2016 Malloc 2 Important Notes about Malloc Lab Malloc lab has been updated from previous years Supports a full 64 bit address space rather than

More information

Fix Bugs Faster Using Activity Tracing

Fix Bugs Faster Using Activity Tracing Core OS #WWDC14 Fix Bugs Faster Using Activity Tracing Session 714 Eric Clements Core OS Engineering 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written

More information

Undefined Behaviour in C

Undefined Behaviour in C Undefined Behaviour in C Report Field of work: Scientific Computing Field: Computer Science Faculty for Mathematics, Computer Science and Natural Sciences University of Hamburg Presented by: Dennis Sobczak

More information

[0569] p 0318 garbage

[0569] p 0318 garbage A Pointer is a variable which contains the address of another variable. Declaration syntax: Pointer_type *pointer_name; This declaration will create a pointer of the pointer_name which will point to the

More information

ITP 342 Mobile App Development. Data Persistence

ITP 342 Mobile App Development. Data Persistence ITP 342 Mobile App Development Data Persistence Persistent Storage Want our app to save its data to persistent storage Any form of nonvolatile storage that survives a restart of the device Want a user

More information

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

Introducing Metal 2. Graphics and Games #WWDC17. Michal Valient, GPU Software Engineer Richard Schreyer, GPU Software Engineer Session Graphics and Games #WWDC17 Introducing Metal 2 601 Michal Valient, GPU Software Engineer Richard Schreyer, GPU Software Engineer 2017 Apple Inc. All rights reserved. Redistribution or public display

More information

CS504 4 th Quiz solved by MCS GROUP

CS504 4 th Quiz solved by MCS GROUP CS504 4 th Quiz solved by MCS GROUP All are solved 100% correct with pages # remember us in ur prayerssss. Quiz Start Time: 01:26 PM Time Left 90 Question # 1 of 10 ( Start time: 01:26:29 PM ) Total Marks:

More information

CS527 Software Security

CS527 Software Security Security Policies Purdue University, Spring 2018 Security Policies A policy is a deliberate system of principles to guide decisions and achieve rational outcomes. A policy is a statement of intent, and

More information

MPATE-GE 2618: C Programming for Music Technology. Syllabus

MPATE-GE 2618: C Programming for Music Technology. Syllabus MPATE-GE 2618: C Programming for Music Technology Instructor Dr. Schuyler Quackenbush schuyler.quackenbush@nyu.edu Lab Teaching Assistant TBD Description Syllabus MPATE-GE 2618: C Programming for Music

More information

18-600: Recitation #3

18-600: Recitation #3 18-600: Recitation #3 Bomb Lab & GDB Overview September 12th, 2017 1 Today X86-64 Overview Bomb Lab Introduction GDB Tutorial 2 3 x86-64: Register Conventions Arguments passed in registers: %rdi, %rsi,

More information

Introduction to Siri Shortcuts

Introduction to Siri Shortcuts #WWDC8 Introduction to Siri Shortcuts Session 2 Ari Weinstein, Siri Willem Mattelaer, Siri 208 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission

More information

Introducing Swift Playgrounds

Introducing Swift Playgrounds Developer Tools #WWDC16 Introducing Swift Playgrounds Exploring with Swift on ipad Session 408 Matt Patenaude Playgrounds Engineer Maxwell Swadling Playgrounds Engineer Jonathan Penn Playgrounds Engineer

More information

Survey. Motivation 29.5 / 40 class is required

Survey. Motivation 29.5 / 40 class is required Survey Motivation 29.5 / 40 class is required Concerns 6 / 40 not good at examination That s why we have 3 examinations 6 / 40 this class sounds difficult 8 / 40 understand the instructor Want class to

More information

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking CS 430 Spring 2015 Mike Lam, Professor Data Types and Type Checking Type Systems Type system Rules about valid types, type compatibility, and how data values can be used Benefits of a robust type system

More information

Static Program Analysis Part 1 the TIP language

Static Program Analysis Part 1 the TIP language Static Program Analysis Part 1 the TIP language http://cs.au.dk/~amoeller/spa/ Anders Møller & Michael I. Schwartzbach Computer Science, Aarhus University Questions about programs Does the program terminate

More information

Improving your Existing Apps with Swift

Improving your Existing Apps with Swift Developer Tools #WWDC15 Improving your Existing Apps with Swift Getting Swifty with It Session 403 Woody L. in the Sea of Swift 2015 Apple Inc. All rights reserved. Redistribution or public display not

More information

What s New in Testing

What s New in Testing #WWDC18 What s New in Testing Session 403 Honza Dvorsky, Xcode Engineer Ethan Vaughan, Xcode Engineer 2018 Apple Inc. All rights reserved. Redistribution or public display not permitted without written

More information

CPSC 3740 Programming Languages University of Lethbridge. Data Types

CPSC 3740 Programming Languages University of Lethbridge. Data Types Data Types A data type defines a collection of data values and a set of predefined operations on those values Some languages allow user to define additional types Useful for error detection through type

More information

Class Information ANNOUCEMENTS

Class Information ANNOUCEMENTS Class Information ANNOUCEMENTS Third homework due TODAY at 11:59pm. Extension? First project has been posted, due Monday October 23, 11:59pm. Midterm exam: Friday, October 27, in class. Don t forget to

More information

Lectures 5-6: Introduction to C

Lectures 5-6: Introduction to C Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most

More information

ECE 15B COMPUTER ORGANIZATION

ECE 15B COMPUTER ORGANIZATION ECE 15B COMPUTER ORGANIZATION Lecture 13 Strings, Lists & Stacks Announcements HW #3 Due next Friday, May 15 at 5:00 PM in HFH Project #2 Due May 29 at 5:00 PM Project #3 Assigned next Thursday, May 19

More information

Introduction to C. Robert Escriva. Cornell CS 4411, August 30, Geared toward programmers

Introduction to C. Robert Escriva. Cornell CS 4411, August 30, Geared toward programmers Introduction to C Geared toward programmers Robert Escriva Slide heritage: Alin Dobra Niranjan Nagarajan Owen Arden Cornell CS 4411, August 30, 2010 1 Why C? 2 A Quick Example 3 Programmer s Responsibilities

More information

CSC 1600 Memory Layout for Unix Processes"

CSC 1600 Memory Layout for Unix Processes CSC 16 Memory Layout for Unix Processes" 1 Lecture Goals" Behind the scenes of running a program" Code, executable, and process" Memory layout for UNIX processes, and relationship to C" : code and constant

More information

Working with Metal Overview

Working with Metal Overview Graphics and Games #WWDC14 Working with Metal Overview Session 603 Jeremy Sandmel GPU Software 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission

More information

Francesco Nidito. Programmazione Avanzata AA 2007/08

Francesco Nidito. Programmazione Avanzata AA 2007/08 Francesco Nidito in the Programmazione Avanzata AA 2007/08 Outline 1 2 3 in the in the 4 Reference: Micheal L. Scott, Programming Languages Pragmatics, Chapter 7 What is a type? in the What is a type?

More information

Introducing Password AutoFill for Apps

Introducing Password AutoFill for Apps Session App Frameworks #WWDC17 Introducing Password AutoFill for Apps Reducing friction for your users 206 Ricky Mondello, ios Engineer 2017 Apple Inc. All rights reserved. Redistribution or public display

More information

Announcements. assign0 due tonight. Labs start this week. No late submissions. Very helpful for assign1

Announcements. assign0 due tonight. Labs start this week. No late submissions. Very helpful for assign1 Announcements assign due tonight No late submissions Labs start this week Very helpful for assign1 Goals for Today Pointer operators Allocating memory in the heap malloc and free Arrays and pointer arithmetic

More information

CSE409, Rob Johnson, Alin Tomescu, November 11 th, 2011 Buffer overflow defenses

CSE409, Rob Johnson,   Alin Tomescu, November 11 th, 2011 Buffer overflow defenses Buffer overflow defenses There are two categories of buffer-overflow defenses: - Make it hard for the attacker to exploit buffer overflow o Address space layout randomization o Model checking to catch

More information

Hacking in C. Memory layout. Radboud University, Nijmegen, The Netherlands. Spring 2018

Hacking in C. Memory layout. Radboud University, Nijmegen, The Netherlands. Spring 2018 Hacking in C Memory layout Radboud University, Nijmegen, The Netherlands Spring 2018 A short recap The & operator gives us the address of data Inverse of & is the * operator (dereferencing) 2 A short recap

More information

Dynamic code analysis tools

Dynamic code analysis tools Dynamic code analysis tools Stewart Martin-Haugh (STFC RAL) Berkeley Software Technical Interchange meeting Stewart Martin-Haugh (STFC RAL) Dynamic code analysis tools 1 / 16 Overview Introduction Sanitizer

More information

Threads Tuesday, September 28, :37 AM

Threads Tuesday, September 28, :37 AM Threads_and_fabrics Page 1 Threads Tuesday, September 28, 2004 10:37 AM Threads A process includes an execution context containing Memory map PC and register values. Switching between memory maps can take

More information

Advanced Memory Analysis with Instruments. Daniel Delwood Performance Tools Engineer

Advanced Memory Analysis with Instruments. Daniel Delwood Performance Tools Engineer Advanced Memory Analysis with Instruments Daniel Delwood Performance Tools Engineer 2 Memory Analysis What s the issue? Memory is critical to performance Limited resource Especially on iphone OS 3 4 Memory

More information

Metal for OpenGL Developers

Metal for OpenGL Developers #WWDC18 Metal for OpenGL Developers Dan Omachi, Metal Ecosystem Engineer Sukanya Sudugu, GPU Software Engineer 2018 Apple Inc. All rights reserved. Redistribution or public display not permitted without

More information

Agenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011

Agenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011 CS 61C: Great Ideas in Computer Architecture (Machine Structures) Introduction to C (Part II) Instructors: Randy H. Katz David A. Patterson http://inst.eecs.berkeley.edu/~cs61c/sp11 Spring 2011 -- Lecture

More information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 11: Structures and Memory (yaseminb@kth.se) Overview Overview Lecture 11: Structures and Memory Structures Continued Memory Allocation Lecture 11: Structures and Memory Structures Continued Memory

More information

Mastering Drag and Drop

Mastering Drag and Drop Session App Frameworks #WWDC17 Mastering Drag and Drop 213 Tom Adriaenssen, UIKit Wenson Hsieh, WebKit Robb Böhnke, UIKit 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted

More information

Hacking in C. Pointers. Radboud University, Nijmegen, The Netherlands. Spring 2019

Hacking in C. Pointers. Radboud University, Nijmegen, The Netherlands. Spring 2019 Hacking in C Pointers Radboud University, Nijmegen, The Netherlands Spring 2019 Allocation of multiple variables Consider the program main(){ char x; int i; short s; char y;... } What will the layout of

More information

Introduction to C. Zhiyuan Teo. Cornell CS 4411, August 26, Geared toward programmers

Introduction to C. Zhiyuan Teo. Cornell CS 4411, August 26, Geared toward programmers Introduction to C Geared toward programmers Zhiyuan Teo Slide heritage: Alin Dobra Niranjan Nagarajan Owen Arden Robert Escriva Cornell CS 4411, August 26, 2011 1 Administrative Information 2 Why C? 3

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Introduce C# as Object Oriented programming language. Explain, tokens,

Introduce C# as Object Oriented programming language. Explain, tokens, Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation

More information

High Performance Computing MPI and C-Language Seminars 2009

High Performance Computing MPI and C-Language Seminars 2009 High Performance Computing - Seminar Plan Welcome to the High Performance Computing seminars for 2009. Aims: Introduce the C Programming Language. Basic coverage of C and programming techniques needed

More information

Touch Bar Fundamentals

Touch Bar Fundamentals Session App Frameworks #WWDC17 Touch Bar Fundamentals 211 Chris Dreessen John Tegtmeyer 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from

More information

Assignment II: Foundation Calculator

Assignment II: Foundation Calculator Assignment II: Foundation Calculator Objective The goal of this assignment is to extend the CalculatorBrain from last week to allow inputting variables into the expression the user is typing into the calculator.

More information

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso Why C? Test on 21 Android Devices with 32-bits and 64-bits processors and different versions

More information

Outline. Classic races: files in /tmp. Race conditions. TOCTTOU example. TOCTTOU gaps. Vulnerabilities in OS interaction

Outline. Classic races: files in /tmp. Race conditions. TOCTTOU example. TOCTTOU gaps. Vulnerabilities in OS interaction Outline CSci 5271 Introduction to Computer Security Day 3: Low-level vulnerabilities Stephen McCamant University of Minnesota, Computer Science & Engineering Race conditions Classic races: files in /tmp

More information

What s New in Cocoa for macos

What s New in Cocoa for macos Session #WWDC18 What s New in Cocoa for macos 209 Ali Ozer, Cocoa Frameworks Chris Dreessen, Cocoa Frameworks Jesse Donaldson, Cocoa Frameworks 2018 Apple Inc. All rights reserved. Redistribution or public

More information