Robert Ende
Robert Ende

Reputation: 406

How exactly does Android debugging work and why does my app behave differently when debugging it?

I have an app that decodes an incoming H264 video stream. When I use the app normally, I get visual artifacts when viewing the stream.

The strange thing is, as soon as I start debugging the process, the artifacts disappear! And when I stop debugging (i.e. unplugging the device from the PC) the artifacts reappear again.

That's why I want to know from you experts: How does debugging on Android work and in what way does it change a process' behaviour?

Upvotes: 2

Views: 317

Answers (1)

fadden
fadden

Reputation: 52343

I'm going to assume you're using the Java-language debugger, and not a native debugger like gdb.

When you attach a debugger, Dalvik stops executing JIT-compiled code and runs everything in the interpreter. It uses a less-efficient version of the interpreter that has some extra debugger support, so if you (say) "step over" a method call, and the method throws an exception, you stop. (If all it did was set a temporary breakpoint on the following instruction, you'd never hit it.)

The "debug interpreter" and the regular "portable" interpreter are built from substantially the same source code -- it's the same source files, built twice, with different macro definitions -- so differences in behavior are usually about performance rather than execution.

The JIT compiler generates and executes code natively, so it's quite a bit different. Like the interpreter, it hasn't changed much over the last few years, except for the occasional OEM modification, and is unlikely to be the cause of problems.

The most significant difference between debug and non-debug is performance. Anything with a race condition will behave differently, because you're going from a fast interpreter with JIT-compiled native code to a slower interpreter. Without knowing the structure of your code it's impossible to say if this is the issue, but you can find an overview of SMP on Android here.

Upvotes: 2

Related Questions