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);
[...]
在上面的代码中,使用 jdb
,我想在 onReceive
方法上设置断点。我使用了以下命令:
> stop in com.android.internal.telephony.dataconnection.DcTrackerBase$mIntentReceiver.onReceive
我从jdb
得到这个:
> Deferring breakpoint com.android.internal.telephony.dataconnection.DcTrackerBase$mIntentReceiver.onReceive.
It will be set after the class is loaded.
我知道该类已经加载,因此我想 jdb 没有找到我想要的方法。那么我应该如何设置断点呢?
争论的方法名称错误。
在 JDB 中,发出以下命令来检查DcTrackerBase
类:
> 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
如我们所见,嵌套类DcTrackerBase$1
可能是我们的BroadcastReceiver
类。要进行验证,请发出以下命令:
> class com.android.internal.telephony.dataconnection.DcTrackerBase$1
Class: com.android.internal.telephony.dataconnection.DcTrackerBase$1
extends: android.content.BroadcastReceiver
就是这样!要正确设置断点,我们键入:
> stop in com.android.internal.telephony.dataconnection.DcTrackerBase$1.onReceive
Set breakpoint com.android.internal.telephony.dataconnection.DcTrackerBase$1.onReceive
当您覆盖 onReceive 时,您正在创建一个匿名类,如上面的代码所示。这应该创建一个名称为 DcTrackerBase$(一个数字)的类,具体取决于您在 DcTrackerBase.java 文件中有多少其他匿名/内部类。我写了一个示例来复制您的问题。
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);
}
}
然后打电话
jdb DebugFun
然后启动调试器:
stop in DebugFun$1.toString
run
现在调试器位于内部类中。