How to view contents of a vector while debugging in Code Blocks? - codeblocks

I use Code::Blocks with a simple application. I have a vector a that contains three integers, {1, 2, 3}. I added the "a" variable to watch, but I can't see its content. In the watch, I right click on a and select properties and check the box "Watch as array". I also clicked on Update. The program is stopped after the vector is initialized with the values. I also removed the variable from watch and added it again. Is there a way to see the content of a?
I already checked the answers to the almost identical question "How to view contents of an array while debugging in Code Blocks?" and it did not help.

Turning off this option works for me :
- Settings -> Debugger... -> GDB/CDB Debugger -> Default -> Disable startup scripts (-nx) (GDB only) -> Set to "off"

I found an answer which provided a working solution: http://forums.codeblocks.org/index.php/topic,22325.msg151987.html#msg151987
I downloaded "TDM-GCC MinGW Compiler" from https://sourceforge.net/projects/tdm-gcc/?source=typ_redirect and I selected it as debugger in Code::Blocks.

Related

How get a breakpoint on variable write in Visual Studio?

How I can set breakpoint on variable change (I think this is write access) in Visual Studio?
This is referred to as a Data Breakpoint in Visual Studio. To create one you'll need the address of the variable in question (just add &variableName) to the watch or immediate window. Then do the following
Debug -> New Breakpoint -> New Data Breakpoint
Enter the address in and size of the value in bytes
Note: This is only supported for C++ applications. Managed languages don't support data break points.
You need to add "Has Changed" condition to your breakpoint. To do this:
Set breakpoint on the line you want it to break when your variable is changed.
Right-click red dot icon, select "Condition".
Enter your variable name and select "Has Changed" option.
You may find more information in this MSDN how-to.
This is now supported in VS2019 for . NET Core 3.0 or higher check this out
How do I set a data breakpoint? Setting a data breakpoint is as easy as right-clicking on the property you’re
interested in watching inside the watch, autos, or locals window and
selecting “Break when value changes” in the context menu. All data
breakpoints are displayed in the Breakpoints window. They are also
represented by the standard, red breakpoint circle next to the
specified property.
If you right click on the break point you can can set Conditions... This lets you specify a if a variable value is true or if its changed.
Break point conditions
You can add a conditional breakpoint by:
Add a normal breakpoint
Right-Click on it and select "Condition"
Select "Has changed"
The breakpoint will only be hit when the condition inside the textbox has changed.
As far as I'm aware, the condition inside the textbox needs to be written in the language you are debugging. I.e. in C#: x >= 5
If you are just looking for the change of a variable, you can simply add the variable itself to the TextBox and the breakpoint will be hit when the variable changes.
HTH,
Christian

Watch Expression in 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.

How do I switch between the header and implementation file in Xcode 4?

