Watch Expression in Xcode - xcode

Say I am debugging. Say I need to know what the value of [somevariable count]
How would I do so?

If what you want to do is know the value of the expression while program execution is halted, then do something like
> p (int)[somevariable count]
in the gdb console.
Note:
People searching for the term "watch" might be expecting an answer about being able to observe when a value changes. For that question these are some answers that are more appropriate:
Watching variables in Xcode
Xcode LLDB watchpoints

Put a breakpoint on the relevant code line.
When Xcode stops on that line, in the debug area (the bottom of the screen is splitted to two parts, look at the right one, if you don't see the bottom part, shift+cmd+Y, plus sometimes the right side or the left side are hidden and there are small buttons on the right bottom side to show them), you see all of the local and global variables.
Right click (or two fingers) that debug area, and you will see a context menu with one of the options "add expression".
Type in your expression.
Note:
above previous user's comment about the word "watch" is pretty clear to whomever comes from any other IDE but not in Xcode.

Related

Can I set a conditional breakpoint without specifying a specific location?

Similar questions: One, Two. But this is not what I am looking for.
Similar questions, but said options are diabled: Three, Four, Five.
Situation: I want to identify the line where the value of the variable ApplianceState changes to the value normal. ApplianceState is an enum type and can have one of 4 different values. The project I am working on is quite huge and looking for it line-by-line could take days.
Question: Is there a way I can set a watch so that visual studio breaks at the line where the value of ApplianceState changes to normal?
I know I can set a conditional breakpoint, but that would mean I have to set a break point on certain line, and I don't want to do that.
Also, I have enabled native code debugging and the menu item New Data Breakpoint, in menu Debug -> New Breakpoint, is disabled (greyed out). So, I can't select it.

Going back to previous line while debugging on visual studio

I am debugging a piece of code on visual studio and I forgot to note down the values I have kept a watch on. Can I go to previous line without rerunning the entire code?
There are similar questions asked on SO but in my case i haven't run through any error or exception. The code is running normally.
After pausing on a break point, right click on the line you want to "go back" to. From the menu that pops up, select "set next statement".
This will adjust the instruction pointer to continue from the specified line of code, but it will not roll back any variables or memory addresses to the values they were at before that line of code was originally executed.
It sounds like what you want to do is rewind / replay your code rather than just move to a specific line. You can move to a specific line, you can just right click and choose set next statement. Unfortunately, this won't rewind the state of the program to some past point (beyond setting the stack and doing a bit of unwinding).
To rewind/replay you need to be a bit trickier. Some options are: -
VMWare replay which will allow you to record and then go back to a certain point in time.
Intellitrace. I haven't tried it, but it allows you to replay to a point.
Which is a bit heavyweight and wont help you right now.
You can use the mouse to drag the yellow arrow pointing to the "next statement to be executed." This actually changes which statement will be executed next. It's not guaranteed to work, but as long as the code is not too complex, it could.

Is there any way to scroll beyond the last line in xcode?

I ask if there is any way to scroll beyond the last line in xcode, because I always end up pressing a lot of enters to the end of my files, so that I don't have to always type my code at the bottom of my window.
I have skimmed through the properties panel of XCode, and had a look at this forum. So far the answer looks negative, but I kept my hopes up. :)
Any ideas for tricking XCode to scroll beyond the last line? (I have XCode 4.5.2)
There is now a plugin for that !
Have a look at SCXcodeEditorInset !
Dont think there is a way to do this but if you are trying to edit the buttom of the code while having it near the top of your display, you can click the middle view button in xcode to bring up the console/watcher and then drag that up to the desirable spot. This does decrease the overall space of your editor but can sometimes be useful if you prefer this or just need to do that temporarily
What I do is, When you finished typing at the bottom, before you go to top, type some unnecessary code "asdf" as error then go where you want. you can come back clicking on top right red error panel.

Xcode 4 code editor questions

