Android的Studio调试器突出错误行突出、错误、调试器、Android

2023-09-06 01:17:07 作者:[]~就风⌒饮酒

我看不出什么功能错在什么被执行条款,但我只是浪费了一个小时,证明我的code和编译器正在做什么,他们应该。

I can't see anything functionally wrong in terms of what gets executed, but I've just wasted an hour proving my code and the compiler are doing what they're supposed to.

考虑这个code:

public int getAnswer(int a) {

    int retval = 18;

    int x = 25;
    int y = 50;

    while (a-- > 0) {
        if (a == 3) {
            retval = a;
            return retval;
        }
    }

    x = 10;
    y = 20;

    return 0;
}

调用方式

int theAnswer = getAnswer(6);

断点既包含返回和运行code之前,尝试和predict的结果,所以这行会被打线。

Breakpoint both of the lines containing return and before you run the code, try and predict the result, and therefore which line will be hit.

正如你可能想象,从我的问题的基调,错线被突出显示,但正确的返回结果。如果通过code步骤,它周围的舞蹈颇有几分。

As you might imagine from the tone of my question, the wrong line is highlighted, but the right result is returned. If you step through the code, it dances around quite a bit.

有没有什么可以配置不同使得正确的行显示? (我使用的是最新的Andr​​oid工作室,我AP preciate可能是不稳定的,但我敢肯定我见过类似的行为在Eclipse上一段时间回来,但我从来没有花的时间,然后跟踪下来,也许这是一个java的东西)。

Is there anything that can be configured differently such that the correct lines are displayed? (I'm using the latest Android Studio, which I appreciate is potentially unstable, but I'm sure I've seen similar behaviour on Eclipse a while back but I never spent the time then tracking it down; perhaps it's a java thing).

推荐答案

这是DX,这是一个将你的Java的.class文件转化为包装成安卓.dx文件生成的部分问题。根据这样的:

This is a problem with dx, which is the part of the build that turns your Java .class files into .dx files for packaging into Android. According to this:

https://$c$c.google.com/p/android/issues/detail?id=34193

如果一个函数有多个返回路径,DX合并返回指令到一个单一的返回指令,所以在调试过程中,调试器无法分辨出哪行回归属于事物四处跳动。通过它的若(a == 3)检查,跳转到返回0 结尾,然后再跳回循环。你看到的最后一个返回0 获得与合并了返回RETVAL 在循环的中间。

if a function has multiple return paths, dx merges the return instruction into a single return instruction, so during debugging, the debugger can't tell which line a return belongs to and things jump around. This corresponds to what I see when I try to reproduce your problem: each time through the loop it does the if (a == 3) check, jumps to the return 0 at the end, and then jumps back into the loop. You're seeing that last return 0 get merged with the return retval in the middle of the loop.

我怀疑这会尽快解决的任何时间,所以你可能只需要学会适应它。对不起,我知道这有点疯狂。

I doubt this will be fixed any time soon, so you may just have to learn to live with it. Sorry, I know it's kinda crazy.