34#pragma mark CommandObjectSourceInfo
36#define LLDB_OPTIONS_source_info
37#include "CommandOptions.inc"
49 const int short_option =
GetDefinitions()[option_idx].short_option;
50 switch (short_option) {
54 option_arg.str().c_str());
58 if (option_arg.getAsInteger(0,
end_line))
60 option_arg.str().c_str());
64 if (option_arg.getAsInteger(0,
num_lines))
66 option_arg.str().c_str());
82 modules.push_back(std::string(option_arg));
85 llvm_unreachable(
"Unimplemented option");
103 return llvm::ArrayRef(g_source_info_options);
120 interpreter,
"source info",
121 "Display source line information for the current target "
122 "process. Defaults to instruction pointer in current stack "
124 nullptr, eCommandRequiresTarget) {}
142 uint32_t start_line =
m_options.start_line;
144 uint32_t num_lines =
m_options.num_lines;
147 uint32_t num_matches = 0;
152 Module *module = sc.module_sp.get();
154 const LineEntry &line_entry = sc.line_entry;
155 assert(module && cu);
163 if (start_line > 0 && line_entry.
line < start_line)
165 if (end_line > 0 && line_entry.
line > end_line)
167 if (num_lines > 0 && num_matches > num_lines)
171 ConstString module_file_name =
module->GetFileSpec().GetFilename();
172 assert(module_file_name);
173 if (module_file_name != last_module_file_name) {
176 strm <<
"Lines found in module `" << module_file_name <<
"\n";
182 last_module_file_name = module_file_name;
197 uint32_t start_line =
m_options.start_line;
199 uint32_t num_lines =
m_options.num_lines;
202 uint32_t num_matches = 0;
206 bool has_path = (file_spec.
GetDirectory().AsCString(
nullptr) !=
nullptr);
208 size_t file_idx = cu_file_list.
FindFileIndex(0, file_spec, has_path);
217 ConstString module_file_name =
module->GetFileSpec().GetFilename();
218 bool cu_header_printed =
false;
219 uint32_t line = start_line;
225 uint32_t start_idx = 0;
226 start_idx = cu->
FindLineEntry(start_idx, line, &cu_file_spec,
232 if (end_line > 0 && line_entry.
line > end_line)
237 line = line_entry.
line;
240 if (num_lines > 0 && num_matches > num_lines)
242 assert(cu_file_spec == line_entry.
GetFile());
243 if (!cu_header_printed) {
246 strm <<
"Lines found for file " << file_spec_name
247 <<
" in compilation unit "
249 << module_file_name <<
"\n";
250 cu_header_printed =
true;
258 start_idx = cu->
FindLineEntry(start_idx, line, &cu_file_spec,
278 uint32_t num_matches = 0;
302 size_t num_matches = 0;
303 assert(module_list.
GetSize() > 0);
308 const size_t num_modules = module_list.
GetSize();
309 for (
size_t i = 0; i < num_modules; ++i) {
313 if (module_sp->ResolveFileAddress(addr, so_addr)) {
316 if (module_sp->ResolveSymbolContextForAddress(
317 so_addr, eSymbolContextEverything, sc) &
318 eSymbolContextLineEntry) {
324 if (num_matches == 0)
325 error_strm.
Printf(
"Source information for file address 0x%" PRIx64
326 " not found in any modules.\n",
338 if (module_sp->ResolveSymbolContextForAddress(
339 so_addr, eSymbolContextEverything, sc) &
340 eSymbolContextLineEntry) {
345 so_addr.
Dump(&addr_strm,
nullptr,
348 "Address 0x%" PRIx64
" resolves to %s, but there is"
349 " no source information available for this address.\n",
354 so_addr.
Dump(&addr_strm,
nullptr,
356 error_strm.
Printf(
"Address 0x%" PRIx64
357 " resolves to %s, but it cannot"
358 " be found in any modules.\n",
362 error_strm.
Printf(
"Unable to resolve address 0x%" PRIx64
".\n", addr);
384 module_list.
FindFunctions(name, eFunctionNameTypeAuto, function_options,
386 size_t num_matches = sc_list_funcs.
GetSize();
395 if (sc.symbol && sc.symbol->ValueIsAddress()) {
396 const Address &base_address = sc.symbol->GetAddressRef();
405 if (num_matches == 0) {
411 bool context_found_for_symbol =
false;
415 sc.GetAddressRange(eSymbolContextEverything, r,
427 addr += addr_byte_size) {
432 sc.GetFunctionName(),
435 context_found_for_symbol =
true;
438 if (!context_found_for_symbol)
440 " for matching symbol '{0}'\n",
441 sc.GetFunctionName());
443 if (sc_list_lines.
GetSize() == 0) {
445 " for any symbols matching '{0}'.\n",
451 module_list, file_spec)) {
453 "Unable to dump line information for symbol '{0}'.\n", name);
466 sc_list, error_strm)) {
473 module_list, file_spec)) {
485 const char *filename =
m_options.file_name.c_str();
490 bool displayed_something =
false;
491 const size_t num_modules = module_list.
GetSize();
492 for (uint32_t i = 0; i < num_modules; ++i) {
497 displayed_something =
true;
499 if (!displayed_something) {
510 if (cur_frame ==
nullptr) {
512 "No selected frame to use to find the default source.");
515 result.
AppendError(
"no debug info for the selected frame");
525 module_list, file_spec)) {
527 "No source line info available for the selected frame.");
540 for (
size_t i = 0, e =
m_options.modules.size(); i < e; ++i) {
542 if (module_file_spec) {
555 result.
AppendError(
"the target has no associated executable images");
572 }
else if (!
m_options.file_name.empty()) {
591#pragma mark CommandObjectSourceList
593#define LLDB_OPTIONS_source_list
594#include "CommandOptions.inc"
606 const int short_option =
GetDefinitions()[option_idx].short_option;
607 switch (short_option) {
611 option_arg.str().c_str());
615 if (option_arg.getAsInteger(0,
num_lines))
617 option_arg.str().c_str());
633 modules.push_back(std::string(option_arg));
648 "Invalid value for file:line specifier: %s", fcl_err.
AsCString());
658 llvm_unreachable(
"Unimplemented option");
677 return llvm::ArrayRef(g_source_list_options);
695 "Display source code for the current target "
696 "process as specified by options.",
697 nullptr, eCommandRequiresTarget) {}
704 uint32_t index)
override {
710 return e.
ref() ==
"-r" || e.
ref() ==
"--reverse";
712 if (iter == current_command_args.
end())
753 if (
line_entry.GetFile().GetDirectory().GetCString() <
756 if (
line_entry.GetFile().GetFilename().GetCString() <
780 if (sc.
block ==
nullptr) {
783 if (!expected_info) {
784 result.
AppendError(llvm::toString(expected_info.takeError()));
787 start_file = expected_info->first;
788 start_line = expected_info->second.GetRangeBase();
789 end_line = expected_info->second.GetRangeEnd();
794 end_line = start_line +
m_options.num_lines;
801 uint32_t extra_lines;
807 if (start_line <= extra_lines)
810 line_no = start_line - extra_lines;
815 if (
m_options.num_lines > end_line - line_no)
816 m_options.num_lines = end_line - line_no + extra_lines;
822 const bool show_inlines =
true;
831 "File: {0}", start_file->GetSpecOnly().GetPath().c_str());
833 const uint32_t column = 0;
835 start_file, line_no, column, 0,
m_options.num_lines,
"",
839 "Could not find function info for: \"%s\".\n",
862 const size_t num_modules =
m_options.modules.size();
863 if (num_modules > 0) {
865 for (
size_t i = 0; i < num_modules; ++i) {
867 if (module_file_spec) {
869 matching_modules.
Clear();
873 function_options, sc_list);
878 function_options, sc_list);
884 const size_t num_modules =
m_options.modules.size();
885 if (num_modules > 0) {
887 for (
size_t i = 0; i < num_modules; ++i) {
889 if (module_file_spec) {
891 matching_modules.
Clear();
918 if (sc.symbol && sc.symbol->ValueIsAddress()) {
919 const Address &base_address = sc.symbol->GetAddressRef();
935 std::set<SourceInfo> source_match_set;
936 bool displayed_something =
false;
939 sc.GetFunctionStartLineEntry());
941 source_match_set.find(source_info) == source_match_set.end()) {
942 source_match_set.insert(source_info);
944 displayed_something =
true;
947 if (displayed_something)
961 const size_t num_modules = module_list.
GetSize();
962 for (
size_t i = 0; i < num_modules; ++i) {
965 module_sp->ResolveFileAddress(
m_options.address, so_addr)) {
968 if (module_sp->ResolveSymbolContextForAddress(
969 so_addr, eSymbolContextEverything, sc) &
970 eSymbolContextLineEntry)
977 "no modules have source information for file address 0x%" PRIx64
990 if (module_sp->ResolveSymbolContextForAddress(
991 so_addr, eSymbolContextEverything, sc) &
992 eSymbolContextLineEntry) {
995 so_addr.
Dump(&error_strm,
nullptr,
998 "is no line table information "
999 "available for this address.\n",
1008 "no modules contain load address 0x%" PRIx64
".\n",
1017 const bool show_inlines =
true;
1021 target.shared_from_this());
1025 bool show_fullpaths =
true;
1026 bool show_module =
true;
1027 bool show_inlined_frames =
true;
1028 const bool show_function_arguments =
true;
1029 const bool show_function_name =
true;
1031 m_exe_ctx.GetBestExecutionContextScope(),
1032 sc.line_entry.range.GetBaseAddress(),
1033 show_fullpaths, show_module, show_inlined_frames,
1034 show_function_arguments, show_function_name);
1040 size_t lines_to_back_up =
1043 const uint32_t column =
1045 ? sc.line_entry.column
1048 sc.comp_unit->GetPrimarySupportFile(),
1049 sc.line_entry.line, column, lines_to_back_up,
1050 m_options.num_lines - lines_to_back_up,
"->",
1055 }
else if (
m_options.file_name.empty()) {
1068 "Reached {0} of the file, no more to page",
1069 m_options.reverse ?
"beginning" :
"end");
1083 const bool show_inlines =
true;
1085 last_file_sp->GetSupportFile()->GetSpecOnly(), 0, show_inlines);
1087 target.shared_from_this());
1093 const uint32_t column = 0;
1108 bool check_inlines =
false;
1113 check_inlines =
true;
1116 size_t num_matches = 0;
1120 for (
size_t i = 0, e =
m_options.modules.size(); i < e; ++i) {
1122 if (module_file_spec) {
1124 matching_modules.
Clear();
1127 file_spec, 1, check_inlines,
1128 SymbolContextItem(eSymbolContextModule |
1129 eSymbolContextCompUnit |
1130 eSymbolContextLineEntry),
1136 file_spec, 1, check_inlines,
1137 eSymbolContextModule | eSymbolContextCompUnit |
1138 eSymbolContextLineEntry,
1142 if (num_matches == 0) {
1148 if (num_matches > 1) {
1149 bool got_multiple =
false;
1155 if (test_cu != sc.comp_unit)
1156 got_multiple =
true;
1159 test_cu = sc.comp_unit;
1164 "Multiple source files found matching: \"%s.\"\n",
1174 const bool show_inlines =
true;
1178 target.shared_from_this());
1185 const uint32_t column = 0;
1195 found_file_sp,
m_options.start_line, column, 0,
1223 "Dump the state of the source code cache. Intended "
1224 "to be used for debugging LLDB itself.",
1251 "Clear the source code cache.\n", nullptr) {}
1263 process_sp->GetSourceFileCache().Clear();
1273 "Commands for managing the source code cache.",
1274 "source cache <sub-command>") {
1289#pragma mark CommandObjectMultiwordSource
1295 "Commands for examining "
1296 "source code described by "
1297 "debug information for the "
1298 "current target process.",
1299 "source <subcommand> [<subcommand-options>]") {
static llvm::raw_ostream & error(Stream &strm)
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectSourceCacheClear(CommandInterpreter &interpreter)
~CommandObjectSourceCacheClear() override=default
~CommandObjectSourceCacheDump() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectSourceCacheDump(CommandInterpreter &interpreter)
CommandObjectSourceCache(CommandInterpreter &interpreter)
~CommandObjectSourceCache() override=default
CommandObjectSourceCache(const CommandObjectSourceCache &)=delete
const CommandObjectSourceCache & operator=(const CommandObjectSourceCache &)=delete
std::vector< std::string > modules
void OptionParsingStarting(ExecutionContext *execution_context) override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
~CommandOptions() override=default
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
void DoExecute(Args &command, CommandReturnObject &result) override
bool DumpLinesForFile(CommandReturnObject &result)
size_t GetSymbolContextsForAddress(const ModuleList &module_list, lldb::addr_t addr, SymbolContextList &sc_list, StreamString &error_strm)
Options * GetOptions() override
uint32_t DumpLinesInSymbolContexts(Stream &strm, const SymbolContextList &sc_list, const ModuleList &module_list, const FileSpec &file_spec)
bool DumpLinesForFrame(CommandReturnObject &result)
uint32_t DumpFileLinesInCompUnit(Stream &strm, Module *module, CompileUnit *cu, const FileSpec &file_spec)
bool DumpLinesInFunctions(CommandReturnObject &result)
bool DumpLinesForAddress(CommandReturnObject &result)
~CommandObjectSourceInfo() override=default
CommandObjectSourceInfo(CommandInterpreter &interpreter)
uint32_t DumpFileLinesInModule(Stream &strm, Module *module, const FileSpec &file_spec)
void OptionParsingStarting(ExecutionContext *execution_context) override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
std::vector< std::string > modules
~CommandOptions() override=default
~CommandObjectSourceList() override=default
void FindMatchingFunctions(Target &target, ConstString name, SymbolContextList &sc_list)
FileLineResolver m_breakpoint_locations
CommandObjectSourceList(CommandInterpreter &interpreter)
void FindMatchingFunctionSymbols(Target &target, ConstString name, SymbolContextList &sc_list)
const SymbolContextList * GetBreakpointLocations()
std::string m_reverse_name
size_t DisplayFunctionSource(const SymbolContext &sc, SourceInfo &source_info, CommandReturnObject &result)
std::optional< std::string > GetRepeatCommand(Args ¤t_command_args, uint32_t index) override
Get the command that appropriate for a "repeat" of the current command.
void DoExecute(Args &command, CommandReturnObject &result) override
Options * GetOptions() override
A section + offset based address range class.
Address & GetBaseAddress()
Get accessor for the base address of the range.
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
A section + offset based address class.
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Function * CalculateSymbolContextFunction() const
@ DumpStyleModuleWithFileAddress
Display as the file address with the module name prepended (if any).
bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style=DumpStyleInvalid, uint32_t addr_byte_size=UINT32_MAX, bool all_ranges=false, std::optional< Stream::HighlightSettings > settings=std::nullopt) const
Dump a description of this object to a Stream.
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
lldb::addr_t GetFileAddress() const
Get the file address.
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
A command line argument class.
const_iterator end() const
CommandObjectMultiwordSource(CommandInterpreter &interpreter)
~CommandObjectMultiwordSource() override
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
CommandObjectMultiword(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
friend class CommandInterpreter
CommandObjectParsed(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
ExecutionContext m_exe_ctx
void AppendError(llvm::StringRef in_string)
void AppendNote(llvm::StringRef in_string)
void AppendWarningWithFormatv(const char *format, Args &&...args)
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void void AppendMessageWithFormatv(const char *format, Args &&...args)
void AppendNoteWithFormatv(const char *format, Args &&...args)
void AppendErrorWithFormatv(const char *format, Args &&...args)
Stream & GetOutputStream()
A class that describes a compilation unit.
const SupportFileList & GetSupportFiles()
Get the compile unit's support file list.
const FileSpec & GetPrimaryFile() const
Return the primary source spec associated with this compile unit.
uint32_t FindLineEntry(uint32_t start_idx, uint32_t line, const FileSpec *file_spec_ptr, bool exact, LineEntry *line_entry)
Find the line entry by line and optional inlined file spec.
A uniqued constant string class.
const char * GetCString() const
Get the string value as a C string.
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
SourceManager::SourceFileCache & GetSourceFileCache()
lldb::StopShowColumn GetStopShowColumn() const
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
This class finds address for source file and line.
static bool Match(const FileSpec &pattern, const FileSpec &file)
Match FileSpec pattern against FileSpec file.
const ConstString & GetFilename() const
Filename string const get accessor.
const ConstString & GetDirectory() const
Directory string const get accessor.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
bool IsSourceImplementationFile() const
Returns true if the filespec represents an implementation source file (files with a "....
A class that describes a function.
llvm::Expected< std::pair< SupportFileNSP, SourceRange > > GetSourceInfo()
Find the file and line number range of the function.
A collection class for Module objects.
uint32_t ResolveSymbolContextsForFileSpec(const FileSpec &file_spec, 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 FileSpec&,...
void FindFunctions(ConstString name, lldb::FunctionNameType name_type_mask, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list) const
size_t GetIndexForModule(const Module *module) const
void Clear()
Clear the object's state.
Module * GetModulePointerAtIndex(size_t idx) const
Get the module pointer for the module at index idx.
void FindModules(const ModuleSpec &module_spec, ModuleList &matching_module_list) const
Finds modules whose file specification matches module_spec.
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
void FindFunctionSymbols(ConstString name, lldb::FunctionNameType name_type_mask, SymbolContextList &sc_list)
size_t GetSize() const
Gets the size of the module list.
A class that describes an executable image and its associated object and symbol files.
lldb::CompUnitSP GetCompileUnitAtIndex(size_t idx)
size_t GetNumCompileUnits()
Get the number of compile units for this module.
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
A command line option parsing protocol class.
"lldb/Core/SearchFilter.h" This is a SearchFilter that searches through all modules.
virtual void Search(Searcher &searcher)
Call this method to do the search using the Searcher.
The SourceFileCache class separates the source manager from the cache of source files.
void Dump(Stream &stream) const
std::shared_ptr< File > FileSP
size_t DisplayMoreWithLineNumbers(Stream *s, uint32_t count, bool reverse, const SymbolContextList *bp_locs=nullptr, lldb::LanguageType language_type=lldb::eLanguageTypeUnknown)
bool AtLastLine(bool reverse)
size_t DisplaySourceLinesWithLineNumbers(SupportFileNSP support_file_nsp, 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, lldb::LanguageType language_type=lldb::eLanguageTypeUnknown)
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, lldb::LanguageType language_type=lldb::eLanguageTypeUnknown)
This base class provides an interface to stack frames.
virtual const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
virtual bool HasDebugInformation()
Determine whether this StackFrame has debug information available or not.
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
bool Success() const
Test for success condition.
const char * GetData() const
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.
A list of support files for a CompileUnit.
const FileSpec & GetFileSpecAtIndex(size_t idx) const
size_t FindFileIndex(size_t idx, const FileSpec &file, bool full) const
@ eEqualFileSpecAndChecksumIfSet
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.
bool AppendIfUnique(const SymbolContext &sc, bool merge_symbol_into_function)
void Append(const SymbolContext &sc)
Append a new symbol context to the list.
Defines a symbol context baton that can be handed other debug core functions.
LineEntry GetFunctionStartLineEntry() const
Get the line entry that corresponds to the function.
Function * function
The Function for a given query.
ConstString GetFunctionName(Mangled::NamePreference preference=Mangled::ePreferDemangled) const
Find a name of the innermost function for the symbol context.
Block * block
The Block for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
void Clear(bool clear_target)
Clear the object's state.
LineEntry line_entry
The LineEntry for a given query.
InlineStrategy GetInlineStrategy() const
SourceManager & GetSourceManager()
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow, bool allow_section_end=false)
const ModuleList & GetImages() const
Get accessor for the images for this process.
const ArchSpec & GetArchitecture() const
#define LLDB_INVALID_INDEX32
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
NonNullSharedPtr< lldb_private::SupportFile > SupportFileNSP
@ eInlineBreakpointsAlways
@ eInlineBreakpointsHeaders
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
std::shared_ptr< lldb_private::Process > ProcessSP
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
bool operator==(const SourceInfo &rhs) const
SourceInfo(ConstString name, const LineEntry &line_entry)
bool operator!=(const SourceInfo &rhs) const
bool operator<(const SourceInfo &rhs) const
llvm::StringRef ref() const
A line table entry class.
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
bool GetDescription(Stream *s, lldb::DescriptionLevel level, CompileUnit *cu, Target *target, bool show_address_only) const
const FileSpec & GetFile() const
Helper to access the file.
SupportFileNSP file_sp
The source file, possibly mapped by the target.source-map setting.
SupportFileNSP original_file_sp
The original source file, from debug info.
Options used by Module::FindFunctions.
bool include_inlines
Include inlined functions.
bool include_symbols
Include the symbol table.
static lldb::addr_t ToAddress(const ExecutionContext *exe_ctx, llvm::StringRef s, lldb::addr_t fail_value, Status *error_ptr)
Try to parse an address.