Xcode debug variable and LLDB po dump are inconsistent - ios

I ran into a situation that Xcode shows different result of one object from the result of po command in LLDB. firstly, all values in the object is nil and the object is displayed with *const type modifier, which it shouldn't be. and when I use po to get datasource variable it shows correct data. However, it shows datasource is nil in Xcode variable list.( please see following screenshot) Can anyone explain why?

This seems like the sort of thing you should file a bug with Apple about. Probably take more back and forth to figure out what is going on than can be easily done in this context.

Related

When I call objective-c functions from Swift, NSLog in those functions do nothing

I have a mixed Swift and Objective-C project (one view controller is in objective C). When I try to print some debug output from that view controller (ie in the .m file using NSLog) I do not see any output.
My swift prints are just fine.
I made a new objective-c project and did some NSLogging, that works fine.
I added this code to my appdelegate (swift), just to immediately test:
NSLog("Testing 1 2 3")
print("Is this thing on?")
and I also do not see the NSLog output, but I do see output from the print statement.
What madness is this?
It seems like the property "OS_ACTIVITY_MODE": "disable" PREVENTS NSlog from showing up in the Xcode 9 log.
Uncheck this value in my scheme restored my logs.
Check this stack overflow post - iOS 10 doesn't print NSLogs
The solution teja_D proposes works, but then there's a lot of garbage in the logs.
Myself, I am just going to use printf. Either that or reach back across the obj-c / swift barrier and make a swift object call 'print' for me.
This kind of thing really makes me shake my head.

How to access 'self' in Console in Xcode 7.3

I am not able to get dictionary/array value in console while debugging.
It always show message while po dictionary/array like
error: warning: Stopped in a context claiming to capture an Objective-C object pointer, but 'self' isn't available; pretending we
are in a generic context
Check the screenshot here
You can check the values of properties and variables using po [self variablename] in console window. This way you can easily access the variables.
Also you can check with other projects weather the problem is with xcode or in your project configurations.
You can also expand the collapsed value in debug area. if it's expanding then you can access values by simply using po variablename otherwise you need to use po [self variablename].
I'd the same issue and found out this solution. Changing this clang module debugging DEBUG to NO and RELEASE to YES will solve your issue.
Checkout this link below.
Accessing Self in LLDB
Please refer the following screen shot where i have printed the value of an array
This is a debugger bug (Yeah, imagine that!)
Simply restart XCode, and it shouldn't be a problem for you anymore :)
EDIT:
Psyche! I was thinking of something else.
You're creating a retain cycle, and as of now, the debugger classifies this specific retain cycle this way (As I said, a bug).
To fix this, create a weak copy of self:
__weak __typeof(self)weakSelf = self;
Then for the self that's giving you trouble:
Change self.object to weakSelf.object
Source: "self" not available in debugger on iOS 5.1

Easiest way to debug objective-c classes in xcode?

I finished writing a class' .h and .m files in objective c in XCode and want to see if all the class functions are implemented correctly. I have not set up anything in the storyboard file yet but would like to test and debug the code. I'm looking to simply declare an object of the class type and to run some of the functions on it similar to using the command line with Python.
If there's no way to simply debug code using command line commands, what would be the easiest way to set up the storyboard?
You can use the XCTest to test your classes.
You can find all the information you need in the Apple documentation is actually pretty easy to use.
https://developer.apple.com/Library/ios/documentation/DeveloperTools/Conceptual/testing_with_xcode/testing_2_testing_basics/testing_2_testing_basics.html#//apple_ref/doc/uid/TP40014132-CH3-SW1
If you want you can check this tutorial as well.
http://rshankar.com/test-driven-development-in-ios-beginners-tutorial-part-1/
If you want you can set break points as well and check that your code is executing properly. Sometimes when I just want to proof-test small classes I do it just setting a couple of break points instead of the XCTest classes but it all depends on your study case. If you have a decent amount of classes I would suggest to use XCTest to check that the classes are actually doing what is expected setting your assertions and the other conditions that XCTest offers as a framework.
Another way you can do your testing if applicable is using NSLog to print in console lines or values of interest at each stage of your code execution.
You mentioned the command line. If you set breakpoints you can use po objName to print the value or print varName to check values of objects and primitive variables correspondingly. po stands for print object and print well... There's different options if you feel comfortable using the console just set NSLogs at certain point of your code or set the break points and print the values using po or print commands in the console.
Here you can check the string format specifiers for NSLog which are the same ones used for NSString
https://developer.apple.com/library/ios/documentation/cocoa/conceptual/Strings/Articles/formatSpecifiers.html

Debugging variables dynamically in xCode?

What do I need to do to have variables display their values in XCode?
I don't have it in Auto pane, and it also does not show when I hover over it. Why is that?
I can go Add Expression and sometimes it will display it correctly, and I can also do NSLog and log it, but this seems really ridiculous in the year of 2013.
I am using XCode 4.6. Am I doing something wrong, or this basic functionality just does not exist?
You can use the local variables section in the content pane to view variable values while debugging:
You can use shift + command + Y to toggle the above pane.
For more information regarding debugging in xCode, check out the following link.
In the console use the command 'po' (stands for print object)
e.g. po [self myVariable]
This will give you more information than this semi-useless variable tree in the content pane.
hints:
1) Make sure your build configuration is set to Debug, or you can't debug local variables.
2) Sometimes you need to debug structs and primitives, in this case use 'p' instead of 'po'
3) you can use dot notation (po self.myVariable), but for some data types this doesn't seem to work. I believe it depends on your xcode version

iOS: How to watch NSManagedObject attributes while debugging

As the title said, I want to debug some Core Data bugs. Instead of using NSLog everywhere in the code, is it possible to watch a entity's attributes in XCode 4's watch window? Like the "quick watch" tool in Entity Framework 4.0 of .NET.
Any value that has a named variable assigned to it can be viewed in the debugger. In Xcode 4 it appears in the debugger's left column. If you select the variable, you can use the contextual menu option "Print to console" to have a detailed description printed to the debugger console. This is useful when examining managed objects as they often contain more info than the list of variables can cleanly display.
(See- Xcode 4 Transition Guide:Control Program Execution in the Debug Area and Source Editor, Figure 5-9
In addition, you can issue any of the standard gdb commands from the command line in the debugger console. The most useful of the these commands is po which stands for print object. Say you have an object myObject that has a property aProperty. You could examine it directly by using:
po [myObject valueForKey:#"aProperty"]
If you create NSManagedObject subclasses, you also have the option of overriding the description method which allows you to produce custom descriptions of the object which will show up in print to console and the po command.

Resources