Coder Social home page Coder Social logo

swift_po's Introduction

swift_po aka spo

Substitute po command for Swift, with fewer corner cases to watch out for.

Avoids Leaks

There's a bug in lldb that creates strong references to any object printed with po. The result is leaked objects, and missing calls to deinit.

(lldb) po self

After running this, self will never be released. This is not specific to self, it happens to any object. A leak will also happen when using p or expression.

There are two work arounds:

  1. frame variable -O
  2. call print(...)

These are what swift_po does for you. If the input can be resolved as a variable, then frame variable is used, otherwise it performs call print(...).

frame variable

LLDB has added a vo command, an alias for frame variable -O. This much like po, but is for variable expressions only, not arbitrary code evaluation. Printing via vo is faster than po. When using swift_po, the first option is perform a vo operaton. If that fails, call print(...) is performed instead.

Object Pointers

From Swift, po 0x76543210 will not work. This does work from objc though. swift_po works with memory addresses too, same as objc.

Installation

First clone swift_po:

git clone https://github.com/kastiglione/swift_po.git

Next, edit your ~/.lldbinit to import the spo command:

command script import path/to/swift_po/spo.py

Usage

Call spo anywhere you'd normally call po.

If you would like to override po to be spo, add these to your ~/.lldbinit:

command unalias po
command alias po spo

What swift_po is doing

A summary of what swift_po does for you.

spo command equivalent lldb
spo 0x76543210 expression -l objc -O -- 0x76543210
spo self frame variable -O self
spo self.objects frame variable -O self.objects
spo self.view expression print(self.view)
spo some.function() expression print(some.function())

This table show that some properties cannot be accessed using frame variable, in those cases print() is used instead.

swift_po's People

Contributors

kastiglione avatar rnapier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  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.