LLDB mainline
DWARFDebugRanges.cpp
Go to the documentation of this file.
1//===-- DWARFDebugRanges.cpp ----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "DWARFDebugRanges.h"
10#include "DWARFUnit.h"
11#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
12
13using namespace lldb_private;
14
16
18 llvm::DWARFDataExtractor extractor =
20 llvm::DWARFDebugRangeList extracted_list;
21 uint64_t current_offset = 0;
22 auto extract_next_list = [&] {
23 if (auto error = extracted_list.extract(extractor, &current_offset)) {
24 consumeError(std::move(error));
25 return false;
26 }
27 return true;
28 };
29
30 uint64_t previous_offset = current_offset;
31 while (extractor.isValidOffset(current_offset) && extract_next_list()) {
32 DWARFRangeList &lldb_range_list = m_range_map[previous_offset];
33 lldb_range_list.Reserve(extracted_list.getEntries().size());
34 for (auto &range : extracted_list.getEntries())
35 lldb_range_list.Append(range.StartAddress,
36 range.EndAddress - range.StartAddress);
37 lldb_range_list.Sort();
38 previous_offset = current_offset;
39 }
40}
41
44 dw_offset_t debug_ranges_offset) const {
45 dw_addr_t debug_ranges_address = cu->GetRangesBase() + debug_ranges_offset;
46 auto pos = m_range_map.find(debug_ranges_address);
47 DWARFRangeList ans =
48 pos == m_range_map.end() ? DWARFRangeList() : pos->second;
49
50 // All DW_AT_ranges are relative to the base address of the compile
51 // unit. We add the compile unit base address to make sure all the
52 // addresses are properly fixed up.
53 ans.Slide(cu->GetBaseAddress());
54 return ans;
55}
static llvm::raw_ostream & error(Stream &strm)
std::map< dw_offset_t, DWARFRangeList > m_range_map
DWARFRangeList FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset) const
void Extract(lldb_private::DWARFContext &context)
dw_addr_t GetRangesBase() const
Definition: DWARFUnit.h:162
dw_addr_t GetBaseAddress() const
Definition: DWARFUnit.h:160
const DWARFDataExtractor & getOrLoadRangesData()
llvm::DWARFDataExtractor GetAsLLVM() const
void Slide(BaseType slide)
Definition: RangeMap.h:283
void Append(const Entry &entry)
Definition: RangeMap.h:179
void Reserve(typename Collection::size_type size)
Definition: RangeMap.h:291
uint64_t dw_offset_t
Definition: dwarf.h:31
lldb_private::RangeVector< dw_addr_t, dw_addr_t, 2 > DWARFRangeList
Definition: dwarf.h:43
uint64_t dw_addr_t
Definition: dwarf.h:27
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14