SlideShare a Scribd company logo
Advanced Debugging
Xcode
By



Ali Akhtar
LLDB
• Debugger in Xcode

• LLDB replaced GDB

• Xcode 5

• Clang is an "LLVM native" C/C++/Objective-C compiler
Optional Types
Raw Display
Static/Dynamic Types
Dynamic Dispatch
Dynamic Dispatch
Dynamic Dispatch
• Use final keyword
• Declaration can’t be overridden
• Allows the compiler to safely elide dynamic dispatc
indirection.
• final keyword enables the sealing of classes and
methods.
Dynamic Type in LLDB
Dynamic Type in LLDB
Protocol
Protocol
Protocol
Debugging Optimized Swift
Code
Objective C and Swift
Variable View
Objective C and Swift
Expression
Objective C and Swift
Expression
Objective C and Swift
Expression
Can’t access utcDate
Expression modify
variable of program
Data Formatters for Swift
Objects
Data Formatters for Swift
Objects
Uniqueness
Uniqueness
Uniqueness
Uniqueness
Commands lldb
• bugreport (full report of current app’s state)

• frame info 

• refcount (shows you reference count for the specific
object)
Commands lldb
Control app’s execution
flow
• Automate debugging. Stuffs
• Speedup Debugging Process
Add Actions
Command Alias
Exploring Memory Address
Defining Reusable
Functions
User Defined Predicate
BreakPoint
Xcode BreakPoint
Multiple Locations
Multiple Locations
View Hierarchy Debugging
• Ability to inspect UI hierarchy
• app’s hierarchy, views, constraints, and view controllers, displayed as a hierarchical list
• Object inspector and size inspector
View Hierarchy Debugging
View Debugging
View Debugging
Address Sanitizer
• Track down memory violations 

• Finds memory corruptions

•  Finds Memory errors at runtime

• LLVM based tool for C languages and Swift 

• These crashes are not deterministic
Limitation
• Detect memory errors at runtime

• Cannot detect memory leaks

•  Cannot detect access uninitialised memory
Address Sanitizer
Advanced_Apple_Debugging_&_Reverse_Engineering_v2.0.pdf
Address Sanitizer
• strlen(s) gives you the length of the string held in
the s variable, up to the first NULL character
Address Sanitizer
use-after-free bug
use-after-free bug
Out-of-Scope
Solution
1)Variable aren’t accessed outside of their
scope
2)Allocate memory using malloc function
Use of Stack Memory After Function
Return
Use of Stack Memory After Function Return
• Function returns a pointer to its local variable

• Once the function returns, that pointer is no longer valid

•  If we use we are again accessing garbage memory

• Either crash or unexpected behaviour
Solution
• Use pointer arguments
 Memory Graph Debugger
• Find  retain cycle

• Find  memory leaks

• Pause app execution when activated

• Display objects currently in a heap

• Live Allocations uncheck when not using

• Clean build when using
1) How to Use
2) How to Use
Allocations
Allocations
Allocations
Memory Leaks
Controller TableView
Visible Cell
Visible Cell
Visible Cell
Visible Cell
Closure
Memory Leaks
Thinking
• Pop Controller

• Why it still in heap

• dealloc also not called 

• Not a simple leak so Memory Graph Debugger don’t tell

• Using heap content we identify
Memory Leaks
Memory Leaks
Memory Leaks
No controller in heap content also
Thread Sanitizer (TSan)
Threading Issues

• Hard to consistently reproduce

• Difficult to debug (Timing matter)

• Lead to unpredictable results
Thread Sanitizer (TSan)
• Use of uninitialised mutexes

• Thread leak (missing pthread_join)

• Unsafe calls in signal handlers

• Unlock from wrong thread

• Data races / Race condition (access same memory
location without proper sync )

• Xcode 8
Thread Sanitizer (TSan)
Data Race
Reasons
Data Race example
Data Race example
Data Race example
Lazy Initialization in Objective C
Lazy Initialization in Swift
Race Condition
Solution
Swift Access Races
• Multiple threads call a mutating method on Structs

• Pass a shared variable as inout  without systematic
manner

• Access races can result in unpredictable behavior
Swift Access Races
Races on Collections and
Other APIs
Races on Collections and
Other APIs
Uninitialised Mutexes
• Detects when a mutex is used before it’s initialized.

• pthread_mutex_lock(_:) or pthread_mutex_unlock(_:) is
called with a pthread_mutex_t variable that wasn’t
initialized

• Attempting to use an uninitialized mutex results in an error
Uninitialised Mutexes
Solution
Main Thread Checker
• Detect invalid use of AppKit, UIKit, and other APIs from a
background thread.

• Missed UI updates

• Visual defects
Main Thread Checker
Main Thread Checker
Static Analyzer
•  Find bugs in your code before you even run your app

• Possible code paths in a few seconds, reporting potential
bugs 

•  Identifies areas in your code that don’t follow
recommended API
Static Analyzer
Problems
• Logic flaws, such as accessing uninitialized variables and
dereferencing null pointers

