+ All Categories
Home > Software > Debugging tips and tricks

Debugging tips and tricks

Date post: 12-Feb-2017
Category:
Upload: tales-andrade
View: 244 times
Download: 0 times
Share this document with a friend
34
Transcript
Page 1: Debugging tips and tricks
Page 2: Debugging tips and tricks

Debugging tips and tricks

Page 3: 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 Kernighan

Page 4: Debugging tips and tricks

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

Page 5: Debugging tips and tricks

Fundamentos

• Breakpoint• Watchpoint• Debug Navigator• Editor Area• Continue to Here (gutter)• Debug bar• Show debug area (cmd + shift +

y)• variable view

• watch• console

Page 6: Debugging tips and tricks

Fundamentos

• Breakpoint• Watchpoint• Debug Navigator• Editor Area• Continue to Here (gutter)• Debug bar• Show debug area (cmd + shift

+ y)• variable view• watch

• console• Frame

Page 7: Debugging tips and tricks

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

Page 8: Debugging tips and tricks

Fundamentos

• Debug bar• Debug View Hierarchy• Simulate Location• Choose stack frame

Page 9: Debugging tips and tricks

Fundamentos

• watchpoint• parece breakpoint• para na mudança de valor• Variável ou endereço de memória

• view memory• breakpoint navigator• edit• condition• action• options (apenas uma)

Page 10: Debugging tips and tricks

lldb - low level debugger

• inicio• terminologia• personalizando comandos

Page 11: Debugging tips and tricks

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

Page 12: Debugging tips and tricks

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 }

Page 13: Debugging tips and tricks

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

Page 14: Debugging tips and tricks

lldb - comandos

• Expression (expression)• Print (print / expression —)• parray

• Print Object (po / expression -O —)• poarray

• Watchpoint (watchpoint)

Page 15: Debugging tips and tricks

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)

Page 16: Debugging tips and tricks

lldb - low level debugger

- Symbolic Breakpoint

Page 17: Debugging tips and tricks

lldb - low level debugger

- Symbolic Breakpoint- Assinatura do método

Page 18: Debugging tips and tricks

lldb - low level debugger

- Symbolic Breakpoint- Assinatura do método- Simbolo

Page 19: Debugging tips and tricks

lldb - low level debugger

- Exception Breakpoint

Page 20: Debugging tips and tricks

lldb - editando breakpoints

Page 21: Debugging tips and tricks

lldb - condições de parada

Page 22: Debugging tips and tricks

lldb - condições de parada

• - [NSManagedObject setValue:forKey:]

Page 23: Debugging tips and tricks

lldb - mais expressões

• e count = 42(NSUInteger) $4 = 42

• e NSMutableDictionary *$dict = [staticDict mutableCopy];e $dict[@“key”] = @“newValue”;e staticDict = $dict;

Page 24: Debugging tips and tricks

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 $str0x7fd04a900040: monk

Page 25: Debugging tips and tricks

lldb - low level debugger

- Watchpoint- Monitora estado/valor de

variável- Inspetor de variáveis

Page 26: Debugging tips and tricks

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

Page 27: Debugging tips and tricks

lldb - low level debugger

Page 28: Debugging tips and tricks

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”

Page 29: Debugging tips and tricks

Python + Chisel

• ~/.lldbinit-Xcode• ~/.lldbinit• Aliases• default settings• type formatting• import python modules• bind python commands

Page 30: Debugging tips and tricks

Chisel - alguns comandos úteis

• (lldb) script import os(lldb) script os.system("open http://concretesolutions.com.br“)

• Permite importar script python comcommand script import ~/myCommands.py

Page 31: Debugging tips and tricks

Chisel - alguns comandos úteis

• Chisel - Instalando:• brew update• brew install chisel

• pviews - exibe hierarquia de view• pvc - exibe hierarquia de view controllers• visualize - abre Preview.app com conteúdo de UIImage,

CGImageRef, UIView, CALayer• fv/fvc - busca view/view controller pelo nome de classe via regex• alamborder - adiciona borda em view com layout ambíguo• mwarning - simula memory warning

Page 32: Debugging tips and tricks

Behaviors

• debug navigator aparecendo - só alterar• console• variables view, etc

Page 33: Debugging tips and tricks

Refereincias

• http://www.slideshare.net/talesp/debugging-fast-track• https://github.com/facebook/chisel• https://www.objc.io/issues/19-debugging/lldb-debugging/#let-s-d

ance• http://lldb.llvm.org/tutorial.html• https://www.bignerdranch.com/blog/xcode-breakpoint-wizardry/

Page 34: Debugging tips and tricks

www.concretesolutions.com.brblog.concretesolutions.com.br

Rio de Janeiro – Rua São José, 90 – cj. 2121Centro – (21) 2240-2030

São Paulo - Rua Sansão Alves dos Santos, 433 4º andar - Brooklin - (11) 4119-0449


Recommended