The LocalVariableTable attribute is an optional variable-length attribute in the attributes table of a Code attribute (§4.7.3). It may be used by debuggers to determine the value of a given local variable during the execution of a method.
If multiple LocalVariableTable attributes are present in the attributes table of a Code attribute, then they may appear in any order.
There may be no more than one LocalVariableTable attribute per local variable in the attributes table of a Code attribute.
The LocalVariableTable attribute has the following format:
LocalVariableTable_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 local_variable_table_length;
{ u2 start_pc;
u2 length;
u2 name_index;
u2 descriptor_index;
u2 index;
} local_variable_table[local_variable_table_length];
}
The items of the LocalVariableTable_attribute structure are as follows:
-
attribute_name_index
The value of the
attribute_name_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Utf8_infostructure (§4.4.7) representing the string "LocalVariableTable". -
attribute_length
The value of the
attribute_lengthitem indicates the length of the attribute, excluding the initial six bytes. -
local_variable_table_length
The value of the
local_variable_table_lengthitem indicates the number of entries in thelocal_variable_tablearray. -
local_variable_table[]
Each entry in the
local_variable_tablearray indicates a range ofcodearray offsets within which a local variable has a value. It also indicates the index into the local variable array of the current frame at which that local variable can be found. Each entry must contain the following five items:-
start_pc, length
The given local variable must have a value at indices into the
codearray in the interval [start_pc,start_pc + length), that is, betweenstart_pcinclusive andstart_pc + lengthexclusive.The value of
start_pcmust be a valid index into thecodearray of thisCodeattribute and must be the index of the opcode of an instruction.The value of
start_pc + lengthmust either be a valid index into thecodearray of thisCodeattribute and be the index of the opcode of an instruction, or it must be the first index beyond the end of thatcodearray. -
name_index
The value of the
name_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must contain aCONSTANT_Utf8_infostructure (§4.4.7) representing a valid unqualified name denoting a local variable (§4.2.2). -
descriptor_index
The value of the
descriptor_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must contain aCONSTANT_Utf8_infostructure (§4.4.7) representing a field descriptor which encodes the type of a local variable in the source program (§4.3.2). -
index
The given local variable must be at
indexin the local variable array of the current frame.If the local variable at
indexis of typedoubleorlong, it occupies bothindexandindex + 1.
-