1ac7ddfbfSEd Maste //===-- FileLineResolver.cpp ------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste //                     The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste 
10ac7ddfbfSEd Maste #include "lldb/Core/FileLineResolver.h"
11ac7ddfbfSEd Maste 
12*b5893f02SDimitry Andric #include "lldb/Core/FileSpecList.h"
13ac7ddfbfSEd Maste #include "lldb/Symbol/CompileUnit.h"
14ac7ddfbfSEd Maste #include "lldb/Symbol/LineTable.h"
15*b5893f02SDimitry Andric #include "lldb/Utility/ConstString.h"
16*b5893f02SDimitry Andric #include "lldb/Utility/Stream.h"
17f678e45dSDimitry Andric 
18*b5893f02SDimitry Andric #include <string>
19f678e45dSDimitry Andric 
20f678e45dSDimitry Andric namespace lldb_private {
21f678e45dSDimitry Andric class Address;
22f678e45dSDimitry Andric }
23ac7ddfbfSEd Maste 
24ac7ddfbfSEd Maste using namespace lldb;
25ac7ddfbfSEd Maste using namespace lldb_private;
26ac7ddfbfSEd Maste 
27ac7ddfbfSEd Maste //----------------------------------------------------------------------
28ac7ddfbfSEd Maste // FileLineResolver:
29ac7ddfbfSEd Maste //----------------------------------------------------------------------
FileLineResolver(const FileSpec & file_spec,uint32_t line_no,bool check_inlines)30435933ddSDimitry Andric FileLineResolver::FileLineResolver(const FileSpec &file_spec, uint32_t line_no,
31435933ddSDimitry Andric                                    bool check_inlines)
32435933ddSDimitry Andric     : Searcher(), m_file_spec(file_spec), m_line_number(line_no),
33435933ddSDimitry Andric       m_inlines(check_inlines) {}
34ac7ddfbfSEd Maste 
~FileLineResolver()35435933ddSDimitry Andric FileLineResolver::~FileLineResolver() {}
36ac7ddfbfSEd Maste 
37ac7ddfbfSEd Maste Searcher::CallbackReturn
SearchCallback(SearchFilter & filter,SymbolContext & context,Address * addr,bool containing)38435933ddSDimitry Andric FileLineResolver::SearchCallback(SearchFilter &filter, SymbolContext &context,
39435933ddSDimitry Andric                                  Address *addr, bool containing) {
40ac7ddfbfSEd Maste   CompileUnit *cu = context.comp_unit;
41ac7ddfbfSEd Maste 
42435933ddSDimitry Andric   if (m_inlines ||
43435933ddSDimitry Andric       m_file_spec.Compare(*cu, m_file_spec, (bool)m_file_spec.GetDirectory())) {
44ac7ddfbfSEd Maste     uint32_t start_file_idx = 0;
45435933ddSDimitry Andric     uint32_t file_idx =
46435933ddSDimitry Andric         cu->GetSupportFiles().FindFileIndex(start_file_idx, m_file_spec, false);
47435933ddSDimitry Andric     if (file_idx != UINT32_MAX) {
48ac7ddfbfSEd Maste       LineTable *line_table = cu->GetLineTable();
49435933ddSDimitry Andric       if (line_table) {
50435933ddSDimitry Andric         if (m_line_number == 0) {
51ac7ddfbfSEd Maste           // Match all lines in a file...
52ac7ddfbfSEd Maste           const bool append = true;
53435933ddSDimitry Andric           while (file_idx != UINT32_MAX) {
54435933ddSDimitry Andric             line_table->FineLineEntriesForFileIndex(file_idx, append,
55435933ddSDimitry Andric                                                     m_sc_list);
564ba319b5SDimitry Andric             // Get the next file index in case we have multiple file entries
574ba319b5SDimitry Andric             // for the same file
58435933ddSDimitry Andric             file_idx = cu->GetSupportFiles().FindFileIndex(file_idx + 1,
59435933ddSDimitry Andric                                                            m_file_spec, false);
60ac7ddfbfSEd Maste           }
61435933ddSDimitry Andric         } else {
62ac7ddfbfSEd Maste           // Match a specific line in a file...
63ac7ddfbfSEd Maste         }
64ac7ddfbfSEd Maste       }
65ac7ddfbfSEd Maste     }
66ac7ddfbfSEd Maste   }
67ac7ddfbfSEd Maste   return Searcher::eCallbackReturnContinue;
68ac7ddfbfSEd Maste }
69ac7ddfbfSEd Maste 
GetDepth()70*b5893f02SDimitry Andric lldb::SearchDepth FileLineResolver::GetDepth() {
71*b5893f02SDimitry Andric   return lldb::eSearchDepthCompUnit;
72ac7ddfbfSEd Maste }
73ac7ddfbfSEd Maste 
GetDescription(Stream * s)74435933ddSDimitry Andric void FileLineResolver::GetDescription(Stream *s) {
75ac7ddfbfSEd Maste   s->Printf("File and line resolver for file: \"%s\" line: %u",
76435933ddSDimitry Andric             m_file_spec.GetPath().c_str(), m_line_number);
77ac7ddfbfSEd Maste }
78ac7ddfbfSEd Maste 
Clear()79435933ddSDimitry Andric void FileLineResolver::Clear() {
80ac7ddfbfSEd Maste   m_file_spec.Clear();
81ac7ddfbfSEd Maste   m_line_number = UINT32_MAX;
82ac7ddfbfSEd Maste   m_sc_list.Clear();
83ac7ddfbfSEd Maste   m_inlines = true;
84ac7ddfbfSEd Maste }
85ac7ddfbfSEd Maste 
Reset(const FileSpec & file_spec,uint32_t line,bool check_inlines)86435933ddSDimitry Andric void FileLineResolver::Reset(const FileSpec &file_spec, uint32_t line,
87435933ddSDimitry Andric                              bool check_inlines) {
88ac7ddfbfSEd Maste   m_file_spec = file_spec;
89ac7ddfbfSEd Maste   m_line_number = line;
90ac7ddfbfSEd Maste   m_sc_list.Clear();
91ac7ddfbfSEd Maste   m_inlines = check_inlines;
92ac7ddfbfSEd Maste }
93