Is there any way to get a map or other data structure of the local variables in the current scope in on the JVM without using a debugger? That is, to get the locals of the current stack frame?
I know that there are stacktrace objects, but StackTraceElement has no way to get access to any state. It just tells you what method was called where, but not what was in it.
Variable names can be included in class files to aid debuggers, but
javacdoesn’t do it by default. It requires the-g:varsoption.If it’s present, a program could use a byte-code engineering library like ASM to access the local variable names and scope.
While this question is poorly phrased, I think it is a duplicate, and its answers may be relevant to your problem. I would add that if you don’t care about the names, the local variable type and scope are always included in each method’s attribute table.