Get pointer to self in LLDB? - conditional-statements

I want to create a breakpoint in xCode which uses LLDB and checks the current object class in condition section.
The problem is LLDB doesn't allow to use self to get a class. How to solve this problem? Maybe through other commands? For example, bt command output contains correct classname but it seems it is not allowed in LLDB too.

I presume this is related to:
Using of symbolic breakpoints for child classes in Xcode?
The problem comes if your breakpoint is in code with no debug information (like in system libraries.) The debugger knows nothing about self in this context, and you have to give it more help. In the case of self, you know that it was passed into a method call as the first argument, so you can use $arg1 to get at the value.

Related

Can I override a method's return value in a breakpoint?

- (BOOL)mySetting
{
return [myObject returnYes];
}
For a method such as the above, is it possible to add a breakpoint with a debugger command so that the -mySetting method automatically returns a different value (such as NO) when the breakpoint is enabled?
I'm looking for an option where the debugger doesn't have to interrupt execution of the app, (a.k.a. has "Automatically continue after evaluating actions" turned on).
While zylenv's answer will work, it'll require you to create a temporary variable and recompile/launch.
The proper way to do this would be to use lldb's thread return command. It is used like this:
A good blog post explaining its usage (and a bunch of other cool LLDB stuff) is here.
You can use lldb debugger to change the return value of the method.
Just did like below.

Cannot inspect Self in method while debugging

I have a method on one of my ViewController's that is called by one of its view's and delivered some value. It then sends out a message to a manager object with some information about the VC's state.
- (void)elementXChangedWithValue:(float)value {
ParameterManager * pMan = [ParameterManager sharedInstance];
[pMan updateParameter:self.elementX.parameter value:value];
}
In debugging, it was important for me to inspect what the .SomeElement.parameter state was so I could know what was getting lost in translation by the time I get to my ParameterManager.
Unfortunately, although Self is definitely non-nil and accessible the debugger shows scant information about the class making quick and practical glancing of the value difficult. (i will sometimes invoke "po" command in the debugger command line, however).
Not sure if it helps but this project is running heavy with the Objective-C/Swift interoperability although the ViewController is a fully Objective-C class.
Here is an image of what I am getting in the debugger. The drop-down arrow shows nothing but empty.
The debugger isn't perfect and sometimes you just cant see what is in certain areas, such as self. What does always work is NSLog's placed in code though, so if all else fails, add one of those in at the right place to print out the object you wish to know about.
The debugger may show more info after you make it execute these commands:
expr #import UIKit;
expr #import Foundation;
This loads the whole UIKit and Foundation symbols in the debugger at runtime, you only need to execute it once per debug session.
You can automate this with a user-defined breakpoint that'll be triggered every time your application starts in the debugger.
Source : http://furbo.org/2015/05/11/an-import-ant-change-in-xcode/

Why is the value of variable different when using CCLog and using print in debug mode?

The strengthbar in my game doesn't work well after playing at least once of the level. So I wrote a method using CCLog to log out some variables and call this method in update: method. And I also set a breakpoint, when this problem appears it gets into debug mode of Xcode, then I use print to check the variables. However it appears that the values are different between using CCLog and using print command. Here's a screenshot that explains everything.
Here is my screenshot:
Does it have something to do with Multithreads(which I know nothing about)? I've checked the declaration of each logged variables, to make sure they're not declared several times using the same name.
OK, problem is solved.
When I wrote some delegate I used "Strong" which causes some retain cycles. Now I changed them all to Weak, and also changed the deployment settings to iOS 5 (or above).
The reason that the values of the variable are different is because in CCLog, the value belongs to the new scene, however there're more than one scene at the same time receiving my touches because of the retain cycles. Nothing wrong about XCode or Cocos2d, or CCBReader :-p
Hope this answer would help others. And many thanks to #Cy-4AH.
Because it was changed after it was printed. In the breakpoint you are lookng at new value.

Compiler warning "may not respond to"

I'm a rank newbie, so please excuse me.
I'm working with a barcode reader sample program from zbar. I wanted to add a sqlite3 daabase for looking up barcodes scanned. The but when I try to instance the sql control from the ViewController I get the following error.
MySQL *MS =[[MySQL alloc ] init];
[ MS viewDidLoad];
^^ MySQL may not respond to viewDidLoad
Any ideas? Thanks
PS The program crashes once it hits the offending line.
"May not respond to" means that your object may not implement the method you want to call. Your program crashes because it's essentially calling a method that does not exist.
I'm not quite sure what you're trying to do, but I don't think an object "MySQL" would have a viewDidLoad method.
There are two possible causes of “may not respond to”. Either:
You forgot to inclue a header file import for the appropriate class.
The method doesn't exist on the class you're calling it on.
Number 2 looks far more likely in your case.

xCode: Accessing properties of an object via console

Is it possible to access the properties of objects in xCode console?
If I try the following I get an error that he property doesn't exist.
po someObject.someprop
If I don't breakpoint the code and run the app it works fine so I know someObject.someprop exists. I don't think I have the grasp on xCode console yet? What I loved about Flex/Flash development is that I could set a break point and in the console window or variables view I could traverse every structure down to the ends of the earth.
I could see SomeDicionary[key].someArray[1].someObject.prop and it would show me the value. Is this not possible in xCode console or is there a trick to get to it?
You'll actually have to use the bracket syntax notation:
po [someObject someprop]
The debugger is sometimes very finnicky about syntax. This is filled with all sorts of helpful tips for debugging in XCode.
Just a side note, variables/properties declared in the implementation file (*.m) instead of the header file (*.h) can sometimes be invisible to the debugger variable list display depending on if the breakpoint is in that class's code, because of scope. Not necessarily required here, but useful to know seeing as how it is kind of relevant.