
Project Goals
Before we dive into the implementation of the project here are the project goals we decided to work on:
Launch an application in debug mode
Creating a connection between the device (Debugee) and PDE (Debugger)
Setting a breakpoint
Implementing Step, Stop, Continue (Code + UI)
Implementation
We decided to break the project into four parts. In the first part we developed a separate prototype written in java, that would connect to the device and would set a watch on a variable and display the changes in its value. (https://github.com/manav-mj/DebuggerTest)
In the second part we integrated the prototype into PDE Android Mode. This included porting java code for the execution as well as adding the UI elements for the debugger. As the UI was already created in the Java Mode and Java Toolbar they were enabled after being inherited.
Moving on to the third part which proved to be the most challenging part for me, we added functionality to the debugger like adding the breakpoints and scrubbed the code by adding new classes. Adding breakpoints required to save the breakpoints when the user sets a breakpoint and then register them with the Java Virtual Machine.
The fourth part of the project was to extend the breakpoint functionality by adding Step, Continue, Stop code and connect it to the UI. This part was comparatively easy as it had already been implemented in the Java Mode, so it worked with some minor changes.
Changes done in existing Classes :
AndroidToolbar[.]java : `stepButton` and `continueButton` are displayed when the debugger is enabled.
AndroidRunner[.]java : It starts the debugger using the `startDebug` function after the app has been launched. It attaches the VM to the device using the `jdi` `AttachingConnector` and stores the VM object connected to the device. It Also closes the VM when debugger is stopped.
Device[.]java : This launches the application in debug mode using `adb`. It also forwards the running device to a TCP port, for the JVM to connect, from the jdwp port.
AndroidEditor[.]java : Creates and holds the instance of the AndroidDebugger.
New classes added :
AndroidDebugger[.]java : Implements all the functionality of the debugger for Android Mode
AndroidLineBreakpoint[.]java : Extends LineBreakpoint[.]java to add some functionality. LineBreakpoint saves the physical sketchClassName (sketch. java) but when a class is in some package its logical name (com.example.sketch. java) is different from its physical name (sketch. java) and in the case of android app the classes are always inside the application package.
Work Product:
Pull Request : https://github.com/processing/processing-android/pull/491
Commits : https://github.com/manav-mj/processing-android/commits/debugger?author=manav-mj
Gitter Room : https://gitter.im/processing-android/GSOC18-debugger
Comments