Viewing complex objects in debugger - xcode

Is it possible to construct custom views for complex objects?
Specifically I want to view the inner workings of a CGPath.
I've found the "view variable as" option with right clicking the variable in the debug view, and I've seen ways to view (eg) strings &tc with it, but I haven't found anything that helps me in this case.

po path in the debugger will print out all of the path's elements. UIBezierPath has quick look support in the debugger, where you can hit space and view a drawing of it, but you have a CGPath. It seems that quick look support is not enabled for CF classes like CGPath.
But you're not stuck. If you right-click the variables list in the debugger (as shown here), and choose add expression, you can create a local UIBezierPath by typing this in the expression field:
UIBezierPath(cgPath: path)
or, if your debugger is in an Objective-C context:
[UIBezierPath bezierPathWithCGPath: path]
Your expression then shows up in the list, and you can press the space bar to see a visual representation.
This example shows how I have it set up in an Objective-C project:
Quick-looking the path shows this:
If po path isn't showing you any components (moveto, curveto etc) in the debugger, then I think you have an empty path, and your problem lies elsewhere. If otherPath is nil, then I get an invalid expression in the debugger when creating the bezier path.

Related

How can I know who calls the method in Xcode?

Does Xcode have a way to show the caller function of a method? I want to know all of the calling functions of a method in a class. A solution would be to find the method in the project, but sometimes different classes have methods with the same name - That could find us a method we're not looking for..
Many other IDEs have this capability, such as Visual C++ 2003/2005/2008,Eclipse ...
Can you do this in XCode?
Xcode 4.4 intrudced this functionality:
New Features in Xcode 4.4 (Scroll down to 'Find and Search Additions')
Move your cursor on top of the function you are interested in
Open the Assistant editor(⌃ +⌘+Enter)
On the top of the assistant editor, Select 'Callers'
You will see a list of all the function that's calling your function
Not the as effective as other IDEs, but does the job.
Yes. Set a breakpoint inside your method, then when it breaks, there are two spots to see a stack. First is in Xcode's "console" area (usually the bottom middle), there is a top-bar which may not immediately appear to be navigable, but it is a select-style UI control which has the entire stack in it. Selecting a different level shows you that scope's variables, etc. and pops your editor to that exact file (where you can mouse-over variables to see their in-memory real-time values). Second is in the left-hand area (where you normally browse files). There is another tab there (besides the file browser) for exactly this purpose. There is a slider at the bottom which controls how many "steps" in the stack you see; clicking on one has a similar affect.
For simple refactoring such as method re-naming, you can use the contextual-menu when you right-click a selected method-name, and Xcode will replace all identical selectors in your project. However, this does not address what you mentioned about different classes having methods with the same signature. It does, however, give you a very nice interface for reviewing the changes in-context and easily accepting or rejecting them one at a time.
It might be noted, however, that changing method signatures often may be a sign of poor design, and particularly if you have to do it with methods which have the same signature on different classes (which are not "siblings" and therefore should both get the rename)

Eclipse-RCP: View pulldown-menu

I would like to add Command's to a View's pulldown-menu (the triangle-shaped button in the upper right corner that the "Problems"-View in Eclipse also has).
Can anyone point me in the right direction how to do this declaratively in plugin.xml?
I found a tutorial that used a viewContribution (extension point org.eclipse.ui.viewActions), but unfortunately using this extension point i can only add Action's to this menu.
The functionality i wish is actually quite similar to the Problems-View (Showing Compiler-Errors and -Warnings in Eclipse):
I want to filter records within my View according to an Entry chosen in the pulldown-menu of the View.
For an example configuration you can use the implementation of the Problem View itself. It uses the org.eclipse.ui.menus extension point to contribute that menuItem through a dynamic contributor. You can check the details in the plugin.xml of the org.eclipse.ui.ide plugin. Look for the usage of the class org.eclipse.ui.internal.views.markers.FiltersContribution. In its "getContributionItems()" method it returns menu contributions dynamically each time the menu is to appear. Of course, doing it this way is not exactly declarative. For that try reading the guide at http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/guide/workbench_cmd_menus.htm (you should use your command instead of the global ones, of course)
Hope it helps!

understanding Xcode debugger var display

newbie question: can anyone tip me to how to understand/interpret what is displayed in the debugger var pane?
Ex: I am passing an NSDictionary as a method param. I set a breakpoint so I can examine the values in the dictionary. The image below (if it comes through..) shows the expanded view of this var in the debugger. It correctly reports that it contains 3 name/value pairs but as I expand all the sections, I simply can not find where these are stored.
Do I have to create local vars of these name/value pairs in order to view them when I want to check? I know I can use NSLog or printf but sometimes I just want a quick peek.
Right click the variable, click "Edit Summary Format" and type the following:
{(NSString*)[$VAR description]}:s
This replaces the GDB formatter for NSDictionary with a call to the more expensive description method.
That is, instead "x key/value pairs", you'll see the contents of the dictionary as produced by -[NSDictionary description].
This is the same as typing po dictionary in the console window. Or right clicking the variable and choosing "Print Description". Both of them call the description method of the object.
If you are curious, you can find this formatter at /Developer/Library/Xcode/CustomDataViews/Foundation.plist under the key NSDictionary. What you type as replacement is saved in /Users/USERNAME/Library/Developer/Xcode/UserData/Debugger/CustomDataFormatters and will persist across runs until you delete that file.
A NSDictionary is really a class cluster and few people know the inside structure. At this point you ain't going to find much use for that debugger tree.
This is what you are looking for :
Click on your dict, then click on the little "i" icon :-)