• Dead store (unused variable) flaws

• API usage flaws
Examples

More Related Content

PDF
Swift, a quick overview
PDF
Scala laboratory: Globus. iteration #3
PPTX
Flow control in Python
PPTX
Functional programming principles and Java 8
PDF
Introduction to c first week slides
PDF
Functional Programming in Java
PDF
Functional programming with Java 8
PPT
Lambdas
Swift, a quick overview
Scala laboratory: Globus. iteration #3
Flow control in Python
Functional programming principles and Java 8
Introduction to c first week slides
Functional Programming in Java
Functional programming with Java 8
Lambdas

What's hot (20)

PDF
Systematic Evaluation of the Unsoundness of Call Graph Algorithms for Java
PPTX
Break Free with Managed Functional Programming: An Introduction to F#
PPTX
Break Free with Managed Functional Programming: An Introduction to F#
PDF
Lambdas in Java 8
PDF
Java 8 features
PPTX
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
PPTX
Functional programming for the Advanced Beginner
PDF
TMPA-2015: Towards a Usable Defect Prediction Tool: Crossbreeding Machine Lea...
PPTX
Functional programming with Java 8
PPTX
Distributed Model Validation with Epsilon
PDF
Preparing for Scala 3
PDF
FPGA Coding Guidelines
PPTX
Beginning Java for .NET developers
PPTX
Critical Section in Operating System
PDF
What To Leave Implicit
PDF
Introduction to Scala Implicits, Pimp my library and Typeclasses
PPTX
Week 2: Getting Your Hands Dirty – Part 2
PDF
Erlang workshopdrammen
DOCX
Critical section operating system
PPTX
Java Chapter 05 - Conditions & Loops: part 2
Systematic Evaluation of the Unsoundness of Call Graph Algorithms for Java
Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#
Lambdas in Java 8
Java 8 features
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Functional programming for the Advanced Beginner
TMPA-2015: Towards a Usable Defect Prediction Tool: Crossbreeding Machine Lea...
Functional programming with Java 8
Distributed Model Validation with Epsilon
Preparing for Scala 3
FPGA Coding Guidelines
Beginning Java for .NET developers
Critical Section in Operating System
What To Leave Implicit
Introduction to Scala Implicits, Pimp my library and Typeclasses
Week 2: Getting Your Hands Dirty – Part 2
Erlang workshopdrammen
Critical section operating system
Java Chapter 05 - Conditions & Loops: part 2
Ad

Similar to Advanced debugging (20)

PPTX
06.1 .Net memory management
PPTX
Design p atterns
PDF
Rethinking the debugger
PDF
C# 8 in Libraries and Applications - BASTA! Frankfurt 2020
PDF
Working With Concurrency In Java 8
PPTX
Practical Windows Kernel Exploitation
PDF
08 subprograms
PPTX
PresentationPatterns_v2
PDF
The Diabolical Developers Guide to Performance Tuning
PPTX
AOP on Android
PPTX
Scheduling Thread
PDF
Jose Luis Soria - XP2014 - Designing a Release Pipeline
PPTX
How to crack java script certification
PDF
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
PPTX
UNIT -5 EMBEDDED DRIVERS AND APPLICATION PORTING.pptx
PPTX
Byte code manipulation and instrumentalization in Java
PPTX
OrigoDB - take the red pill
PPT
14274730 (1).ppt
PDF
Java 8 - Project Lambda
PDF
Tool Up Your LAMP Stack
06.1 .Net memory management
Design p atterns
Rethinking the debugger
C# 8 in Libraries and Applications - BASTA! Frankfurt 2020
Working With Concurrency In Java 8
Practical Windows Kernel Exploitation
08 subprograms
PresentationPatterns_v2
The Diabolical Developers Guide to Performance Tuning
AOP on Android
Scheduling Thread
Jose Luis Soria - XP2014 - Designing a Release Pipeline
How to crack java script certification
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
UNIT -5 EMBEDDED DRIVERS AND APPLICATION PORTING.pptx
Byte code manipulation and instrumentalization in Java
OrigoDB - take the red pill
14274730 (1).ppt
Java 8 - Project Lambda
Tool Up Your LAMP Stack
Ad

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPT
Teaching material agriculture food technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Machine learning based COVID-19 study performance prediction
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf
The AUB Centre for AI in Media Proposal.docx
Teaching material agriculture food technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Review of recent advances in non-invasive hemoglobin estimation
“AI and Expert System Decision Support & Business Intelligence Systems”
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation_ Review paper, used for researhc scholars
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MIND Revenue Release Quarter 2 2025 Press Release
Machine learning based COVID-19 study performance prediction
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
sap open course for s4hana steps from ECC to s4
Reach Out and Touch Someone: Haptics and Empathic Computing
Network Security Unit 5.pdf for BCA BBA.
Agricultural_Statistics_at_a_Glance_2022_0.pdf

Advanced debugging