134

Is it possible to do reverse execution in Eclipse debugger? The current project I'm working on requires a minimum of 5 seconds to read and initialize data from a file before anything can be done. If I overstep in the debugger, I have to terminate the program and restart, and this takes a fair bit of time.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Jason
  • 11,263
  • 21
  • 87
  • 181

6 Answers6

138

You can use Eclipse's drop to frame command to re-enter the current method from the top. But it won't unroll any state changes that have happened, so it may not work depending on the sort of method you're in.

Another really cool tool that actually does let you step back and forward in time is the Omniscient Debugger. It works by instrumenting classes as they're loaded in the classloader, so it can record everything that your code does. It can do very cool things, like answer "when, where, and why was this field assigned its current value?". The UI is rather clunky, and it can have a hard time handling large code bases, but for some cases it can really save a lot of time.

Update: Chronon provides a commercial product that it describes as a "DVR for Java", which appears to do a lot of the same things as the ODB.

Lii
  • 11,553
  • 8
  • 64
  • 88
Matt McHenry
  • 20,009
  • 8
  • 65
  • 64
  • @Matt McHenry I was trying to use ODB1.5; with a standalone java program but I am not sure how to get it to work? Do you have any resources other than ODB site explaining the steps to make it work standalone and with Eclipse? – Ayusman Aug 30 '12 at 23:20
  • @Ayusman: no, I'm sorry, I don't have anything to share beyond what's on the ODB site. I wouldn't be surprised if it doesn't work with newer .class file formats, among other things. :( – Matt McHenry Aug 31 '12 at 03:51
  • Appears the Omnscient Debugger website has been domainsquatted. – Thorbjørn Ravn Andersen Jan 07 '16 at 07:44
47

Beyond what's been mentioned in earlier answers - i.e. Eclipse's drop to frame feature in the debug view, which restarts debugging earlier in the stack frame (but does not revert global/static data) and Omniscient debugger, which is a bit raw and not so much evolving - there are a few Eclipse-based tools that could be used to "go back" in (run)time:

JIVE extends Eclipse Java debugger with the ability to record the program states. The JIVE perspective provides some useful UML diagrams that are updated while the program is running. These diagrams provide an overview of the state of the application (object diagram) and of the stack trace (sequence diagram). You can query the memorized trace and step back and forward in time and see the corresponding diagrams.

Diver only records method calls and does not really record program states like JIVE. Every method call event is stored for later retrieval and analysis. It extends the Java Run and Debug configurations mainly to specify filters. Trace can be paused/resumed/filtered at runtime. Once recorded, the Diver perspective can display it in an interactive sequence diagram.

JIVE and Diver are open source projects issued from academic research. As of November 2012 both projects are active.

Chronon is a commercial product, but they have free licenses for students and open source projects. From what's being claimed on their website it's probably the most comprehensive recorder since it's able to replay the recorded history, step back and forth, allowing as they say time traveling debugging. Also Eclipse isn't needed for recording.

All of these plugin are quite greedy in resources so it's best to have a good spec machine and use their filter feature. A definite requirement to run them successfully is to extend the heap space in eclipse.ini.

In my case I've tried to use JIVE and Diver to debug an XML parsing program but always ended up freezing eclipse due to lack of resources. Diver could be tricky to run on linux 64bit, it works on ubuntu 32bit and possibly other 32bit distros using these tips. Diver works on Windows, better yet on a Windows 64bit + 64bit JVM otherwise you will be limited to a maximum heap space of 1.3-1.6Gb on 32bit windows. JIVE works great on my linux 64bit, and seems to work fine on other platforms.

Community
  • 1
  • 1
fmjrey
  • 1,141
  • 1
  • 10
  • 16
15

Yes, Eclipse CDT has support of historical debugger feature.

Open Debug Configuration -> Debugger -> Enable Reverse Debugging at startup .

Than you can press shift+F5 or shift+F6 for step back like F5 or F6 for step forward.