How can I turn on curly brace matching?
This worked fine in Xcode 3.x. In Xcode 4 is doesn't work. I've already checked the box for "Automatically insert closing '}'" in the Preferences->Text Editing->Editing panel.
How can I turn on parenthesis matching?
How can I turn on code compeletion for "if/else-if", "for" etc?
In Xcode 3.x I would start to type "for" and autocomplete would provide the parenthesis, curly braces, semi-colons etc. I could then press escape for a menu containing (amongst other things) the option to do a "for i" loop (in which case Xcode would fill in "int i; i < n; i++" with n selected so I could just type a value).
In Xcode 3.x I could do something similar for if/else-if blocks. I could just start to type "if" and autocomplete would provide parenthesis, curly braces etc.
Edit: after looking for the "get info" option for a source code file (was simply right click the file name in Xcode 3) for five minutes I decided to downgrade to version 3.2.x. Which means hours of downloading. This really stinks :-(
Auto-} works a little differently in Xcode4. It doesn't appear as soon as you type the {. You have to hit return after to get the closing brace. So typing { gives the autocomplete. It feels a little odd at first, it took me awhile to adjust, but I think it makes sense. Most coding styles dictate a return after the opening brace, so it pretty much will always auto-close when you want it to. It doesn't give the } though in a case like making a single line if into a multi-line one. You can now add in the opening brace, move the curser to after the line, and enter the closing brace. Before when I did something like that I'd have to spend time deleting the auto-}.
For code completion, it sounds like you're having an indexing issue. Code completion still works as you want (it's actually a lot smarter now) in Xcode4. Your syntax coloring is also usually off when this happens. I ran into it with one of my projects and fixed it by editing my build settings, I had a bad one in it. You might also try deleting the project's derived data in the organizer. That'll force a rebuild of the index.
The "get info" items have moved. It's one of the land mines of the IDE rewrite. They're not in the file inspector. Show the utilities pane and then select the file inspector (the first icon in the tab bar).
Xcode 4 is a bit alien when coming from Xcode 3. They changed a lot of stuff. I'd recommend getting a feel for it. At some time in the near future Xcode 3 will be deprecated and you won't get the new SDks for it. You can have Xcode 3 and 4 both installed at once which is helpful for making the switch. That way you can fall back to Xcode 3 when you get stuck on something and will allow you to gradually make the change.

Eclipse: Improve debugging and display variable values on mouseOver

Is it possible to view variable values in Eclipse when debugging? Right now when I "mouse over" a variable all I get is the definition.
e.g. for [int mLastView] I get [com.company.samples.MyClass.mLastView] instead of 1. The value that was assigned to it.
Also, is there anyway to improve debugging in Eclipse?
For starter: making the breakpoints visible as in VS (see below)?
Eclipse Break Point
Visual Studio Break Point
I posted this over at Stack Overflow and one of the suggestions was to go into Window -> Preferences -> Java -> Editor -> Hovers and select the Variable Values option and assign a modifier.
When I was first trying to resolve this issue, this was one of the options I looked at, but oddly enough, there was no Variable Values preference available, it was missing. Once my “fix” above was applied, it magically appeared:
Click to see the pictureBroken Link
Actually, since eclipse3.4, not only do you see the value of a variable when you pass the mouse over it, you can actually inspect it:
When debugging, hovers for variables have been enhanced to display an object inspector. The inspector will display logical structures according to the toggle setting in the visible Variables or Expressions view.
If you hit the breakpoint while you are debugging, you do see the value of the variable when you mouse over. You can also select an expression, and inspect the value of it's evaluation using the "Inspect" menu option. You can also use the "Variables" view to see the current value of all in-scope variables.
About breakpoint visibility:
Right-click on the right outline of the editor, you'll see some Preferences, and there in Annotations you can select Breakpoints. I personally added Text as Highlighted and some pinky colour. Shame that the highlighting is really buggy, sticks here and there, breaks between lines, etc. But it somehow works for most cases.
(Another shame is that breakpoint bullet is often hidden behind some suggestion icon or what - why they can't make the gutter wider like Idea does, I don't know.)
I got similar but a little different problem with the thread-starter. Sometimes during debugging, I mouse over a variable, I see it current value. Sometimes it's just the definition, like in coding mode. So what caused the first case, what the second?
PS: Of course I can always choose to view Variables (Alt+Shift+Q,V) but it's faster if you have mouse over value instantly.
Thanks

Resources