Post

Debugging in Xcode Basics (Part 1)

You can print any object in the debug area using the print function.

Screenshot-2020-09-15-at-4.21.14-PM-768x597

Literal expressions can be added too in the print function

LiteralTypeValue
#fileStringThe name of the file and module in which it appears.
#filePathStringThe path to the file in which it appears.
#lineIntThe line number on which it appears.
#columnIntThe column number in which it begins.
#functionStringThe name of the declaration in which it appears.
#dsohandleUnsafeRawPointerThe DSO (dynamic shared object) handles in use where it appears.

Source: https://docs.swift.org/swift-book/ReferenceManual/Expressions.html

Screenshot-2020-09-15-at-6.14.20-PM-768x590

Buildtime Swift Compiler Warnings

Screenshot-2020-09-15-at-6.40.20-PM-768x461

In the above screenshot, you can see the build time warning that can be resolved by adding @discardableResult in the function or you can treat as a warning too. (see below screenshot)

Screenshot-2020-09-15-at-8.22.24-PM-1-768x461

Runtime Swift Compiler Issues

Xcode Runtime Issues are reports of programming errors found at run time. Issues can be found by a variety of tools, including Address Sanitizer (ASan), Main Thread Checker (MTC), Thread Sanitizer (TSan), and Undefined Behavior Sanitizer (UBSan).

Source: Apple Doc

Screenshot-2020-09-15-at-9.06.29-PM-768x461

Debugging In Xcode With LLDB

Now we can see how the current thread’s call stack looks when we forced a crash. (see screenshot)

Screenshot-2020-09-16-at-1.48.54-PM-768x453

We can also check the stop-reason by running the “thread info” command in the debug area.

Screenshot-2020-09-16-at-1.55.04-PM-768x322

During a debugging session, we can check the call stack in the debug area too by running the command “bt“(backtrace). For more debugger commands type “help” in the debug area.

Screenshot-2020-09-16-at-1.58.19-PM-768x460

This post is licensed under CC BY 4.0 by the author.