Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
39644 views
//===-- DWARFDebugRanges.cpp ----------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "DWARFDebugRanges.h"9#include "DWARFUnit.h"10#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"1112using namespace lldb_private;13using namespace lldb_private::plugin::dwarf;1415DWARFDebugRanges::DWARFDebugRanges() : m_range_map() {}1617void DWARFDebugRanges::Extract(DWARFContext &context) {18llvm::DWARFDataExtractor extractor =19context.getOrLoadRangesData().GetAsLLVMDWARF();20llvm::DWARFDebugRangeList extracted_list;21uint64_t current_offset = 0;22auto extract_next_list = [&] {23if (auto error = extracted_list.extract(extractor, ¤t_offset)) {24consumeError(std::move(error));25return false;26}27return true;28};2930uint64_t previous_offset = current_offset;31while (extractor.isValidOffset(current_offset) && extract_next_list()) {32DWARFRangeList &lldb_range_list = m_range_map[previous_offset];33lldb_range_list.Reserve(extracted_list.getEntries().size());34for (auto &range : extracted_list.getEntries())35lldb_range_list.Append(range.StartAddress,36range.EndAddress - range.StartAddress);37lldb_range_list.Sort();38previous_offset = current_offset;39}40}4142DWARFRangeList43DWARFDebugRanges::FindRanges(const DWARFUnit *cu,44dw_offset_t debug_ranges_offset) const {45dw_addr_t debug_ranges_address = cu->GetRangesBase() + debug_ranges_offset;46auto pos = m_range_map.find(debug_ranges_address);47DWARFRangeList ans =48pos == m_range_map.end() ? DWARFRangeList() : pos->second;4950// All DW_AT_ranges are relative to the base address of the compile51// unit. We add the compile unit base address to make sure all the52// addresses are properly fixed up.53ans.Slide(cu->GetBaseAddress());54return ans;55}565758