Skip to content
Advertisement

How to hide variables from Java’s JDI?

I am instrumenting some classes and introducing some new local variables. Now, when the user places a breakpoint in the code, and execution is stopped, the newly introduced local variables can be seen inside Intellij IDEA’s debugger window. How can I hide them?

UPDATE: I will have to somehow remove debug info from the instrumented code, but not sure how to do it.

UPDATE 2: I am using the ASM library for instrumentation.

JavaScript

__my__data__ is shown inside Intellij IDEA.

Advertisement

Answer

https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.13

Based on the JVM specs, you can remove your local variables from LocalVariableTable. Javassist does that automatically in generated code and I cannot see the variable secretCode during the run:

enter image description here

Decompiling the result class can show that there are no LocalVariableTable entries for it:

JavaScript

So when you are instrumenting your class, drop all your local variables from the table (or do not add them).

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement