Display the value of a variable property in LLDB debugger? - xcode

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]}

Related

Ruby: usage of ? in if condition

In Ruby, what is the difference of using "?" inside if condition?
if object.property
or
if object.property?
I found the usage of both of them in a method, without understanding the difference
Thanks a lot
? can be part of the function name. It is not a special operator if it comes at the end of a method name. Also ! can be part of the method name too. So what that line is doing is calling both object.property and object.property? methods.
What are the restrictions for method names in Ruby?
In Ruby, foo.bar is the syntax for a message send. It will first evaluate the expression foo (which is either dereferencing a local variable or a receiverless message send to the implicit receiver self) and then send the message bar to the resulting object.
Once you know what message send in Ruby looks like, it is easy to see what object.property? does: It will first evaluate the expression object (which is either dereferencing a local variable or a receiverless message send to the implicit receiver self) and then send the message property? to the resulting object.
So, what is the difference between the two? Well, the first one sends the message property and the second one sends the message property?. This is no different than if the first one had been object.foo and the second one had been object.bar.
Method names ending in ? are typically used for predicate methods, i.e. for methods that ask a "Yes/No" question. A good example is Numeric#zero?.

Swift debugging generic type variables

I'm trying out generics in swift an came across something unusual while debugging:
instead of printing out the value assigned to the variable, it just prints something different. Heres the example code:
class GenericExample<T: Comparable>{
var someVar: T
init(myVar: T){
someVar = myVar
}
}
let generics = GenericExample<Int>(myVar: 57)
print(generics.someVar)
the result is fine(57) but when running the program for debugging, as in with breakpoints, the value is presented as something like 4301684792
any tips would be appreciated
Don't examine, in the debugger, the value of a variable whose value is not assigned until the line you're breakpointed in or later. That line has not been executed yet, so you will see a random value! (Namely, whatever happens to be sitting in memory at that address.)
Only examine earlier variable values! And don't even look at the little tooltips that pop up. Look only at the variables pane and the lldb console.

How to trigger a break when an Array is empty?

In my app, I have a problème when I try to reach an index in an Array, the Array is actually empty. I cannot find what is emptying it so I was wondering if it's possible with the debugger to create a dynamic breakpoint that will pop up when my array is empty. So as soon as something is either resetting the array or taking away its last object, I'd like to know.
I tried to create a symbolic breakpoint with "myArray.isEmpty == true" as the condition but it doesn't look to work the way I want.
Is it possible or I'm just dreaming?
Thanks
As #kendall mentions, you could use didSet to detect when the array is being emptied, and put a breakpoint on it:
// a acts like a normal variable
var a: [Int] = [] {
// but whenever it’s updated, the following runs:
didSet {
if a.isEmpty {
// put a breakpoint on the next line:
println("Array is empty")
}
}
}
a.append(1)
a.append(2)
println(a.removeLast())
// will print “Array is empty” before the value is printed:
println(a.removeLast())
What you want is called a Watchpoint, which lets you monitor changes in memory. I'm not sure yet how to set one on a Swift Array, but that could be a good starting point for research.
One idea would be to add a didSet{} block to the property that holds the array, adding a log statement within - break on that based on your condition that the array is empty.
To the best of my knowledge this isn't possible with Swift and Xcode (or with any other language of IDE I have used). To make this work the IDE would have to continually evaluate the given expression at every step of programs execution.
Now, if arrays were classes, you could subclass and add a breakpoint in an override isEmpty method, but as they are classed you cannot. :-(

DIA SDK how to get parent function of FuncDebugStart / FuncDebugEnd?

The documentation for SymTagFuncDebugStart and SymTagFuncDebugEnd state that calling IDiaSymbol::get_lexicalParent will return a symbol for the enclosing function. I interpret this as I will get an IDiaSymbol whose get_symTag method returns SymTagFunction. However, when I do this it returns me the SymTagCompiland and not the function. So the documentation appears wrong, but worse I'm not sure how to actually tie the SymTagFuncDebugStart and SymTagFuncDebugEnd to the containing SymTagFunction.
Does anyone know? A few dumps suggest that SymTagFuncDebugStart and SymTagFuncDebugEnd always come immediately after the corresponding SymTagFunction when enumerating the symbols via IEnumSymbols. Or put another way, that if IDiaSymbol::get_symIndexId returns n for the function, it will return n+1 and n+2 respectively for the func debug start and func debug end.
But I can't be sure this is always true, and this seems unreliable and hackish.
Does anyone have any suggestions on the correct way to do this?
Could you paste your code here? I guess there is something wrong in your code. Call get_lexicalParent on SymTagFuncDebugStart and SymTagFuncDebugEnd should return the symbol associated the enclosing function (SymTagFunction).
I got this working eventually. The problem is that when you enumerate all the symbols in the global scope using SymTagNull, you will find the FuncDebugStart and FuncDebugEnd symbols. The lexical parent of these symbols is the global scope, because it's the "parent" in the sense that it vended you the pointers to the FuncDebugStart and FuncDebugEnd symbols.
If you get the FuncDebugStart and FuncDebugEnd by calling findChildren on an actual SymTagFunction symbol, however, then its lexical parent will in fact be the original function. So this was an issue of unclear documentation.

"Expression Too Complex" error on simple property assignment

I'm getting (fairly reguarly) an "Error 16: Expression too complex" runtime error on a simple assigment to a property from a class.
public property PropertyName() as double
PropertyName = mvarPropertyName
end property
The debug window points to the crash being on the assignment line in the above code.
Some inital reading here and elsewhere suggested that it was related to the line calling the property. However, that now looks like this:
variableName = ObjectName.PropertyName
And all arithmetic is done with variableName.
Even more oddly, if I just hit debug, then resume/F5 immediatley, everything is fine.
Trying to use the error handling code to do this doesn't seem to have worked however.
Any ideas what is causing this error?
Stop using Not (Not MyArray) to test for uninitialized arrays. This uses a bug in the compiler that has a known side effect of destabilizing the run-time leading to "Expression too complex" on random places.
VB6 - Returning/Detecting Empty Arrays is fairly complete thread on different ways to test for empty and uninitialized arrays.
A string expression is too complicated. Strings not assigned to variables (such as those returned by functions) are assigned to temporary locations during string expression evaluation. Having a large number of these strings can cause this error. Try assigning these strings to variables and use the variables in the expression instead.

Resources