Debugging with Swift & Xcode 6.4? - ios

Why po returns these strange errors? (with Xcode 6.4 & Swift)
I try to debug with p / po:
NSDictionary, String and NSNumber all getting similar kind of errors all the time.
For now, I use println() but I am curious what could be the reason?
error: A fatal parse error has occurred. LLDB may become unstable; please restart your debug session as soon as possible.
error: <EXPR>:1:11: error: use of undeclared type '$__lldb_context'
extension $__lldb_context {
^~~~~~~~~~~~~~~
<EXPR>:11:5: error: use of unresolved identifier '$__lldb_injected_self'
$__lldb_injected_self.$__lldb_wrapped_expr_7(
^

For swift language use println() method.For debugging in console you have to keep in mind that you can only get debug info for swift's variables, but can't get it for swift's constants. So change let someVariable to var someVariable.
then in debugger do po someVarible. It will work.
If it doesn't work for arrays & dictionary ,for arrays do something like po print(myArray). Same goes for dictionary.

Related

XCode : Cannot print object in console when debuging

Without any reason, Xcode show an error when i whan ton print using the debuger console :
(lldb) po self
warning: Swift error in scratch context: error: failed to load module 'XXX'
.
Shared Swift state for XXX.app has developed fatal errors and is being discarded.
REPL definitions and persistent names/types will be lost.
error: expression failed to parse:
unknown error
It's an iOS project with cocoapods. I'm on an M1 pro chip.
Any idea ?
I would start with simply print(self) instruction and check what appears in the console.
I like also debug(self) function (prints the whole object hierarchy).
If you want to print thread, you can use Thread.callStackSymbols.forEach { print($0) }
Have you tried set a breakpoint and then browse the Variable List (left side of the Debug Area)?

Xcode po is not printing output in debugging area

Xcode is not giving expected results when i try to print any object. I am using Xcode 12.4 .. In another mac its working fine.
Ex: When i try to print the text inside the UITextField getting below
error
(lldb) po emailTextField.text
expression produced error: error:
/var/folders/5q/9vj8df5s0xs_2splf1fbwgzh0000gn/T/expr39-7ad9b9..swift:1:51:
error: cannot specialize a non-generic definition
Swift._DebuggerSupport.stringForPrintObject(Swift.UnsafePointer<Swift.Optional<Swift.String>>(bitPattern:
0x10ba5a660)!.pointee)
^
/var/folders/5q/9vj8df5s0xs_2splf1fbwgzh0000gn/T/expr39-7ad9b9..swift:1:64:
note: while parsing this '<' as a type parameter bracket
Swift._DebuggerSupport.stringForPrintObject(Swift.UnsafePointer<Swift.Optional<Swift.String>>(bitPattern:
0x10ba5a660)!.pointee)
^
(lldb)
I have tried all the options given in the App Dev answers and tried changing the xcode, still no luck
Spammers stay and Don't spam with your unrelated answers

Swift unit-testing: Debug info from this module will be unavailable in the debugger

I have Objective-C project and I decided to write unit test in Swift.
Everything runs normally however I cannot see param values during debugging.
When I set cursor on value I see its name and not value:
when I try to print it out in lldb I get following error:
(lldb) po expectedEncryptedStr
warning: Swift error in module AppLibTests.
Debug info from this module will be unavailable in the debugger.
error: in auto-import:
failed to get module 'AppLibTests' from AST context:
I use Version 8.2.1 (8C1002)
Any ideas?
[EDIT]
When I enter with braking point to Objective-C code - everything works as expected

Clunky lldb error while printing variables in XCode's debugger console

Lately I've got problem to print any kind of variable into XCode's debugger console. It doesn't matter which platform I'm building against. I've tried to reinstall whole XCode, command line tools + cleaned/removed the derived data of swift project I'm working on. None of these steps solved my issue, this error prevent me from using XCode for 100%.
Everytime I'm trying to print something I've got this error in debug console.
Printing description of X:
expression produced error: /var/folders/4y/mm1fk7rn5c57ct91syb3ndf40000gn/T/lldb/6651/expr11.swift:1:1:
error: cannot convert value of type 'Int' to expected argument type 'random type'
$__lldb__DumpForDebugger(Swift.UnsafePointer<Swift.Bool>(bitPattern: 0x104c5ced0).memory)
^~~~~~~~~~~~~~~~~~~~~~~~
<EXPR>:18:7: error: cannot convert value of type 'Int' to expected argument type 'random type'
if (1==1) {
where random type can be any type of class/type.
Have anybody came across the same problem lately? Seems like lldb is bit broken when it comes down to print values of swift variables.
I'm using XCode 7.3.1 (7D1014) with latest update of Mac OS X.

lldb inspection of swift variables within dynamic framework

I am unable to inspect variable state within dynamic frameworks in the lldb debugging console. I am able to inspect the same code when I add it to the main application. Why is this? Is there a workaround? Any ideas?
(lldb) po URLSessionDataTask
error: <EXPR>:1:1: error: use of unresolved identifier 'URLSessionDataTask'
URLSessionDataTask
^
I had the same situation. I could create a class instant of anything in the main app but nothing in the dynamic libraries, when it was Swift code.
(lldb) exp let $a = RustyAppInfo() //class from framework
error: <EXPR>:3:10: error: use of unresolved identifier 'RustyAppInfo'
Fix for me:
(lldb) expr -- import rusty_nails //framework name
(lldb) exp let $a = RustyAppInfo()
My lldb version: 902.0.79.7. Notice, lldb knew I was trying to write swift code. In an iOS app, where you have Swift and Objective-C code, I always find it useful to type:
(lldb) settings set target.language swift
Answer was inspired by LLDB (Swift): Casting Raw Address into Usable Type

Resources