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