1

I am writing a Java debugger which needs to access operand stack.

Basically, I am trying to record execution trace of a Java program with JPDA (https://docs.oracle.com/javase/7/docs/technotes/guides/jpda/index.html). For each trace step, I would like to retrieve the read/written variables. For the application code, I can analyze the variable expression (e.g., a[i]) to get its runtime value. Nevertheless, when the Java program runs into the library bytecode (without source code), I can only know what Java bytecode is running (e.g., aaload), which makes it hard to get its running value with JPDA.

Does anyone know to retrieve the value in Java operand stack? Thanks!

Yun Lin
  • 11
  • 4
  • Are you mixing up operand stack and local variables? Both reside within the stack frame, but as far as I know, there is no access to the operand stack whether you have the source code or not. The availability of the local variables depends on the presence of the [`LocalVariableTable` attribute](https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.13) in the class file, not the availability of the source code. I vaguely remember having read something about a tool to generate pseudo local variable tables for class files not having them… – Holger Oct 17 '17 at 09:19
  • I do need operand stack for my purpose. I can retrieve the working bytecode by JPDA, e.g., aaload. In the case of aaload instruction, I need to know which array element is being loaded. Without the access of operand stack, I can only conservatively estimate all the elements in an array are read. – Yun Lin Oct 17 '17 at 14:08
  • As said, as far as I know, there is no access to the operand stack through the API. But you may instrument the code to maintain that information in a form you can inspect… – Holger Oct 17 '17 at 16:42
  • Adapting my code from JPDA to instrumentation may take quite a while. But I will still think about your suggestion, thanks. – Yun Lin Oct 18 '17 at 03:31

0 Answers0