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