On Apr 2, 5:02 am, Jesper T <[email protected]> wrote:
> While doing debugging with Eclipse I noted that the debugger
> highlights the wrong line as "next line to execute" for methods with
> multiple return points. It fools the developer that the last line of
> the method is executed, where in fact it is not.
You can view the code and "positions" tables with:
% dexdump -d myapp.apk
Search for your method (DebugProblem1.m). Skip past the instructions
to find the "positions" table, which has pairs of Dalvik instruction
offsets and line numbers. When I do this in a test class that matches
yours I get:
000108: |[000108] Foo.m:(I)I
000118: 1210 |0000: const/4 v0, #int
1 // #1
00011a: 3302 0300 |0001: if-ne v2, v0,
0004 // +0003
00011e: 1200 |0003: const/4 v0, #int
0 // #0
000120: 0f00 |0004: return v0
catches : (none)
positions :
0x0001 line=18
0x0003 line=19
0x0004 line=22
locals :
0x0000 - 0x0005 reg=1 this LFoo;
The code is very simple:
0000 load 1 into v0
0001 if the method argument (v2) does not equal v0, branch to 0004
0003 load 0 into v0
0004 return v0
As you can see, there's only one "return" statement, shared by both
code paths. This is why the debugger leaps around. The situation
could be avoided by adding additional instructions, but that's
generally undesirable.
It's a bit like debugging native code built with "-g -O2". (That
thought inspired me to try it with "dx --no-optimize", but that still
used a common return statement and suffered from the same problem.)
The Java bytecode for this class does have two returns, and would
display correctly in a debugger:
private int m(int);
Code:
Stack=2, Locals=2, Args_size=2
0: iload_1
1: iconst_1
2: if_icmpne 7
5: iconst_0
6: ireturn
7: iconst_1
8: ireturn
LineNumberTable:
line 18: 0
line 19: 5
line 22: 7
Bottom line: this is an artifact of the conversion from Java bytecode
to Dalvik bytecode.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---