Path: blob/main/contrib/llvm-project/lldb/source/Core/AddressResolverFileLine.cpp
39587 views
//===-- AddressResolverFileLine.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 "lldb/Core/AddressResolverFileLine.h"910#include "lldb/Core/Address.h"11#include "lldb/Core/AddressRange.h"12#include "lldb/Symbol/CompileUnit.h"13#include "lldb/Symbol/LineEntry.h"14#include "lldb/Symbol/SymbolContext.h"15#include "lldb/Utility/ConstString.h"16#include "lldb/Utility/LLDBLog.h"17#include "lldb/Utility/Log.h"18#include "lldb/Utility/Stream.h"19#include "lldb/Utility/StreamString.h"20#include "lldb/lldb-enumerations.h"21#include "lldb/lldb-types.h"2223#include <cinttypes>24#include <vector>2526using namespace lldb;27using namespace lldb_private;2829// AddressResolverFileLine:30AddressResolverFileLine::AddressResolverFileLine(31SourceLocationSpec location_spec)32: AddressResolver(), m_src_location_spec(location_spec) {}3334AddressResolverFileLine::~AddressResolverFileLine() = default;3536Searcher::CallbackReturn37AddressResolverFileLine::SearchCallback(SearchFilter &filter,38SymbolContext &context, Address *addr) {39SymbolContextList sc_list;40CompileUnit *cu = context.comp_unit;4142Log *log = GetLog(LLDBLog::Breakpoints);4344// TODO: Handle SourceLocationSpec column information45cu->ResolveSymbolContext(m_src_location_spec, eSymbolContextEverything,46sc_list);47for (const SymbolContext &sc : sc_list) {48Address line_start = sc.line_entry.range.GetBaseAddress();49addr_t byte_size = sc.line_entry.range.GetByteSize();50if (line_start.IsValid()) {51AddressRange new_range(line_start, byte_size);52m_address_ranges.push_back(new_range);53} else {54LLDB_LOGF(log,55"error: Unable to resolve address at file address 0x%" PRIx6456" for %s:%d\n",57line_start.GetFileAddress(),58m_src_location_spec.GetFileSpec().GetFilename().AsCString(59"<Unknown>"),60m_src_location_spec.GetLine().value_or(0));61}62}63return Searcher::eCallbackReturnContinue;64}6566lldb::SearchDepth AddressResolverFileLine::GetDepth() {67return lldb::eSearchDepthCompUnit;68}6970void AddressResolverFileLine::GetDescription(Stream *s) {71s->Printf(72"File and line address - file: \"%s\" line: %u",73m_src_location_spec.GetFileSpec().GetFilename().AsCString("<Unknown>"),74m_src_location_spec.GetLine().value_or(0));75}767778