Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging in Android Studio... off by a line?

Something has been bothering me for awhile, and I'm wondering if I'm misremembering how things work or if something is wrong with my IDE setup.

Say I have a method

    public void normalDebuggerBehavior(String x) {
(BP)    int y = 12;
        int z = 10;
    }

If I set a breakpoint on the first line of the method (BP), and the debugger stops on that breakpoint, shouldn't I be able to see the value of the passed parameter x without needing to step to the next line (int z = 10) either by right-clicking -> evaluate expression or by adding it to the watchlist? I would think this would be in scope at this point.

If I'm not able to do this, and I'm supposed to be able, what would cause this?

Screenshot: variable not in scope

Stepping to the next line brings vendor into scope. Yes, this is a "fresh" compile.

like image 595
loeschg Avatar asked Oct 14 '25 19:10

loeschg


1 Answers

Debuggers run on bytecode and not on Java source code. The mapping between Java source and bytecode is not always one-to-one.

When you place a breakpoint on the first line of a method, it is placed on the method entry point in the bytecode. The bytecode that actually reads in the method parameters has not been executed yet. You can observe this by looking at the bytecode disassembly and noticing the aload instructions at the beginning of a method with parameters.

like image 73
laalto Avatar answered Oct 17 '25 07:10

laalto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!