Greg Clayton | 176761e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 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/lldb-private-log.h" |
| 14 | #include "lldb/Core/Log.h" |
| 15 | #include "lldb/Core/StreamString.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame^] | 16 | #include "lldb/Symbol/CompileUnit.h" |
Greg Clayton | 176761e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 17 | #include "lldb/Symbol/LineTable.h" |
| 18 | |
| 19 | using namespace lldb; |
| 20 | using namespace lldb_private; |
| 21 | |
| 22 | //---------------------------------------------------------------------- |
| 23 | // FileLineResolver: |
| 24 | //---------------------------------------------------------------------- |
| 25 | FileLineResolver::FileLineResolver |
| 26 | ( |
| 27 | const FileSpec &file_spec, |
| 28 | uint32_t line_no, |
| 29 | bool check_inlines |
| 30 | ) : |
| 31 | Searcher (), |
| 32 | m_file_spec (file_spec), |
| 33 | m_line_number (line_no), |
| 34 | m_inlines (check_inlines) |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | FileLineResolver::~FileLineResolver () |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | Searcher::CallbackReturn |
| 43 | FileLineResolver::SearchCallback |
| 44 | ( |
| 45 | SearchFilter &filter, |
| 46 | SymbolContext &context, |
| 47 | Address *addr, |
| 48 | bool containing |
| 49 | ) |
| 50 | { |
| 51 | CompileUnit *cu = context.comp_unit; |
| 52 | |
| 53 | if (m_inlines || m_file_spec.Compare(*cu, m_file_spec, m_file_spec.GetDirectory())) |
| 54 | { |
| 55 | uint32_t start_file_idx = 0; |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 56 | uint32_t file_idx = cu->GetSupportFiles().FindFileIndex(start_file_idx, m_file_spec, false); |
Greg Clayton | 176761e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 57 | if (file_idx != UINT32_MAX) |
| 58 | { |
| 59 | LineTable *line_table = cu->GetLineTable(); |
| 60 | if (line_table) |
| 61 | { |
| 62 | if (m_line_number == 0) |
| 63 | { |
| 64 | // Match all lines in a file... |
| 65 | const bool append = true; |
| 66 | while (file_idx != UINT32_MAX) |
| 67 | { |
| 68 | line_table->FineLineEntriesForFileIndex (file_idx, append, m_sc_list); |
| 69 | // Get the next file index in case we have multiple file |
| 70 | // entries for the same file |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 71 | file_idx = cu->GetSupportFiles().FindFileIndex(file_idx + 1, m_file_spec, false); |
Greg Clayton | 176761e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | else |
| 75 | { |
| 76 | // Match a specific line in a file... |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | return Searcher::eCallbackReturnContinue; |
| 82 | } |
| 83 | |
| 84 | Searcher::Depth |
| 85 | FileLineResolver::GetDepth() |
| 86 | { |
| 87 | return Searcher::eDepthCompUnit; |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | FileLineResolver::GetDescription (Stream *s) |
| 92 | { |
| 93 | s->Printf ("File and line resolver for file: \"%s%s%s\" line: %u", |
| 94 | m_file_spec.GetDirectory().GetCString(), |
| 95 | m_file_spec.GetDirectory() ? "/" : "", |
| 96 | m_file_spec.GetFilename().GetCString(), |
| 97 | m_line_number); |
| 98 | } |
| 99 | |
| 100 | void |
| 101 | FileLineResolver::Clear() |
| 102 | { |
| 103 | m_file_spec.Clear(); |
| 104 | m_line_number = UINT32_MAX; |
| 105 | m_sc_list.Clear(); |
| 106 | m_inlines = true; |
| 107 | } |
| 108 | |
| 109 | void |
| 110 | FileLineResolver::Reset (const FileSpec &file_spec, |
| 111 | uint32_t line, |
| 112 | bool check_inlines) |
| 113 | { |
| 114 | m_file_spec = file_spec; |
| 115 | m_line_number = line; |
| 116 | m_sc_list.Clear(); |
| 117 | m_inlines = check_inlines; |
| 118 | } |
| 119 | |