35#include "llvm/ADT/Twine.h" 
   67  return std::string(llvm::formatv(
"{0}", checksum.
digest()));
 
 
   85  assert(support_file_sp && 
"SupportFileSP must be valid");
 
   87  FileSpec file_spec = support_file_sp->GetSpecOnly();
 
   96  if (!debugger_sp || !debugger_sp->GetUseSourceCache()) {
 
   97    LLDB_LOG(log, 
"Source file caching disabled: creating new source file: {0}",
 
  100      return std::make_shared<File>(support_file_sp, target_sp);
 
  101    return std::make_shared<File>(support_file_sp, debugger_sp);
 
  110            process_sp->GetSourceFileCache().FindSourceFile(file_spec)) {
 
  111      LLDB_LOG(log, 
"Found source file in the process cache: {0}", file_spec);
 
  112      if (file_sp->PathRemappingIsStale()) {
 
  113        LLDB_LOG(log, 
"Path remapping is stale: removing file from caches: {0}",
 
  118        debugger_sp->GetSourceFileCache().RemoveSourceFile(file_sp);
 
  119        process_sp->GetSourceFileCache().RemoveSourceFile(file_sp);
 
  129  FileSP file_sp = debugger_sp->GetSourceFileCache().FindSourceFile(file_spec);
 
  134    LLDB_LOG(log, 
"Found source file in the debugger cache: {0}", file_spec);
 
  137  if (file_sp && file_sp->PathRemappingIsStale()) {
 
  138    LLDB_LOG(log, 
"Path remapping is stale: {0}", file_spec);
 
  143  if (file_sp && file_sp->ModificationTimeIsStale()) {
 
  144    LLDB_LOG(log, 
"Modification time is stale: {0}", file_spec);
 
  150                     file_sp->GetSupportFile()->GetSpecOnly())) {
 
  151    LLDB_LOG(log, 
"File doesn't exist on disk: {0}", file_spec);
 
  158    LLDB_LOG(log, 
"Creating and caching new source file: {0}", file_spec);
 
  162      file_sp = std::make_shared<File>(support_file_sp, target_sp);
 
  164      file_sp = std::make_shared<File>(support_file_sp, debugger_sp);
 
  168    debugger_sp->GetSourceFileCache().AddSourceFile(file_spec, file_sp);
 
  170      process_sp->GetSourceFileCache().AddSourceFile(file_spec, file_sp);
 
 
  182  if (!debugger_sp->GetUseColor())
 
  185  return debugger_sp->GetHighlightSource();
 
 
  196  if (!debugger_sp->GetUseColor())
 
  202  const auto value = debugger_sp->GetStopShowColumn();
 
 
  215  const auto value = debugger_sp->GetStopShowColumn();
 
 
  225  return debugger_sp && debugger_sp->GetUseColor();
 
 
  229    uint32_t start_line, uint32_t count, uint32_t curr_line, uint32_t column,
 
  230    const char *current_line_cstr, 
Stream *s,
 
  237  if (start_line == 0) {
 
  251    const uint32_t end_line = start_line + count - 1;
 
  252    for (uint32_t line = start_line; line <= end_line; ++line) {
 
  253      if (!last_file_sp->LineIsValid(line)) {
 
  263          prefix = llvm::formatv(
"[{0}]", bp_count);
 
  269      snprintf(buffer, 
sizeof(buffer), 
"%2.2s",
 
  270               (line == curr_line) ? current_line_cstr : 
"");
 
  271      std::string current_line_highlight(buffer);
 
  276            (debugger_sp->GetStopShowLineMarkerAnsiPrefix() +
 
  277             current_line_highlight +
 
  278             debugger_sp->GetStopShowLineMarkerAnsiSuffix())
 
  282      s->
Printf(
"%s%s %-4u\t", prefix.c_str(), current_line_highlight.c_str(),
 
  288      std::optional<size_t> columnToHighlight;
 
  289      if (line == curr_line && column)
 
  290        columnToHighlight = column - 1;
 
  292      size_t this_line_size =
 
  293          last_file_sp->DisplaySourceLines(line, columnToHighlight, 0, 0, s);
 
  294      if (column != 0 && line == curr_line &&
 
  297        std::string src_line;
 
  298        last_file_sp->GetLine(line, src_line);
 
  301        for (
size_t i = 0; i + 1 < column && i < src_line.length(); ++i)
 
  302          s->
PutChar(src_line[i] == 
'\t' ? 
'\t' : 
' ');
 
  306      if (this_line_size == 0) {
 
  313        last_file_sp->GetSupportFile()->GetChecksum();
 
  314    Checksum on_disk_checksum = last_file_sp->GetChecksum();
 
  315    if (line_table_checksum && line_table_checksum != on_disk_checksum)
 
  318              "{0}: source file checksum mismatch between line table " 
  319              "({1}) and file on disk ({2})",
 
  320              last_file_sp->GetSupportFile()->GetSpecOnly().GetFilename(),
 
  322          std::nullopt, &last_file_sp->GetChecksumWarningOnceFlag());
 
 
  329    uint32_t context_before, uint32_t context_after,
 
  330    const char *current_line_cstr, 
Stream *s,
 
  332  assert(support_file_sp && 
"SupportFile must be valid");
 
  336  uint32_t count = context_before + context_after + 1;
 
  337  if (line > context_before)
 
  338    start_line = line - context_before;
 
  343  if (last_file_sp.get() != file_sp.get()) {
 
  350      start_line, count, line, column, current_line_cstr, s, bp_locs);
 
 
  358  const bool have_default_file_line = last_file_sp && 
m_last_line > 0;
 
  380      } 
else if (have_default_file_line)
 
  385    const uint32_t column = 0;
 
 
  394  assert(support_file_sp && 
"SupportFile must be valid");
 
 
  407std::optional<SourceManager::SupportFileAndLine>
 
  420      Module *executable_ptr = target_sp->GetExecutableModulePointer();
 
  421      if (executable_ptr) {
 
  430                                      lldb::eFunctionNameTypeFull,
 
  431                                      function_options, sc_list);
 
  435            if (sc.function->GetAddress().CalculateSymbolContextLineEntry(
 
 
  453                                           std::vector<uint32_t> &match_lines) {
 
  458  return file_sp->FindLinesMatchingRegex(regex, start_line, end_line,
 
 
  472      m_debugger_wp(target_sp ? target_sp->GetDebugger().shared_from_this()
 
 
  492        FileSpec file_spec = support_file_sp->GetSpecOnly();
 
  494          bool check_inlines = 
false;
 
  497              target_sp->GetImages().ResolveSymbolContextForFilePath(
 
  499                  SymbolContextItem(eSymbolContextModule |
 
  500                                    eSymbolContextCompUnit),
 
  502          bool got_multiple = 
false;
 
  503          if (num_matches != 0) {
 
  504            if (num_matches > 1) {
 
  509                    if (test_cu != sc.comp_unit)
 
  513                    test_cu = sc.comp_unit;
 
  529        FileSpec file_spec = support_file_sp->GetSpecOnly();
 
  534          auto remapped = target_sp->GetSourcePathMap().FindFile(file_spec);
 
  537            if (target_sp->GetImages().FindSourceFile(file_spec, new_spec))
 
  542                *remapped, support_file_sp->GetChecksum()));
 
 
  557  FileSpec file_spec = support_file_sp->GetSpecOnly();
 
  560      std::make_shared<SupportFile>(file_spec, support_file_sp->GetChecksum());
 
 
  588  if (line_offset < m_data_sp->GetByteSize())
 
  589    return (
const char *)
m_data_sp->GetBytes() + line_offset;
 
 
  594                                            bool include_newline_chars) {
 
  603  if (end_offset > start_offset) {
 
  604    uint32_t length = end_offset - start_offset;
 
  605    if (!include_newline_chars) {
 
  606      const char *line_start =
 
  607          (
const char *)
m_data_sp->GetBytes() + start_offset;
 
  609        const char last_char = line_start[length - 1];
 
  610        if ((last_char == 
'\r') || (last_char == 
'\n'))
 
 
  636  return curr_mod_time != llvm::sys::TimePoint<>() &&
 
 
  643           target_sp->GetSourcePathMap().GetModificationID();
 
 
  648                                               std::optional<size_t> column,
 
  649                                               uint32_t context_before,
 
  650                                               uint32_t context_after,
 
  672    style.
selected.
Set(debugger_sp->GetStopShowColumnAnsiPrefix(),
 
  673                       debugger_sp->GetStopShowColumnAnsiSuffix());
 
  682  const uint32_t start_line =
 
  683      line <= context_before ? 1 : line - context_before;
 
  684  const uint32_t start_line_offset = 
GetLineOffset(start_line);
 
  686    const uint32_t end_line = line + context_after;
 
  689      end_line_offset = 
m_data_sp->GetByteSize();
 
  691    assert(start_line_offset <= end_line_offset);
 
  692    if (start_line_offset < end_line_offset) {
 
  693      size_t count = end_line_offset - start_line_offset;
 
  694      const uint8_t *cstr = 
m_data_sp->GetBytes() + start_line_offset;
 
  696      auto ref = llvm::StringRef(
reinterpret_cast<const char *
>(cstr), count);
 
  698      h.Highlight(style, ref, column, 
"", *s);
 
 
  710    std::vector<uint32_t> &match_lines) {
 
  716  if (start_line > end_line)
 
  719  for (uint32_t line_no = start_line; line_no < end_line; line_no++) {
 
  724      match_lines.push_back(line_no);
 
 
  749      const char *start = (
const char *)
m_data_sp->GetBytes();
 
  751        const char *end = start + 
m_data_sp->GetByteSize();
 
  759        for (s = start; s < end; ++s) {
 
  765                if (curr_ch != next_ch)
 
  773          if (
m_offsets.back() < 
size_t(end - start))
 
  780      assert(
"Not implemented yet" && 
false);
 
  785    assert(
"Not implemented yet" && 
false);
 
 
  799  buffer.assign((
const char *)
m_data_sp->GetBytes() + start_offset,
 
  800                end_offset - start_offset);
 
 
  807  llvm::sys::ScopedWriter guard(
m_mutex);
 
  809  assert(file_sp && 
"invalid FileSP");
 
  812  const FileSpec &resolved_file_spec = file_sp->GetSupportFile()->GetSpecOnly();
 
  813  if (file_spec != resolved_file_spec)
 
 
  818  llvm::sys::ScopedWriter guard(
m_mutex);
 
  820  assert(file_sp && 
"invalid FileSP");
 
  826    if (it->second == file_sp)
 
 
  839    if (file_sp != pos->second)
 
 
  846  llvm::sys::ScopedReader guard(
m_mutex);
 
  848  FileCache::const_iterator pos = 
m_file_cache.find(file_spec);
 
 
  856  stream << 
"Modification time   MD5 Checksum (on-disk)           MD5 Checksum (line table)        Lines    Path\n";
 
  857  stream << 
"------------------- -------------------------------- -------------------------------- -------- --------------------------------\n";
 
  862    FileSP file = entry.second;
 
  863    stream.
Format(
"{0:%Y-%m-%d %H:%M:%S} {1,32} {2,32} {3,8:d} {4}\n",
 
  864                  file->GetTimestamp(), 
toString(file->GetChecksum()),
 
  865                  toString(file->GetSupportFile()->GetChecksum()),
 
  866                  file->GetNumLines(), entry.first.GetPath());
 
 
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
static void resolve_tilde(FileSpec &file_spec)
static bool should_highlight_source(DebuggerSP debugger_sp)
static bool is_newline_char(char ch)
static bool should_show_stop_column_with_caret(DebuggerSP debugger_sp)
static bool should_show_stop_line_with_ansi(DebuggerSP debugger_sp)
static bool should_show_stop_column_with_ansi(DebuggerSP debugger_sp)
std::string digest() const
A class that describes a compilation unit.
lldb::SupportFileSP GetPrimarySupportFile() const
Return the primary source file associated with this compile unit.
Represents a generic declaration context in a program.
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
const char * GetCString() const
Get the string value as a C string.
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report warning events.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
const ConstString & GetFilename() const
Filename string const get accessor.
const ConstString & GetDirectory() const
Directory string const get accessor.
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
llvm::sys::TimePoint GetModificationTime(const FileSpec &file_spec) const
Returns the modification time of the given file.
static FileSystem & Instance()
std::shared_ptr< DataBuffer > CreateDataBuffer(const llvm::Twine &path, uint64_t size=0, uint64_t offset=0)
Create memory buffer from path.
void Set(llvm::StringRef prefix, llvm::StringRef suffix)
Sets the prefix and suffix strings.
Manages the available highlighters.
const Highlighter & getHighlighterFor(lldb::LanguageType language_type, llvm::StringRef path) const
Queries all known highlighter for one that can highlight some source code.
A class that describes an executable image and its associated object and symbol files.
void FindFunctions(const LookupInfo &lookup_info, const CompilerDeclContext &parent_decl_ctx, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list)
Find functions by lookup info.
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...
lldb::TargetWP m_target_wp
bool ModificationTimeIsStale() const
llvm::sys::TimePoint m_mod_time
uint32_t GetSourceMapModificationID() const
void FindLinesMatchingRegex(RegularExpression ®ex, uint32_t start_line, uint32_t end_line, std::vector< uint32_t > &match_lines)
const char * PeekLineData(uint32_t line)
bool LineIsValid(uint32_t line)
Checksum m_checksum
Keep track of the on-disk checksum.
bool PathRemappingIsStale() const
uint32_t GetLineLength(uint32_t line, bool include_newline_chars)
bool CalculateLineOffsets(uint32_t line=UINT32_MAX)
File(lldb::SupportFileSP support_file_sp, lldb::TargetSP target_sp)
lldb::DataBufferSP m_data_sp
lldb::SupportFileSP GetSupportFile() const
void CommonInitializer(lldb::SupportFileSP support_file_sp, lldb::TargetSP target_sp)
lldb::DebuggerWP m_debugger_wp
bool GetLine(uint32_t line_no, std::string &buffer)
uint32_t GetLineOffset(uint32_t line)
void SetSupportFile(lldb::SupportFileSP support_file_sp)
Set file and update modification time.
uint32_t m_source_map_mod_id
size_t DisplaySourceLines(uint32_t line, std::optional< size_t > column, uint32_t context_before, uint32_t context_after, Stream *s)
lldb::SupportFileSP m_support_file_sp
The support file.
void AddSourceFileImpl(const FileSpec &file_spec, FileSP file_sp)
void RemoveSourceFile(const FileSP &file_sp)
FileSP FindSourceFile(const FileSpec &file_spec) const
llvm::sys::RWMutex m_mutex
void Dump(Stream &stream) const
void AddSourceFile(const FileSpec &file_spec, FileSP file_sp)
void FindLinesMatchingRegex(lldb::SupportFileSP support_file_sp, RegularExpression ®ex, uint32_t start_line, uint32_t end_line, std::vector< uint32_t > &match_lines)
bool SetDefaultFileAndLine(lldb::SupportFileSP support_file_sp, uint32_t line)
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)
std::shared_ptr< File > FileSP
std::optional< SupportFileAndLine > GetDefaultFileAndLine()
bool AtLastLine(bool reverse)
lldb::SupportFileSP m_last_support_file_sp
SourceManager(const lldb::DebuggerSP &debugger_sp)
A source manager can be made with a valid Target, in which case it can use the path remappings to fin...
lldb::DebuggerWP m_debugger_wp
lldb::TargetWP m_target_wp
FileSP GetFile(lldb::SupportFileSP support_file_sp)
size_t DisplayMoreWithLineNumbers(Stream *s, uint32_t count, bool reverse, const SymbolContextList *bp_locs=nullptr)
size_t DisplaySourceLinesWithLineNumbers(lldb::SupportFileSP support_file_sp, 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)
A stream class that can stream formatted output to a file.
void Format(const char *format, Args &&... args)
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t EOL()
Output and End of Line character to the stream.
size_t GetWrittenBytes() const
Wraps a FileSpec and an optional Checksum.
Defines a list of symbol context objects.
bool GetContextAtIndex(size_t idx, SymbolContext &sc) const
Get accessor for a symbol context at index idx.
uint32_t NumLineEntriesWithLine(uint32_t line) const
Defines a symbol context baton that can be handed other debug core functions.
CompileUnit * comp_unit
The CompileUnit for a given query.
std::string FormatAnsiTerminalCodes(llvm::StringRef format, bool do_color=true)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
bool operator==(const Address &lhs, const Address &rhs)
const char * toString(AppleArm64ExceptionClass EC)
std::shared_ptr< lldb_private::SupportFile > SupportFileSP
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Debugger > DebuggerSP
@ eStopShowColumnAnsiOrCaret
std::shared_ptr< lldb_private::Target > TargetSP
Represents style that the highlighter should apply to the given source code.
static HighlightStyle MakeVimStyle()
Returns a HighlightStyle that is based on vim's default highlight style.
ColorStyle selected
The style for the token which is below the cursor of the user.
A line table entry class.
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
lldb::SupportFileSP file_sp
The source file, possibly mapped by the target.source-map setting.
Options used by Module::FindFunctions.
bool include_inlines
Include inlined functions.
bool include_symbols
Include the symbol table.