Class: ElfUtils::Section::DebugLine::LineNumberProgram::StateMachine
- Inherits:
-
Object
- Object
- ElfUtils::Section::DebugLine::LineNumberProgram::StateMachine
- Includes:
- CTypes::Helpers
- Defined in:
- lib/elf_utils/section/debug_line/line_number_program/state_machine.rb
Defined Under Namespace
Classes: StateRegisters
Constant Summary collapse
- StandardOpCodes =
ElfUtils::Types::Dwarf::StandardOpCodes
- ExtendedOpCodes =
ElfUtils::Types::Dwarf::ExtendedOpCodes
- ULEB128 =
ElfUtils::Types::ULEB128
- SLEB128 =
ElfUtils::Types::SLEB128
Instance Method Summary collapse
-
#initialize(program) ⇒ StateMachine
constructor
A new instance of StateMachine.
- #process(opcodes) ⇒ Object
Constructor Details
#initialize(program) ⇒ StateMachine
Returns a new instance of StateMachine.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 67 def initialize(program) @opcode_base = program.header.opcode_base @standard_opcode_lengths = program.standard_opcode_lengths @special_opcodes = build_special_opcode_table(program.header) @addr_type = program.file.elf_type(:Addr) # initial state @initial_registers = StateRegisters.new( minimum_instruction_length: program.header.minimum_instruction_length, maximum_operations_per_instruction: (program.header.version >= 4) ? program.header.maximum_operations_per_instruction : 1, is_stmt: program.header.default_is_stmt == 1 ).freeze end |
Instance Method Details
#process(opcodes) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/elf_utils/section/debug_line/line_number_program/state_machine.rb', line 82 def process(opcodes) buf = opcodes opcode_base = @opcode_base matrix = [] registers = @initial_registers.dup # TODO merge unpack & eval steps for extended & special opcodes until buf.empty? byte = uint8.unpack(buf) if byte == 0 opcode, args, buf = unpack_extended_op(buf[1..]) eval_extended_opcode(matrix, registers, opcode, args) elsif byte < opcode_base buf = eval_standard_opcode(buf, matrix, registers) else opcode, buf = byte, buf[1..] opcode = @special_opcodes[opcode] eval_special_opcode(matrix, registers, opcode) end end matrix end |