1 //===-- FileLineResolver.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/FileLineResolver.h" 10 11 #include "lldb/Core/FileSpecList.h" 12 #include "lldb/Symbol/CompileUnit.h" 13 #include "lldb/Symbol/LineTable.h" 14 #include "lldb/Utility/ConstString.h" 15 #include "lldb/Utility/Stream.h" 16 17 #include <string> 18 19 namespace lldb_private { 20 class Address; 21 } 22 23 using namespace lldb; 24 using namespace lldb_private; 25 26 //---------------------------------------------------------------------- 27 // FileLineResolver: 28 //---------------------------------------------------------------------- 29 FileLineResolver::FileLineResolver(const FileSpec &file_spec, uint32_t line_no, 30 bool check_inlines) 31 : Searcher(), m_file_spec(file_spec), m_line_number(line_no), 32 m_inlines(check_inlines) {} 33 34 FileLineResolver::~FileLineResolver() {} 35 36 Searcher::CallbackReturn 37 FileLineResolver::SearchCallback(SearchFilter &filter, SymbolContext &context, 38 Address *addr, bool containing) { 39 CompileUnit *cu = context.comp_unit; 40 41 if (m_inlines || 42 m_file_spec.Compare(*cu, m_file_spec, (bool)m_file_spec.GetDirectory())) { 43 uint32_t start_file_idx = 0; 44 uint32_t file_idx = 45 cu->GetSupportFiles().FindFileIndex(start_file_idx, m_file_spec, false); 46 if (file_idx != UINT32_MAX) { 47 LineTable *line_table = cu->GetLineTable(); 48 if (line_table) { 49 if (m_line_number == 0) { 50 // Match all lines in a file... 51 const bool append = true; 52 while (file_idx != UINT32_MAX) { 53 line_table->FineLineEntriesForFileIndex(file_idx, append, 54 m_sc_list); 55 // Get the next file index in case we have multiple file entries 56 // for the same file 57 file_idx = cu->GetSupportFiles().FindFileIndex(file_idx + 1, 58 m_file_spec, false); 59 } 60 } else { 61 // Match a specific line in a file... 62 } 63 } 64 } 65 } 66 return Searcher::eCallbackReturnContinue; 67 } 68 69 lldb::SearchDepth FileLineResolver::GetDepth() { 70 return lldb::eSearchDepthCompUnit; 71 } 72 73 void FileLineResolver::GetDescription(Stream *s) { 74 s->Printf("File and line resolver for file: \"%s\" line: %u", 75 m_file_spec.GetPath().c_str(), m_line_number); 76 } 77 78 void FileLineResolver::Clear() { 79 m_file_spec.Clear(); 80 m_line_number = UINT32_MAX; 81 m_sc_list.Clear(); 82 m_inlines = true; 83 } 84 85 void FileLineResolver::Reset(const FileSpec &file_spec, uint32_t line, 86 bool check_inlines) { 87 m_file_spec = file_spec; 88 m_line_number = line; 89 m_sc_list.Clear(); 90 m_inlines = check_inlines; 91 } 92