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) {
53 error.SetErrorStringWithFormat(
"invalid line number: '%s'",
54 option_arg.str().c_str());
58 if (option_arg.getAsInteger(0,
end_line))
59 error.SetErrorStringWithFormat(
"invalid line number: '%s'",
60 option_arg.str().c_str());
64 if (option_arg.getAsInteger(0,
num_lines))
65 error.SetErrorStringWithFormat(
"invalid line count: '%s'",
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) {}
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)
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;
202 uint32_t num_matches = 0;
208 size_t file_idx = cu_file_list.
FindFileIndex(0, file_spec, has_path);
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().AsCString(),
435 context_found_for_symbol =
true;
438 if (!context_found_for_symbol)
440 " for matching symbol '%s'.\n",
441 sc.GetFunctionName().AsCString());
443 if (sc_list_lines.
GetSize() == 0) {
445 " for any symbols matching '%s'.\n",
451 module_list, file_spec)) {
453 "Unable to dump line information for symbol '%s'.\n",
467 sc_list, error_strm)) {
474 module_list, file_spec)) {
491 bool displayed_something =
false;
492 const size_t num_modules = module_list.
GetSize();
493 for (uint32_t i = 0; i < num_modules; ++i) {
498 displayed_something =
true;
500 if (!displayed_something) {
511 if (cur_frame ==
nullptr) {
513 "No selected frame to use to find the default source.");
516 result.
AppendError(
"No debug info for the selected frame.");
526 module_list, file_spec)) {
528 "No source line info available for the selected frame.");
547 if (module_file_spec) {
560 result.
AppendError(
"The target has no associated executable images.");
596#pragma mark CommandObjectSourceList
598#define LLDB_OPTIONS_source_list
599#include "CommandOptions.inc"
611 const int short_option =
GetDefinitions()[option_idx].short_option;
612 switch (short_option) {
615 error.SetErrorStringWithFormat(
"invalid line number: '%s'",
616 option_arg.str().c_str());
620 if (option_arg.getAsInteger(0,
num_lines))
621 error.SetErrorStringWithFormat(
"invalid line count: '%s'",
622 option_arg.str().c_str());
638 modules.push_back(std::string(option_arg));
652 error.SetErrorStringWithFormat(
653 "Invalid value for file:line specifier: %s",
664 llvm_unreachable(
"Unimplemented option");
683 return llvm::ArrayRef(g_source_list_options);
701 "Display source code for the current target "
702 "process as specified by options.",
703 nullptr, eCommandRequiresTarget) {}
710 uint32_t index)
override {
716 return e.
ref() ==
"-r" || e.
ref() ==
"--reverse";
718 if (iter == current_command_args.
end())
786 if (sc.
block ==
nullptr) {
789 if (start_line == 0) {
791 "start of function: \"%s\".\n",
807 uint32_t extra_lines;
813 if (start_line <= extra_lines)
816 line_no = start_line - extra_lines;
828 const bool show_inlines =
true;
838 const uint32_t column = 0;
844 "Could not find function info for: \"%s\".\n",
868 if (num_modules > 0) {
870 for (
size_t i = 0; i < num_modules; ++i) {
872 if (module_file_spec) {
874 matching_modules.
Clear();
878 function_options, sc_list);
883 function_options, sc_list);
890 if (num_modules > 0) {
892 for (
size_t i = 0; i < num_modules; ++i) {
894 if (module_file_spec) {
896 matching_modules.
Clear();
923 if (sc.symbol && sc.symbol->ValueIsAddress()) {
924 const Address &base_address = sc.symbol->GetAddressRef();
940 std::set<SourceInfo> source_match_set;
941 bool displayed_something =
false;
944 sc.GetFunctionStartLineEntry());
946 source_match_set.find(source_info) == source_match_set.end()) {
947 source_match_set.insert(source_info);
949 displayed_something =
true;
952 if (displayed_something)
966 const size_t num_modules = module_list.
GetSize();
967 for (
size_t i = 0; i < num_modules; ++i) {
973 if (module_sp->ResolveSymbolContextForAddress(
974 so_addr, eSymbolContextEverything, sc) &
975 eSymbolContextLineEntry)
982 "no modules have source information for file address 0x%" PRIx64
996 if (module_sp->ResolveSymbolContextForAddress(
997 so_addr, eSymbolContextEverything, sc) &
998 eSymbolContextLineEntry) {
1001 so_addr.
Dump(&error_strm,
nullptr,
1004 "is no line table information "
1005 "available for this address.\n",
1014 "no modules contain load address 0x%" PRIx64
".\n",
1023 const bool show_inlines =
true;
1027 target.shared_from_this());
1031 bool show_fullpaths =
true;
1032 bool show_module =
true;
1033 bool show_inlined_frames =
true;
1034 const bool show_function_arguments =
true;
1035 const bool show_function_name =
true;
1038 sc.line_entry.range.GetBaseAddress(),
1039 show_fullpaths, show_module, show_inlined_frames,
1040 show_function_arguments, show_function_name);
1046 size_t lines_to_back_up =
1049 const uint32_t column =
1051 ? sc.line_entry.column
1054 sc.comp_unit->GetPrimaryFile(), sc.line_entry.line, column,
1079 const bool show_inlines =
true;
1083 target.shared_from_this());
1089 const uint32_t column = 0;
1104 bool check_inlines =
false;
1106 size_t num_matches = 0;
1112 if (module_file_spec) {
1114 matching_modules.
Clear();
1117 filename, 0, check_inlines,
1118 SymbolContextItem(eSymbolContextModule |
1119 eSymbolContextCompUnit),
1125 filename, 0, check_inlines,
1126 eSymbolContextModule | eSymbolContextCompUnit, sc_list);
1129 if (num_matches == 0) {
1135 if (num_matches > 1) {
1136 bool got_multiple =
false;
1142 if (test_cu != sc.comp_unit)
1143 got_multiple =
true;
1146 test_cu = sc.comp_unit;
1151 "Multiple source files found matching: \"%s.\"\n",
1161 const bool show_inlines =
true;
1165 target.shared_from_this());
1172 const uint32_t column = 0;
1202 "Dump the state of the source code cache. Intended "
1203 "to be used for debugging LLDB itself.",
1230 "Clear the source code cache.\n", nullptr) {}
1242 process_sp->GetSourceFileCache().Clear();
1252 "Commands for managing the source code cache.",
1253 "source cache <sub-command>") {
1268#pragma mark CommandObjectMultiwordSource
1274 "Commands for examining "
1275 "source code described by "
1276 "debug information for the "
1277 "current target process.",
1278 "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
ExecutionContext m_exe_ctx
void void AppendError(llvm::StringRef in_string)
void AppendWarningWithFormat(const char *format,...) __attribute__((format(printf
Stream & GetErrorStream()
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
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 * 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.
SourceManager::SourceFileCache & GetSourceFileCache()
lldb::StopShowColumn GetStopShowColumn() const
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
const lldb::ProcessSP & GetProcessSP() const
Get accessor to get the process shared pointer.
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
This class finds address for source file and line.
const SymbolContextList & GetFileLineMatches()
void Reset(const FileSpec &file_spec, uint32_t line, bool check_inlines)
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.
void Clear()
Clears the object state.
A class that describes a function.
void GetStartLineSourceInfo(FileSpec &source_file, uint32_t &line_no)
Find the file and line number of the source location of the start of the function.
void GetEndLineSourceInfo(FileSpec &source_file, uint32_t &line_no)
Find the file and line number of the source location of the end of the function.
A collection class for Module objects.
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.
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,...
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 the first module whose file specification matches file_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.
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
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.
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, bool allow_section_end=false) const
The SourceFileCache class separates the source manager from the cache of source files.
void Dump(Stream &stream) const
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
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)
size_t DisplayMoreWithLineNumbers(Stream *s, uint32_t count, bool reverse, const SymbolContextList *bp_locs=nullptr)
This base class provides an interface to stack frames.
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
bool HasDebugInformation()
Determine whether this StackFrame has debug information available or not.
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.
void SetAddressByteSize(uint32_t addr_size)
Set the address size in bytes.
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.
SourceManager & GetSourceManager()
SectionLoadList & GetSectionLoadList()
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.
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.
lldb::SupportFileSP original_file_sp
The original source file, from debug info.
bool IsValid() const
Check if a line entry object is valid.
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.
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.