I have read that it is possible to set a conditional breakpoint at some specific line in the code, by setting the breakpoint as usual and then set the condition.
That is fine, but what I need now is different. I want my program to stop when a given variable takes a particular value or simply changes its value. But I do not know where this happens.
So I need a kind of (general) conditional breakpoint, not one at a specific line.
Is this possible? It would be a bit like what is possible with exception breakpoints.
Symbolic breakpoint is what you are looking for. Debug->Breakpoints->Create symbolic breakpoint or follow instructions from apple docs:
In the bottom-left corner of the breakpoint navigator, click the Add button.
Choose Add Symbolic Breakpoint.
Enter the symbol name in the Symbol field.
If the symbol is declared in more than one library, enter the name of the appropriate library in the Module field.
To specify that program execution be suspended only if an expression evaluates to true, enter the expression in the Condition field.
Click Done.
As symbol i would use setter of property you want to track...
Related
The breakpoints that are working are defined twice (I don't know how or why they were created twice). When editing those breakpoints the condition item has two radio buttons. The first one is on with the text: "Use parent breakpoint condition, which is not set". The other radio button is near the "classical" text field for the condition. The breakpoints that don't work have only the text field for the condition. I can't find any documentation for this. My questions : What makes I produce one kind of breakpoint and the other one ? Is it a bug ? (Only the working one, with radio buttons should be produced ?). It is not clear for me. What means the text: "Use parent breakpoint condition, which is not set" ? What is a parent breakpoint ? Why are they -when working- produced by pair ? Actually setting a working breakpoint seems to work randomly for me. Does anyone have the same problems ?
The Xcode breakpoint display is mirroring the way lldb treats breakpoints under the covers.
lldb breakpoints come in two parts.
The first part is the "breakpoint specification" - so for instance "line 12 of the file foo.c" or "symbols named foo". lldb also allows broader search specifications like "any function name matching a regular expression" (break set -r) or even "any line of source code matching a given regular expression" (break set -p) though Xcode doesn't have UI for these fancier ones.
The root node of the breakpoint in the Xcode display represents the breakpoint specification.
Each specification can resolve to one or more locations in the generated code for your application. This can happen, for instance, if the breakpoint was on an inlineable function in a header file, which will emit code into each of the compile units that include the header file and use the function. Or is you set a symbolic breakpoint and that name shows up in more than one shared library. It can also happen when you set a breakpoint on source lines like
for (i = foo(); i < bar(); i += baz()) {
since that source line contributes code that gets run in three distinct parts of the evaluation of the for loop.
So the child nodes of each breakpoint listing in Xcode show you the individual locations in the generated code which matched the breakpoint specification.
If a breakpoint has no location nodes, that means lldb couldn't find any places in your code that matched the specification. You can sometimes see this more clearly if you issue the:
(lldb) break list
command in the lldb console.
I can't tell why, from your description, some of your breakpoints aren't resolving to locations in your code. This can happen if you have set a breakpoint in a source file that got built without debug information, for instance. It can happen if the source location is between some #ifdef's where the condition fails so no code is emitted for those lines. I'd need more details to know why your particular breakpoints aren't resolving.
Is there a way to debug a bunch of variables and see their contents live while running the simulator?
I know I can access variables immediately from the console/debug window if I use breakpoints but what I'm looking for is a bit different.
Is there a way to debug a bunch of variables and see their contents - live - while running the simulator?
Yes in Xcode you can use po to see your object when you are on your breakpoint:
Just type in the console:
po myvariable
I've made a little example for you:
I create a variable, I set it to one, and I put a breakpoint. I access to the console to see the value of my variable
I set the variable to two and I retype po myvariable to see the new value of my variable
Yes, you can do this, by editing breakpoints: At the point where you want to see your variable's value, add a breakpoint. Then right click it to "edit breakpoint." Click "automatically continue after evaluating actions." Click "Add Action" Note that after you do this, there is a + and - control to add more actions. Choose "log message" and type in a string so you'll know what variable value you're about to display. Click the + button, leave it at "Debugger Command" and type "po name-of-your-variable" (replace with name of your variable, of course) Now when your code hits this point, it will print the log message and value in the console and continue execution. Repeat to taste.
Apart from using po to inspect an object in lldb, Xcode provides a nifty feature to print the description in the console.
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.
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
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