debugging tips and tricks

Post on 12-Feb-2017

238 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

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

Fundamentos

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

y)• variable view

• watch• console

Fundamentos

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

+ y)• variable view• watch

• console• Frame

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

Fundamentos

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

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)

lldb - low level debugger

• inicio• terminologia• personalizando comandos

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

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 }

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

lldb - comandos

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

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

• Watchpoint (watchpoint)

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)

lldb - low level debugger

- Symbolic Breakpoint

lldb - low level debugger

- Symbolic Breakpoint- Assinatura do método

lldb - low level debugger

- Symbolic Breakpoint- Assinatura do método- Simbolo

lldb - low level debugger

- Exception Breakpoint

lldb - editando breakpoints

lldb - condições de parada

lldb - condições de parada

• - [NSManagedObject setValue:forKey:]

lldb - mais expressões

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

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

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

lldb - low level debugger

- Watchpoint- Monitora estado/valor de

variável- Inspetor de variáveis

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

lldb - low level debugger

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”

Python + Chisel

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

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

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

Behaviors

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

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/

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

top related