Xcode debug inspector shows values as nil - ios

I'm having a very weird problem - as you can see in the picture below, the debug shows that the program entered to the if statement, but the value of color is shown as nil !!!
obviously that's can't be true, and I suspect that the Xcode is showing incorrect values on the inspector \ variable view (at the debug area).
I have no idea - maybe my Xcode had too much vodka?
any HELP please???
updates:
I tried to restart my mac - didn't help.
my Xcode version: 6.4

I've seen the "extracting data from value failed" message (when doing a po foo at the LLDB prompt), even on debug builds . This appears to be an LLDB bug.
A workaround that worked for me was to cast the value to the expected return type (e.g. if it's an NSNumber, po (NSNumber *)foo).

Check your scheme - Run tab on the left should have the Debug executable option checked.
If you are running on AdHoc \ Release mode, the debugger will not show the right values.
Change the "Build Configuration" to "Debug".

Related

nw_host_stats_add_src recv too small, received 24, expected 28

nw_host_stats_add_src recv too small, received 24, expected 28
So I'm getting this appear in the console and I'm not sure whether it is an issue that I should be bothered about or not. I noticed it after attaching my app to Firebase and writing to the database with anonymous sign in. Just wondering whether I need to do anything about this and if so what those actions would be.
Thanks!
This is a bug with logs in Xcode8 + iOS10.
We can get round it in this way:
When on simulator, add the Name OS_ACTIVITY_MODE and the Value
Variables disable and check it (Product -> Scheme -> Edit Scheme -> Run -> Arguments -> Environment).
When on device, only add OS_ACTIVITY_MODE and check it(don't add the Value). You'll see the NSLog in the Xcode8 Console.
Cause: iOS 10 & Xcode 8. Also can be replicated by an odd inputField bug:
Issue belongs to an InputField whom width is smaller than the inputs
chars : 96px vs (4 * 28px)
This leads to a 100% CPU and it is fixed
when width is set to 128px
Link to the above fix and reasoning
Or just silence everything:
Press ⌘<
Edit simulator scheme by adding or setting the OS_ACTIVITY_MODE under Environment Variables in the Run Arguments to a value of disable.
Do the same for the device but remove the value for OS_ACTIVITY_MODE , leaving it empty. The logs will display for the device as they should.
I found this answer in a video on Reddit located here: https://www.reddit.com/r/ios/comments/5p0fvy/xcode_nw_host_stats_add_src_recv_too_small/
This warning comes from XCode and can be disabled by adding an Environmental variable to the Scheme's Run section. The Environmental name is OS_ACTIVITY_MODE and the value is "disable".
This appears to suppress all of the "nw_" warning messages. Note that this just suppresses the warnings. I'm not sure if the warnings are significant or not or whether this indicates that there are "real" underlying problems that should be fixed.
How to edit a Scheme's Run Environmental Variables section in XCode
Adding the OS_ACTIVITY_MODE value of "disable"
I was getting this exact same error message on Xcode-8.2 iOS-10.2, but I was not using Firebase, so I'm not sure if that makes a difference. Setting OS_ACTIVITY_MODE to disable did not solve the problem, however, I realized it was coming from the All Exceptions Breakpoint I had set. I changed it to from All to Objective-C (removing C) and it no longer stops on that line anymore. You can do this by right-clicking on breakpoint in the breakpoints tab on the left, then selecting edit, then making the change.

iOS 10 doesn't print NSLogs

Nothing prints from NSLog on Xcode 8.0 beta (8S128d). printf is unchanged
Here's my code:
NSLog(#"hello from NSLog");
printf("hello from printf");
Here's the output on iOS 9 Simulator:
2016-06-17 09:49:10.887 calmapp-dev[28517:567025] hello from NSLog
hello from printf
Here's the output on iOS 10 Simulator:
hello from printf
It could be that you added the property "OS_ACTIVITY_MODE": "disable" in the Scheme environment variables (to hide OS output from the simulator) and forgot about it, and now are running on a real device.
In Xcode 8:
Product -> Scheme -> Edit Scheme -> Run -> Arguments -> Environment Variables
Only add OS_ACTIVITY_MODE and check it(Don't add a value)
Summary:
This is a bug of Xcode 8 + iOS10, we can solve it in this way:
When using the simulator, add the Name "OS_ACTIVITY_MODE" and the Value "disable" and check it.
When on a real device, only add "OS_ACTIVITY_MODE" and check it(Don't add the Value).
You will see the NSLog in the Xcode8 Console.
If you check the Xcode 8 beta release notes, you'll find that it says:
When debugging an app running on Simulator, logs may not be visible in the console.
Workaround: Use command + / in Simulator.app to open the system log in the Console app to view NSLogs. (26457535)
the NSlog or print actually is executed but is hidden among lots of other console debug outputs to solve this issue
Open Xcode8:
Product -> Scheme -> Edit Scheme -> Run -> Arguments -> Environment Variables
add "OS_ACTIVITY_MODE" and set the Value to "disable" and check it.
click close
xcode9
add "OS_ACTIVITY_MODE" and set the Value to "default" and check it.
Also, make sure the Console is actually visible in Xcode (i.e., make sure the right-hand side icon is highlighted in blue, as per the image below). After I upgraded Xcode, it hide the Console and showed me just the Variables view. This made it look like NSLog() was not working properly, whereas it was indeed working correct, I just couldn't see the output.
I can't see NSLog output in real iOS 10 device neither. If you're using real devices, you can open Devices window from Xcode (Shift + Command + 2) and see device logs there, but it's hard to look at your app's logs because the console shows logs from system and all apps.
(I'm using Xcode 7, so it's may not Xcode's problem but iOS 10 problem)
For anyone who comes upon this in the future. The reason NSLog doesn't print to syslog in iOS 10 and iOS 11 is due to Apple changing to Unified Logging.
You can see the WWDC talk about it here: https://developer.apple.com/videos/play/wwdc2016/721/
Documentation here: https://developer.apple.com/documentation/os/logging
From 10 on you should be using os_log instead of NSLog.
How to find the logs on disk: https://www.blackbagtech.com/blog/2017/09/22/accessing-unified-logs-image/
To summarize, the logs are located in /var/db/diagnostics which can be found for a VM at /Users/USERNAME/Library/Developer/CoreSimulator/Devices/SIMULATOR-GUID/data/var/db/
Copy all items inside diagnostics and uuidtext into a single folder (don't include the folders diagnostics or uuidtext just what is inside).
Rename that folder foldername.xarchive.
Open it in Console.app or use the OSX util log: log show <path to archive> --info --predicate <options>
Hmmm... it seems like the property "OS_ACTIVITY_MODE": "disable" PREVENTS NSlog from showing up in the Xcode 9 log.
Unchecking this value in my scheme restored my logs.
I'm using Xcode 8,so I also encountered the same problem . And I solved this problem by adding value = disable on the simulator, but on a real machine I don't add value.
NSLog messages no longer displayed when I upgraded to Xcode 9.1 + iOS 11.1. Initially the accepted answer gave me a way to work around this using the Console app and enabling the Simulator (see Lucas' answer).
In the Console app under Action I tried selecting Include Debug Messages and deselecting Include Info Messages (so the Console isn't swamped with system messages). NSLog messages appeared in the Console window in Xcode but not in the Console app.
I realised there had to be a more direct way to disable or enable (i.e. default) NSLogs thanks to Coeur's comment in response to this answer. In my opinion it is the best answer because setting OS_ACTIVITY_MODE to disable or default will make more sense for beginners.

NSLog not showing in handleWatchKitExtensionRequest, but breakpoints works [duplicate]

I'm just getting started with Apple Watch. I found instructions from "Five Minute Watchkit", on getting the iOS app and the watch kit app both running in the simulator and both processes attached to the LLDB debugger.
What I do is launch and quit the iOS app to install a current version in the sim. Then I switch to the watchKit scheme and launch that, which displays my watch app UI on the watch simulator.
I then launch the corresponding iOS app in the simulator, then user "attach to process" in the Xcode menu to attach the debugger to the running iOS app.
This works. I can set breakpoints in either the watch kit InterfaceController or in my iOS app and the debugger breaks there when it should.
However, I'm not seeing NSLog() statements in the debug console from my iOS app. (I do see log statements from the WatchKit extension code.) If I set a breakpoint in my iOS app, it does stop at that breakpoint when it should. I assume the lack of console output from NSLog has SOMETHING to do with attaching to a running process on the sim rather than launching it from Xcode, but I don't know what that something is.
(BTW, attaching an action to a breakpoint that invokes NSLog from the breakpoint also doesn't display, but the "log message" debugger command DOES display.
Does anybody have any insights?)
EDIT:
The code in the iOS app doesn't seem to matter. In my case, it was a dirt simple IBAction that was attached to a button in the iOS app storyboard:
- (IBAction)buttonAction:(UIButton *)sender;
{
NSLog(#"Button clicked on iPhone");
}
I can set a breakpoint on that NSLog statement. The debugger stops at that line, but I don't see the log statement in the debug console.
I can reproduce that with a simple test app, sans WatchKit. The app consists of a NSTimer that prints "Timer fired" every second. (This code is 100% correct ;). Nothing shows in the log after I have manually attached to the process.
As far as I know NSLog outputs to stderr, I guess attaching the debugger does not redirect stderr to the Xcode terminal.
If you are okay with using the console app or the terminal to look at your logs you can do that. iOS8 stores simulator logs in ~/Library/Logs/CoreSimulator/<Device-UUID>. In this directory you will find a system.log, which contains all your NSLog output.
You can look at it in terminal (cat, grep, tail), or open it in the Console.app.
Apple confirms that (at least for GDB) in Technical Note TN2239: iOS Debugging Magic.
Console Output
Many programs, and indeed many system frameworks, print debugging
messages to stderr. The destination for this output is ultimately
controlled by the program: it can redirect stderr to whatever
destination it chooses. However, in most cases a program does not
redirect stderr, so the output goes to the default destination
inherited by the program from its launch environment. This is
typically one of the following:
If you launch a GUI application as it would be launched by a normal
user, the system redirects any messages printed on stderr to the
system log. You can view these messages using the techniques described
earlier.
If you run a program from within Xcode, you can see its
stderr output in Xcode's debugger Console window (choose the Console
menu item from the Run menu to see this window).
Attaching to a
running program (using Xcode's Attach to Process menu, or the attach
command in GDB) does not automatically connect the program's stderr to
your GDB window. You can do this from within GDB using the trick
described in the "Seeing stdout and stderr After Attaching" section of
Technical Note TN2030, 'GDB for MacsBug Veterans'.
The mentioned TN2030 is no longer available on their server (mirror). It showed how you can redirect stdout and stderr to the Xcode console. However, since shell tty isn't a valid command for LLDB it won't help much. But maybe there is a different way to access the tty Xcodes console uses, so I attach the important part of that TN.
Seeing stdout and stderr After Attaching
If you attach GDB to a process (as opposed to starting the process
from within GDB), you won't be able to see anything that the process
prints to stdout or stderr. Programs launched by the Finder typically
have stdout and stderr connected to "/dev/console", so the information
they print goes to the console. You can view this by launching the
Console application (in the Utilities folder), however, it's
inconvenient to have to look in a separate window. Another alternative
is to connect the process's stdout or stderr to the terminal device
for GDB's Terminal window. Listing 9 shows how to do this.
Listing 9. Connecting stdout and stderr to GDB's terminal device.
(gdb) attach 795
[... output omitted ...]
(gdb) call (void) DebugPrintMenuList()
No output )-:
Close the stdout and stderr file descriptors.
(gdb) call (void) close(1)
(gdb) call (void) close(2)
Determine the name of the terminal device for GDB itself.
(gdb) shell tty
/dev/ttyp1
Reopen stdout and stderr, but connected to GDB's terminal.
The function results should be 1 and 2; if not, something
is horribly wrong.
(gdb) call (int) open("/dev/ttyp1", 2, 0)
$1 = 1
(gdb) call (int) open("/dev/ttyp1", 2, 0)
$2 = 2
Try the DebugPrintMenuList again.
(gdb) call (void) DebugPrintMenuList()
Yay output!
Index MenuRef ID Title
----- ---------- ---- -----
<regular menus>
00001 0x767725D3 -21629 Ed
00002 0x76772627 1128 <Apple>
00003 0x767726CF 1129 File
00004 0x76772567 1130 Edit
[... remaining output omitted ...]
To add onto Filipp Keks answer, here's a visual representation of a much much simpler way to do it than the accepted answer.
From Filipp Keks's answer:
Plug in the device and open Xcode
Choose Window -> Devices from the menu bar
Under the DEVICES section in the left column, choose the device
To see the device console, click the up-triangle at the bottom left of the right hand panel
Click the down arrow on the bottom right to save the console as a file"
This screenshot was taken in Xcode 7.3.1 of the Devices window.
With Xcode Version 7.2 and iOS 9.2 etc, I found the following works:
Kill both the phone app and watch apps
Select the Watch Extension Target and hit Cmd+R (build and run)
Select the Phone target and hit Ctrl+Cmd+R (Run without building)
In my case, I have both apps up in their simulators and get NSLog output for both. I don't need to attach separately. Hope this helps.
https://developer.apple.com/library/ios/qa/qa1747/_index.html
Plug in the device and open Xcode
Choose Window -> Devices from the menu bar
Under the DEVICES section in the left column, choose the device
To see the device console, click the up-triangle at the bottom left of the right hand panel
Click the down arrow on the bottom right to save the console as a file
When your Provisioning profile is set to AdHoc or Distribution then Xcode doesnot show log, you need set development to view log
This might not solve showing up NSLog messages, but it might be helpful when debugging app started in background.
You can use the breakpoint feature that allows you to log messages.
The idea is to:
Create a breakpoint with "Automatically continue after evaluating actions" checked
add "Log message" action (you can also use expressions and print out values, for example: "Log message #variable#")
Attach debugger using anticipated process name (XCode will wait for the process to start)
Trigger app start.
Credits and details:
https://fluffy.es/how-to-debug-app-which-got-launched-push-notification/
In my case a set Automatically to see NSLog, before don't show at all
I came to this question, via this one (Xcode console empty after attaching to process) which is now closed.
My issue is that the debug console in Xcode is showing nothing (just an empty white box).
The solution for me is a tiny toggle at the bottom which changes between "variable view" and the actual debug console.

Xcode - My app crash and the error is "Invalid pointer dequeued from free list *** set a breakpoint in malloc_error_break to debug"

My app runs perfect on simulator.
But when I run it on device the app crash and display error :
"malloc: * error for object 0x17415d0c0: Invalid pointer dequeued
from free list
* set a breakpoint in malloc_error_break to debug";
I searched and set a breakpoint in malloc_error_break to debug, but still cannot find the problem. I tried to changed the scheme of project, enabled Zombie Object, but can not find the answer.
I also try to use instrument, but I am not good at it.
I've fixed this error with Xcode 8 on iOS 8.3.
I've just changed Deployment Target from 8.3 to 8.0.
If the error appears now after migration to Xcode 8 and your device works under control iOS 8 it may be temporary decision.
UPD: Xcode 8.1 beta is fixed this error.
Just fixed this same issue with Xcode 8.
Preparing an iOS10 compatible build, updated to recommended Swift Migration 2.3, runs perfectly on iOS9 and iOS10 but crashes on iOS8.4. I reverted the changes in the code and the Main.storyboard and built the same content on the iOS8 with Xcode 7.3 fixed my issues.
I met this strange error too, I google it and people said it is Swift's bug, hasn't been fixed.
I debug line by line, find out the solution.
The reason this error appears
In EditRecordVC I have generic type function func update<RO>(operation: RO) where RO : RealmOperation, RO.R == EditRecordVC.R
In its subclass ConflictedRecordEditVC, I override the function, I input update, and Xcode helps me finishing the whole function override func update<RO>(record: Record?, operation: RO?) where RO : RealmOperation, RO.R == Record, compile well.
Run the code, after the overridden function is executed, this error will appear, the Xcode will stop at some random line, nobody can find out it is caused by this function.
I debug line by line, find out I have to change the generic type to override func update<RO>(operation: RO) where RO : RealmOperation, RO.R == Record, everything will work well again.
I forget when I added the ? by mistake and Xcode isn't angry.
So check you generic type function and make sure it is exactly same with super class

Unable to set a watchpoint in either gdb or lldb

I am trying to set a watchpoint while debugging my app on the device. I am unable to set it on either gdb or lldb.
On lldb, I don't see the watchpoint set option in the debugger even though this page mentioned that it exists. When I try to run watchpoint set, lldb tells me that the command is not valid.
On gdb, I do get to set the watchpoint (using watch var), but when I try to continue execution I get this:
Can't set hardware watchpoints without the 'Z2' (write-watchpoint) packet.
I see no further output in the gdb window nor do I think I can interact with it. The app also remains hung at this point.
I am using Xcode 4.3.2 (4E2002) on OS X Lion. I tried setting the watchpoint on devices with iOS 5.1 and iOS 5.0.1 but encounter the same problem on both.
Before Xcode 4.5, watchpoints were not supported for iOS development with either lldb or gdb.
With Xcode 4.5, they are supported for iOS and Mac OS X debugging with lldb.
In Xcode, in the locals window, you can right-click/control-click on a variable and there will be an option to set a watchpoint on it. From the debugger console, to add a watchpoint on a variable called foo, you can do
(lldb) watchpoint set variable foo
the shortest unambiguous command is always valid in lldb so this would do the same thing,
(lldb) w s v foo
The current x86 and arm cpus only support 4 watchpoints being set simultaneously.
I read this somewhere in the Apple Dev Forums :
"The set command exists in the trunk version but not in the Xcode version yet."
I am also stuck with this problem where I want to keep a watch on a variable and see where its value changes...

Resources