diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -569,6 +569,24 @@ return LT; } +struct AdvanceAddrProperties { + uint8_t AdjustedOpcode; + uint8_t OperationAdvance; +}; + +static AdvanceAddrProperties +getOperationAdvance(uint8_t Opcode, uint8_t OpcodeBase, uint8_t LineRange) { + AdvanceAddrProperties Result; + Result.AdjustedOpcode = Opcode - OpcodeBase; + Result.OperationAdvance = Result.AdjustedOpcode / LineRange; + return Result; +} + +static uint64_t advanceAddr(uint64_t OperationAdvance, + const DWARFDebugLine::Prologue &Prologue) { + return OperationAdvance * Prologue.MinInstLength; +} + Error DWARFDebugLine::LineTable::parse( DWARFDataExtractor &DebugLineData, uint64_t *OffsetPtr, const DWARFContext &Ctx, const DWARFUnit *U, @@ -796,7 +814,7 @@ // result to the address register of the state machine. { uint64_t AddrOffset = - DebugLineData.getULEB128(OffsetPtr) * Prologue.MinInstLength; + advanceAddr(DebugLineData.getULEB128(OffsetPtr), Prologue); State.Row.Address.Address += AddrOffset; if (OS) *OS << " (" << AddrOffset << ")"; @@ -852,13 +870,13 @@ // than twice that range will it need to use both DW_LNS_advance_pc // and a special opcode, requiring three or more bytes. { - uint8_t AdjustOpcode = 255 - Prologue.OpcodeBase; + AdvanceAddrProperties AdvanceAddr = + getOperationAdvance(255, Prologue.OpcodeBase, Prologue.LineRange); uint64_t AddrOffset = - (AdjustOpcode / Prologue.LineRange) * Prologue.MinInstLength; + advanceAddr(AdvanceAddr.OperationAdvance, Prologue); State.Row.Address.Address += AddrOffset; if (OS) - *OS - << format(" (0x%16.16" PRIx64 ")", AddrOffset); + *OS << format(" (0x%16.16" PRIx64 ")", AddrOffset); } break; @@ -951,11 +969,11 @@ // // line increment = line_base + (adjusted opcode % line_range) - uint8_t AdjustOpcode = Opcode - Prologue.OpcodeBase; - uint64_t AddrOffset = - (AdjustOpcode / Prologue.LineRange) * Prologue.MinInstLength; + AdvanceAddrProperties AdvanceAddr = + getOperationAdvance(Opcode, Prologue.OpcodeBase, Prologue.LineRange); + uint64_t AddrOffset = advanceAddr(AdvanceAddr.OperationAdvance, Prologue); int32_t LineOffset = - Prologue.LineBase + (AdjustOpcode % Prologue.LineRange); + Prologue.LineBase + (AdvanceAddr.AdjustedOpcode % Prologue.LineRange); State.Row.Line += LineOffset; State.Row.Address.Address += AddrOffset;