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