How to enable ILOGV statements in the Android source code?

时间:2016-08-31 17:56:15

标签: android dalvik

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?

1 个答案:

答案 0 :(得分:0)

如果启用这些ILOGV语句,您将获得大量的日志垃圾邮件。设备上的每个进程都会为每个执行的dalvik指令打印一条消息给logcat。

如果我这样做,我会采取不同的方法。我会使用像ptrace之类的东西从进程中提取dex文件,然后在其上运行baksmali。

但如果您真的想要启用它,那么很容易找到ILOGV is defined的位置。如您所见,ILOGV仅在定义LOG_INSTR符号时启用。另一个快速搜索显示文件中较早的handy #define statement for LOG_INSTR已注释掉。

看起来您应该能够取消注释并重新编译dalvik,以便生成您似乎想要的疯狂大量的垃圾邮件。

请记住,dalvik有different interpretersportable c interpreterarch specific interpreters等等。因此,您需要了解设备上使用的解释器,并确保修改正确的解释器 - 或者只修改所有解释器他们。例如。通过修改公共header.cpp并运行rebuild.sh来重新生成各种解释器。