How do I debug an applet?
Right now, you most likely can't debug a Java Card applet at source level, because the Java Card Virtual Machine you're working on doesn't support the Java Platform Debugger Architecture (JPDA) and thus cannot be controlled by your favorite debugger. It looks like the Java Card community has acknowledged this problem and is taking steps to improve the situation (hopefully).
In the meantime, what can you do? Here are a few tips:
- Code more carefully: Java Card is an embedded environment and you really have to be much more cautious, so stay focused!
- Try to run most of your code in Java land, not in Java Card land. This way, you can easily debug your application logic and then run it safely on Java Card.
- When running on the card, use ISOException.throwIt((short)((short)0x9000+myValue)) to inspect a variable.
- If your simulator provides access to the bytecode executed by the Virtual Machine, you can really see a lot of what's happening. Go to the Java Card 2.1.1 Virtual Machine Specification for the meaning of each bytecode instruction. It's just like debugging assembly language!
- If you think you've stumbled upon a platform bug, there's nothing you can do unless you have an emulator, mask sources, etc. Go bug (pun not intended) whoever has that.