Eclipse conditional breakpoints and global variables? - java

I have a global variable
static int debugNumber;
and a breakpoint with a condition
debugNumber > 1
with Suspend thread, Conditional and Suspend when 'true' checked. Currently, if I pause the execution of the program and hover over the declaration the value displayed is 2. Still, this breakpoint doesn't break.
As far as I can see on Google and here at SE debugNumber > 1 should be fine. What am I doing wrong?

Just so we're clear: That line means: If code execution gets to this line (the line with the breakpoint), then do what breakpoints usually do: Freeze the thread (or if you've configured things to be that way, and pause all other threads, which is not the default). However, a conditional breakpoint means: Before breaking as usual, check the condition. If the condition is false, then don't do anything.
A conditional breakpoint is going to break as often, or less often, than a normal breakpoint, never more often.
It sounds like what you want is to 'breakpoint' every line in the codebase that sets the debugNumber variable, if the value it is being set to is 2 or higher. If that's what you want, make a 'watch' on debugNumber and configure the watch to break execution.
If that's not what you wanted, then, well, you made no mistakes in what you describes, so then it's one of a billion things that could be wrong:
The line with your breakpoint was never hit.
The debugNumber was 1 or less when it hit your breakpoint.
You used 'run' to start your application and not 'debug' (there's pretty much no reason to ever 'run' anything, always pick 'debug')
The global 'disable all breakpoints' toggle within eclipse has been toggled off. It's (unless you changed things) on the toolbar: a larger 'breakpoint dot' (blueish circle) with a big slash through it. It's a toggle button. Is it pressed in?
Eclipse debugger has desynced. It will throw you a dialog if this happens, but one of the options in this dialog is 'ignore now and in the future' (It's a more succint text than that, but that's the gist of it). If you ever pressed that, it can desync. The debug view will tell you. This can happen if you change compiled code as eclipse runs, or change signatures in your source files and save the source file in the middle of a run.
Many many more things

Related

debug issue how i can solve <terminated, exit value: 0>C:\Program Files\Java\jdk1.8.0_151\bin\javaw.exe (Mar 4, 2020, 12:02:48 PM)

I have placed a breakpoint, but when I run the code in debug mode, it keeps skipping the breakpoints and I don't see any variables:
I'm new to this can someone help me out here, thank you.
You have somewhere a so-called trigger point that have to be hit first to enable the breakpoint in line 11.
Trigger points are decorated with a T and regular breakpoints are, if there are trigger points, decorated with a crossed-out T (like the breakpoint in line 11). In your case, with the trigger point not be hit the regular breakpoint will not become active and your program runs to the end without stopping at a breakpoint (terminated means finished and exit value: 0 means successfully).
To disable, delete or convert the trigger point(s):
Go to the Breakpoints view
Do one of the following with all trigger points (those decorated with a T):
Uncheck them to disable them
Select them and hit Delete to delete them
Select them one after the other and uncheck the Trigger Point checkbox to convert them into regular breakpoints

NetBeans conditional breakpoint not working

I have a conditional break point set within a long loop. Here it is:
maBuyPeriod==55 && maSellPeriod==65 && quote.Symbol.equals("VAW")
Suspend is set to "Breakpoint thread".
In debugging mode, I can step over, step into, etc just fine. But when I click the Continue button, the debugging suspends on the current line without proceeding to the breakpoint.
This is NetBeans IDE 10.0. I have never been successful at getting conditional breakpoints to work. Suggestions?

Stop at breakpoints only in certain thread

I have some multithreaded code and am trying to set up some breakpoints in Eclipse so I can do some debugging.
The breakpoint I want to set is in a class used by all of the threads. However, I only want the breakpoint to be hit when I am in the main thread. Is there a way to do this in Eclipse?
I have tried to use the 'conditional' breakpoint options but cannot get it to work.
Conditional breakpoint approach is good. The condition should looks like: Thread.currentThread().getName().equals("main").
If you want to set up a breakpoint for another thread you just have to change "main" to a thread-specific name, which can be provided via the Thread constructor.
You should be able to set up a conditional breakpoint by using a condition dependent on thread-local data. Two examples:
Thread.currentThread().getName(),
some value stored in a ThreadLocal.
There should be an item Filtering in the breakpoint properties dialog. There, you can limit the breakpoint to specific threads. But this only works when the program is already running since that dialog shows all threads from the running JVM.

Debugging and counting breakpoint hits

Sometimes when I examine a code I didn’t write, I launch eclipse in debug mode and use figures to understand a program. For example, if they are n items retrieved from the DB, it can be interesting to know that there’re n processed items in a service, etc.
When loops are used, things get more complicated: if we’re in a “while” loop, the number of execution is not defined and if there are alternatives, the flow of execution can greatly change.
For this purpose, I sometimes set a breakpoint in a portion of code and count how many times we reach it.
Of course, it’s not very convenient and I wonder if there is a way to count the number of breakpoint hits. I know that Eclipse can suspend execution after a fixed number of hits but I just want Eclipse to count them in a normal flow of execution.
I’d be glad to hear your opinions about it.
Thanks!
You can add a condition into your breakpoint. The simplest one could look something like this:
System.err.println("Passing checkpoint");
return false;
You can also extend it by calling your own static class:
org.foo.StaticCounter.COUNTER++;
System.err.println("Passing checkpoint " + org.foo.StaticCounter.COUNTER);
return false;
As an alternative to counting breakpoints, you could use a profiling tool, such as the one here.

How do I write to the Netbeans Debugger Console (in Java)?

Netbeans has a tabbed window in the Output section called "Debugger Console". Is it possible to write a message to this window using Java? If so, how?
The messages you see in the debugger console are either
informations given by the debugger itself (breakpoint added, for example)
custom messages associated with a breakpoint
When you add a breakpoint to a line of code, the default behavior of the breakpoint is to suspend the thread that executed the line of code, and to print the text "Breakpoint hit at line {lineNumber} in class {className} by thread {threadName}.".
You can configure a breakpoint to print a custom text. This text will be output in the debugger console when it reaches the breakpoint. To do so, right click on a breakpoint, open the propoerties window, and enter your text in the field Print text.
A useful trick is to configure a breakpoint so that it does not block (suspend : no thread), and to enter a text. The effect is the same than adding println lines in your code, but the benefit is that you don't have to recompile the code, and it's easier to activate/deactivate these debugger logs (and it obviously does not stay on production code).
Note that, in the text of the breakpoint, you can use one of the special values {lineNumber}, {methodName}, {className} or {threadName}, and you can also evaluate some code with the syntax {=xxx}. Just replace xxx with a variable name, or a method call, or whatever.
OK for me it's in Output > Glassfish server 3+ Console
I wrote a simply System.out.println in my program and when the debugger arrive on this instructions the console diplay the result of my simply writing.
For others situation I don't know

Categories

Resources