10

typically I set a breakpoint in my Java application when I want to observe the run.

However sometimes I just want to know if a method is called or not. Therefore a breakpoint does not help me, and I insert a "systrace" statement System.out.println("method signature");

I thought it would be a nice feature If I could set a breakpoint and when the breakpoint is reached to just print out the systrace message and continue the run.

Do you know if this is possible?

7
  • 1
    Why not you set a breakpoint in that method?
    – Tony
    Commented Jul 15, 2014 at 11:23
  • As @Tony said why don't you place a breakpoint in or on that method? If you place the breakpoint on the method signature it will be executed whenever that method is called independent of the line or whether there are other debug instructions in the code or not.
    – Thomas
    Commented Jul 15, 2014 at 11:28
  • 1) I don't want the program to stop
    – matthias
    Commented Jul 15, 2014 at 11:36
  • 2) I don't want to manually insert code
    – matthias
    Commented Jul 15, 2014 at 11:37
  • @Thomas Sorry, but I don't know 'other debug instructions'. Any tutorial?
    – Tony
    Commented Jul 15, 2014 at 11:53

1 Answer 1

15

You have to make it a conditional breakpoint with a following condition:

System.out.printf(Thread.currentThread().getStackTrace()[1].getMethodName() + "\n") == null

Works fine in my Eclipse. I'm using printf to make printing code evaluate to boolean. Not sure if there's a way to automate inserting this code into a breakpoint.

2
  • Hi, thanks. This is I was looking for. However it would be nice withouth the need of an conditional breakpoint. An option like "print systrace on breakpoint" would be cool
    – matthias
    Commented Jul 15, 2014 at 11:52
  • 3
    not working with eclipse Neon: "operator == is undefined for the argument type(s) void, null". The condition should be System.out.printf(...); return false;
    – user85421
    Commented Jan 12, 2017 at 14:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.