Xcode debugging - displaying images

I love using the Xcode debugger. You can take a look at a variable's value and even change it.
But can I somehow DISPLAY the image that is referenced by an image variable? I know I can see its raw bytes, but it would be much more human-friendly to display a window with its contents.
Xcode might not support this. Maybe there is an external tool that would help display images?
Use Quick Look to inspect images in the Xcode debugger.
Select an NSImage or UIImage in the debugger, then click the Quick Look "eye" icon.
Like other areas of OS X, you can also use spacebar to Quick Look!
Quick Look in the debugger can also be implemented for your own classes:
Enabling Quick Look for Custom Types
The variables Quick Look feature in the Xcode debugger allows you to obtain a quick visual assessment of the state of an object variable through a graphical rendering, displayed in a popover window either in the debugger variables view or in place in your source code.
This chapter describes how you implement a Quick Look method for your custom class types so that object variables of those types can also be rendered visually in the Quick Look popover window.
If you like to work with the lldb console, use chisel command "visualize"
tip:
after the installation, you can set a conditional breakpoint after setting the UIImage with the action:
"visualize myUIImageToShowWithQuickLook"
this will show you the image automatically when the debugger stops.
EDIT:
As of Xcode 5, the debugger can show you the visual representation of UIImage/CGImageRef variables!
Xcode itself can't do it. I don't know about external tools.
What i'm doing to test images while debugging is to convert that raw data into an image-file format, like .png, and then saving it somewhere, and then i'm opening the image with any image viewing tool.
I have a piece of code for that purpose, which look basically like that:
NSData *imageData = UIImagePNGRepresentation(self.myUIImage);
[imageData writeToURL:desktopURL atomically:YES];
And i'm just copy-pasting this code where i want to see content of an image on the run.
Make sure to get rid of this code as soon as possible due to the high-cost of the conversion of UIImage to NSData
Edit for Xcode 5: Now when you hover over an image variable name, there is an "eye" icon on the right. Just click it to see the current image!
NOTE: sometimes this fails in Xcode, even if the image is correct. If this happens, OR if you don't have a UIImage variable (e.g. it's a property of another object, you can still use the older answer:
Older answer: Starting with Avraham's answer, I tried a few experiments for displaying an iOS image from lldb without having to recompile or add it to a view. I finally came up with:
e [UIImagePNGRepresentation(myImage) writeToFile:#"/Users/<userName>/Desktop/myImage.png" atomically:NO];
I keep this string in a text editor and paste it when I need it. This stores the current image I'm interested in (in this case, "myImage") to a PNG file on the Desktop. Then I can just open this file with Preview.
If you're working on an iOS device, then you can use
e [UIImagePNGRepresentation(myImage) writeToFile:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingString:#"/myImage.png"] atomically:NO];
Then you can use the Finder; select your device; "Files"; then your dev app, and copy the image to your Desktop to view it.
What if you can't get to the image via the variables view?
Echoing what #pkamb said - you can use the variables view to quick look at an image. But what if you can't get to the image?
for example I have an image at (contentViewController.view.subviews[0].subviews[1] as? UIImageView).image
but if I try to expand contentViewController in the variable view it doesn't expose my subviews
what you can do is right click, add an expression, and then you can see it!
Click the eye icon when hovering over a variable in Xcode:
You can put a breakpoint in the line of your image, and then in the debugger, just write:
po your_UIImage_object
po stands for print object, it's a GDB command which will display several useful informations about the object passed, in your case the image.

Flatten inherited members in Visual Studio's Watch window?

Is there some way to make the Watch window display all inherited properties and fields in one long flat list, rather than hidden behind a nested "base" node?
I'm debugging some C# code that makes massive use of inheritance - some of the properties I want to watch are behind three levels of "base" in the Watch window. This would be more or less bearable if I just wanted to examine a single such object, but I'm actually looking at a tree of them...
see http://blogs.msdn.com/b/jaredpar/archive/2010/02/19/flattening-class-hierarchies-when-debugging-c.aspx
UPDATE: I wrote a commercial tool called OzCode that solves this problem. The idea is that if you're interested in a property of the base class, you can "Star" that property, which causes the property to appear at the top of members list, and also in the text of its parent.
So for example, in the following scenario, I had to expand two base nodes to get to see the properties I wanted, "Important" and "Interesting":
But once I star these properties, they will always appear at the top, even when viewing variables of the Derived type, so I'll see:
These stars are persisted and will be shown whenever you view a an object of that type in the DataTip or QuickWatch window from that moment on, so the next time you a variable of that type, you won't need to expand those "base" nodes. And because starred values appear as the parent node's text, if you're looking at a tree datastructure of these heavily nested objects (as you stated you were), you will be able to see these properties without even expanding the nodes at all.
FULL DISCLOSURE: I'm the co-author of the tool I've described here.
Not as such. You see, it is a feature! The ability to see where a property comes from is important most of the time.
I understand your pain though. There are some work arounds. First, you can just put the object.property in the watch window. This will just display the property you are looking for. It is great for digging into a specific property but not so much for getting all the others.
You can also try (BaseClass)object. This will cast it to the base object that contains the property (properties?) you are looking for. Again it is great for looking a a specific subset of properties but completly hides all the others.
Good luck and good hunting.

Resources