xref: /src/contrib/llvm-project/lldb/source/Core/FileLineResolver.cpp (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1cfca06d7SDimitry Andric //===-- FileLineResolver.cpp ----------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste 
9f034231aSEd Maste #include "lldb/Core/FileLineResolver.h"
10f034231aSEd Maste 
11f034231aSEd Maste #include "lldb/Symbol/CompileUnit.h"
12f034231aSEd Maste #include "lldb/Symbol/LineTable.h"
1394994d37SDimitry Andric #include "lldb/Utility/ConstString.h"
147fa27ce4SDimitry Andric #include "lldb/Utility/FileSpecList.h"
1594994d37SDimitry Andric #include "lldb/Utility/Stream.h"
1674a628f7SDimitry Andric 
1794994d37SDimitry Andric #include <string>
1874a628f7SDimitry Andric 
1974a628f7SDimitry Andric namespace lldb_private {
2074a628f7SDimitry Andric class Address;
2174a628f7SDimitry Andric }
22f034231aSEd Maste 
23f034231aSEd Maste using namespace lldb;
24f034231aSEd Maste using namespace lldb_private;
25f034231aSEd Maste 
26f034231aSEd Maste // FileLineResolver:
FileLineResolver(const FileSpec & file_spec,uint32_t line_no,bool check_inlines)2714f1b3e8SDimitry Andric FileLineResolver::FileLineResolver(const FileSpec &file_spec, uint32_t line_no,
2814f1b3e8SDimitry Andric                                    bool check_inlines)
2914f1b3e8SDimitry Andric     : Searcher(), m_file_spec(file_spec), m_line_number(line_no),
3014f1b3e8SDimitry Andric       m_inlines(check_inlines) {}
31f034231aSEd Maste 
32344a3780SDimitry Andric FileLineResolver::~FileLineResolver() = default;
33f034231aSEd Maste 
34f034231aSEd Maste Searcher::CallbackReturn
SearchCallback(SearchFilter & filter,SymbolContext & context,Address * addr)3514f1b3e8SDimitry Andric FileLineResolver::SearchCallback(SearchFilter &filter, SymbolContext &context,
36ead24645SDimitry Andric                                  Address *addr) {
37f034231aSEd Maste   CompileUnit *cu = context.comp_unit;
38f034231aSEd Maste 
39706b4fc4SDimitry Andric   if (m_inlines || m_file_spec.Compare(cu->GetPrimaryFile(), m_file_spec,
40706b4fc4SDimitry Andric                                        (bool)m_file_spec.GetDirectory())) {
41f034231aSEd Maste     uint32_t start_file_idx = 0;
4214f1b3e8SDimitry Andric     uint32_t file_idx =
4314f1b3e8SDimitry Andric         cu->GetSupportFiles().FindFileIndex(start_file_idx, m_file_spec, false);
4414f1b3e8SDimitry Andric     if (file_idx != UINT32_MAX) {
45f034231aSEd Maste       LineTable *line_table = cu->GetLineTable();
4614f1b3e8SDimitry Andric       if (line_table) {
4714f1b3e8SDimitry Andric         if (m_line_number == 0) {
48f034231aSEd Maste           // Match all lines in a file...
49f034231aSEd Maste           const bool append = true;
5014f1b3e8SDimitry Andric           while (file_idx != UINT32_MAX) {
517fa27ce4SDimitry Andric             line_table->FindLineEntriesForFileIndex(file_idx, append,
5214f1b3e8SDimitry Andric                                                     m_sc_list);
53f73363f1SDimitry Andric             // Get the next file index in case we have multiple file entries
54f73363f1SDimitry Andric             // for the same file
5514f1b3e8SDimitry Andric             file_idx = cu->GetSupportFiles().FindFileIndex(file_idx + 1,
5614f1b3e8SDimitry Andric                                                            m_file_spec, false);
57f034231aSEd Maste           }
5814f1b3e8SDimitry Andric         } else {
59f034231aSEd Maste           // Match a specific line in a file...
60f034231aSEd Maste         }
61f034231aSEd Maste       }
62f034231aSEd Maste     }
63f034231aSEd Maste   }
64f034231aSEd Maste   return Searcher::eCallbackReturnContinue;
65f034231aSEd Maste }
66f034231aSEd Maste 
GetDepth()6794994d37SDimitry Andric lldb::SearchDepth FileLineResolver::GetDepth() {
6894994d37SDimitry Andric   return lldb::eSearchDepthCompUnit;
69f034231aSEd Maste }
70f034231aSEd Maste 
GetDescription(Stream * s)7114f1b3e8SDimitry Andric void FileLineResolver::GetDescription(Stream *s) {
72f034231aSEd Maste   s->Printf("File and line resolver for file: \"%s\" line: %u",
7314f1b3e8SDimitry Andric             m_file_spec.GetPath().c_str(), m_line_number);
74f034231aSEd Maste }
75f034231aSEd Maste 
Clear()7614f1b3e8SDimitry Andric void FileLineResolver::Clear() {
77f034231aSEd Maste   m_file_spec.Clear();
78f034231aSEd Maste   m_line_number = UINT32_MAX;
79f034231aSEd Maste   m_sc_list.Clear();
80f034231aSEd Maste   m_inlines = true;
81f034231aSEd Maste }
82f034231aSEd Maste 
Reset(const FileSpec & file_spec,uint32_t line,bool check_inlines)8314f1b3e8SDimitry Andric void FileLineResolver::Reset(const FileSpec &file_spec, uint32_t line,
8414f1b3e8SDimitry Andric                              bool check_inlines) {
85f034231aSEd Maste   m_file_spec = file_spec;
86f034231aSEd Maste   m_line_number = line;
87f034231aSEd Maste   m_sc_list.Clear();
88f034231aSEd Maste   m_inlines = check_inlines;
89f034231aSEd Maste }
90