Bug 51801

Summary: Eclipse debugger fails on BCEL-instrumented methods having generic local variables.
Product: BCEL - Now in Jira Reporter: Byron Hawkins <byron>
Component: MainAssignee: issues <issues>
Status: NEW ---    
Severity: normal    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description Byron Hawkins 2011-09-12 04:17:32 UTC
When any method is instrumented with BCEL to include additional constants, and the method was originally compiled with local variables that have generic arguments, the method is no longer viewable in the Eclipse debugger. For these methods, it complains "com.sun.jdi.InternalException: Got error code in reply:35 occurred retrieving 'this' from stack frame." It sounds like the local variable table is somehow not compatible with the debugger, even if the instrumentation activity did not touch the generic local variables. 

I'm currently using the 6.0-20110805.040858-2 snapshot. Please let me know if there is any workaround. Thanks!
Comment 1 Byron Hawkins 2011-09-12 06:12:00 UTC
Here is an icky workaround:


        Method method = <initialize>;
        MethodGen methodGenerator = new MethodGen(method, ...);
    	InstructionList instructions = methodGenerator.getInstructionList();

		Map<Integer, InstructionHandle> handlesByPosition = new HashMap<Integer, InstructionHandle>();
		for (InstructionHandle handle : instructions.getInstructionHandles())
		{
			handlesByPosition.put(handle.getPosition(), handle);
		}

		if (method.getLocalVariableTable() != null)
		{
			methodGenerator.removeLocalVariables();
			for (LocalVariable local : method.getLocalVariableTable().getLocalVariableTable())
			{
				methodGenerator.addLocalVariable(local.getName(), Type.getType(local.getSignature()), local.getIndex(),
						handlesByPosition.get(local.getStartPC()), handlesByPosition.get(local.getStartPC() + local.getLength()));
			}
		}