LLDB  mainline
SourceManager.cpp
Go to the documentation of this file.
1 //===-- SourceManager.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/Address.h"
12 #include "lldb/Core/AddressRange.h"
13 #include "lldb/Core/Debugger.h"
14 #include "lldb/Core/FormatEntity.h"
15 #include "lldb/Core/Highlighter.h"
16 #include "lldb/Core/Module.h"
17 #include "lldb/Core/ModuleList.h"
18 #include "lldb/Host/FileSystem.h"
20 #include "lldb/Symbol/Function.h"
21 #include "lldb/Symbol/LineEntry.h"
24 #include "lldb/Target/Target.h"
29 #include "lldb/Utility/Stream.h"
30 #include "lldb/lldb-enumerations.h"
31 
32 #include "llvm/ADT/Twine.h"
33 
34 #include <memory>
35 #include <utility>
36 
37 #include <cassert>
38 #include <cstdio>
39 
40 namespace lldb_private {
41 class ExecutionContext;
42 }
43 namespace lldb_private {
44 class ValueObject;
45 }
46 
47 using namespace lldb;
48 using namespace lldb_private;
49 
50 static inline bool is_newline_char(char ch) { return ch == '\n' || ch == '\r'; }
51 
52 static void resolve_tilde(FileSpec &file_spec) {
53  if (!FileSystem::Instance().Exists(file_spec) &&
54  file_spec.GetDirectory() &&
55  file_spec.GetDirectory().GetCString()[0] == '~') {
56  FileSystem::Instance().Resolve(file_spec);
57  }
58 }
59 
60 // SourceManager constructor
61 SourceManager::SourceManager(const TargetSP &target_sp)
62  : m_last_line(0), m_last_count(0), m_default_set(false),
63  m_target_wp(target_sp),
64  m_debugger_wp(target_sp->GetDebugger().shared_from_this()) {}
65 
66 SourceManager::SourceManager(const DebuggerSP &debugger_sp)
67  : m_last_line(0), m_last_count(0), m_default_set(false), m_target_wp(),
68  m_debugger_wp(debugger_sp) {}
69 
70 // Destructor
71 SourceManager::~SourceManager() = default;
72 
73 SourceManager::FileSP SourceManager::GetFile(const FileSpec &file_spec) {
74  if (!file_spec)
75  return nullptr;
76 
77  FileSpec resolved_fspec = file_spec;
78  resolve_tilde(resolved_fspec);
79 
80  DebuggerSP debugger_sp(m_debugger_wp.lock());
81  FileSP file_sp;
82  if (debugger_sp && debugger_sp->GetUseSourceCache())
83  file_sp = debugger_sp->GetSourceFileCache().FindSourceFile(resolved_fspec);
84 
85  TargetSP target_sp(m_target_wp.lock());
86 
87  // It the target source path map has been updated, get this file again so we
88  // can successfully remap the source file
89  if (target_sp && file_sp &&
90  file_sp->GetSourceMapModificationID() !=
91  target_sp->GetSourcePathMap().GetModificationID())
92  file_sp.reset();
93 
94  // Update the file contents if needed if we found a file
95  if (file_sp)
96  file_sp->UpdateIfNeeded();
97 
98  // If file_sp is no good or it points to a non-existent file, reset it.
99  if (!file_sp || !FileSystem::Instance().Exists(file_sp->GetFileSpec())) {
100  if (target_sp)
101  file_sp = std::make_shared<File>(resolved_fspec, target_sp.get());
102  else
103  file_sp = std::make_shared<File>(resolved_fspec, debugger_sp);
104 
105  if (debugger_sp && debugger_sp->GetUseSourceCache())
106  debugger_sp->GetSourceFileCache().AddSourceFile(file_sp);
107  }
108  return file_sp;
109 }
110 
111 static bool should_highlight_source(DebuggerSP debugger_sp) {
112  if (!debugger_sp)
113  return false;
114 
115  // We don't use ANSI stop column formatting if the debugger doesn't think it
116  // should be using color.
117  if (!debugger_sp->GetUseColor())
118  return false;
119 
120  return debugger_sp->GetHighlightSource();
121 }
122 
123 static bool should_show_stop_column_with_ansi(DebuggerSP debugger_sp) {
124  // We don't use ANSI stop column formatting if we can't lookup values from
125  // the debugger.
126  if (!debugger_sp)
127  return false;
128 
129  // We don't use ANSI stop column formatting if the debugger doesn't think it
130  // should be using color.
131  if (!debugger_sp->GetUseColor())
132  return false;
133 
134  // We only use ANSI stop column formatting if we're either supposed to show
135  // ANSI where available (which we know we have when we get to this point), or
136  // if we're only supposed to use ANSI.
137  const auto value = debugger_sp->GetStopShowColumn();
138  return ((value == eStopShowColumnAnsiOrCaret) ||
139  (value == eStopShowColumnAnsi));
140 }
141 
142 static bool should_show_stop_column_with_caret(DebuggerSP debugger_sp) {
143  // We don't use text-based stop column formatting if we can't lookup values
144  // from the debugger.
145  if (!debugger_sp)
146  return false;
147 
148  // If we're asked to show the first available of ANSI or caret, then we do
149  // show the caret when ANSI is not available.
150  const auto value = debugger_sp->GetStopShowColumn();
151  if ((value == eStopShowColumnAnsiOrCaret) && !debugger_sp->GetUseColor())
152  return true;
153 
154  // The only other time we use caret is if we're explicitly asked to show
155  // caret.
156  return value == eStopShowColumnCaret;
157 }
158 
159 static bool should_show_stop_line_with_ansi(DebuggerSP debugger_sp) {
160  return debugger_sp && debugger_sp->GetUseColor();
161 }
162 
164  uint32_t start_line, uint32_t count, uint32_t curr_line, uint32_t column,
165  const char *current_line_cstr, Stream *s,
166  const SymbolContextList *bp_locs) {
167  if (count == 0)
168  return 0;
169 
170  Stream::ByteDelta delta(*s);
171 
172  if (start_line == 0) {
173  if (m_last_line != 0 && m_last_line != UINT32_MAX)
174  start_line = m_last_line + m_last_count;
175  else
176  start_line = 1;
177  }
178 
179  if (!m_default_set) {
180  FileSpec tmp_spec;
181  uint32_t tmp_line;
182  GetDefaultFileAndLine(tmp_spec, tmp_line);
183  }
184 
185  m_last_line = start_line;
186  m_last_count = count;
187 
188  if (FileSP last_file_sp = GetLastFile()) {
189  const uint32_t end_line = start_line + count - 1;
190  for (uint32_t line = start_line; line <= end_line; ++line) {
191  if (!last_file_sp->LineIsValid(line)) {
193  break;
194  }
195 
196  std::string prefix;
197  if (bp_locs) {
198  uint32_t bp_count = bp_locs->NumLineEntriesWithLine(line);
199 
200  if (bp_count > 0)
201  prefix = llvm::formatv("[{0}]", bp_count);
202  else
203  prefix = " ";
204  }
205 
206  char buffer[3];
207  sprintf(buffer, "%2.2s", (line == curr_line) ? current_line_cstr : "");
208  std::string current_line_highlight(buffer);
209 
210  auto debugger_sp = m_debugger_wp.lock();
211  if (should_show_stop_line_with_ansi(debugger_sp)) {
212  current_line_highlight = ansi::FormatAnsiTerminalCodes(
213  (debugger_sp->GetStopShowLineMarkerAnsiPrefix() +
214  current_line_highlight +
215  debugger_sp->GetStopShowLineMarkerAnsiSuffix())
216  .str());
217  }
218 
219  s->Printf("%s%s %-4u\t", prefix.c_str(), current_line_highlight.c_str(),
220  line);
221 
222  // So far we treated column 0 as a special 'no column value', but
223  // DisplaySourceLines starts counting columns from 0 (and no column is
224  // expressed by passing an empty optional).
225  llvm::Optional<size_t> columnToHighlight;
226  if (line == curr_line && column)
227  columnToHighlight = column - 1;
228 
229  size_t this_line_size =
230  last_file_sp->DisplaySourceLines(line, columnToHighlight, 0, 0, s);
231  if (column != 0 && line == curr_line &&
232  should_show_stop_column_with_caret(debugger_sp)) {
233  // Display caret cursor.
234  std::string src_line;
235  last_file_sp->GetLine(line, src_line);
236  s->Printf(" \t");
237  // Insert a space for every non-tab character in the source line.
238  for (size_t i = 0; i + 1 < column && i < src_line.length(); ++i)
239  s->PutChar(src_line[i] == '\t' ? '\t' : ' ');
240  // Now add the caret.
241  s->Printf("^\n");
242  }
243  if (this_line_size == 0) {
245  break;
246  }
247  }
248  }
249  return *delta;
250 }
251 
253  const FileSpec &file_spec, uint32_t line, uint32_t column,
254  uint32_t context_before, uint32_t context_after,
255  const char *current_line_cstr, Stream *s,
256  const SymbolContextList *bp_locs) {
257  FileSP file_sp(GetFile(file_spec));
258 
259  uint32_t start_line;
260  uint32_t count = context_before + context_after + 1;
261  if (line > context_before)
262  start_line = line - context_before;
263  else
264  start_line = 1;
265 
266  FileSP last_file_sp(GetLastFile());
267  if (last_file_sp.get() != file_sp.get()) {
268  if (line == 0)
269  m_last_line = 0;
270  m_last_file_spec = file_spec;
271  }
273  start_line, count, line, column, current_line_cstr, s, bp_locs);
274 }
275 
277  Stream *s, uint32_t count, bool reverse, const SymbolContextList *bp_locs) {
278  // If we get called before anybody has set a default file and line, then try
279  // to figure it out here.
280  FileSP last_file_sp(GetLastFile());
281  const bool have_default_file_line = last_file_sp && m_last_line > 0;
282  if (!m_default_set) {
283  FileSpec tmp_spec;
284  uint32_t tmp_line;
285  GetDefaultFileAndLine(tmp_spec, tmp_line);
286  }
287 
288  if (last_file_sp) {
289  if (m_last_line == UINT32_MAX)
290  return 0;
291 
292  if (reverse && m_last_line == 1)
293  return 0;
294 
295  if (count > 0)
296  m_last_count = count;
297  else if (m_last_count == 0)
298  m_last_count = 10;
299 
300  if (m_last_line > 0) {
301  if (reverse) {
302  // If this is the first time we've done a reverse, then back up one
303  // more time so we end up showing the chunk before the last one we've
304  // shown:
307  else
308  m_last_line = 1;
309  } else if (have_default_file_line)
311  } else
312  m_last_line = 1;
313 
314  const uint32_t column = 0;
316  m_last_line, m_last_count, UINT32_MAX, column, "", s, bp_locs);
317  }
318  return 0;
319 }
320 
322  uint32_t line) {
323  m_default_set = true;
324  FileSP file_sp(GetFile(file_spec));
325 
326  if (file_sp) {
327  m_last_line = line;
328  m_last_file_spec = file_spec;
329  return true;
330  } else {
331  return false;
332  }
333 }
334 
336  if (FileSP last_file_sp = GetLastFile()) {
337  file_spec = m_last_file_spec;
338  line = m_last_line;
339  return true;
340  } else if (!m_default_set) {
341  TargetSP target_sp(m_target_wp.lock());
342 
343  if (target_sp) {
344  // If nobody has set the default file and line then try here. If there's
345  // no executable, then we will try again later when there is one.
346  // Otherwise, if we can't find it we won't look again, somebody will have
347  // to set it (for instance when we stop somewhere...)
348  Module *executable_ptr = target_sp->GetExecutableModulePointer();
349  if (executable_ptr) {
350  SymbolContextList sc_list;
351  ConstString main_name("main");
352 
353  ModuleFunctionSearchOptions function_options;
354  function_options.include_symbols =
355  false; // Force it to be a debug symbol.
356  function_options.include_inlines = true;
357  executable_ptr->FindFunctions(main_name, CompilerDeclContext(),
358  lldb::eFunctionNameTypeBase,
359  function_options, sc_list);
360  size_t num_matches = sc_list.GetSize();
361  for (size_t idx = 0; idx < num_matches; idx++) {
362  SymbolContext sc;
363  sc_list.GetContextAtIndex(idx, sc);
364  if (sc.function) {
365  lldb_private::LineEntry line_entry;
366  if (sc.function->GetAddressRange()
367  .GetBaseAddress()
368  .CalculateSymbolContextLineEntry(line_entry)) {
369  SetDefaultFileAndLine(line_entry.file, line_entry.line);
370  file_spec = m_last_file_spec;
371  line = m_last_line;
372  return true;
373  }
374  }
375  }
376  }
377  }
378  }
379  return false;
380 }
381 
383  RegularExpression &regex,
384  uint32_t start_line,
385  uint32_t end_line,
386  std::vector<uint32_t> &match_lines) {
387  match_lines.clear();
388  FileSP file_sp = GetFile(file_spec);
389  if (!file_sp)
390  return;
391  return file_sp->FindLinesMatchingRegex(regex, start_line, end_line,
392  match_lines);
393 }
394 
396  lldb::DebuggerSP debugger_sp)
397  : m_file_spec_orig(file_spec), m_file_spec(file_spec),
398  m_mod_time(FileSystem::Instance().GetModificationTime(file_spec)),
399  m_debugger_wp(debugger_sp) {
400  CommonInitializer(file_spec, nullptr);
401 }
402 
403 SourceManager::File::File(const FileSpec &file_spec, Target *target)
404  : m_file_spec_orig(file_spec), m_file_spec(file_spec),
405  m_mod_time(FileSystem::Instance().GetModificationTime(file_spec)),
406  m_debugger_wp(target ? target->GetDebugger().shared_from_this()
407  : DebuggerSP()) {
408  CommonInitializer(file_spec, target);
409 }
410 
412  Target *target) {
413  if (m_mod_time == llvm::sys::TimePoint<>()) {
414  if (target) {
415  m_source_map_mod_id = target->GetSourcePathMap().GetModificationID();
416 
417  if (!file_spec.GetDirectory() && file_spec.GetFilename()) {
418  // If this is just a file name, lets see if we can find it in the
419  // target:
420  bool check_inlines = false;
421  SymbolContextList sc_list;
422  size_t num_matches =
424  file_spec.GetFilename().AsCString(), 0, check_inlines,
425  SymbolContextItem(eSymbolContextModule |
426  eSymbolContextCompUnit),
427  sc_list);
428  bool got_multiple = false;
429  if (num_matches != 0) {
430  if (num_matches > 1) {
431  SymbolContext sc;
432  CompileUnit *test_cu = nullptr;
433 
434  for (unsigned i = 0; i < num_matches; i++) {
435  sc_list.GetContextAtIndex(i, sc);
436  if (sc.comp_unit) {
437  if (test_cu) {
438  if (test_cu != sc.comp_unit)
439  got_multiple = true;
440  break;
441  } else
442  test_cu = sc.comp_unit;
443  }
444  }
445  }
446  if (!got_multiple) {
447  SymbolContext sc;
448  sc_list.GetContextAtIndex(0, sc);
449  if (sc.comp_unit)
450  m_file_spec = sc.comp_unit->GetPrimaryFile();
451  m_mod_time = FileSystem::Instance().GetModificationTime(m_file_spec);
452  }
453  }
454  }
455  resolve_tilde(m_file_spec);
456  // Try remapping if m_file_spec does not correspond to an existing file.
457  if (!FileSystem::Instance().Exists(m_file_spec)) {
458  // Check target specific source remappings (i.e., the
459  // target.source-map setting), then fall back to the module
460  // specific remapping (i.e., the .dSYM remapping dictionary).
461  auto remapped = target->GetSourcePathMap().FindFile(m_file_spec);
462  if (!remapped) {
463  FileSpec new_spec;
464  if (target->GetImages().FindSourceFile(m_file_spec, new_spec))
465  remapped = new_spec;
466  }
467  if (remapped) {
468  m_file_spec = *remapped;
469  m_mod_time = FileSystem::Instance().GetModificationTime(m_file_spec);
470  }
471  }
472  }
473  }
474 
475  if (m_mod_time != llvm::sys::TimePoint<>())
476  m_data_sp = FileSystem::Instance().CreateDataBuffer(m_file_spec);
477 }
478 
480  if (line == 0)
481  return UINT32_MAX;
482 
483  if (line == 1)
484  return 0;
485 
486  if (CalculateLineOffsets(line)) {
487  if (line < m_offsets.size())
488  return m_offsets[line - 1]; // yes we want "line - 1" in the index
489  }
490  return UINT32_MAX;
491 }
492 
494  CalculateLineOffsets();
495  return m_offsets.size();
496 }
497 
499  if (!LineIsValid(line))
500  return nullptr;
501 
502  size_t line_offset = GetLineOffset(line);
503  if (line_offset < m_data_sp->GetByteSize())
504  return (const char *)m_data_sp->GetBytes() + line_offset;
505  return nullptr;
506 }
507 
509  bool include_newline_chars) {
510  if (!LineIsValid(line))
511  return false;
512 
513  size_t start_offset = GetLineOffset(line);
514  size_t end_offset = GetLineOffset(line + 1);
515  if (end_offset == UINT32_MAX)
516  end_offset = m_data_sp->GetByteSize();
517 
518  if (end_offset > start_offset) {
519  uint32_t length = end_offset - start_offset;
520  if (!include_newline_chars) {
521  const char *line_start =
522  (const char *)m_data_sp->GetBytes() + start_offset;
523  while (length > 0) {
524  const char last_char = line_start[length - 1];
525  if ((last_char == '\r') || (last_char == '\n'))
526  --length;
527  else
528  break;
529  }
530  }
531  return length;
532  }
533  return 0;
534 }
535 
537  if (line == 0)
538  return false;
539 
540  if (CalculateLineOffsets(line))
541  return line < m_offsets.size();
542  return false;
543 }
544 
546  // TODO: use host API to sign up for file modifications to anything in our
547  // source cache and only update when we determine a file has been updated.
548  // For now we check each time we want to display info for the file.
549  auto curr_mod_time = FileSystem::Instance().GetModificationTime(m_file_spec);
550 
551  if (curr_mod_time != llvm::sys::TimePoint<>() &&
552  m_mod_time != curr_mod_time) {
553  m_mod_time = curr_mod_time;
554  m_data_sp = FileSystem::Instance().CreateDataBuffer(m_file_spec);
555  m_offsets.clear();
556  }
557 }
558 
560  llvm::Optional<size_t> column,
561  uint32_t context_before,
562  uint32_t context_after,
563  Stream *s) {
564  // Nothing to write if there's no stream.
565  if (!s)
566  return 0;
567 
568  // Sanity check m_data_sp before proceeding.
569  if (!m_data_sp)
570  return 0;
571 
572  size_t bytes_written = s->GetWrittenBytes();
573 
574  auto debugger_sp = m_debugger_wp.lock();
575 
576  HighlightStyle style;
577  // Use the default Vim style if source highlighting is enabled.
578  if (should_highlight_source(debugger_sp))
580 
581  // If we should mark the stop column with color codes, then copy the prefix
582  // and suffix to our color style.
583  if (should_show_stop_column_with_ansi(debugger_sp))
584  style.selected.Set(debugger_sp->GetStopShowColumnAnsiPrefix(),
585  debugger_sp->GetStopShowColumnAnsiSuffix());
586 
587  HighlighterManager mgr;
588  std::string path = GetFileSpec().GetPath(/*denormalize*/ false);
589  // FIXME: Find a way to get the definitive language this file was written in
590  // and pass it to the highlighter.
591  const auto &h = mgr.getHighlighterFor(lldb::eLanguageTypeUnknown, path);
592 
593  const uint32_t start_line =
594  line <= context_before ? 1 : line - context_before;
595  const uint32_t start_line_offset = GetLineOffset(start_line);
596  if (start_line_offset != UINT32_MAX) {
597  const uint32_t end_line = line + context_after;
598  uint32_t end_line_offset = GetLineOffset(end_line + 1);
599  if (end_line_offset == UINT32_MAX)
600  end_line_offset = m_data_sp->GetByteSize();
601 
602  assert(start_line_offset <= end_line_offset);
603  if (start_line_offset < end_line_offset) {
604  size_t count = end_line_offset - start_line_offset;
605  const uint8_t *cstr = m_data_sp->GetBytes() + start_line_offset;
606 
607  auto ref = llvm::StringRef(reinterpret_cast<const char *>(cstr), count);
608 
609  h.Highlight(style, ref, column, "", *s);
610 
611  // Ensure we get an end of line character one way or another.
612  if (!is_newline_char(ref.back()))
613  s->EOL();
614  }
615  }
616  return s->GetWrittenBytes() - bytes_written;
617 }
618 
620  RegularExpression &regex, uint32_t start_line, uint32_t end_line,
621  std::vector<uint32_t> &match_lines) {
622  match_lines.clear();
623 
624  if (!LineIsValid(start_line) ||
625  (end_line != UINT32_MAX && !LineIsValid(end_line)))
626  return;
627  if (start_line > end_line)
628  return;
629 
630  for (uint32_t line_no = start_line; line_no < end_line; line_no++) {
631  std::string buffer;
632  if (!GetLine(line_no, buffer))
633  break;
634  if (regex.Execute(buffer)) {
635  match_lines.push_back(line_no);
636  }
637  }
638 }
639 
641  const SourceManager::File &rhs) {
642  if (lhs.m_file_spec != rhs.m_file_spec)
643  return false;
644  return lhs.m_mod_time == rhs.m_mod_time;
645 }
646 
648  line =
649  UINT32_MAX; // TODO: take this line out when we support partial indexing
650  if (line == UINT32_MAX) {
651  // Already done?
652  if (!m_offsets.empty() && m_offsets[0] == UINT32_MAX)
653  return true;
654 
655  if (m_offsets.empty()) {
656  if (m_data_sp.get() == nullptr)
657  return false;
658 
659  const char *start = (const char *)m_data_sp->GetBytes();
660  if (start) {
661  const char *end = start + m_data_sp->GetByteSize();
662 
663  // Calculate all line offsets from scratch
664 
665  // Push a 1 at index zero to indicate the file has been completely
666  // indexed.
667  m_offsets.push_back(UINT32_MAX);
668  const char *s;
669  for (s = start; s < end; ++s) {
670  char curr_ch = *s;
671  if (is_newline_char(curr_ch)) {
672  if (s + 1 < end) {
673  char next_ch = s[1];
674  if (is_newline_char(next_ch)) {
675  if (curr_ch != next_ch)
676  ++s;
677  }
678  }
679  m_offsets.push_back(s + 1 - start);
680  }
681  }
682  if (!m_offsets.empty()) {
683  if (m_offsets.back() < size_t(end - start))
684  m_offsets.push_back(end - start);
685  }
686  return true;
687  }
688  } else {
689  // Some lines have been populated, start where we last left off
690  assert("Not implemented yet" && false);
691  }
692 
693  } else {
694  // Calculate all line offsets up to "line"
695  assert("Not implemented yet" && false);
696  }
697  return false;
698 }
699 
701  if (!LineIsValid(line_no))
702  return false;
703 
704  size_t start_offset = GetLineOffset(line_no);
705  size_t end_offset = GetLineOffset(line_no + 1);
706  if (end_offset == UINT32_MAX) {
707  end_offset = m_data_sp->GetByteSize();
708  }
709  buffer.assign((const char *)m_data_sp->GetBytes() + start_offset,
710  end_offset - start_offset);
711 
712  return true;
713 }
714 
716  FileSpec file_spec = file_sp->GetFileSpec();
717  FileCache::iterator pos = m_file_cache.find(file_spec);
718  if (pos == m_file_cache.end())
719  m_file_cache[file_spec] = file_sp;
720  else {
721  if (file_sp != pos->second)
722  m_file_cache[file_spec] = file_sp;
723  }
724 }
725 
727  const FileSpec &file_spec) const {
728  FileSP file_sp;
729  FileCache::const_iterator pos = m_file_cache.find(file_spec);
730  if (pos != m_file_cache.end())
731  file_sp = pos->second;
732  return file_sp;
733 }
should_highlight_source
static bool should_highlight_source(DebuggerSP debugger_sp)
Definition: SourceManager.cpp:111
RegularExpression.h
lldb_private::AddressRange::GetBaseAddress
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:209
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::SymbolContext::comp_unit
CompileUnit * comp_unit
The CompileUnit for a given query.
Definition: SymbolContext.h:319
lldb_private::SourceManager::File::PeekLineData
const char * PeekLineData(uint32_t line)
Definition: SourceManager.cpp:498
lldb_private::SourceManager::File::FindLinesMatchingRegex
void FindLinesMatchingRegex(RegularExpression &regex, uint32_t start_line, uint32_t end_line, std::vector< uint32_t > &match_lines)
Definition: SourceManager.cpp:619
lldb_private::FileSystem::CreateDataBuffer
std::shared_ptr< DataBuffer > CreateDataBuffer(const llvm::Twine &path, uint64_t size=0, uint64_t offset=0)
Create memory buffer from path.
Definition: common/FileSystem.cpp:308
lldb_private::LineEntry::file
FileSpec file
The source file, possibly mapped by the target.source-map setting.
Definition: LineEntry.h:140
lldb_private::RegularExpression
Definition: RegularExpression.h:18
FileSystem.h
lldb_private::HighlightStyle::MakeVimStyle
static HighlightStyle MakeVimStyle()
Returns a HighlightStyle that is based on vim's default highlight style.
Definition: Highlighter.cpp:56
CompileUnit.h
lldb_private::Function::GetAddressRange
const AddressRange & GetAddressRange()
Definition: Function.h:457
lldb_private::HighlightStyle::ColorStyle::Set
void Set(llvm::StringRef prefix, llvm::StringRef suffix)
Sets the prefix and suffix strings.
Definition: Highlighter.cpp:22
lldb_private::HighlighterManager::getHighlighterFor
const Highlighter & getHighlighterFor(lldb::LanguageType language_type, llvm::StringRef path) const
Queries all known highlighter for one that can highlight some source code.
Definition: Highlighter.cpp:65
lldb_private::SourceManager::File
Definition: SourceManager.h:33
lldb_private::SourceManager::File::m_file_spec
FileSpec m_file_spec
Definition: SourceManager.h:72
Module.h
SourceManager.h
lldb_private::SymbolContextList
Definition: SymbolContext.h:379
lldb_private::SymbolContextList::GetContextAtIndex
bool GetContextAtIndex(size_t idx, SymbolContext &sc) const
Get accessor for a symbol context at index idx.
Definition: SymbolContext.cpp:1258
lldb_private::Module
Definition: Module.h:85
lldb_private::ConstString::AsCString
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:193
lldb_private::FileSpec::GetFilename
const ConstString & GetFilename() const
Filename string const get accessor.
Definition: FileSpec.h:240
lldb_private::HighlightStyle::selected
ColorStyle selected
The style for the token which is below the cursor of the user.
Definition: Highlighter.h:52
should_show_stop_column_with_caret
static bool should_show_stop_column_with_caret(DebuggerSP debugger_sp)
Definition: SourceManager.cpp:142
lldb_private::SourceManager::DisplaySourceLinesWithLineNumbers
size_t DisplaySourceLinesWithLineNumbers(const FileSpec &file, uint32_t line, uint32_t column, uint32_t context_before, uint32_t context_after, const char *current_line_cstr, Stream *s, const SymbolContextList *bp_locs=nullptr)
Definition: SourceManager.cpp:252
lldb_private::SourceManager::File::UpdateIfNeeded
void UpdateIfNeeded()
Definition: SourceManager.cpp:545
resolve_tilde
static void resolve_tilde(FileSpec &file_spec)
Definition: SourceManager.cpp:52
lldb_private::Stream
Definition: Stream.h:28
lldb_private::FileSystem
Definition: FileSystem.h:28
lldb_private::ModuleFunctionSearchOptions::include_symbols
bool include_symbols
Include the symbol table.
Definition: Module.h:65
Debugger.h
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb_private::Target
Definition: Target.h:467
lldb_private::SourceManager::File::m_mod_time
llvm::sys::TimePoint m_mod_time
Definition: SourceManager.h:77
lldb_private::Target::GetImages
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition: Target.h:942
lldb_private::SourceManager::DisplaySourceLinesWithLineNumbersUsingLastFile
size_t DisplaySourceLinesWithLineNumbersUsingLastFile(uint32_t start_line, uint32_t count, uint32_t curr_line, uint32_t column, const char *current_line_cstr, Stream *s, const SymbolContextList *bp_locs=nullptr)
Definition: SourceManager.cpp:163
lldb_private::SourceManager::File::GetLineOffset
uint32_t GetLineOffset(uint32_t line)
Definition: SourceManager.cpp:479
lldb_private::ModuleFunctionSearchOptions::include_inlines
bool include_inlines
Include inlined functions.
Definition: Module.h:67
lldb_private::CompileUnit
Definition: CompileUnit.h:38
Target.h
lldb::eStopShowColumnCaret
@ eStopShowColumnCaret
Definition: lldb-enumerations.h:503
lldb_private::Address::CalculateSymbolContextLineEntry
bool CalculateSymbolContextLineEntry(LineEntry &line_entry) const
Definition: Address.cpp:907
lldb_private::operator==
bool operator==(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1016
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::SourceManager::SourceFileCache::AddSourceFile
void AddSourceFile(const FileSP &file_sp)
Definition: SourceManager.cpp:715
lldb_private::HighlighterManager
Manages the available highlighters.
Definition: Highlighter.h:136
ModuleList.h
should_show_stop_line_with_ansi
static bool should_show_stop_line_with_ansi(DebuggerSP debugger_sp)
Definition: SourceManager.cpp:159
lldb_private::SourceManager::GetDefaultFileAndLine
bool GetDefaultFileAndLine(FileSpec &file_spec, uint32_t &line)
Definition: SourceManager.cpp:335
lldb_private::SourceManager::m_last_count
uint32_t m_last_count
Definition: SourceManager.h:157
lldb_private::Stream::ByteDelta
Definition: Stream.h:43
LineEntry.h
lldb_private::SourceManager::File::File
File(const FileSpec &file_spec, Target *target)
Definition: SourceManager.cpp:403
lldb_private::ModuleList::ResolveSymbolContextForFilePath
uint32_t ResolveSymbolContextForFilePath(const char *file_path, uint32_t line, bool check_inlines, lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) const
Resolve items in the symbol context for a given file and line. (const char
Definition: ModuleList.cpp:702
lldb_private::SourceManager::File::GetLineLength
uint32_t GetLineLength(uint32_t line, bool include_newline_chars)
Definition: SourceManager.cpp:508
lldb::eStopShowColumnAnsiOrCaret
@ eStopShowColumnAnsiOrCaret
Definition: lldb-enumerations.h:501
lldb_private::SymbolContext::function
Function * function
The Function for a given query.
Definition: SymbolContext.h:320
lldb_private::SymbolContextList::GetSize
uint32_t GetSize() const
Get accessor for a symbol context list size.
Definition: SymbolContext.cpp:1274
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::SourceManager::GetFile
FileSP GetFile(const FileSpec &file_spec)
Definition: SourceManager.cpp:73
lldb-enumerations.h
lldb_private::SourceManager::m_last_line
uint32_t m_last_line
Definition: SourceManager.h:156
lldb_private::SourceManager::m_debugger_wp
lldb::DebuggerWP m_debugger_wp
Definition: SourceManager.h:160
Highlighter.h
lldb_private::FileSystem::GetModificationTime
llvm::sys::TimePoint GetModificationTime(const FileSpec &file_spec) const
Returns the modification time of the given file.
Definition: common/FileSystem.cpp:96
lldb_private::CompileUnit::GetPrimaryFile
const FileSpec & GetPrimaryFile() const
Return the primary source file associated with this compile unit.
Definition: CompileUnit.h:227
lldb_private::Module::FindFunctions
void FindFunctions(const LookupInfo &lookup_info, const CompilerDeclContext &parent_decl_ctx, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list)
Find functions by lookup info.
Definition: Module.cpp:825
is_newline_char
static bool is_newline_char(char ch)
Definition: SourceManager.cpp:50
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb::eStopShowColumnAnsi
@ eStopShowColumnAnsi
Definition: lldb-enumerations.h:502
lldb_private::Stream::PutChar
size_t PutChar(char ch)
Definition: Stream.cpp:104
lldb_private::SourceManager::SetDefaultFileAndLine
bool SetDefaultFileAndLine(const FileSpec &file_spec, uint32_t line)
Definition: SourceManager.cpp:321
Address.h
AnsiTerminal.h
lldb_private::SymbolContextList::NumLineEntriesWithLine
uint32_t NumLineEntriesWithLine(uint32_t line) const
Definition: SymbolContext.cpp:1278
lldb_private::CompilerDeclContext
Represents a generic declaration context in a program.
Definition: CompilerDeclContext.h:30
lldb_private::LineEntry::line
uint32_t line
The source line number, or zero if there is no line number information.
Definition: LineEntry.h:143
lldb_private::ModuleFunctionSearchOptions
Options used by Module::FindFunctions.
Definition: Module.h:63
should_show_stop_column_with_ansi
static bool should_show_stop_column_with_ansi(DebuggerSP debugger_sp)
Definition: SourceManager.cpp:123
lldb_private::PathMappingList::FindFile
llvm::Optional< FileSpec > FindFile(const FileSpec &orig_spec) const
Finds a source file given a file spec using the path remappings.
Definition: PathMappingList.cpp:216
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
lldb_private::SourceManager::m_last_file_spec
FileSpec m_last_file_spec
Definition: SourceManager.h:155
lldb::eLanguageTypeUnknown
@ eLanguageTypeUnknown
Unknown or invalid language value.
Definition: lldb-enumerations.h:437
lldb_private::SourceManager::GetLastFile
FileSP GetLastFile()
Definition: SourceManager.h:122
lldb_private::SourceManager::m_target_wp
lldb::TargetWP m_target_wp
Definition: SourceManager.h:159
uint32_t
lldb_private::FileSpec::GetDirectory
const ConstString & GetDirectory() const
Directory string const get accessor.
Definition: FileSpec.h:223
lldb_private::SourceManager::m_default_set
bool m_default_set
Definition: SourceManager.h:158
lldb_private::Stream::EOL
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:128
lldb_private::SourceManager::File::GetNumLines
uint32_t GetNumLines()
Definition: SourceManager.cpp:493
lldb_private::HighlightStyle
Represents style that the highlighter should apply to the given source code.
Definition: Highlighter.h:23
lldb_private::PathMappingList::GetModificationID
uint32_t GetModificationID() const
Definition: PathMappingList.h:107
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:19
FormatEntity.h
lldb_private::ConstString::GetCString
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
Function.h
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::FileSystem::Instance
static FileSystem & Instance()
Definition: common/FileSystem.cpp:46
lldb_private::SourceManager::SourceFileCache::FindSourceFile
FileSP FindSourceFile(const FileSpec &file_spec) const
Definition: SourceManager.cpp:726
SymbolContext.h
lldb_private::SourceManager::FileSP
std::shared_ptr< File > FileSP
Definition: SourceManager.h:91
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::SourceManager::FindLinesMatchingRegex
void FindLinesMatchingRegex(FileSpec &file_spec, RegularExpression &regex, uint32_t start_line, uint32_t end_line, std::vector< uint32_t > &match_lines)
Definition: SourceManager.cpp:382
lldb_private::SourceManager::File::GetLine
bool GetLine(uint32_t line_no, std::string &buffer)
Definition: SourceManager.cpp:700
lldb_private::Stream::GetWrittenBytes
size_t GetWrittenBytes() const
Definition: Stream.h:107
lldb_private::RegularExpression::Execute
bool Execute(llvm::StringRef string, llvm::SmallVectorImpl< llvm::StringRef > *matches=nullptr) const
Execute a regular expression match using the compiled regular expression that is already in this obje...
Definition: RegularExpression.cpp:23
lldb_private::SourceManager::File::CalculateLineOffsets
bool CalculateLineOffsets(uint32_t line=UINT32_MAX)
Definition: SourceManager.cpp:647
ConstString.h
lldb_private::SourceManager::DisplayMoreWithLineNumbers
size_t DisplayMoreWithLineNumbers(Stream *s, uint32_t count, bool reverse, const SymbolContextList *bp_locs=nullptr)
Definition: SourceManager.cpp:276
lldb_private::TargetProperties::GetSourcePathMap
PathMappingList & GetSourcePathMap() const
Definition: Target.cpp:4263
Stream.h
PathMappingList.h
DataBuffer.h
lldb_private::SourceManager::File::DisplaySourceLines
size_t DisplaySourceLines(uint32_t line, llvm::Optional< size_t > column, uint32_t context_before, uint32_t context_after, Stream *s)
Definition: SourceManager.cpp:559
lldb_private::SourceManager::File::CommonInitializer
void CommonInitializer(const FileSpec &file_spec, Target *target)
Definition: SourceManager.cpp:411
AddressRange.h
lldb
Definition: SBAddress.h:15
lldb_private::SourceManager::File::LineIsValid
bool LineIsValid(uint32_t line)
Definition: SourceManager.cpp:536
lldb_private::LineEntry
Definition: LineEntry.h:20
lldb_private::ansi::FormatAnsiTerminalCodes
std::string FormatAnsiTerminalCodes(llvm::StringRef format, bool do_color=true)
Definition: AnsiTerminal.h:83
lldb_private::ModuleList::FindSourceFile
bool FindSourceFile(const FileSpec &orig_spec, FileSpec &new_spec) const
Definition: ModuleList.cpp:601