32#include "llvm/ADT/Twine.h"
63 : m_last_line(0), m_last_count(0), m_default_set(false),
64 m_target_wp(target_sp),
65 m_debugger_wp(target_sp->GetDebugger().shared_from_this()) {}
68 : m_last_line(0), m_last_count(0), m_default_set(false), m_target_wp(),
69 m_debugger_wp(debugger_sp) {}
83 if (debugger_sp && debugger_sp->GetUseSourceCache())
84 file_sp = debugger_sp->GetSourceFileCache().FindSourceFile(resolved_fspec);
90 if (target_sp && file_sp &&
91 file_sp->GetSourceMapModificationID() !=
92 target_sp->GetSourcePathMap().GetModificationID())
97 file_sp->UpdateIfNeeded();
102 file_sp = std::make_shared<File>(resolved_fspec, target_sp.get());
104 file_sp = std::make_shared<File>(resolved_fspec, debugger_sp);
106 if (debugger_sp && debugger_sp->GetUseSourceCache())
107 debugger_sp->GetSourceFileCache().AddSourceFile(file_sp);
118 if (!debugger_sp->GetUseColor())
121 return debugger_sp->GetHighlightSource();
132 if (!debugger_sp->GetUseColor())
138 const auto value = debugger_sp->GetStopShowColumn();
151 const auto value = debugger_sp->GetStopShowColumn();
161 return debugger_sp && debugger_sp->GetUseColor();
166 const char *current_line_cstr,
Stream *s,
173 if (start_line == 0) {
190 const uint32_t end_line = start_line + count - 1;
191 for (
uint32_t line = start_line; line <= end_line; ++line) {
192 if (!last_file_sp->LineIsValid(line)) {
202 prefix = llvm::formatv(
"[{0}]", bp_count);
208 snprintf(buffer,
sizeof(buffer),
"%2.2s",
209 (line == curr_line) ? current_line_cstr :
"");
210 std::string current_line_highlight(buffer);
215 (debugger_sp->GetStopShowLineMarkerAnsiPrefix() +
216 current_line_highlight +
217 debugger_sp->GetStopShowLineMarkerAnsiSuffix())
221 s->
Printf(
"%s%s %-4u\t", prefix.c_str(), current_line_highlight.c_str(),
227 std::optional<size_t> columnToHighlight;
228 if (line == curr_line && column)
229 columnToHighlight = column - 1;
231 size_t this_line_size =
232 last_file_sp->DisplaySourceLines(line, columnToHighlight, 0, 0, s);
233 if (column != 0 && line == curr_line &&
236 std::string src_line;
237 last_file_sp->GetLine(line, src_line);
240 for (
size_t i = 0; i + 1 < column && i < src_line.length(); ++i)
241 s->
PutChar(src_line[i] ==
'\t' ?
'\t' :
' ');
245 if (this_line_size == 0) {
257 const char *current_line_cstr,
Stream *s,
262 uint32_t count = context_before + context_after + 1;
263 if (line > context_before)
264 start_line = line - context_before;
269 if (last_file_sp.get() != file_sp.get()) {
275 start_line, count, line, column, current_line_cstr, s, bp_locs);
283 const bool have_default_file_line = last_file_sp &&
m_last_line > 0;
311 }
else if (have_default_file_line)
350 Module *executable_ptr = target_sp->GetExecutableModulePointer();
351 if (executable_ptr) {
360 lldb::eFunctionNameTypeBase,
361 function_options, sc_list);
362 size_t num_matches = sc_list.
GetSize();
363 for (
size_t idx = 0; idx < num_matches; idx++) {
388 std::vector<uint32_t> &match_lines) {
393 return file_sp->FindLinesMatchingRegex(regex, start_line, end_line,
398 lldb::DebuggerSP debugger_sp)
399 : m_file_spec_orig(file_spec), m_file_spec(file_spec),
400 m_mod_time(
FileSystem::Instance().GetModificationTime(file_spec)),
401 m_debugger_wp(debugger_sp) {
406 : m_file_spec_orig(file_spec), m_file_spec(file_spec),
407 m_mod_time(
FileSystem::Instance().GetModificationTime(file_spec)),
408 m_debugger_wp(target ? target->GetDebugger().shared_from_this()
415 if (m_mod_time == llvm::sys::TimePoint<>()) {
422 bool check_inlines =
false;
427 SymbolContextItem(eSymbolContextModule |
428 eSymbolContextCompUnit),
430 bool got_multiple =
false;
431 if (num_matches != 0) {
432 if (num_matches > 1) {
436 for (
unsigned i = 0; i < num_matches; i++) {
470 m_file_spec = *remapped;
477 if (m_mod_time != llvm::sys::TimePoint<>())
488 if (CalculateLineOffsets(line)) {
489 if (line < m_offsets.size())
490 return m_offsets[line - 1];
496 CalculateLineOffsets();
497 return m_offsets.size();
501 if (!LineIsValid(line))
504 size_t line_offset = GetLineOffset(line);
505 if (line_offset < m_data_sp->GetByteSize())
506 return (
const char *)m_data_sp->GetBytes() + line_offset;
511 bool include_newline_chars) {
512 if (!LineIsValid(line))
515 size_t start_offset = GetLineOffset(line);
516 size_t end_offset = GetLineOffset(line + 1);
518 end_offset = m_data_sp->GetByteSize();
520 if (end_offset > start_offset) {
521 uint32_t length = end_offset - start_offset;
522 if (!include_newline_chars) {
523 const char *line_start =
524 (
const char *)m_data_sp->GetBytes() + start_offset;
526 const char last_char = line_start[length - 1];
527 if ((last_char ==
'\r') || (last_char ==
'\n'))
542 if (CalculateLineOffsets(line))
543 return line < m_offsets.size();
553 if (curr_mod_time != llvm::sys::TimePoint<>() &&
554 m_mod_time != curr_mod_time) {
555 m_mod_time = curr_mod_time;
562 std::optional<size_t> column,
586 style.
selected.
Set(debugger_sp->GetStopShowColumnAnsiPrefix(),
587 debugger_sp->GetStopShowColumnAnsiSuffix());
590 std::string path = GetFileSpec().GetPath(
false);
596 line <= context_before ? 1 : line - context_before;
597 const uint32_t start_line_offset = GetLineOffset(start_line);
599 const uint32_t end_line = line + context_after;
600 uint32_t end_line_offset = GetLineOffset(end_line + 1);
602 end_line_offset = m_data_sp->GetByteSize();
604 assert(start_line_offset <= end_line_offset);
605 if (start_line_offset < end_line_offset) {
606 size_t count = end_line_offset - start_line_offset;
607 const uint8_t *cstr = m_data_sp->GetBytes() + start_line_offset;
609 auto ref = llvm::StringRef(
reinterpret_cast<const char *
>(cstr), count);
611 h.Highlight(style, ref, column,
"", *s);
623 std::vector<uint32_t> &match_lines) {
626 if (!LineIsValid(start_line) ||
627 (end_line !=
UINT32_MAX && !LineIsValid(end_line)))
629 if (start_line > end_line)
632 for (
uint32_t line_no = start_line; line_no < end_line; line_no++) {
634 if (!GetLine(line_no, buffer))
637 match_lines.push_back(line_no);
654 if (!m_offsets.empty() && m_offsets[0] ==
UINT32_MAX)
657 if (m_offsets.empty()) {
658 if (m_data_sp.get() ==
nullptr)
661 const char *start = (
const char *)m_data_sp->GetBytes();
663 const char *end = start + m_data_sp->GetByteSize();
671 for (s = start; s < end; ++s) {
677 if (curr_ch != next_ch)
681 m_offsets.push_back(s + 1 - start);
684 if (!m_offsets.empty()) {
685 if (m_offsets.back() < size_t(end - start))
686 m_offsets.push_back(end - start);
692 assert(
"Not implemented yet" &&
false);
697 assert(
"Not implemented yet" &&
false);
703 if (!LineIsValid(line_no))
706 size_t start_offset = GetLineOffset(line_no);
707 size_t end_offset = GetLineOffset(line_no + 1);
709 end_offset = m_data_sp->GetByteSize();
711 buffer.assign((
const char *)m_data_sp->GetBytes() + start_offset,
712 end_offset - start_offset);
718 FileSpec file_spec = file_sp->GetFileSpec();
719 FileCache::iterator pos = m_file_cache.find(file_spec);
720 if (pos == m_file_cache.end())
721 m_file_cache[file_spec] = file_sp;
723 if (file_sp != pos->second)
724 m_file_cache[file_spec] = file_sp;
731 FileCache::const_iterator pos = m_file_cache.find(file_spec);
732 if (pos != m_file_cache.end())
733 file_sp = pos->second;
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)
Address & GetBaseAddress()
Get accessor for the base address of the range.
bool CalculateSymbolContextLineEntry(LineEntry &line_entry) const
A class that describes a compilation unit.
const FileSpec & GetPrimaryFile() 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.
"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.
const AddressRange & GetAddressRange()
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.
bool FindSourceFile(const FileSpec &orig_spec, FileSpec &new_spec) const
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*,uint32_t,...
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.
std::optional< FileSpec > FindFile(const FileSpec &orig_spec) const
Finds a source file given a file spec using the path remappings.
uint32_t GetModificationID() const
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...
llvm::sys::TimePoint m_mod_time
void FindLinesMatchingRegex(RegularExpression ®ex, uint32_t start_line, uint32_t end_line, std::vector< uint32_t > &match_lines)
const char * PeekLineData(uint32_t line)
File(const FileSpec &file_spec, Target *target)
bool LineIsValid(uint32_t line)
uint32_t GetLineLength(uint32_t line, bool include_newline_chars)
bool CalculateLineOffsets(uint32_t line=UINT32_MAX)
void CommonInitializer(const FileSpec &file_spec, Target *target)
bool GetLine(uint32_t line_no, std::string &buffer)
uint32_t GetLineOffset(uint32_t line)
size_t DisplaySourceLines(uint32_t line, std::optional< size_t > column, uint32_t context_before, uint32_t context_after, Stream *s)
FileSP FindSourceFile(const FileSpec &file_spec) const
void AddSourceFile(const FileSP &file_sp)
FileSpec m_last_file_spec
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)
bool SetDefaultFileAndLine(const FileSpec &file_spec, uint32_t line)
std::shared_ptr< File > FileSP
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)
SourceManager(const lldb::DebuggerSP &debugger_sp)
lldb::DebuggerWP m_debugger_wp
lldb::TargetWP m_target_wp
void FindLinesMatchingRegex(FileSpec &file_spec, RegularExpression ®ex, uint32_t start_line, uint32_t end_line, std::vector< uint32_t > &match_lines)
bool GetDefaultFileAndLine(FileSpec &file_spec, uint32_t &line)
FileSP GetFile(const FileSpec &file_spec)
size_t DisplayMoreWithLineNumbers(Stream *s, uint32_t count, bool reverse, const SymbolContextList *bp_locs=nullptr)
A stream class that can stream formatted output to a file.
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
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 GetSize() const
Get accessor for a symbol context list size.
uint32_t NumLineEntriesWithLine(uint32_t line) const
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
PathMappingList & GetSourcePathMap() const
const ModuleList & GetImages() const
Get accessor for the images for this process.
std::string FormatAnsiTerminalCodes(llvm::StringRef format, bool do_color=true)
A class that represents a running process on the host machine.
bool operator==(const Address &lhs, const Address &rhs)
@ eLanguageTypeUnknown
Unknown or invalid language value.
@ eStopShowColumnAnsiOrCaret
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.
FileSpec file
The source file, possibly mapped by the target.source-map setting.
uint32_t line
The source line number, or zero if there is no line number information.
Options used by Module::FindFunctions.
bool include_inlines
Include inlined functions.
bool include_symbols
Include the symbol table.