Breakpoints in already-loaded classes don't work #21

Open
opened 2025-08-09 17:12:59 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @fancypantalons on 11/30/2023

I'm not sure if this is new behaviour in ADB, but it appears that the classprepare event doesn't get triggered if the JVM has already loaded a class.

The trouble is that the plugin relies on those events to learn about classes when setting breakpoints. So if you set a breakpoint before you start the debugger, then the event is registered before the class is loaded and everything works fine.

But if you set a breakpoint after the application has started in an already-loaded class, the plugin is never notified that the class exists and so the breakpoint can never be enabled.

I've thrown together a PR that changes this behaviour so that the plugin calls getAllClasses (which doesn't actually appear to be that slow?) if a class isn't known, and only after that fails does it then register for a classprepare event so that the JVM will notify the plugin when the class finally loads.

It all seems to work, both for BPs set before the debugger is started and after its already loaded. Feel free to take a look. To be honest it feels a little hacky, and I'm sure there's a more elegant approach possible, but I'm low on sleep and pretty far outta my depth!

*Originally created by @fancypantalons on 11/30/2023* I'm not sure if this is new behaviour in ADB, but it appears that the `classprepare` event doesn't get triggered if the JVM has already loaded a class. The trouble is that the plugin relies on those events to learn about classes when setting breakpoints. So if you set a breakpoint before you start the debugger, then the event is registered before the class is loaded and everything works fine. But if you set a breakpoint after the application has started in an already-loaded class, the plugin is never notified that the class exists and so the breakpoint can never be enabled. I've thrown together a PR that changes this behaviour so that the plugin calls getAllClasses (which doesn't actually appear to be that slow?) if a class isn't known, and only after *that* fails does it then register for a `classprepare` event so that the JVM will notify the plugin when the class finally loads. It all seems to work, both for BPs set before the debugger is started and after its already loaded. Feel free to take a look. To be honest it *feels* a little hacky, and I'm sure there's a more elegant approach possible, but I'm low on sleep and pretty far outta my depth!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/android-dev-ext#21
No description provided.