How to properly set a breakpoint in a nested class using JDB?

2.4k Views Asked by At
package com.android.internal.telephony.dataconnection;

public abstract class DcTrackerBase extends Handler {
    protected BroadcastReceiver mIntentReceiver = new BroadcastReceiver ()
    {
        @Override
        public void onReceive(Context context, Intent intent)
        {
            String action = intent.getAction();
            if (DBG) log("onReceive: action=" + action);
[...]

In the above code, using jdb, I'd like to set a breakpoint on the onReceive method. I used the following command :

> stop in com.android.internal.telephony.dataconnection.DcTrackerBase$mIntentReceiver.onReceive

And I get this from jdb :

> Deferring breakpoint com.android.internal.telephony.dataconnection.DcTrackerBase$mIntentReceiver.onReceive.
It will be set after the class is loaded.

I know that the class is already loaded, so I imagine that jdb is not finding the method I want. How should I set my breakpoint then ?

2

There are 2 best solutions below

0
On BEST ANSWER

The wrangled method name is wrong.

In JDB, issue this command to inspect the DcTrackerBase class :

> class com.android.internal.telephony.dataconnection.DcTrackerBase
Class: com.android.internal.telephony.dataconnection.DcTrackerBase
extends: android.os.Handler
subclass: com.android.internal.telephony.dataconnection.DcTracker
nested: com.android.internal.telephony.dataconnection.DcTrackerBase$1

As we can see, the nested class DcTrackerBase$1 could be our BroadcastReceiver class. To verify, issue the following command :

> class com.android.internal.telephony.dataconnection.DcTrackerBase$1
Class: com.android.internal.telephony.dataconnection.DcTrackerBase$1
extends: android.content.BroadcastReceiver

That's it ! To set the breakpoint properly, we type :

> stop in com.android.internal.telephony.dataconnection.DcTrackerBase$1.onReceive
Set breakpoint com.android.internal.telephony.dataconnection.DcTrackerBase$1.onReceive
0
On

You are creating an anonymous class when you override the onReceive like in the above code. This should create a class with a name in the form DcTrackerBase$(a number) depending on how many other anonymous/inner classes you have in DcTrackerBase.java file. I wrote an example to replicate your problem.

public class DebugFun{

    public static void main(String[] args){
        Object myObj = new Object(){

            public String toString(){
                int x = 1;
                x++;
                return "X is:"+x;               
            }
        };
        System.out.println(myObj);

    }


}

Then call

jdb DebugFun

to start the debugger then:

stop in DebugFun$1.toString
run 

And now the debugger is inside the internal class.