How do I switch between the header and implementation file in Xcode 4?
In XCode 3 it was cmd and right or left (I think)
Ctrl+Cmd+Up or Down, but the shortcut seems a bit finicky and sometimes stops working, not yet sure when and why.
Be sure to FIRST click ON the actual code window...
that's the critical tip to ensure it works. Click anywhere at all on the actual code. (If you're active in one of the other many panes of Xcode, the keystroke combo has no, or different, meaning(s).)
Also, you can 3 finger swipe up and down on the touchpad if you have one.
Ctrl+Cmd+Up or Down
The shortcut sometimes stops working!!
The menu option has moved to "Navigate->Jump to Next Counterpart" and "Navigate->Jump to Previous Counterpart".
In preferences the key binding is now under "Jump to Next Counterpart" and "Jump to Previous Counterpart".
Why Apple insist on changing the menu positions AND names of these things is beyond me! I mean "Counterpart"!?
Worth nothing that Ctrl+Cmd+Left or Right move between previous and next files that were viewed (I mean "counterparts") too. These are also under the key bindings "Jump to Next Counterpart" & "Jump to Previous Counterpart").
The reason the menu option has been split between:
"Navigate->Jump to Next Counterpart" and "Navigate->Jump to Previous Counterpart"
is because you can have more than just one header file and one source file with the same file name. Besides having matching .xib files for view controllers, I have separate .vsh and .fsh files for vertex and fragment shaders in my OpenGL program. Along with my .h and .cpp files that's a list of 4 files that I can navigate up or down through with one key binding, instead of hitting the same key binding 3 times in a row to cycle back from file 2 to file 1.
Also in Xcode 6.1/7.1 shortucts are the same:
Jump to next counterpart:
Ctrl+Cmd+Up
Jum to previous counterpart:
Ctrl+Cmd+Down
Personally, coming from eclipse, I change this shortcut with:
Ctrl+Tab
this combination insn't already binded to anything else.
Xcode -> Preferences -> Key Bindings
search for "Jump to next counterpart" and put the new keys combination.
PRO
This is more efficient than default bindings see that you can use one hand instead of two!
"but the shortcut seems a bit finicky and sometimes stops working, not yet sure when and why."
Sometimes Xcode loses track of which .m and .h belong together. This is e.g. the case
when you open one of the files directly from the Finder. When you open the file from
the file list in Xcode, it normally works okay. Although when you have moved files between
folders & groups in the file list of Xcode, it will also list the relation between the files.
The command to swap between m and h files is CTL-CMD-up/down. It sometimes get stuck. To unstick it simply save the file, i.e. CMD-S, and the hotkey should work again.

Xcode: view references for a variable?

I am new to Xcode. I am not sure if there is a way to view a variable's references just like "Find all references" in Visual Studio by right click on a var?
For example, in my .h file, I would like to know or view all the references for property isSet:
#interface MyInterface {
...
BOOL isSet; // view all references to this var?
...
}
Try using: Find in project -> As symbol context menu. Sometimes you may want to search as definition instead.
Beside Xcode, there is AppCode IDE from JetBrains. And in AppCode it is easily possible, just select Search --> Find Usages.
I was looking for similar option. I do not know why XCode did not included that.
But there is a work around I use until Apple give that option in XCode.
Try this in the source code (.m) file,
Select the symbol, right click -> Refactor -> Rename
-> Give a name whatever you wish, then press Preview.
Now you can find all the references. Now you can Cancel it or do not rename it. :)
i'm using xcode ver 4.5 and i can select the method or property, right click and pick Find Selected Text in Workspace...
You're conflating two different things in your question: finding references to a variable, and finding references to a property. Finding references to a property can be done via the 'Related Files' menu, as described in my answer here: https://stackoverflow.com/a/17931752/1709587
Finding references to a variable can be sort-of done via 'Find Navigator' tab of the Navigator. (That's the magnifying-glass-icon tab of the left side menu.) Go to Find -> References -> Matching and type in the variable you're looking for. That said, I can't see that this is particularly useful, because:
It will match all occurrences of a variable with that name, even if they're unrelated to the particular variable you're looking for.
Why would you ever need this? You shouldn't generally be using public member variables (use properties instead), so 99% of the time, all references to the variable you're interested in will be within the file in which it is declared. Just using cmd+f and doing a simple text search within that file has always sufficed for me, and I've never felt the need to bring out heavier machinery. If you hit a couple of comments while doing this, who cares?
If you truly, truly do need the functionality you're asking for, and neither the 'Related Files' menu, Find -> References, nor a simple text search will do, then your only options are to use some third party tool like AppCode or the (cumbersome, slow) 'refactor' hack proposed by Karim.
Update for XCode 12: right click on definition -> Show code actions -> Callers...
This will show every place in the project where this method or property is referenced.
Find selected symbol in workspace is what you need
right click on the method/property -> Find -> Find selected symbol in
workspace
focus the property/method and press ⇧ + ⌃ + ⌘ + F (or you
can have a custom one)
Does basically the same search as Refactor -> Rename does

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