Sergei Krivonos
  • 4,217
  • 3
  • 39
  • 54
  • 1
    Does this option exist in all versions of Eclipse? I'm danged if I can find it anywhere. – DeejUK Jun 02 '13 at 10:54
  • 1
    Its GDB feature http://sourceware.org/gdb/wiki/ReverseDebug that supported in Eclipse by this https://bugs.eclipse.org/bugs/show_bug.cgi?id=258284 request. Well I suppose answer is yes since 2009. – Sergei Krivonos Jun 02 '13 at 21:16
  • It is accessible in CDT. – Sergei Krivonos Sep 03 '13 at 21:26
  • I'm a Java developer, so I'm guessing CDT won't be much use to me? – DeejUK Sep 04 '13 at 08:18
  • @Sergei I am doing this under WIndows 7 SP1 with an old Springsource version. To enable reverse debugging you must first debug as->Debug Configurations->Main. At the bottom of the page is the process launcher. It will say "Using Standard Create Process Launcher" and there will be a hyperlink to "Select other...". Click this and make sure "Use configuration specific settings" is checked then select "GDB (GSF) Create Process Launcher" and click okay. "Using GDB (GSF) Create Process Launcher" will now be displayed at the bottom of the main tab. – Sammy Oct 15 '15 at 04:29
  • @Sergei Now when you click the the "Debugger" tab a new checkbox is shown "Enable Reverse Debugging at startup (Note: Requires Reverse GDB). Unfortunately when I tried it I got the error "Error in final launch sequence Failed to execute MI command: record" I guess the version of GDB I'm using isn't capable of it. – Sammy Oct 15 '15 at 04:29
  • @Sergei And I have my answer as to why "Error message from debugger back end: Process record: the current architecture doesn't support record function." http://stackoverflow.com/questions/20365117/gdb-error-process-record-the-current-architecture-doesnt-support-record-func – Sammy Oct 15 '15 at 04:34
  • @Sammy Looks like the feature is enabled for Linux gdb build only. Did you try under Ubuntu or other linux based OS? – Sergei Krivonos Apr 02 '16 at 07:47
  • I discovered there are a very small number of operating systems that allow step back. I tried under RHEL 5. https://www.gnu.org/software/gdb/news/reversible.html – Sammy Apr 03 '16 at 09:00
  • @Sammy, I wouldn't made it OS specific. – Sergei Krivonos Oct 13 '16 at 13:31
5

I am biased, but Chronon does exactly what you are looking for.

Drop to Frame isnt exactly stepping back, since if the method has changed anything on the heap it wont be reverted.

pdeva
  • 43,605
  • 46
  • 133
  • 171
  • 1
    Does Chronon allow you to do that in real time? My understanding is that you first need to record a session using chronon and then you can possibly step back in that session. Isnt that as good as restarting the application? Or maybe I am missing something.. – Raam Jul 20 '11 at 05:49
  • 2
    yes you do need to record your application first and can then debug it anytime afterwards from the recording. Its different from restarting the application since you dont need to go through all the steps to reproduce the bug. All you do is record the bug once and then you can look at it anytime you want to debug using only the recording. You dont need any part of the original environment to playback the recording. – pdeva Jul 22 '11 at 22:43
  • Does Chronon work in docker environment? My eclise is not on the local.. – Choi Jun 10 '19 at 11:45
3

I was looking for this feature in eclipse too. I know the visual studio can do that. Actually you can drag the current line marker and drop anywhere back in code. I'm not pretty sure if the changes to variables can be undone. But it is still very useful even so and saves lots of time. I've been waiting for this in eclipse for a very long.

1

The question doesn't specify an Eclipse language, and many of the answers assume Java.

If using C++ and GCC with the GDB debugger, Eclipse has Run->Move to Line which does the job and functions like the Visual Studio Set Next Statement. In this case, Eclipse is using the capability that is in GDB.

If using Java, I'm not aware of a way to it with Eclipse or Netbeans, although other answers have suggested plugins. Eclipse does have the "drop to frame" command which works for Java in my version (Juno SR1). If I modify and save code within a function in debug mode, the execution line automatically moves to the top of the current function and I can continue from there. Not the same as specifying the line, but it is something.

GravityWell
  • 1,547
  • 1
  • 18
  • 22