Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
39644 views
//===-- DWARFCompileUnit.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 "DWARFCompileUnit.h"9#include "DWARFDebugAranges.h"10#include "SymbolFileDWARFDebugMap.h"1112#include "lldb/Symbol/CompileUnit.h"13#include "lldb/Symbol/LineTable.h"14#include "lldb/Utility/Stream.h"1516using namespace lldb;17using namespace lldb_private;18using namespace lldb_private::plugin::dwarf;1920void DWARFCompileUnit::Dump(Stream *s) const {21s->Format(2223"{0:x16}: Compile Unit: length = {1:x8}, version = {2:x}, "24"abbr_offset = {3:x8}, addr_size = {4:x2} (next CU at "25"[{5:x16}])\n",26GetOffset(), GetLength(), GetVersion(), (uint32_t)GetAbbrevOffset(),27GetAddressByteSize(), GetNextUnitOffset());28}2930void DWARFCompileUnit::BuildAddressRangeTable(31DWARFDebugAranges *debug_aranges) {32// This function is usually called if there in no .debug_aranges section in33// order to produce a compile unit level set of address ranges that is34// accurate.3536size_t num_debug_aranges = debug_aranges->GetNumRanges();3738// First get the compile unit DIE only and check contains ranges information.39const DWARFDebugInfoEntry *die = GetUnitDIEPtrOnly();4041const dw_offset_t cu_offset = GetOffset();42if (die) {43DWARFRangeList ranges =44die->GetAttributeAddressRanges(this, /*check_hi_lo_pc=*/true);45for (const DWARFRangeList::Entry &range : ranges)46debug_aranges->AppendRange(cu_offset, range.GetRangeBase(),47range.GetRangeEnd());4849if (!ranges.IsEmpty())50return;51}5253if (debug_aranges->GetNumRanges() == num_debug_aranges) {54// We got nothing from the debug info, try to build the arange table from55// the debug map OSO aranges.56SymbolContext sc;57sc.comp_unit = m_dwarf.GetCompUnitForDWARFCompUnit(*this);58if (sc.comp_unit) {59SymbolFileDWARFDebugMap *debug_map_sym_file =60m_dwarf.GetDebugMapSymfile();61if (debug_map_sym_file) {62auto *cu_info =63debug_map_sym_file->GetCompileUnitInfo(&GetSymbolFileDWARF());64// If there are extra compile units the OSO entries aren't a reliable65// source of information.66if (cu_info->compile_units_sps.empty())67debug_map_sym_file->AddOSOARanges(&m_dwarf, debug_aranges);68}69}70}7172if (debug_aranges->GetNumRanges() == num_debug_aranges) {73// We got nothing from the functions, maybe we have a line tables only74// situation. Check the line tables and build the arange table from this.75SymbolContext sc;76sc.comp_unit = m_dwarf.GetCompUnitForDWARFCompUnit(*this);77if (sc.comp_unit) {78if (LineTable *line_table = sc.comp_unit->GetLineTable()) {79LineTable::FileAddressRanges file_ranges;80const bool append = true;81const size_t num_ranges =82line_table->GetContiguousFileAddressRanges(file_ranges, append);83for (uint32_t idx = 0; idx < num_ranges; ++idx) {84const LineTable::FileAddressRanges::Entry &range =85file_ranges.GetEntryRef(idx);86debug_aranges->AppendRange(GetOffset(), range.GetRangeBase(),87range.GetRangeEnd());88}89}90}91}92}9394DWARFCompileUnit &DWARFCompileUnit::GetNonSkeletonUnit() {95return llvm::cast<DWARFCompileUnit>(DWARFUnit::GetNonSkeletonUnit());96}9798DWARFDIE DWARFCompileUnit::LookupAddress(const dw_addr_t address) {99if (DIE()) {100const DWARFDebugAranges &func_aranges = GetFunctionAranges();101102// Re-check the aranges auto pointer contents in case it was created above103if (!func_aranges.IsEmpty())104return GetDIE(func_aranges.FindAddress(address));105}106return DWARFDIE();107}108109110