What is the diffrence between diamond and circular breakpoints in android studio? - java

Today when I was working like every day I have noticed something odd in the android studio. The 2 kinds of breakpoints I have never seen it before. I want to know what is the differences and why?
Thanks.

copied from IntelliJ
a circular breakpoint is a line breakpoint, while a diamond breakpoint is a method breakpoint.
Line breakpoints: suspend the program upon reaching the line of code where the breakpoint was set. This type of breakpoints can be set on any executable line of code.
Method breakpoints: suspend the program upon entering or exiting the specified method or one of its implementations, allowing you to check the method's entry/exit conditions.
for more info about breakpoints and their types check this link

Related

How do I skip execution of a line of code? [duplicate]

This question already has answers here:
How to modify Java code while running in debug mode?
(4 answers)
Closed 7 years ago.
I am debugging my application in Eclipse. Finally I reached a breakpoint in a state which will trigger the bug in the next line of code.
Due to a breaking change in the class, the most likely solution would be to remove that line of code.
Of course I could do that now: remove the line, recompile and reproduce the sitatuation again. However, since it is hard to reproduce the bug, can I simply skip the execution of that line of code now? E.g. can I set the "instruction pointer" in Eclipse?
Things I did:
I don't want F6 (Step Over), since that will execute the line.
Also "Run to cursor" is not what I want, since that will also execute the problematic line.
Comment out the code according to How to modify Java code during debugging, but that re-executed the method, thus changing the state
I have tried to find an answer on this question, but I don't only want to run a single line of code but all the rest.
This question only has answers which run code in between.
The drop to frame feature is also not helpful.
The linked questions are from 2009 to 2013, so I hope to get new answers.
I'm using Eclipse 4.5.1 (Mars.1), latest official version at the time of asking.
If you want execute the line after the one you want to skip. When you reach the line before the line to be skipped, select the code and right click, choose Inspect from menu. This will execute the selected code and provide you the result in a popup.
If you know the lines that have to be skipped. you can put them in an if statement and change the value of the boolean in the variables view in eclipse. And then proceed to other lines.
(using code from comments)
if (skipped){
//yourcode
};
It is also possible to create expressions in eclipse.
One thing which I missed out was eclipse also supports hot code swap. You can comment out the line and save it. It will drop the debugger control back to the starting of the method. Hot deploy has supported the code changes in the method implementation only. If you add a new class or a new method, restart is still required. If you have the server in eclispe, here is how you can make that possible http://www.mkyong.com/eclipse/how-to-configure-hot-deploy-in-eclipse/

Why eclipse while debugging access areas that has no break points?

When we debug, breakpoints are set before attaching to the process(even before starting application) and even though there are times that debugger go to places that has not been set to access.
I've checked and not modified the breakpoints list before starting program.
Regards
In eclipse preferences there is Java -> Debug. Check if the option Suspend execution on uncaught exceptions is checked. If that option is checked, the debugger will suspend execution when such an exception is thrown.
My friend who has no SO has solved that issue. There were break points in library that was imported by debugged project.
Those breakpoints are not visible in main project.

How do I invoke the debugger from code?

From Javascript, I can simply write
debugger;
and when that line executes, it stops the code as if I had put a breakpoint there.
Is there an equivalent in Java? I need it to work in Eclipse specifically.
EDIT: can we take it as read that I am not an idiot and if placing a breakpoint with the IDE itself were an option, I would have already done so?
FURTHER EDIT: I had not thought it necessary to point out that since placing a breakpoint with IDE is not an option, any answer that revolves around placing a breakpoint with IDE is not likely to be helpful. In case everybody is dying of curiosity, the original code is not written in Java -- it's processed down to Java byte-code. As a result, Eclipse is confused enough it doesn't want to set breakpoints.
The JVM debugger, which Eclipse uses (mostly) under the covers, can set breakpoint at a line number in a method IF compiled with certain optional debugging info OR at method entry (always).
If your classes were compiled without debugging "lines" so the debugger can't set a line breakpoint, and you don't want to or can't recompile them, you can still set a method-entry breakpoint. In Package Explorer -- NOT an edit window for the source -- right-click the method name/signature and Toggle Method Breakpoint to on.
This can be combined with the comment by #ajp: add a method e.g. void [static] debugger(){} that doesn't do anything when you call it, but provides a convenient target where you can set a method breakpoint.
Warning: although it is possible to compile with partial debugging info, like debugging "vars" but not debugging "lines", generally people just use "debug on" or "debug off". If your classes are compiled without debugging "vars", the debugger will be much less useful.
I am probably going to get a few downvotes, but so be it...
If you open a source file in Eclipse and right-click on the left edge of the document view, you will get the popup menu illustrated in the image below.
As you can see, you have the option to toggle a breakpoint and also to turn off and on the line numbers. So, I am not sure what you mean by "My Eclipse is being operated in an environment where it cannot find line numbers to the source code". Unless you have some modified version of Eclipse that does not show this menu, I don't know what you mean by that. The option is there.
You wrote:
From Javascript, I can simply write
debugger;
and when that line executes, it stops the code as if I had put a breakpoint there.
And also:
can we take it as read that I am not an idiot and if placing a
breakpoint with the IDE itself were an option, I would have already
done so?
Option 1: The simple, "incorrect" answer is that there is no instruction in the Java language to make the program pause in a breakpoint nor there is an option like in languages like C++ to
make a debug build. So, your "ONLY" option is to execute a breakpoint from the IDE.
Option 2: The complicated, correct answer is that you can do what you want following these instructions: https://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html
In your case, I don't believe that you don't have the option to place a breakpoint with the IDE to debug your program; no matter how complex your program is. BUT, I am not here to debate that point. According to your post, you have to do option 2 laid out here.

Debugging a continuas value Android Studio

At the moment I've been using logging to keep a track of my continuously changing values within an update loop. Problem is is that this can be time consuming.
I can use the debugger but it stops code executing and due to what I'm doing causes weird results and false values.
Does anyone know if it's possible to "watch" the variables while keeping the code running. Like having one watch within a scope.
Android Studio/IntelliJ have some really nice features in breakpoints that let the IDE take an action when it hits a breakpoint instead of just dropping your app into the debugger (which it can of course also do). On any given breakpoint, there's a checkbox in the options that controls whether it will actually suspend your app and drop it into the debugger; you can turn that on or off independently. You can have it log a message to the debugger console, or have it evaluate any expression and log the results to the console.
I find these options super-handy; it's the equivalent of adding debug logging to your code, but you can add and change it on the fly without modifying your code and doing a rebuild-restart cycle.
There's also some really powerful filtering that will selectively control whether or not the breakpoint is triggered based on certain criteria; you can even set up cascades of breakpoints where one doesn't fire until a previous one is hit.
Experiment with some of the options.

Eclipse - Execute Expression on at Point in Code?

Is it possible to have Eclipse execute an arbitrary expression at a particular point in code when debugging?
The Execute/Display functionality allows you to run arbitrary code in the context of debugging. A breakpoint stops flow.
What I'd like is something like a breakpoint that can be inserted at a particular point in a class, doesn't suspend application flow, but instead executes a snippet of code.
The background is I'm trying to debug some multithreaded code which I can't edit, and I want to do some naive System.out.printlns to see when various things happen. If I use breakpoints then the flow of the events will be disturbed.
Aha! There's an undocumented feature whereby conditional breakpoints can execute other code, dubbed 'Printpoints'.
You may use the "Breakpoint Properties" of a breakpoint to add some code. Hit the "Conditional" Checkbox in the dialog and place your code there.

Categories