Obj-C keeping memory addresses the same on next debug
I'm not sure if there is a name for this technique, but I remember doing something like this a long time 开发者_StackOverflow中文版ago in C++. I would like to breakpoint and observe a specific object of which there are hundreds in my program. It would be nice if you can tell the compiler to use a reserved space of memory so that I can run once, pull out a memory address, then run again with the guaruntee of having the objects allocated to the same address in memory so that I can see what happens to this specific object the next time around.
At the moment I am just assigning a 'debug id' which gets incremented with each allocation but thought there might be a cleaner way of doing it. I'm sure I've done this before with Vis Studio / C++...
You can set a conditional breakpoint in Xcode so that it will only break into the debugger if a certain condition is satisfied.
To do this, set the breakpoint normally and then right-click on it and select Edit Breakpoint.
Locate the breakpoint in the Breakpoints window and double click the "Condition" column. You can then enter an expression, something like:
(BOOL)[[yourObject name] isEqualToString:@"foo"]
This will break only when the name
property of yourObject
is foo
.
Note that you need to cast the result of the expression to a boolean, otherwise gdb doesn't know how to deal with the result of the expression. You also can't use dot notation syntax, you must use the full square bracket syntax.
精彩评论