How do I skip a breakpoint a set number of times in jdb?
jdb's help provides this hint:
!! -- repeat last command
<n> <command> -- repeat command n times
# <command> -- discard (no-op)
When I attempt to skip breakpoints n number of times however, like this:
80 cont
or like this:
80 run
jdb barfs:
main[1] 80 cont
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
Breakpoint hit: main[1] > Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.Exception in thread "event-handler" java.lang.NullPointerException
at com.sun.tools.example.debug.tty.TTY.printCurrentLocation(TTY.java:212)
at com.sun.tools.example.debug.tty.TTY.vmInterrupted(TTY.java:189)
at com.sun.tools.example.debug.tty.EventHandler.run(EventHandler.java:86)
at java.lang.Thread.run(Thread.java:619)
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended开发者_StackOverflow中文版.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
> Nothing suspended.
What is happening here? How can I get the desired behavior?
Version:
> version
This is jdb version 1.6 (J2SE version 1.6.0_16)
Java Debug Interface (Reference Implementation) version 1.6
Java Debug Wire Protocol (Reference Implementation) version 1.6
JVM Debug Interface version 1.1
JVM version 1.6.0_17 (Java HotSpot(TM) Client VM, mixed mode, sharing)
To clarify, I am debugging remotely. For example, my first window starts like this:
% java -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n LZWDecompress
and my second window starts like this:
% jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=8000
Unfortunately, the breakpoints in jdb do not offer any fancy features, such as conditional breakpoints or "stop every n iterations".
However, since you are connecting remotely anyway, you might want to consider using the debugger in your editor, since most editors will let you connect to remote machines. Since most of the debugging work is done in the JVM, and only display is done by the editor, it won't be that much slower than using jdb.
This is not exactly answering your question, but a quick workaround could be to set some global counter variable and do
if(counter>=num_skips)
{counter++;} //set breakpoint on this line
else
{counter++;}
Would using an ide like eclipse or netbeans be acceptable for you?
Both offer hitcounters and other forms of conditional breakpoints.
精彩评论