Is it possible to add Dependent Breakpoints(Not a Conditional Bp) ( Breakpoint1 is enabled if B2 is enabled etc..) in Eclipse...
I know it is possible in Intellij IDea ..but havent found a way to get this working in Eclipse.
Thanks,
Pavan
Eclipse thus far only supports conditional breakpoints, where the execution will suspend if a condition supplied evaluates to true. Thus, you could set the conditional of your breakpoint to be
objectReference == null
and eclipse will hit that break point if and only if that condition evaluates to true. These expressions can be as complex as you would like, but they can only reference values from your source code, not values from the eclipse environment (thus, you can't hit a second break point if a first one was hit, like you originally asked for). This conditional logic can be accessed by right clicking on a breakpoint and selecting "Breakpoint Properties...".
Instead, what I've found helpful is the "Run to Line" ability ([ctrl]+R, in the Run menu). When you're insertion point is on any later line while the execution is suspended, you can use the "Run to line" command to continue execution to that point in the source as if there was a break point set there. In essence, it basically sets and unsets a temporary breakpoint on the line of code your insertion point is at. The greatest part of the command is that it works across files, so that you can hit a break point in one file, go to the file where you would place the dependent break point, [ctrl]+R to that line in the second file. Its a great way to "breakpoint" to a specific line in a file without setting a full breakpoint that will be hit everytime.
Do you mean a conditional breakpoint.
If you mean a conditional breakpoint, it is possible in Eclipse. Right click on the break point select breakpoint properties.
Then you can add the condition.
If you want to toggle a set of breakpoints at once, you can put them in a "Breakpoint Working Set". Group the Breakpoints view by "Breakpoint Working Sets" (view menu > Group By > Breakpoint Working Sets) and you can toggle the whole working set at once.
Related
I am trying to solve the issue where one of unit tests fails only when I run all the tests in the project.
Thus I would like to come inside some common code only when my failing test is executed. I was trying to find out how to achieve it in Intellij IDEA because there is a feature of condition breakpoints, but for now I fail because don't understand how I can write this type of condition plus it seems that other possibilities don't really allow this.
Is it possible?
Put a breakpoint in the test case that fails (in the image its line 28). Put another break point(in the image its line 42) in the common-code and make that as a conditional one that is disabled till the break point in the test case is hit. To get this window, right click the breakpoint (sometimes you'll have to disable and then re-enable the suspend checkbox).
Hope it helps!
I'm not aware of an IDEA feature which lets you do this, however there are some manual steps that you can take to do this type of debugging:
Add a breakpoint to the first line of the unit test that is failing.
When this breakpoint hits, add another breakpoint in the common class you're interested in.
Alternatively, you can do this in a more automated, repeatable way by making some minor modifications to your unit test code.
Add a public static boolean field to your Unit test class which is set to false by default.
set this to true in the first line of the failing test
Use this field in your test condition. e.g. if your unit test was "ThingTest" and your field "footest" - you're condition will be "ThingTest.footest == true"
Set it to false at the end of your failing test (if you want the follow on tests to run normally)
How about declaring a boolean value, set it to false by default, and only set it to true when you test is failing.
Then you can set a condition on your in your breakpoint, to watch only when the boolean is set to true.
In IntelliJ, you add your breakpoint as per normal, then right click on it, and select View Breakpoint. Another window open, and you can enter your condition.
Hope this helps.
You have two options:
You can like you said use an conditional breakpoint if there is some state (value) in the common code, that is specific to the test you are trying to check. For example a specific string parameter.
You can put an extra breakpoint in the test you are trying to check
before the common code is called from this test. Once this breakpoint
is hit you activate the original breakpoint. You can do this
manually or using the option "Disabled until selected breakpoint is
hit" in the breakpoint dialog of the original breakpoint by
choosing your extra breakpoint in the combo box. If you use the
"automatic"-way you can even uncheck "Suspend" for the extra
breakpoint. This way it will only halt/suspend on your original breakpoint.
I have searched and found that indeed Eclipse does not support this 'direct' feature. But, Did I stil miss something? and Is it present in other IDEs?
Let me elaborate my question more -
if a statement falls under execution flow based on an expression evaluation, then why can't we force execute it? (without the execution of the expression).
For example consider this -
... if(bool returnsABoolean) {
<execute some statement>;
}
...
Can the execution of 'if' be skipped and the statement be executed as a 'next statement'? (I obviously can control the value of 'returnAsBoolean' in the Variables view; but can I not skip (in a controlloed manner) all the statements until a particular statement in the execution?)
Highlight the code you want to run and right-click/Execute or press Ctrl+U.
Alternatively to "Execute", use "Display" (Ctrl+Shift+D) or "Inspect" (Ctrl+Shift+I) to see the result.
Looks like you want the 'Display' view - in the Debug perspective, do :
Window -> ShowView -> Display.
You can enter Java statements to execute there (you have to select the bit of text each time that you want to execute)
http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fviews%2Fdisplay%2Fref-display_view.htm
Debugging allows you to run a program interactively while watching the source code and the variables during the execution.
So debugging is nothing but executing program but inspecting the elements during execution but you can not jump into something which is not there in execution.
You can use keyboard buttons F5,F6 ,F8 etc. (For Eclipse) and other Shortcuts during debugging for your convinience but you can't jump to something directly which is not in the execution sequence.
Debugging Shortcuts:
F5 Step into
F6 Step over
F8 Resume and will take you to the break point
Ctrl+Shift+B Toggle breakpoint
Ctrl+Shift+D Display Info of current statement
Ctrl+Shift+I Inspect the selected element
You can Skip some code by the use of breakpoint you can directly jump to specific point and avoid debugging of code which you believe works fine.Or you can jump out code snippet if you want to.
The question really was to set the Instruction pointer at will. This has been discussed and through url's i pasted on the comments above - this is not an eclipse feature (yet).
I'm working with the Android tutorial and I just got to the debugging section and I'm wondering what the purpose of a Breakpoint is. I can't tell just yet... is it actually stopping the app so I can be sure it runs up until that point, or can I set multiple breakpoints and use them as markers to "stop and go" from breakpoint to breakpoint checking my code?
A breakpoint is a place where the execution stops, and you can start inspecting the current situation in your debugger. This includes:
the point has actually been reached
the current values of all variables
the ability to change manually all variables
the current stacktrace - i.e. which methods were executed before the current one
the ability to add and execute arbitrary code
the ability to inspect the results of a method invocation, while not actually proceeding with the execution
In addition to that, you can manually step forward, line by line in your application. There are three options:
step into - enters a method which is invoked in the current line
step over - goes to the next line
step return - returns from the current method (to the method that invoked it)
You can set multiple breakpoints if you have multiple places where you want to do any of the above.
Generally speaking, a debugger is a very upgraded version of using System.out.println(..) or log.debug(..) all over the place in order to make sure certain conditions are present. (thanks to BalusC for this point)
You can definitely set multiple breakpoints. The questions answered by the breakpoint (alongside all of Eclipse's other debug tooling) include not only "did it get here" but also "how did it get here" (the stack trace) and "with what values" (you can observe the variables while the code is paused).
Can I move the instruction pointer directly to a line of my choice (within the current method) while debugging a Java program in Eclipse (Galileo)?
It's straightforward to drag the instruction pointer to the desired line within a method in Visual Studio, but I don't see a way to do that in Eclipse (and don't find anything about it in the docs or on google).
This is possible...
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.jdt.doc.user/tips/jdt_tips.html
Drop to frame - When stepping through your code, you might occasionally step too far, or step over a line you meant to step into.
Rather than restarting your debug session, you can use the Drop to
Frame action to quickly go back to the beginning of a method. Select
the stack frame corresponding to the Java method you wish to restart,
and select Drop to Frame from Debug view toolbar or the stack frame's
context menu. The current instruction pointer will be reset to the
first executable statement in the method. This works for non-top stack
frames as well.
Note that Drop to frame is only available when debugging with a 1.4 or
higher VM, or the J9 VM. There are some situations where a JVM may be
unable to pop the desired frames from the stack. For example, it is
generally impossible to drop to the bottom frame of the stack or to
any frame below a native method.
This is not possible.
If you simply want to execute some code at the current place you can use the Expressions view and enter your code as an expression. The methods called by the expression evaluation will run in the current debugging context.
Moving the pointer like in Visual Studio is not possible, however workarounds are:
Going backwards to the beginning of the currently executed method:
Select the method from the debug call stack, right click -> "Drop to frame"
et voila you're back at the beginning of the method.
Now to reach your desired line select the line by clicking in it and hit ctrl+r or right click the line and select "Run to line".
These techniques are hugely helpful and reduce debugging efforts massively, enjoy!
A trick I use is to type a space in your class, somewhere safe such as in the comment line; immediately delete it and save the class. This forces the execution point to jump to the beginning of your current method. Not ideal, I admit, but it can sometimes be used as a workaround to achieve what you want.
Although in the default installation of eclipse it is not possible to do directly move the execution point like in Visual Studio, there may exist an eclipse plugin which provides that functionality somewhere. Have a search around.
I like ankon's answer best, but another option (that will only work for your specific instance -- if that) is to stop at a breakpoint on your if and modify the variable(s) evaluated in the conditional such that it returns false (from the "Variables" view, right click on a variable and click "Change Value...")
I thought that this was totally possible in older versions of eclipse, I thought I had the memory of doing it, but I guess I just implanted that memory when I worked in Visual Studio. From what I'm reading it might come to the jvm and not eclipse itself, there are pages where it's suggested that the jvm cannot handle that.
In my opinion Eclipse is many many times better than VS, I worked extensively in both and since I discovered Eclipse I was always in pain when I had to work in VS. But not having this feature is definitely hurting right now hehe.
You can jump directly to any other method call inside of the currently debugged method. Select some method call below your current instruction pointer and use "Step into selection" from the context menu.
unfortunately not possible to step forward with instruction pointer (program counter), so what you need to do instead is to introduce your own "debugging" variables that you can test on - lets say you want to step around a loop that takes too long, then add a variable and test on its increased value and then encapsulate the loop in an if with that variable. I know this is ugly, but it gets it done - or you could just develop in C++ :-)
Just right click on desired line and choose run to line.That's it...
Put the cursor on the line of your choice and either hit ctrl-R ("Run to line") or right-click and select "Run to line" from the context menu.
Suppose I have a class
public class MyClass {
private Set<String> set = new HashSet<String>();
//and many methods here
}
is there a possibility to make an eclipse debugger stop at every line where set member is used?
I haven't used Eclipse for a while, but from what I remember this was possible in the Callisto release at least. If you set a breakpoint on the line containing the declaration, and then go into the advanced properties for that breakpoint, I believe you can set options for modification and access of that variable.
Edit: I just checked with Eclipse Europa. It does work broadly as I thought; the breakpoint is called a watchpoint when you set it on a variable; and in the "Breakpoint Properties" page (accessible by right-clicking on the breakpoint's bauble in the margin, and possibly in other ways) you can determine whether the debugger should stop on "Field access" and "Field Modification". In your case, you want the first one selected.
This has been part of the eclipse debugger from very start. You just have to set a breakpoint at the line where the variable is declared. For more control you can right click on the breakpoint and select breakpoint properties where you can set if you want to stop only on Access or Modification.
Please keep in mind that modification is actually the change in the value for value types and change in reference for reference types. For example if you set a modification breakpoint (watchpoint) on a HashMap then the debugger wont stop if you add items into this hashmap since adding items doesn't change the address/reference of the variable.
Yes. You can put a breakpoint at the expression
private String propString;
The breakpoint gets another symbol and shows the tool tip "Watchpoint [Acess and modification] "
Whith Shift+Ctrl+I you can watch the value of a selected variable name when the debugger is in step mode.
You also can change variable values at runtime when the debugger is in step mode.
The eclipse debugger is a very useful and powerful tool.