Is it possible to debug an already running Java program in Eclipse?

I ask if the following steps can be taken in the following order:

  • Running as ... Java Application
  • Let the program run until it reaches the point I want to debug
  • Debug this program when it reaches this point.

The reason I run the program using "Run from ..." rather than "Debug as ..." is because the program freezes at some point (I suspect an infinite loop), but I cannot repeat it in sequence. I mean, I can make it hang sequentially, but this happens in random cases.

For what it's worth, my program is a game, and it hangs at different points in the game, so I canโ€™t be sure where to put a breakpoint, so it would be great if I could start it first and then switch to debugging at a point, where it hangs / loops.

+4
source share
6 answers

Why don't you just run your program using "Debug As ..." without setting a breakpoint. Then, when it freezes, switch to the Eclipse debugging perspective and pause your program using the double vertical bars button?

+9
source

If you always run it using "Debug As ...", you can pause execution if the program freezes. This will open the debugger and allow you to check the running threads.

+5
source

You can use the Remote Java Application functionality in eclipse to join a Java virtual machine. When starting the application, you need to add additional parameters:

-Xdebug -Xrunjdwp: transport = dt_socket, address =, server = y, suspend = n

You can do even more here: http://blog.javachap.com/index.php/debugging-in-java/

+1
source

Perhaps you can add a debug log to determine where it hangs.

The best way to register it in a file so that it is in theory. System.out.println ("before some code"); some code that may be problematic System.out.println ("after some code");

When you see that โ€œafter some codeโ€ is not reached, you know that it hangs in front of this part. Or, if you use log4j, do some time-stamped debugging information with log4j, then you can come closer and add additional debugging information closer to where it hangs, and you will eventually find out where to put a breakpoint and execute code through code.

0
source

In addition to solutions that suggest not setting any breakpoints, you can also learn how to attach a java debugger to a running program.

There is a basic explanation of how this happens with InformIT .

A quick google search gave this tutorial on how to do this using eclipse.

If I remember correctly, you must run your program with additional parameters in order to allow attachment - this can be a problem if your program is completely frozen, as this may prevent the connection from working: check fooobar.com/questions/142665 / ... for more information.

This will actually launch your application in debug mode, but you can delay adding a debugger until you need it.

0
source

"Run As" never picks breakpoints and therefore does not stop at the place where you want to debug, and so the answer to your question is no. But point number 2 in your question contradicts your statement in the paragraph below, in which you explain why you decided not to use 'debug as'. If you donโ€™t know where the program hangs, how can you run the program until it reaches the point you want to debug? (point number 2).

I would debug it using 'debug as' as @Nicola Musatti pointed out

0
source

Source: https://habr.com/ru/post/1485786/


All Articles