
This week my goal was to develop a prototype debugger that establishes a connection with the running android device and watch a variable.
The java mode of the PDE already has a debugger built for it that uses the JDI (Java Debugger Interface) package present in the ECJ (Eclipse Compiler for Java). After having a read and understanding the code for the debugger I came to a conclusion that this code can be reused for the android-mode Debugger with the changes being in the code to connect to the running device. Android devices are also Java Virtual Machines (JVM) so I could achieve this by using JPDA.
Steps followed to establish a connection :
Run a debuggable application on android device
Connect it using Android Debug Bridge (ADB)
Forward the application to a specific TCP port using its JDWP port
Connect to this port using the JDI classes and connectors (Socket Attaching)'
Once the connection was established I proceeded to the next goal -> Adding a watch i.e. listening to changes in the value of any variable in the debuggable code.
Steps for adding a watch :
Use EventRequestManager class to add a ClassWatch and a FieldWatch
Check for useful events in a thread. If a WatchPoint event is encountered a log is displayed
With this the prototype debugger is complete and running.
Github link : https://github.com/manav-mj/DebuggerTest
Reference :
~ http://illegalargumentexception.blogspot.com/2009/03/java-using-jpda-to-write-debugger.html
~ http://www2.sys-con.com/itsg/virtualcd/java/archives/0603/loton/index.html#s1
Comments