This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Debugging in Java

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I have one application on which debugging it little difficult and every i debug i need to put System.out.println to get the call stack.

So is it possible during one operation what all java api in what all java classes it is passing through ???

e.g
I have a Test class which has main method() and it goes Via Class A ,B, C, D, E and finally to F , In this duration i want to find out
all the api it passed through.

Help would be greatly appreciated.

--Subrata Saha

 
Marshal
Posts: 65089
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not quite sure I understand the question; maybe the easiest thing is to use an IDE like Eclipse and use its debugging capcaities.
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use AspectJ aspects to inject logging into every method in your app. Search for AspectJ logging. Takes about 2-3 hours to learn aspectj basics.
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're not currently using an IDE, then the easiest way to get debugging capabilities would probably be to run the application in a debugger like JSwat.
 
Subrata Saha
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Eclipse for 6 years,its quite easy to debug there. But what if your application runs only on suppose Ipad.

so you have one application and that has suppose 15 java class and when press one submit button it goes through all 15 claases
and finally does something.

My question is ,
Is it possible to get the call stack for all classes (and what api it went through)???
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Write your application classes and build them. Apply an aspect which advices System.out.println() at method entries and exits. You can decide which classes need it by writing an appropriate pointcut.

So if your app call is something like
A.meth1
B.meth2
C.meth3,

you'll get a trace like
Entering A.meth1
Entering B.meth2
Entering C.meth3
Exiting C.meth3
Exiting B.meth2
Exiting A.meth1

on the 'console' of the iPad.

Is this what you're looking for?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are not able to debug remotely (and I'm pretty sure you're not running Java applications on an iPad, and if you are, don't let Apple see you're violating their license) then you can either instrument your code with AOP as Karthik suggested, or if you just need to do it under extraordinary circumstances just throw and catch an exception, and print its stack trace.
 
Subrata Saha
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Karthik Shiraly wrote:Yes. Write your application classes and build them. Apply an aspect which advices System.out.println() at method entries and exits. You can decide which classes need it by writing an appropriate pointcut.

So if your app call is something like
A.meth1
B.meth2
C.meth3,

you'll get a trace like
Entering A.meth1
Entering B.meth2
Entering C.meth3
Exiting C.meth3
Exiting B.meth2
Exiting A.meth1

on the 'console' of the iPad.

Is this what you're looking for?


Exactly , this wat i want . But let me google how to write aspect to do this. FYI my jre 1.3 as the device i am working on have memory constraints so we are using java 1.3 .

Thanks again for your help.
Bye the way if you have small example to do the above Please send me @ saha.subrata@gmail.com
 
Subrata Saha
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Karthik Shiraly wrote:Yes. Write your application classes and build them. Apply an aspect which advices System.out.println() at method entries and exits. You can decide which classes need it by writing an appropriate pointcut.

So if your app call is something like
A.meth1
B.meth2
C.meth3,

you'll get a trace like
Entering A.meth1
Entering B.meth2
Entering C.meth3
Exiting C.meth3
Exiting B.meth2
Exiting A.meth1

on the 'console' of the iPad.

Is this what you're looking for?



One more thing to remember is that i dont know in advance how many class and api it will go through.
So as you said
A.meth1
B.meth2
C.meth3
So i dont know from advance that it has 3 java class to finish the api call once started.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need that info at all.

Easy way: Apply the aspect to all classes and methods before deploying. It'll be the simplest pointcut. But it could affect your app performance since this is System.out.println(). Personally, I'd prefer a logger like log4j or java logging.

Harder way: Apply aspect to selected important classes and methods. It'll perform better, but the pointcut will be more complex (and needs to be maintained in sync with code changes in your app).

If you have some plugin concept or something like that, then those plugin classes need to be adviced as well, if you want their traces.
 
Subrata Saha
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks I will try that.
 
Campbell Ritchie
Marshal
Posts: 65089
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No longer a "beginning" topic. Moving thread.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!