Xcode debugger not printing variables in some files - ios

I have an issue with the Xcode debugger. Everything works fine in general, I can print variables using po <var> normally... Except in some files, where I can't print anything, and I have a error: Couldn't apply expression side effects : couldn't get the data for variable self
error in the console.
Weirdly, Xcode shows values correctly on the left debugger panel.
Does anyone have an idea?
Thanks!

Similar observations, all good on the left panel but printing ends with the same message. Quick improvement was to use:
po print(variable)
or
po debugPrint(variable)
Result - prints variable and appends the same error message.

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 Console "po" error: expression failed to parse

My Xcode cannot po anything suddenly, such as:
po param
error: expression failed to parse:
error: Couldn't realize type of self.
Everytime I use "po" to print something in console, it will show the errors above. It happens one month ago.
I know this does not fix the problem, but meanwhile you can use v param to achieve the expected result.
https://stackoverflow.com/a/60064468/2347811
well, you could click right button and choose "print..." at console.

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

Unable to set a symbolic breakpoint to some Classes

I had to investigate when a certain cookie was being set but unfortunately, I couldn't figure it out just seeking in the codebase. So as usual, when the game gets tough, I go and set a symbolic breakpoint. This time, against all odds, I wasn't able to.
In particular, I have been trying to set a symbolic breakpoint to the NSHTTPCookieStorage method setCookie: and neither from the Breakpoint navigator nor from the debug console I couldn't manage to set it.
For example:
(lldb) br set -F '-[NSHTTPCookieStorage setCookie:]'
Breakpoint 6: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
I have also tried to set the Module (Foundation) but nothing changed. The same happened also for the NSURLSession method downloadTaskWithResumeData:completionHandler: Then I tried with some other Foundation's classes and it always worked, except for all of those who are part of this group inside the Apple Documentation as NSHTTPCookieStorage and NSURLSession.
I thought it could be related to some security concerns but I also remember I applied a symbolic breakpoint to some Keychain and SecKey's symbols.
Did anyone else experience the same? I haven't found any doc where something similar was mentioned.
I do get a resolved bp in my case with the same:
br set -F '-[NSHTTPCookieStorage setCookie:]'
command (side note b '-[NSHTTPCookieStorage setCookie:]' would work to).
It seems in your case lldb has not loaded CFNetwork for whatever reason.
Mine
image lookup -vn '-[NSHTTPCookieStorage setCookie:]'
yields
1 match found in /Users/myusername/Library/Developer/Xcode/iOS DeviceSupport/12.4.1 (16G102)/Symbols/System/Library/Frameworks/CFNetwork.framework/CFNetwork:
Address: CFNetwork[0x0000000181478fbc] (CFNetwork.__TEXT.__text + 51832)
Summary: CFNetwork`-[NSHTTPCookieStorage setCookie:]
Module: file = "/Users/myusername/Library/Developer/Xcode/iOS DeviceSupport/12.4.1 (16G102)/Symbols/System/Library/Frameworks/CFNetwork.framework/CFNetwork", arch = "arm64"
Symbol: id = {0x00000af7}, range = [0x00000001b6628fbc-0x00000001b6629020), name="-[NSHTTPCookieStorage setCookie:]"
If you're on real device try
image add '/Users/myusername/Library/Developer/Xcode/iOS DeviceSupport/12.4.1 (16G102)/Symbols/System/Library/Frameworks/CFNetwork.framework/CFNetwork'
(obviously path substitute for appropriate iOS version^)
If you're on simulator try
image add '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CFNetwork.framework/CFNetwork'
If you don't get an error then try setting your symbolic breakpoint at that point.

Stanford calculator app crashes with error "unexpectedly found nil"

I'm new to programming and I've started taking the stanford course on iTunes U for making an iPhone 8 app. They're using Xcode 6 and Swift 1 while I'm in El Capitan using Xcode 7 and Swift 2. I've found a few differences in code that Xcode has been able to pick up on and help me correct ("println" is now "print" for example), but I'm getting tripped up on one particular part of the code:
var displayValue: Double {
get {
return NSNumberFormatter().numberFromString(display.text!)!.doubleValue
}
set {
display.text = "\(newValue)"
userIsInTheMiddleOfTypingANumber = false
}
}
I've double checked several times to make sure this is exactly how the teacher wrote it. His built correctly and functioned correctly, while mine builds correctly, but shows this fatal error when I try to operate it, "unexpectedly found nil while unwrapping an Optional value" (see screenshot for all the details).
Screenshot of the error
I've been looking around the internet and found a few similar examples, including one on this site (Stanford Calculator app keeps crashing), but after trying everything that was suggested I concluded that something must be unique in my system or I'm operating in a new Xcode/Swift environment than the others that had this problem. None of the solutions have resolved the problem, and all of them added errors of their own.
In responding to someone else's question someone suggested that we use this code to ensure that if "nil" is returned by "display" that it will provide "0" instead:
return (NSNumberFormatter().numberFromString(display.text) as? Double) ?? 0
I tried this, but it only gave me more errors, some seem to be related to Swift 2 (it required a comma after double, wanted me to unwrap display.text, and complained that there was an expected expression missing—maybe the suggested code was good in Swift 1??).
I've double checked several times to make sure this is exactly how the teacher wrote it. His built correctly and functioned correctly, while mine builds correctly, but shows this fatal error when I try to operate it, "unexpectedly found nil while unwrapping an Optional value"
I suspect that display is an IBOutlet property that needs to be connected to something in the user interface, probably a text field. If it's not connected, then even though your code is exactly the same, you'll get nil when you try to use its text property, and unwrapping that will cause the error you're seeing.
Whether or not the advice above actually solves your problem, what you really need to do is to set a breakpoint a line or two before the spot where the crash occurs and step through the code. Look at the variables involved and figure out where that nil value is coming from. You can work backward from there and figure out why the thing that you expect not to be nil is, in fact, nil. Learning to work that way will help you work out these kinds of problems when they occur (and they will occur again).
Not sure if you've found the answer or not by now, but I ran into a similar problem this morning and thought I'd share what I found.
While debugging, I entered two console logs to a simplified version of my operate like so:
case "x": if operandStack.count >= 2 {
print(" display before popping is: \(display.text!) ")
displayValue = operandStack.removeLast() * operandStack.removeLast()
print(" display after popping is: \(display.text!) ")
enter()
}
Display after popping came up as "newValue". I couldn't figure out what that meant at first, but realized that my issue is the setter. newValue is an optional that should be unwrapped i.e. "(newValue)!"
P.S. I opted to return:
return (display.text! as NSString).doubleValue
in my get.
Also, since newValue is unwrapped, keep in mind it will crash if display is set to nil.

Resources