2

Is there a way to set inline breakpoints (with a plugin) in the Eclipse IDE?

For example when multiple methods are called in the same line, is there a way to set a breakpoint for a specific method call in that line and not for the complete line?

foo(bar(), baz());
           ^

(In this example it would be possible to set a breakpoint at the definition of the method baz, but if it is called by other methods as well, then it might be annoying if you have to continue most of the time.)

If I understand it correctly, the Java Debug Interface would allow this, see Location#codeIndex().

Marcono1234
  • 5,856
  • 1
  • 25
  • 43

1 Answers1

1
foo(bar(), 
    baz());

The easiest way to do this is to do a line break before baz() and place your breakpoint as normal on the line baz() is found on. In Java, surrounding a method call with a line break in this way, will not impact its evaluation.

screenshot from eclipse

Update:

OP wants to select the invocation of baz and make a breakpoint on the evaluation of that expression itself without any extra conditions on your breakpoint or editing of the source code.

As far as I know that is not possible with the standard debugging tool shipped with Eclipse.

However, you can achieve this effect using conditional breakpoints. In Eclipse, you make or select a breakpoint as normal, then access the conditional options in the Breakpoints View.

Access Breakpoint View through the menu item Window -> Show View -> Breakpoints. Once there, select or create your breakpoint, then check the conditional option. Then you must describe a conditional that suits your surrounding code and needs. Your breakpoint will trigger when the conditional is true. For example, by specifying the call-site line number or method name.

Breakpoints View in Eclipse, with conditionals enabled

I based my answer on this SO answer.

In my own example code I have the following setup:

a(){
  baz(); 
  m();
}

m(){
  foo(bar(), baz());
}

and my breakpoint is positioned in baz(). Adding the conditional statement

Thread.currentThread().getStackTrace()[2].getMethodName().equals("m")

to my breakpoint means that it triggers only when baz() is called from m(), not from a().

AnnaME
  • 24
  • 4
  • Yes thank you, that would work, but in this specific case I would like to not have to change the source code just to be able to debug it better. – Marcono1234 Nov 01 '18 at 22:45
  • You may be able to do what you want with conditioned breakpoints. Here is a [link](https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fbreakpoints%2Fref-condition_option.htm) to the documentation: in general you go to the menu Window-> Show View -> Breakpoints, make a line breakpoint as normal, either on your foo(bar(), baz()) -line or inside of baz(), and describe a suitable condition for it to trigger. It is impossible to me to give you further suggestions on the conditions without more information about your program. – AnnaME Nov 02 '18 at 17:07
  • Thank you very much. These workarounds are good, but I am looking for a general solution for the described problem. Therefore I don't have specific code to share, it could apply to any, but it is also not a problem for me if there is (at the moment) no direct solution for this. – Marcono1234 Nov 02 '18 at 21:57
  • 1
    Let me make sure I understand you correctly: you want to select the invocation of baz and make a breakpoint on the evaluation of that expression itself without any extra conditions on your breakpoint or editing of the source code? As far as I know that is not possible with the standard debugging tool shipped with Eclipse. However, using conditionals you can do that, and write your [conditions against the surrounding code](https://stackoverflow.com/questions/14381446/conditional-breakpoint-by-caller-in-java-eclipse), for example, by specifying the call-site line number or method name. – AnnaME Nov 02 '18 at 22:21
  • Yes that is exactly what I am looking for. I guess your workaroud is close enough, would you mind writing it in a separate answer or updating your existing one? – Marcono1234 Nov 03 '18 at 18:36