Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print source code flow as program is executed

Tags:

java

debugging

is there a way to print each line of source when the program executes without having to insert System.out.println after each line?

like image 797
afx111 Avatar asked Jul 25 '11 11:07

afx111


3 Answers

Use a debugger. Debuggers provide a number of useful tools to step through your program. Check your IDE, it probably has one.

like image 72
tskuzzy Avatar answered Sep 19 '22 20:09

tskuzzy


First a question: Why would you need that? You might use a debugger if it's just for debugging. If it is for logging purposes, logging each line would be overkill.

Second a suggestion: you might use AOP to log each method call (assignments etc. could not be intercepted), but that might require a lot of work (incorporate AOP into your build process etc.) and might not be worth the hassle.

like image 36
Thomas Avatar answered Sep 20 '22 20:09

Thomas


Eclipse Test & Performance Tools Platform Project has a way to show you a sequence diagram of the program execution:

http://www.eclipse.org/tptp/home/documents/tutorials/profilingtool/profilingexample_32.html

For printing as text, AOP is nice but complicated, debug statements are easiest but most invasive.

like image 21
Christopher Oezbek Avatar answered Sep 19 '22 20:09

Christopher Oezbek