Home | History | Annotate | Download | only in Core
      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"
     16 #include "lldb/Symbol/CompileUnit.h"
     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;
     56         uint32_t file_idx = cu->GetSupportFiles().FindFileIndex(start_file_idx, m_file_spec, false);
     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
     71                         file_idx = cu->GetSupportFiles().FindFileIndex(file_idx + 1, m_file_spec, false);
     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\" line: %u",
     94                m_file_spec.GetPath().c_str(),
     95                m_line_number);
     96 }
     97 
     98 void
     99 FileLineResolver::Clear()
    100 {
    101     m_file_spec.Clear();
    102     m_line_number = UINT32_MAX;
    103     m_sc_list.Clear();
    104     m_inlines = true;
    105 }
    106 
    107 void
    108 FileLineResolver::Reset (const FileSpec &file_spec,
    109                          uint32_t line,
    110                          bool check_inlines)
    111 {
    112     m_file_spec = file_spec;
    113     m_line_number = line;
    114     m_sc_list.Clear();
    115     m_inlines = check_inlines;
    116 }
    117 
    118