1 //===-- AddressResolverFileLine.cpp -----------------------------*- C++ -*-===// 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 "lldb/Core/AddressResolverFileLine.h" 10 11 #include "lldb/Core/Address.h" 12 #include "lldb/Core/AddressRange.h" 13 #include "lldb/Symbol/CompileUnit.h" 14 #include "lldb/Symbol/LineEntry.h" 15 #include "lldb/Symbol/SymbolContext.h" 16 #include "lldb/Utility/ConstString.h" 17 #include "lldb/Utility/Log.h" 18 #include "lldb/Utility/Logging.h" 19 #include "lldb/Utility/Stream.h" 20 #include "lldb/Utility/StreamString.h" 21 #include "lldb/lldb-enumerations.h" 22 #include "lldb/lldb-types.h" 23 24 #include <inttypes.h> 25 #include <vector> 26 27 using namespace lldb; 28 using namespace lldb_private; 29 30 //---------------------------------------------------------------------- 31 // AddressResolverFileLine: 32 //---------------------------------------------------------------------- 33 AddressResolverFileLine::AddressResolverFileLine(const FileSpec &file_spec, 34 uint32_t line_no, 35 bool check_inlines) 36 : AddressResolver(), m_file_spec(file_spec), m_line_number(line_no), 37 m_inlines(check_inlines) {} 38 39 AddressResolverFileLine::~AddressResolverFileLine() {} 40 41 Searcher::CallbackReturn 42 AddressResolverFileLine::SearchCallback(SearchFilter &filter, 43 SymbolContext &context, Address *addr, 44 bool containing) { 45 SymbolContextList sc_list; 46 uint32_t sc_list_size; 47 CompileUnit *cu = context.comp_unit; 48 49 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS)); 50 51 sc_list_size = 52 cu->ResolveSymbolContext(m_file_spec, m_line_number, m_inlines, false, 53 eSymbolContextEverything, sc_list); 54 for (uint32_t i = 0; i < sc_list_size; i++) { 55 SymbolContext sc; 56 if (sc_list.GetContextAtIndex(i, sc)) { 57 Address line_start = sc.line_entry.range.GetBaseAddress(); 58 addr_t byte_size = sc.line_entry.range.GetByteSize(); 59 if (line_start.IsValid()) { 60 AddressRange new_range(line_start, byte_size); 61 m_address_ranges.push_back(new_range); 62 if (log) { 63 StreamString s; 64 // new_bp_loc->GetDescription (&s, lldb::eDescriptionLevelVerbose); 65 // log->Printf ("Added address: %s\n", s.GetData()); 66 } 67 } else { 68 if (log) 69 log->Printf( 70 "error: Unable to resolve address at file address 0x%" PRIx64 71 " for %s:%d\n", 72 line_start.GetFileAddress(), 73 m_file_spec.GetFilename().AsCString("<Unknown>"), m_line_number); 74 } 75 } 76 } 77 return Searcher::eCallbackReturnContinue; 78 } 79 80 lldb::SearchDepth AddressResolverFileLine::GetDepth() { 81 return lldb::eSearchDepthCompUnit; 82 } 83 84 void AddressResolverFileLine::GetDescription(Stream *s) { 85 s->Printf("File and line address - file: \"%s\" line: %u", 86 m_file_spec.GetFilename().AsCString("<Unknown>"), m_line_number); 87 } 88