1

I am using Android Studio IDE (v1.5.1) and its Gradle debugger to step thru my Java application. I can single-step, step-over, step-out, break, set breakpoints etc., but I cannot find a way to manually set the next instruction/statement to be executed or alter the execution flow.

An example of this feature is Visual Studio's "Set next statement" under the DEBUG menu. Another example is MSDOS's g =address where you can specify the next instruction to be executed.

Does the Android Studio Debugger provide a means to change or specify the execution point of the target application?

Morrison Chang
  • 11,691
  • 3
  • 41
  • 77
Rod Dewell
  • 840
  • 1
  • 7
  • 18
  • You may be looking for a feature called Instant Run and is still in preview for Android Studio 2.0. See: http://tools.android.com/tech-docs/instant-run – Morrison Chang Feb 04 '16 at 21:33
  • Instant Run is more like an incremental compile feature as best I can tell. It allows you to switchout modules dynamically which is kool but not the same as modifying the instruction flow. For example, in the case of an if-else statement, I would like to ignore the results of the if condition and select the block of code to be executed manually. – Rod Dewell Feb 05 '16 at 19:14
  • Realized what you were looking for later. I believe not possible in Java (and ergo Android) based on this SO post: http://stackoverflow.com/questions/1651379/moving-the-instruction-pointer-while-debugging-java-in-eclipse – Morrison Chang Feb 05 '16 at 19:21
  • You are right. This post refers to the same issue/feature. And the comments on that post are also relevant. So I guess the answer to my question is NO. Anyone who is reading this post might want to review the comments of http://stackoverflow.com/questions/1651379/moving-the-instruction-pointer-while-debugging-java-in-eclipse. Thanks. – Rod Dewell Feb 05 '16 at 22:28

1 Answers1

1

While this is not possible, I usually workaround in the case of simple blocks of code that I might want (or not) to jump.

First you catch the block in a if statement:

       int foo = bar.toFoo();
       ...
       boolean doThis = Boolean.TRUE;
(B)    if (doThis) {
          ...
          // stuff that I might want to jump
          ...
       }

Here (B) is a breakpoint. Now when it is reached, I just click Evaluate expression and, if needed, evaluate doThis = false;.

One might argue that a decent compiler should get rid of doThis, but it actually works in Android Studio 1.5, probably thanks to Boolean.TRUE instead of true.

If willing to, Evaluate expression will also let you execute full blocks of code while stuck at the breakpoint.

natario
  • 24,954
  • 17
  • 88
  • 158
  • Thanks. I'll give this a try. – Rod Dewell Feb 05 '16 at 22:31
  • The short answer to this question is NO. You cannot modify the execution point freely as with other programs. This answer at least provides a method of allowing a manual change in execution flow at a specific breakpoint. – Rod Dewell Jul 07 '20 at 14:34