Giter Club home page Giter Club logo

swiftaveiro2017's Introduction

Swift Aveiro 2017: Debugging Workshop

Part 1: Symbolic Debugging

We looked at using symbolic breakpoints to inspect how an app works.

Symbolic breakpoints

For example, how does the navigation in an app work? We can try adding breakpoints at some common navigation locations:

  • -[UINavigationController pushViewController:animated:]
  • -[UIViewController presentViewController:animated:completion:]
  • -[UIViewController addChildViewController:]

We can combine our knowledge of UIKit with lldb to find good places for symbolic breakpoints.

LLDB Tips

Remember to import UIKit! You might need to import it in both "Swift mode" and "Objective-C" mode.

expr -l swift -- import UIKit
expr @import UIKit

Swift variables in lldb: get typed variables in LLDB Swift mode:

expr -l Swift -- let $view = unsafeBitCast(0x7df67c50, to: UIView.self)
expr -l Swift -- print($view.frame)

Swift in LLDB: If you like Swift, you can add a command alias to your ~/.lldbinit file:

command alias sc expression -l swift --

Then in lldb, you can use sc import UIKit rather than expr -l swift -- import UIKit. Hat tip to Jorge Ortiz for the alias!

Part 2: Chisel

We looked at Chisel, an open-source project from Facebook that adds extra debugging commands to lldb.

Remember, you can replace <obj> below with an instance or a hex address.

Some favorites:

Command Notes
pviews Print the recursiveDescription of the key window
pvc Print the recursive view controller hierarchy of the key window
pinternals Print the internals (instance variables, etc.) of the object
pclass Print the class hierarchy of an object
mask/unmask Put a transparent color view on top of the view
border/unborder Draw a border around the view
visualize Render the target to a PNG and open it in Preview.app
pdocspath Print out the Documents directory path
pbundlepath Print out the app bundle directory path

Part 2.5: View Debugging

We took a quick sidebar to talk about FLEX and UIDebuggingInformationOverlay for visual debugging.

FLEX is an amazing debugging tool (not just for view debugging) and it's very easy to integrate into your own apps.

Part 3: New Debugging Features in Xcode

We looked at the memory graph debugger in Xcode to inspect memory usage and detect retain cycles. Note that you can't activate the memory graph debugger if you have the thread sanitizer option turned on.

Memory graph debugger button

Next, we looked at the thread sanitizer to help find race conditions and threading issues.

The thread sanitizer only works in the simulator and slows down the app. You can activate it in the scheme editor.

Thread sanitizer

Here's the lovely retain cycle I made special for this session:

Retain cycle

๐Ÿ˜œ

swiftaveiro2017's People

Contributors

gregheo avatar victorg1991 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.