Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use F5 to step into function while debugging on Eclipse

Sometimes (about 50% of the times) , while debugging an Android app, in order to step into a function , I use F5 (F6 is for going over it) yet it doesn't do anything

Sometimes, none of the regular debugging keys work (F5,F6,F7,F8, maybe other that i don't know about too).

Currently, the only way to overcome this is to choose the current thread from the "Debug" view (that shows the current stack of each thread) and then press on F5 . When the situation is even worse (unable to use the content assist, for example), I restart eclipse.

Speaking of threads, I've noticed that if I have multiple threads running, sometimes when I try to go further, it goes to another thread and this is annoying as I lose the concentration I had on the current thread. I know it does make some sense, but it's really annoying especially if I've taken into account that there are multiple threads.

Why do those things occur, and how can I fix them?

Note: I have the latest version of both Eclipse, ADT and the Android SDK . the problem occurs on both devices and emulators.

like image 210
android developer Avatar asked Mar 06 '13 21:03

android developer


People also ask

Why is step in Eclipse disabled?

Sounds like you don't have any breakpoints set. The functions to step will only be available if code is suspended. The debugger will execute code until it hits a breakpoint or the end of the program. If you don't have any breakpoints set then it will just execute it until the end of the program.

How do I fix debugging in Eclipse?

A Java program can be debugged simply by right clicking on the Java editor class file from Package explorer. Select Debug As → Java Application or use the shortcut Alt + Shift + D, J instead.

What is the use of F5 F6 F7 F8 in debugging Eclipse?

To control execution use the Step Into, Step Over and Step Return buttons. They have the shortcuts F5 , F6 and F7 respectively. To allow execution to continue normally or until it hits the next breakpoint, hit the Resume button or F8 .

How do you step through a breakpoint in Eclipse?

Use F5 to trace into, F6 to step over, CTRL-SHIFT-B to set/remove breakpoints.

How do I enable debugging in Eclipse?

Starting the Debugger. To debug your application, select a Java file with a main method. Right-click on it and select Debug As Java Application. If you started an application once via the context menu, you can use the created launch configuration again via the Debug button in the Eclipse toolbar.


3 Answers

You can't control the execution pattern of threads as they don't run in sequence, but debugger does.

I have faced similar issues with threads and async operations that run in the background.

How I manage it:

  • What I do is run the same code without thread and after confirmation I put that in thread
  • Use android.os.Debug.waitForDebugger(); in your thread. It will automatically bring you there and force the debugger to halt here. There onwards you can carry on with your debugguing.

Precautions

Don't forget to comment this line before launching the application, otherwise it will result in endless waiting as it will go to debug mode in real device also.

Moreover its not the fault of Eclipse, it's purely because of nature of threading as it starts getting executed in its own environment. Visual Studio behaves the same with threads.

like image 91
DeltaCap019 Avatar answered Oct 19 '22 11:10

DeltaCap019


You might try to reset your perspective (just in case you moved something without wanting to).

This can be accomplished in the Debug perspective by:

  1. Right-clicking the Debug Perspective (upper right "zone" of Eclipse) and choosing "Reset"

  2. Switching to the Debug Perspective and clicking the menu Window->Reset Perspective...

like image 2
DigCamara Avatar answered Oct 19 '22 10:10

DigCamara


Sometimes, none of the regular debugging keys work (F5,F6,F7,F8, maybe other that i don't know about too).

None of these keys will work in a view other than the debug view. It is by design.

When the situation is even worse (unable to use the content assist, for example), I restart eclipse.

You have a buggy eclipse installation or a faulty keyboard. I'm positive of it after reading your other comments. I've had plugins mess up my eclipse installation and can relate with this. Make sure your eclipse code window has focus before trying the shortcuts. That could contribute to the problem too. If all else fails try moving to another version of eclipse to try and isolate the problem.

I had this weird bug for eclipse for a while where when I press the backspace key, it deletes characters on a previously opened file on the same line. It was horrific and I had to reinstall and move to another version of eclipse (I cannot recall what the previous version was). May be your situation is similar.

Speaking of threads, I've noticed that if I have multiple threads running, sometimes when I try to go further, it goes to another thread and this is annoying as I lose the concentration I had on the current thread.

I know the pain. Unfortunately there is no way to get around it. Eclipse does not consider the priority of a breakpoint while suspending threads. Take a look at this related question - How to deprioritize Java testrunner in Eclipse breakpoints?. If you can setup conditional breakpoints to prevent the debugger from moving to the other thread, that will help.

like image 1
Deepak Bala Avatar answered Oct 19 '22 10:10

Deepak Bala