AddressResolverFileLine.cpp revision 360784
1331722Seadler//===-- AddressResolverFileLine.cpp -----------------------------*- C++ -*-===// 21590Srgrimes// 31590Srgrimes// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 41590Srgrimes// See https://llvm.org/LICENSE.txt for license information. 51590Srgrimes// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 61590Srgrimes// 71590Srgrimes//===----------------------------------------------------------------------===// 81590Srgrimes 91590Srgrimes#include "lldb/Core/AddressResolverFileLine.h" 101590Srgrimes 111590Srgrimes#include "lldb/Core/Address.h" 121590Srgrimes#include "lldb/Core/AddressRange.h" 131590Srgrimes#include "lldb/Symbol/CompileUnit.h" 141590Srgrimes#include "lldb/Symbol/LineEntry.h" 151590Srgrimes#include "lldb/Symbol/SymbolContext.h" 161590Srgrimes#include "lldb/Utility/ConstString.h" 171590Srgrimes#include "lldb/Utility/Log.h" 181590Srgrimes#include "lldb/Utility/Logging.h" 191590Srgrimes#include "lldb/Utility/Stream.h" 201590Srgrimes#include "lldb/Utility/StreamString.h" 211590Srgrimes#include "lldb/lldb-enumerations.h" 221590Srgrimes#include "lldb/lldb-types.h" 231590Srgrimes 241590Srgrimes#include <inttypes.h> 251590Srgrimes#include <vector> 261590Srgrimes 271590Srgrimesusing namespace lldb; 281590Srgrimesusing namespace lldb_private; 291590Srgrimes 3087705Smarkm// AddressResolverFileLine: 3187705SmarkmAddressResolverFileLine::AddressResolverFileLine(const FileSpec &file_spec, 3287705Smarkm uint32_t line_no, 3387705Smarkm bool check_inlines) 341590Srgrimes : AddressResolver(), m_file_spec(file_spec), m_line_number(line_no), 3528368Scharnier m_inlines(check_inlines) {} 361590Srgrimes 371590SrgrimesAddressResolverFileLine::~AddressResolverFileLine() {} 3887705Smarkm 391590SrgrimesSearcher::CallbackReturn 401590SrgrimesAddressResolverFileLine::SearchCallback(SearchFilter &filter, 4187705Smarkm SymbolContext &context, Address *addr) { 4228368Scharnier SymbolContextList sc_list; 431590Srgrimes CompileUnit *cu = context.comp_unit; 441590Srgrimes 4523693Speter Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS)); 46200462Sdelphij 4728368Scharnier cu->ResolveSymbolContext(m_file_spec, m_line_number, m_inlines, false, 48200462Sdelphij eSymbolContextEverything, sc_list); 4987705Smarkm uint32_t sc_list_size = sc_list.GetSize(); 50245767Sandrew for (uint32_t i = 0; i < sc_list_size; i++) { 511590Srgrimes SymbolContext sc; 521590Srgrimes if (sc_list.GetContextAtIndex(i, sc)) { 531590Srgrimes Address line_start = sc.line_entry.range.GetBaseAddress(); 5423693Speter addr_t byte_size = sc.line_entry.range.GetByteSize(); 55200462Sdelphij if (line_start.IsValid()) { 56200462Sdelphij AddressRange new_range(line_start, byte_size); 5723693Speter m_address_ranges.push_back(new_range); 58131846Stjr if (log) { 59131846Stjr StreamString s; 601590Srgrimes // new_bp_loc->GetDescription (&s, lldb::eDescriptionLevelVerbose); 611590Srgrimes // LLDB_LOGF(log, "Added address: %s\n", s.GetData()); 62227188Sed } 63227188Sed } else { 6498214Stjr LLDB_LOGF(log, 65131846Stjr "error: Unable to resolve address at file address 0x%" PRIx64 6692922Simp " for %s:%d\n", 671590Srgrimes line_start.GetFileAddress(), 681590Srgrimes m_file_spec.GetFilename().AsCString("<Unknown>"), 69102944Sdwmalone m_line_number); 701590Srgrimes } 71131846Stjr } 72131846Stjr } 73131846Stjr return Searcher::eCallbackReturnContinue; 74131846Stjr} 7598214Stjr 76144840Sstefanflldb::SearchDepth AddressResolverFileLine::GetDepth() { 771590Srgrimes return lldb::eSearchDepthCompUnit; 7898210Stjr} 7911895Sache 8098214Stjrvoid AddressResolverFileLine::GetDescription(Stream *s) { 8198214Stjr s->Printf("File and line address - file: \"%s\" line: %u", 821590Srgrimes m_file_spec.GetFilename().AsCString("<Unknown>"), m_line_number); 8398214Stjr} 8498214Stjr