SlideShare a Scribd company logo
Brian Kernighan
Debugging tips and tricks
Everyone knows that debugging is twice as hard
as writing a program in the first place. So if you're
as clever as you can be when you write it, how
will you ever debug it?
Brian Kerninghan
Basic notions
○Breakpoint
○Watchpoint
○Continue to Here (gutter)
○Debug bar
○Show debug area (cmd + shift + y)
○variable view
○watch
○console
○Frame
Basic notions
○ Debug bar
○ (de)activate breakpoints
○ Continue execution
○ Step over
○ Execute current line and go to the next
○ Step in
○ “enter” the called method/function
○ Step out
○ “exit” the called method/function
Basic notions
○ Debug bar
○ Debug view hierarchy
○ Simulate location
○ Choose stack frame
Basic notions
○ watchpoint
○ Behaviors like a breakpoint
○ Stop at value change
○ Variable or memory address
○ Command line
○ Click
○ view memory
○ breakpoint navigator
○ edit
○ condition
○ action
lldb - low level debugger
○ Have you done that?: 

print("log just for debug: (self.object)")
○ Or that?

let n = 0 // self.someMethodThatReturnInteger()
○ Or that?

if true !|| self.someMethodThatReturnBool() {
○ Or that?

func someMethodThatReturnBool() !-> Bool {

return true !//TODO: implement

}
lldb - breakpoints
○ Breakpoint stop execution of a instruction
○ Allow add command just for debug
○ May have stop condition
○ Via command

breakpoint set —file ViewController.swift —line 7
○ One shot - code execute just once, automatically removed

breakpoint set —oneshot true —name MyType.myMethod()
○ Via Xcode - just click gutter
lldb - stop conditions
lldb - condições de parada
○ - NSManagedObject.setValue(Any?, forKey: String)
lldb - low level debugger
○ Exception Breakpoint
○ Symbolic Breakpoint

UIKit symbols in Objective-C
○ Method signature
○ Symbols
lldb - exception breakpoint - stopping on crash
- Exception Breakpoint
lldb - commands and expressions
○ Expression (expression)
○ Print - p / expression — : - lldb internal formatters
○ parray
○ Print Object - po / expression -O — - use implementation of debugDescription
○ poarray
○ Frame variable (only Xcode 10.2) - v

Print variables of current stack frame. Can be way faster
○ Watchpoint (watchpoint)
Moving breakpoint position
Skipping line and returning value
Expressions
○ Evaluated as code
○ Result is shown and storage in convenience variable ($1, $2, etc)
○ Can do a lot
○ Arithmetic
○ function/method calling
○ type casting
○ Attributions
○ Variable declaration (let variable: Type = value)
lldb - mais expressões
(lldb) e let user.name = “John Doe”
(lldb) e let $count = 42
(lldb) po $count
42
(lldb) e let $dict: Dictionary<String, Int> = ["answer": 42]
(lldb) po $dict
▿ 1 element
▿ 0 : 2 elements
- key : "answer"
- value : 42
lldb - low level debugger
○ Watchpoint
○ Monitor state/value of a variable
○ Variable inspector
lldb - low level debugger
○ Watchpoint
○ Monitor state/value of a variable
○ Since Xcode 10 shown in breakpoint navigator
lldb - low level debugger
○ Rule of Thumb - keep it fast
○ “Automatically continue after evaluating”
○ po $arg1
○ Audible breakpoints
○ breakpoint with shell command
○ Command: say
○ Arguments: -v, Zarvox, “Your breakpoint %B has been hit %H times”
Referências
○ http://www.slideshare.net/talesp/debugging-fast-track
○ https://github.com/facebook/chisel
○ https://www.objc.io/issues/19-debugging/lldb-debugging/#let-s-
dance
○ http://lldb.llvm.org/tutorial.html
○ https://www.bignerdranch.com/blog/xcode-breakpoint-wizardry/
○ https://developer.apple.com/videos/play/wwdc2018/412/
N Ó S M O V E M O S O M U N D O .
RIO SÃO PAULO BH RECIFE
Centro
Av. Presidente Wilson, 231 
29º andar
(21) 2240-2030
Cidade Monções
Av. Nações Unidas, 11.541 
3º andar

(11) 4119-0449
Savassi
Av. Getúlio Vargas, 671 
Sala 800 - 8º andar
(31) 3360-8900
Ilha do Leite
Rua Sen. José Henrique, 199
2º andar
(81) 3018-6299
W W W. C O N C R E T E . C O M . B R

More Related Content

PPSX
C++ quik notes
PDF
Refactoring
PPTX
New presentation oop
PPTX
C++ Programming Club-Lecture 2
PPTX
DOCX
Program: Inheritance in Class - to find topper out of 10 students
PPTX
C++ Programming Club-Lecture 1
PDF
Bind me if you can
C++ quik notes
Refactoring
New presentation oop
C++ Programming Club-Lecture 2
Program: Inheritance in Class - to find topper out of 10 students
C++ Programming Club-Lecture 1
Bind me if you can

What's hot (20)

PDF
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
DOCX
Concatenation of two strings using class in c++
PPTX
Roslyn: el futuro de C#
PPTX
PPTX
Builtin Functions and variables naming rules
PDF
Richard Salter: Using the Titanium OpenGL Module
PDF
Illicium: Compiling Pharo to C
PDF
Android Development Course in HSE lecture #2
PDF
Do while loop
 
PPT
Measuring SGX Texturing Performance
PDF
Program for axisymmetric problem matlab
PDF
Scheme 核心概念(一)
PDF
Dynamic Swift
KEY
Ruby performance
PDF
Program for axisymmetric problem kant
PDF
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
DOCX
Oop lab report
ZIP
Lisp Macros in 20 Minutes (Featuring Clojure)
PPTX
Andriy Slobodyanyk "How to Use Hibernate: Key Problems and Solutions"
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Concatenation of two strings using class in c++
Roslyn: el futuro de C#
Builtin Functions and variables naming rules
Richard Salter: Using the Titanium OpenGL Module
Illicium: Compiling Pharo to C
Android Development Course in HSE lecture #2
Do while loop
 
Measuring SGX Texturing Performance
Program for axisymmetric problem matlab
Scheme 核心概念(一)
Dynamic Swift
Ruby performance
Program for axisymmetric problem kant
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
Oop lab report
Lisp Macros in 20 Minutes (Featuring Clojure)
Andriy Slobodyanyk "How to Use Hibernate: Key Problems and Solutions"
Ad

Similar to Debugging tips and tricks - coders on beers Santiago (20)

PDF
Introduction to nand2 tetris
PDF
HKG15-211: Advanced Toolchain Usage Part 4
PDF
HKG15-207: Advanced Toolchain Usage Part 3
PDF
Coding with Vim
PPT
Debugging Applications with GNU Debugger
PDF
BUD17-310: Introducing LLDB for linux on Arm and AArch64
PDF
Short Introduction To "perl -d"
PDF
05-Debug.pdf
PDF
Writing mruby Debugger
PDF
More than `po`: Debugging in lldb
PDF
Cryptography 202
PPTX
Learn JavaScript From Scratch
PDF
DALL-E.pdf
PDF
Designate Install and Operate Workshop
PPT
EMBEDDED SYSTEMS 4&5
PDF
Floripa on Rails - dev workflow
PPTX
C++ theory
PDF
PDF
SOLID Ruby SOLID Rails
PDF
from Binary to Binary: How Qemu Works
Introduction to nand2 tetris
HKG15-211: Advanced Toolchain Usage Part 4
HKG15-207: Advanced Toolchain Usage Part 3
Coding with Vim
Debugging Applications with GNU Debugger
BUD17-310: Introducing LLDB for linux on Arm and AArch64
Short Introduction To "perl -d"
05-Debug.pdf
Writing mruby Debugger
More than `po`: Debugging in lldb
Cryptography 202
Learn JavaScript From Scratch
DALL-E.pdf
Designate Install and Operate Workshop
EMBEDDED SYSTEMS 4&5
Floripa on Rails - dev workflow
C++ theory
SOLID Ruby SOLID Rails
from Binary to Binary: How Qemu Works
Ad

More from Tales Andrade (8)

PDF
Delegateless Coordinators - take 2
PDF
Delegateless Coordinator
PDF
Swift na linha de comando
PPTX
Debugging tips and tricks
PPTX
Usando POP com Programação Funcional
PDF
Swift!.opcionais.oh!.my()?!?
PDF
Debugging fast track
PDF
Tales@tdc
Delegateless Coordinators - take 2
Delegateless Coordinator
Swift na linha de comando
Debugging tips and tricks
Usando POP com Programação Funcional
Swift!.opcionais.oh!.my()?!?
Debugging fast track
Tales@tdc

Recently uploaded (20)

PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
PPT on Performance Review to get promotions
PPT
Project quality management in manufacturing
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Well-logging-methods_new................
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Digital Logic Computer Design lecture notes
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
Welding lecture in detail for understanding
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
web development for engineering and engineering
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Geodesy 1.pptx...............................................
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
UNIT-1 - COAL BASED THERMAL POWER PLANTS
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPT on Performance Review to get promotions
Project quality management in manufacturing
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Well-logging-methods_new................
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Digital Logic Computer Design lecture notes
Automation-in-Manufacturing-Chapter-Introduction.pdf
Welding lecture in detail for understanding
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
web development for engineering and engineering
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Operating System & Kernel Study Guide-1 - converted.pdf
Geodesy 1.pptx...............................................
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Embodied AI: Ushering in the Next Era of Intelligent Systems

Debugging tips and tricks - coders on beers Santiago

  • 3. Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? Brian Kerninghan
  • 4. Basic notions ○Breakpoint ○Watchpoint ○Continue to Here (gutter) ○Debug bar ○Show debug area (cmd + shift + y) ○variable view ○watch ○console ○Frame
  • 5. Basic notions ○ Debug bar ○ (de)activate breakpoints ○ Continue execution ○ Step over ○ Execute current line and go to the next ○ Step in ○ “enter” the called method/function ○ Step out ○ “exit” the called method/function
  • 6. Basic notions ○ Debug bar ○ Debug view hierarchy ○ Simulate location ○ Choose stack frame
  • 7. Basic notions ○ watchpoint ○ Behaviors like a breakpoint ○ Stop at value change ○ Variable or memory address ○ Command line ○ Click ○ view memory ○ breakpoint navigator ○ edit ○ condition ○ action
  • 8. lldb - low level debugger ○ Have you done that?: 
 print("log just for debug: (self.object)") ○ Or that?
 let n = 0 // self.someMethodThatReturnInteger() ○ Or that?
 if true !|| self.someMethodThatReturnBool() { ○ Or that?
 func someMethodThatReturnBool() !-> Bool {
 return true !//TODO: implement
 }
  • 9. lldb - breakpoints ○ Breakpoint stop execution of a instruction ○ Allow add command just for debug ○ May have stop condition ○ Via command
 breakpoint set —file ViewController.swift —line 7 ○ One shot - code execute just once, automatically removed
 breakpoint set —oneshot true —name MyType.myMethod() ○ Via Xcode - just click gutter
  • 10. lldb - stop conditions
  • 11. lldb - condições de parada ○ - NSManagedObject.setValue(Any?, forKey: String)
  • 12. lldb - low level debugger ○ Exception Breakpoint ○ Symbolic Breakpoint
 UIKit symbols in Objective-C ○ Method signature ○ Symbols
  • 13. lldb - exception breakpoint - stopping on crash - Exception Breakpoint
  • 14. lldb - commands and expressions ○ Expression (expression) ○ Print - p / expression — : - lldb internal formatters ○ parray ○ Print Object - po / expression -O — - use implementation of debugDescription ○ poarray ○ Frame variable (only Xcode 10.2) - v
 Print variables of current stack frame. Can be way faster ○ Watchpoint (watchpoint)
  • 16. Skipping line and returning value
  • 17. Expressions ○ Evaluated as code ○ Result is shown and storage in convenience variable ($1, $2, etc) ○ Can do a lot ○ Arithmetic ○ function/method calling ○ type casting ○ Attributions ○ Variable declaration (let variable: Type = value)
  • 18. lldb - mais expressões (lldb) e let user.name = “John Doe” (lldb) e let $count = 42 (lldb) po $count 42 (lldb) e let $dict: Dictionary<String, Int> = ["answer": 42] (lldb) po $dict ▿ 1 element ▿ 0 : 2 elements - key : "answer" - value : 42
  • 19. lldb - low level debugger ○ Watchpoint ○ Monitor state/value of a variable ○ Variable inspector
  • 20. lldb - low level debugger ○ Watchpoint ○ Monitor state/value of a variable ○ Since Xcode 10 shown in breakpoint navigator
  • 21. lldb - low level debugger ○ Rule of Thumb - keep it fast ○ “Automatically continue after evaluating” ○ po $arg1 ○ Audible breakpoints ○ breakpoint with shell command ○ Command: say ○ Arguments: -v, Zarvox, “Your breakpoint %B has been hit %H times”
  • 22. Referências ○ http://www.slideshare.net/talesp/debugging-fast-track ○ https://github.com/facebook/chisel ○ https://www.objc.io/issues/19-debugging/lldb-debugging/#let-s- dance ○ http://lldb.llvm.org/tutorial.html ○ https://www.bignerdranch.com/blog/xcode-breakpoint-wizardry/ ○ https://developer.apple.com/videos/play/wwdc2018/412/
  • 23. N Ó S M O V E M O S O M U N D O . RIO SÃO PAULO BH RECIFE Centro Av. Presidente Wilson, 231  29º andar (21) 2240-2030 Cidade Monções Av. Nações Unidas, 11.541  3º andar
 (11) 4119-0449 Savassi Av. Getúlio Vargas, 671  Sala 800 - 8º andar (31) 3360-8900 Ilha do Leite Rua Sen. José Henrique, 199 2º andar (81) 3018-6299 W W W. C O N C R E T E . C O M . B R