Search code examples
androiddalvik

How to enable ILOGV statements in the Android source code?


In Android 4.3 according to the source code documentation, the Dalvik interpreter is located in dalvik/vm/mterp/. But how can I enable the ILOGV statements so I can see the interpreted byte code in assembly code at runtime?

For example, in the InterpC-portable.cpp line #1185, it seems that the assembly code for the move opcode (byte code) is in the ILOGV statement:

ILOGV("|move%s v%d,v%d %s(v%d=0x%08x)",(INST_INST(inst) == OP_MOVE) ? "" : "-object", vdst, vsrc1,
kSpacing, vdst, GET_REGISTER(vsrc1)); 

I just need to enable the ILOGV statement to print its content. By default, ILOGV statements are disabled in the Android source code and I need to enable them.

Update1:

The above code seems to print bytecode but not assembly language code or machine language code. Where to the put the print statement in the Android source code to print the interpreted bytecode (assembly language code or machine language code) just before the CPU executes it?


Solution

  • If you enable those ILOGV statement, you are going to get an insane amount of log spam. Every process on the device is going to print a message to logcat for every dalvik instruction that is executed.

    If I were doing this, I would take a different approach. I would extract the dex file from the process, using something like ptrace, and then run baksmali on it.

    But if you really do want to enable that, it's easy to find where ILOGV is defined. As you can see, ILOGV is only enabled if the LOG_INSTR symbol is defined. Another quick search shows a handy #define statement for LOG_INSTR earlier in the file that is commented out.

    It looks like you should be able to uncomment that and recompile dalvik in order to generate the insanely massive amounts of logspam that you seem to want.

    Keep in mind that dalvik has different interpreters. The portable c interpreter, and arch specific interpreters, etc. So you'll need to be aware of which interpreter is being used on your device, and make sure to modify the correct one -- or just modify all them. E.g. by modifying the common header.cpp and running rebuild.sh to regenerate the various interpreters.