用的Andr​​oid采用了waitForDebugger加多宝混乱 [英] Android with jdb confusion using waitForDebugger

查看:353
本文介绍了用的Andr​​oid采用了waitForDebugger加多宝混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的设备(Nexus One的 - 而不是仿真器)上调试我的Andr​​oid应用程序,使用命令行

I'd like to debug my Android application on my device (Nexus One - not the emulator) using the command line.

我很困惑如何设置结合使用加多宝断点与 android.os.Debug.waitForDebugger

I'm confused at how to set a breakpoint using jdb in combination with android.os.Debug.waitForDebugger.

说我把下面的code在我的主要活动的onCreate

Say I put the following code in my main activity onCreate:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    android.os.Debug.waitForDebugger();
    int j = 10;
    int r = j;
}

使用 DDMS 我可以看到我的申请正在等待调试器(红色错误图标),当我开始吧。

Using ddms I can see that my application is waiting for the debugger (red bug icon) when I start it.

不过,我不知道如何在了waitForDebugger()通话后设置一个断点,这样我就可以开始加强。

However, I don't understand how to set a breakpoint after the waitForDebugger() call so that I can start stepping.

显然只是附加加多宝将会立即继续不停止运行的应用程序。

Obviously just attaching jdb is going to immediately continue running the app without stopping.

例如。

jdb -attach localhost:8700

有没有办法preSET断点运行之前加多宝或方式开始加多宝设置断点再附上?

Is there way to preset breakpoints prior to running jdb or a way to start jdb set breakpoints and then attach?

推荐答案

不幸的是,没有办法让虚拟机来告诉它已经暂停调试器。各种调试器我已经试过感到困惑,如果初始状态是什么,除了跑。其结果是,在调试器连接之后,VM具有恢复所有线程。 (如果虚拟机刚启动的唯一例外上面,在这种情况下,它可以发送一个特殊的我刚刚开始的消息,表示无论是要来了运行还是留暂停。这不利于在这里。)

Unfortunately, there is no way for the VM to tell the debugger that it's already suspended. The various debuggers I've tried get confused if the initial state is anything other than "running". As a result, after the debugger connects, the VM has to resume all threads. (The only exception to the above is if the VM was just started, in which case it can send a special "I just started" message indicating whether it's going to come up running or stay suspended. This doesn't help here.)

什么了waitForDebugger()不会做的是等待,直到活动的初始突发的调试平静下来了。调试器连接后,该方法将一觉睡到一直没有从调试程序的活动1.5秒。这使得调试器有机会设定任何断点的虚拟机恢复之前。

What waitForDebugger() does do is wait until the initial burst of activity from the debugger quiets down. After the debugger connects, the method will sleep until there has been no activity from the debugger for 1.5 seconds. This allows the debugger a chance to set any breakpoints before the VM resumes.

对于Eclipse,这个技巧的作品了pretty的好,因为您可以将之前你可以配置你的断点。对于加多宝,有没有办法,我可以看到,告诉后,已启动了它附着,所以你必须要在键盘上快速或使用某种类型的配置文件中(这也是我没有看到)。

For Eclipse, this hack works out pretty well, because you can configure your breakpoints before you attach. For jdb, there's no way I can see to tell it to attach after it has started up, so you have to be quick on the keyboard or use some sort of config file (which I also don't see).

您可以解决这个问题以不同的方式:下面了waitForDebugger电话加入一个循环,如:

You could solve this a different way: below the waitForDebugger call, add a loop like:

static volatile boolean staticField = false;
  ...
while (!MyClass.staticField) {
    Log.d(tag, "waiting for go");
    Thread.sleep(2000);
}

那么,你有后,加多宝设置你想要的方式,使用类似:

Then, after you've got jdb configured the way you want, use something like:

> set MyClass.staticField = true

如果你快,你可以​​跳过循环,只是视频下载(5000)给自己一点额外的时间来踩住断点

If you're quick, you could skip the loop and just Thread.sleep(5000) to give yourself a little extra time to slam breakpoints in.

这篇关于用的Andr​​oid采用了waitForDebugger加多宝混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