1 //===-- FileLineResolver.cpp ----------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Core/FileLineResolver.h"
11 #include "lldb/Symbol/CompileUnit.h"
12 #include "lldb/Symbol/LineTable.h"
13 #include "lldb/Utility/ConstString.h"
14 #include "lldb/Utility/FileSpecList.h"
15 #include "lldb/Utility/Stream.h"
19 namespace lldb_private
{
24 using namespace lldb_private
;
27 FileLineResolver::FileLineResolver(const FileSpec
&file_spec
, uint32_t line_no
,
29 : Searcher(), m_file_spec(file_spec
), m_line_number(line_no
),
30 m_inlines(check_inlines
) {}
32 FileLineResolver::~FileLineResolver() = default;
34 Searcher::CallbackReturn
35 FileLineResolver::SearchCallback(SearchFilter
&filter
, SymbolContext
&context
,
37 CompileUnit
*cu
= context
.comp_unit
;
39 if (m_inlines
|| m_file_spec
.Compare(cu
->GetPrimaryFile(), m_file_spec
,
40 (bool)m_file_spec
.GetDirectory())) {
41 uint32_t start_file_idx
= 0;
43 cu
->GetSupportFiles().FindFileIndex(start_file_idx
, m_file_spec
, false);
44 if (file_idx
!= UINT32_MAX
) {
45 LineTable
*line_table
= cu
->GetLineTable();
47 if (m_line_number
== 0) {
48 // Match all lines in a file...
49 const bool append
= true;
50 while (file_idx
!= UINT32_MAX
) {
51 line_table
->FindLineEntriesForFileIndex(file_idx
, append
,
53 // Get the next file index in case we have multiple file entries
55 file_idx
= cu
->GetSupportFiles().FindFileIndex(file_idx
+ 1,
59 // Match a specific line in a file...
64 return Searcher::eCallbackReturnContinue
;
67 lldb::SearchDepth
FileLineResolver::GetDepth() {
68 return lldb::eSearchDepthCompUnit
;
71 void FileLineResolver::GetDescription(Stream
*s
) {
72 s
->Printf("File and line resolver for file: \"%s\" line: %u",
73 m_file_spec
.GetPath().c_str(), m_line_number
);
76 void FileLineResolver::Clear() {
78 m_line_number
= UINT32_MAX
;
83 void FileLineResolver::Reset(const FileSpec
&file_spec
, uint32_t line
,
85 m_file_spec
= file_spec
;
88 m_inlines
= check_inlines
;