Debugging é difícil e requer técnicas específicas. O documento discute fundamentos de debugging como breakpoints, watchpoints e expressões no lldb para inspecionar e modificar variáveis. Também apresenta dicas como usar Chisel para facilitar debugging em Xcode e personalizar comportamentos do debugger.
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 Kernighan
4. The first moral of the story is that
program testing can be used very
effectively to show the presence of
bugs but never their absence
Edsger W. Dijkstra
5. Fundamentos
• Breakpoint
• Watchpoint
• Debug Navigator
• Editor Area
• Continue to Here (gutter)
• Debug bar
• Show debug area (cmd + shift + y)
• variable view
• watch
• console
6. Fundamentos
• Breakpoint
• Watchpoint
• Debug Navigator
• Editor Area
• Continue to Here (gutter)
• Debug bar
• Show debug area (cmd + shift + y)
• variable view
• watch
• console
• Frame
7. Fundamentos
• Debug bar
• (des)ativar breakpoints
• Continuar execução
• Step over
• Executa a linha azul e segue para próxima
• Step in
• “entra” no método chamado
• Step out
• “Sai” do método chamado
11. lldb - low level debugger
• LLDB
• next generation
• high-performance debugger.
• It is built as a set of reusable components which highly leverage
existing libraries in the larger LLVM Project, such as the Clang
expression parser and LLVM disassembler.
• clang embutido
• usa o compilador para parse das expressões
12. lldb - low level debugger
• Usando Breakpoint
• Você já fez isso:
NSLog(@“Log just for debug: [%@]", self.objects);
• Ou isso?
NSInteger n = 0; //[self someMethodThatReturnInteger];
• Ou isso?
if (YES || [self someMethodThatReturnBool]) {
• Ou isso?
- (BOOL)someMethodThatReturnBool {
return YES;
//TODO: implement
}
13. lldb - breakpoints
• Breakpoint para a execução em uma instrução
• Permitem adicionar comandos apenas do debug
• condições de parada
• Via comando
breakpoint set —file ViewController.swift —line 7
• Via Xcode - basta clicar no gutter
15. Expressões
• avaliam como código
• resultado exibido e guardado em variável de conveniência ($1, $2, etc)
• podem fazer muito
• aritmetica
• chamada de funções
• type casting
• atribuições
• declaração de variáveis (tipo variável = valor ou tipo $variavel = valor)
22. lldb - condições de parada
• - [NSManagedObject setValue:forKey:]
23. lldb - mais expressões
• e count = 42
(NSUInteger) $4 = 42
• e NSMutableDictionary *$dict = [staticDict mutableCopy];
e $dict[@“key”] = @“newValue”;
e staticDict = $dict;
24. lldb - mais expressões
(lldb) e char *$str = (char *)malloc(8)
(lldb) e (void)strcpy($str, "munkeys")
(lldb) e $str[1] = 'o'
(char) $0 = 'o'
(lldb) p $str
(char *) $str = 0x00007fd04a900040 “monkeys"
(lldb) x/4c $str
0x7fd04a900040: monk
25. lldb - low level debugger
- Watchpoint
- Monitora estado/valor de
variável
- Inspetor de variáveis
26. lldb - low level debugger
- Watchpoint
- Monitora estado/valor de
variável
- Inspetor de variáveis
- Console
- Permite editar wp e
adicionar condição de
parada
- não aparece no Breakpoint
Navigator
28. lldb - low level debugger
• Rule of Thumb - keep it fast
• “Automatically continue after evaluating”
• po $arg1
• bt/bt all
• Audible breakpoints
• breakpoint com linha de comando
• Command: say
• Arguments: -v, Zarvox, “Your breakpoint %B has been hit %H times”