Call a block from XCode's debugger - xcode

Can I call a block from the XCode debugger? I just tried:
po zoomCurve(0)
Which has the type:
typedef CGFloat (^STAnimationCurveBlock)(CGFloat t);
And the debugger says:
error: called object type 'STAnimationCurveBlock' (aka '__block_literal_generic *') is not a function or function pointer
error: 1 errors parsing expression

As described in this answer, the debugger doesn't seem to know the type of the block. You need to cast the block to its type. In the specific case you have there:
po ((CGFloat(^)(CGFloat))zoomCurve)(0.9)
For some reason, casting to the typdef type also doesn't work, and gives the same error. Specifically, this will give the same error:
po ((STAnimationCurveBlock)zoomCurve)(0.9)

Related

iterator error/conflict on Android with push_back (FMX, C++) [duplicate]

I have some simple C++ code which won't be compiled by the Clang based C++11 compiler bccaarm of C++ Builder 10.1 Berlin.
This is the code:
TComponent* Comp = new TComponent(this);
std::vector<TComponent*> Comps;
Comps.push_back(Comp);
And this is the error:
[bccaarm error] stl_iterator.h(963): rvalue reference to type
'value_type' (aka 'System: classes::TComponent * __strong') can not be
bound to lvalue of type '__borland_class * isTObj __strong' (aka
'System::Classes::TComponent * __strong')
The compiler stops at line 963 in the file stl_iterator.h:
The other C++ compilers bcc32 and bcc32c(also Clang based) have no problems with this code.
When Compis not from type TComponent or another descendant from TObject the code compiles without any problem.
I have no idea what is wrong with this code and why there is a problem with R and L values...
Does anybody know what to do here?
To get the above code compiled the vector type has to be defined as an unsafe pointer.
TComponent* Comp = new TComponent(this);
std::vector<__unsafe TComponent*> Comps;
Comps.push_back(Comp);
I openened a support case for an other problem I had. The embarcadero support gave me the following information which I applied to this problem and it seems to work:
__unsafe tells the compiler that object lifetimes will be handled and no ARC code is generated for the objects
More about this topic:
http://docwiki.embarcadero.com/RADStudio/Berlin/en/Automatic_Reference_Counting_in_C%2B%2B#weak_and_unsafe_pointers

PasteboardPutItemFlavor Null passed to a callee that requires a non-null argument

I know there are plenty of questions asking about how to solve "Null passed to a callee that requires a non-null argument", but I really can't seem to find a solution for my problem.
I use a function called PasteboardPutItemFlavor in my code. It compiles alright if I set the deploy target to 10.12 built against macSDK10.12. After I set the deploy target to 10.8, but still compile it against macSDK10.12, I got an error on PasteboardPutItemFlavor call. The error message is "Null passed to a callee that requires a non-null argument". What does this error mean? kPasteboardFlavorNoFlags is defined as 0, changing to other constant value doesn't change anything.
How do I solve this error with 10.8 as deploy target and compile against 10.12?
PasteboardPutItemFlavor(
m_pboard,
nullptr,
flavorType,
dataRef,
kPasteboardFlavorNoFlags);
The function declaration is
OSStatus PasteboardPutItemFlavor(PasteboardRef inPasteboard, PasteboardItemID inItem, CFStringRef inFlavorType, CFDataRef inData, PasteboardFlavorFlags inFlags);
I looked into the header file from 10.12 SDK. The header file is warped with nonnull macro. So any pointer with that macro would be declared as nonnull. In my case is the nullptr parameter. I simply create a local variable and set to 0 then pass it in PasteboardPutItemFlavor. That solves the error.

Incompatible integer to pointer conversion assigning to 'BOOL

I just inherent a new app from a previous programmer and keep on running into a "Incompatible integer to pointer conversion assigning to 'BOOL *' (aka 'bool *') from 'BOOL' (aka 'bool') ".
Code like such as
_backButtonPressed = YES;
_isEdited = YES;
come up with the same error. I tried *(_backButtonPressed) = YES; and
*_backButtonPressed = Yes, but both scenarios crashes the program.
Program still work if I leave it alone, but I wanted to keep the code clean. Any suggestion?
My guess is that the two variables in question were declared incorrectly. For example, _backButtonPressed is probably declared as
BOOL* _backButtonPressed;
but should be
BOOL _backButtonPressed;
The crash occurs because _backButtonPress is not a pointer: if it was, there would be a statement like
_backButtonPressed = (BOOL*)malloc(sizeof(BOOL));
somewhere. If this was not done before you try to assign to
*(_backButtonPressed), then you will see a crash.
It is easy to make the mistake of declaring BOOL* instead of BOOL, because Cocoa objects are always declared with the *
I recommend that you fix the declarations. I am pretty sure everything will work if you do that.

how to avoid g++ linker error "undefined reference"

if function definition is not available and only the function prototype is externed in header files, then g++ compiler wont give any errors. but during linking, g++ linker will identify the error and says "undefined reference" to corresponding fn. i don't care abt fn definition. i just want to get the binary image and whenever corresponding fn called from that image, then that time only i want to crash. may i know the linker flags to suppress this "undefined reference" linker error?. In VC++, there is a options called /FORCE. is there any similar flags?
It's completely undefined behaviour, but if you want a crash ...
If you have an undefined symbol such as a function void h() then its mangled name will be _Z1hv, so if you define a symbol that name and external linkage it will be found, even if the type is wrong:
int _Z1hv = 0;
void h();
int main()
{
h();
}
This will link, but crash at run-time because the call to h() will try to "run" a function at the address of the integer variable.
Doing this is wrong and disgusting and kills kittens.

Display the value of a variable property in LLDB debugger?

I'm using a breakpoint with Action "Log Message", and I want to print the row of an NSIndexPath. So I tried: cell row #indexPath.row# but nothing gets printed. I also tried using a debugger command: expr (void)NSLog(#"indexPath row:%i", indexPath.row) but I get an error: error: property 'row' not found on object of type 'NSIndexPath *'
What am I doing wrong?
The dot syntax is just syntactic sugar added by the compiler. I've always disagreed with adding it to Objective-C, but some people love it. What you have to remember is that these dots are getting converted into method calls by the compiler, so when you message something directly, like in the debugger, you must use the actual method call. Try rewriting your expression:
expr (void)NSLog(#"indexPath row: %ld", (long int)[indexPath row])
I'm not sure if the debugger's basic log method will execute method calls like this, so you may have to use the expression type.
I think this is a special case. The code below will work, but only if row is initialised to some value.
(lldb) print (NSInteger)[indexPath row]
I think this might be related to the fact that the row property is an extension of NSIndexPath in UIKit and is implemented as a category on that class.
Try to set this summary format in Xcodes variable view:
section:{(int)[$VAR section]},row:{(int)[$VAR row]}

Resources