LLDB  mainline
FileLineResolver.cpp
Go to the documentation of this file.
1 //===-- FileLineResolver.cpp ----------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 #include "lldb/Core/FileSpecList.h"
13 #include "lldb/Symbol/LineTable.h"
15 #include "lldb/Utility/Stream.h"
16 
17 #include <string>
18 
19 namespace lldb_private {
20 class Address;
21 }
22 
23 using namespace lldb;
24 using namespace lldb_private;
25 
26 // FileLineResolver:
27 FileLineResolver::FileLineResolver(const FileSpec &file_spec, uint32_t line_no,
28  bool check_inlines)
29  : Searcher(), m_file_spec(file_spec), m_line_number(line_no),
30  m_inlines(check_inlines) {}
31 
33 
36  Address *addr) {
37  CompileUnit *cu = context.comp_unit;
38 
40  (bool)m_file_spec.GetDirectory())) {
41  uint32_t start_file_idx = 0;
42  uint32_t file_idx =
43  cu->GetSupportFiles().FindFileIndex(start_file_idx, m_file_spec, false);
44  if (file_idx != UINT32_MAX) {
45  LineTable *line_table = cu->GetLineTable();
46  if (line_table) {
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->FineLineEntriesForFileIndex(file_idx, append,
52  m_sc_list);
53  // Get the next file index in case we have multiple file entries
54  // for the same file
55  file_idx = cu->GetSupportFiles().FindFileIndex(file_idx + 1,
56  m_file_spec, false);
57  }
58  } else {
59  // Match a specific line in a file...
60  }
61  }
62  }
63  }
65 }
66 
69 }
70 
72  s->Printf("File and line resolver for file: \"%s\" line: %u",
73  m_file_spec.GetPath().c_str(), m_line_number);
74 }
75 
79  m_sc_list.Clear();
80  m_inlines = true;
81 }
82 
83 void FileLineResolver::Reset(const FileSpec &file_spec, uint32_t line,
84  bool check_inlines) {
85  m_file_spec = file_spec;
86  m_line_number = line;
87  m_sc_list.Clear();
88  m_inlines = check_inlines;
89 }
lldb_private::FileLineResolver::SearchCallback
Searcher::CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context, Address *addr) override
Definition: FileLineResolver.cpp:35
lldb::eSearchDepthCompUnit
@ eSearchDepthCompUnit
Definition: lldb-enumerations.h:287
lldb_private::SymbolContext::comp_unit
CompileUnit * comp_unit
The CompileUnit for a given query.
Definition: SymbolContext.h:319
lldb_private::CompileUnit::GetSupportFiles
const FileSpecList & GetSupportFiles()
Get the compile unit's support file list.
Definition: CompileUnit.cpp:387
lldb_private::FileLineResolver::Clear
void Clear()
Definition: FileLineResolver.cpp:76
lldb::SearchDepth
SearchDepth
Definition: lldb-enumerations.h:283
lldb_private::FileLineResolver::Reset
void Reset(const FileSpec &file_spec, uint32_t line, bool check_inlines)
Definition: FileLineResolver.cpp:83
CompileUnit.h
lldb_private::FileLineResolver::m_line_number
uint32_t m_line_number
Definition: FileLineResolver.h:55
lldb_private::FileLineResolver::m_sc_list
SymbolContextList m_sc_list
Definition: FileLineResolver.h:57
lldb_private::FileLineResolver::GetDepth
lldb::SearchDepth GetDepth() override
Definition: FileLineResolver.cpp:67
lldb_private::Stream
Definition: Stream.h:28
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb_private::SymbolContextList::Clear
void Clear()
Clear the object's state.
Definition: SymbolContext.cpp:1244
lldb_private::CompileUnit
Definition: CompileUnit.h:38
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::FileSpec::Compare
static int Compare(const FileSpec &lhs, const FileSpec &rhs, bool full)
Compare two FileSpec objects.
Definition: FileSpec.cpp:274
lldb_private::LineTable
Definition: LineTable.h:40
lldb_private::SearchFilter
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:83
lldb_private::LineTable::FineLineEntriesForFileIndex
size_t FineLineEntriesForFileIndex(uint32_t file_idx, bool append, SymbolContextList &sc_list)
Definition: LineTable.cpp:328
FileLineResolver.h
FileSpecList.h
lldb_private::Searcher::CallbackReturn
CallbackReturn
Definition: SearchFilter.h:44
lldb_private::CompileUnit::GetPrimaryFile
const FileSpec & GetPrimaryFile() const
Return the primary source file associated with this compile unit.
Definition: CompileUnit.h:227
lldb_private::CompileUnit::GetLineTable
LineTable * GetLineTable()
Get the line table for the compile unit.
Definition: CompileUnit.cpp:161
lldb_private::FileSpec::Clear
void Clear()
Clears the object state.
Definition: FileSpec.cpp:261
lldb_private::FileLineResolver::m_file_spec
FileSpec m_file_spec
Definition: FileLineResolver.h:54
lldb_private::FileLineResolver::m_inlines
bool m_inlines
Definition: FileLineResolver.h:58
uint32_t
lldb_private::Address
Definition: Address.h:59
LineTable.h
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private::FileLineResolver::~FileLineResolver
~FileLineResolver() override
lldb_private::FileLineResolver::GetDescription
void GetDescription(Stream *s) override
Prints a canonical description for the searcher to the stream s.
Definition: FileLineResolver.cpp:71
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::FileSpec::GetDirectory
ConstString & GetDirectory()
Directory string get accessor.
Definition: FileSpec.cpp:335
ConstString.h
lldb_private::Searcher
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:42
Stream.h
lldb_private::FileSpec::GetPath
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:348
lldb
Definition: SBAddress.h:15
lldb_private::Searcher::eCallbackReturnContinue
@ eCallbackReturnContinue
Definition: SearchFilter.h:46