33#pragma mark CommandObjectSourceInfo
35#define LLDB_OPTIONS_source_info
36#include "CommandOptions.inc"
48 const int short_option =
GetDefinitions()[option_idx].short_option;
49 switch (short_option) {
52 error.SetErrorStringWithFormat(
"invalid line number: '%s'",
53 option_arg.str().c_str());
57 if (option_arg.getAsInteger(0,
end_line))
58 error.SetErrorStringWithFormat(
"invalid line number: '%s'",
59 option_arg.str().c_str());
63 if (option_arg.getAsInteger(0,
num_lines))
64 error.SetErrorStringWithFormat(
"invalid line count: '%s'",
65 option_arg.str().c_str());
81 modules.push_back(std::string(option_arg));
84 llvm_unreachable(
"Unimplemented option");
102 return llvm::ArrayRef(g_source_info_options);
119 interpreter,
"source info",
120 "Display source line information for the current target "
121 "process. Defaults to instruction pointer in current stack "
123 nullptr, eCommandRequiresTarget) {}
151 Module *module = sc.module_sp.get();
153 const LineEntry &line_entry = sc.line_entry;
154 assert(module && cu);
162 if (start_line > 0 && line_entry.
line < start_line)
164 if (end_line > 0 && line_entry.
line > end_line)
166 if (num_lines > 0 && num_matches > num_lines)
171 assert(module_file_name);
172 if (module_file_name != last_module_file_name) {
175 strm <<
"Lines found in module `" << module_file_name <<
"\n";
181 last_module_file_name = module_file_name;
207 size_t file_idx = cu_file_list.
FindFileIndex(0, file_spec, has_path);
217 bool cu_header_printed =
false;
225 start_idx = cu->
FindLineEntry(start_idx, line, &cu_file_spec,
231 if (end_line > 0 && line_entry.
line > end_line)
236 line = line_entry.
line;
239 if (num_lines > 0 && num_matches > num_lines)
241 assert(cu_file_spec == line_entry.
file);
242 if (!cu_header_printed) {
245 strm <<
"Lines found for file " << file_spec_name
246 <<
" in compilation unit "
248 << module_file_name <<
"\n";
249 cu_header_printed =
true;
257 start_idx = cu->
FindLineEntry(start_idx, line, &cu_file_spec,
301 size_t num_matches = 0;
302 assert(module_list.
GetSize() > 0);
307 const size_t num_modules = module_list.
GetSize();
308 for (
size_t i = 0; i < num_modules; ++i) {
312 if (module_sp->ResolveFileAddress(addr, so_addr)) {
315 if (module_sp->ResolveSymbolContextForAddress(
316 so_addr, eSymbolContextEverything, sc) &
317 eSymbolContextLineEntry) {
323 if (num_matches == 0)
324 error_strm.
Printf(
"Source information for file address 0x%" PRIx64
325 " not found in any modules.\n",
337 if (module_sp->ResolveSymbolContextForAddress(
338 so_addr, eSymbolContextEverything, sc) &
339 eSymbolContextLineEntry) {
344 so_addr.
Dump(&addr_strm,
nullptr,
347 "Address 0x%" PRIx64
" resolves to %s, but there is"
348 " no source information available for this address.\n",
353 so_addr.
Dump(&addr_strm,
nullptr,
355 error_strm.
Printf(
"Address 0x%" PRIx64
356 " resolves to %s, but it cannot"
357 " be found in any modules.\n",
361 error_strm.
Printf(
"Unable to resolve address 0x%" PRIx64
".\n", addr);
383 module_list.
FindFunctions(name, eFunctionNameTypeAuto, function_options,
385 size_t num_matches = sc_list_funcs.
GetSize();
394 if (sc.symbol && sc.symbol->ValueIsAddress()) {
395 const Address &base_address = sc.symbol->GetAddressRef();
404 if (num_matches == 0) {
410 bool context_found_for_symbol =
false;
414 sc.GetAddressRange(eSymbolContextEverything, r,
426 addr += addr_byte_size) {
431 sc.GetFunctionName().AsCString(),
434 context_found_for_symbol =
true;
437 if (!context_found_for_symbol)
439 " for matching symbol '%s'.\n",
440 sc.GetFunctionName().AsCString());
442 if (sc_list_lines.
GetSize() == 0) {
444 " for any symbols matching '%s'.\n",
450 module_list, file_spec)) {
452 "Unable to dump line information for symbol '%s'.\n",
466 sc_list, error_strm)) {
473 module_list, file_spec)) {
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.");
536 if (target ==
nullptr) {
538 if (target ==
nullptr) {
539 result.
AppendError(
"invalid target, create a debug target using the "
540 "'target create' command.");
554 if (module_file_spec) {
567 result.
AppendError(
"The target has no associated executable images.");
604#pragma mark CommandObjectSourceList
606#define LLDB_OPTIONS_source_list
607#include "CommandOptions.inc"
619 const int short_option =
GetDefinitions()[option_idx].short_option;
620 switch (short_option) {
623 error.SetErrorStringWithFormat(
"invalid line number: '%s'",
624 option_arg.str().c_str());
628 if (option_arg.getAsInteger(0,
num_lines))
629 error.SetErrorStringWithFormat(
"invalid line count: '%s'",
630 option_arg.str().c_str());
646 modules.push_back(std::string(option_arg));
660 error.SetErrorStringWithFormat(
661 "Invalid value for file:line specifier: %s",
672 llvm_unreachable(
"Unimplemented option");
691 return llvm::ArrayRef(g_source_list_options);
709 "Display source code for the current target "
710 "process as specified by options.",
711 nullptr, eCommandRequiresTarget) {}
724 return e.
ref() ==
"-r" || e.
ref() ==
"--reverse";
726 if (iter == current_command_args.
end())
790 if (sc.
block ==
nullptr) {
793 if (start_line == 0) {
795 "start of function: \"%s\".\n",
817 if (start_line <= extra_lines)
820 line_no = start_line - extra_lines;
832 const bool show_inlines =
true;
848 "Could not find function info for: \"%s\".\n",
872 if (num_modules > 0) {
874 for (
size_t i = 0; i < num_modules; ++i) {
876 if (module_file_spec) {
878 matching_modules.
Clear();
882 function_options, sc_list);
887 function_options, sc_list);
894 if (num_modules > 0) {
896 for (
size_t i = 0; i < num_modules; ++i) {
898 if (module_file_spec) {
900 matching_modules.
Clear();
927 if (sc.symbol && sc.symbol->ValueIsAddress()) {
928 const Address &base_address = sc.symbol->GetAddressRef();
944 std::set<SourceInfo> source_match_set;
945 bool displayed_something =
false;
948 sc.GetFunctionStartLineEntry());
950 source_match_set.find(source_info) == source_match_set.end()) {
951 source_match_set.insert(source_info);
953 displayed_something =
true;
956 if (displayed_something)
970 const size_t num_modules = module_list.
GetSize();
971 for (
size_t i = 0; i < num_modules; ++i) {
977 if (module_sp->ResolveSymbolContextForAddress(
978 so_addr, eSymbolContextEverything, sc) &
979 eSymbolContextLineEntry)
986 "no modules have source information for file address 0x%" PRIx64
1000 if (module_sp->ResolveSymbolContextForAddress(
1001 so_addr, eSymbolContextEverything, sc) &
1002 eSymbolContextLineEntry) {
1005 so_addr.
Dump(&error_strm,
nullptr,
1008 "is no line table information "
1009 "available for this address.\n",
1018 "no modules contain load address 0x%" PRIx64
".\n",
1027 const bool show_inlines =
true;
1031 target->shared_from_this());
1035 bool show_fullpaths =
true;
1036 bool show_module =
true;
1037 bool show_inlined_frames =
true;
1038 const bool show_function_arguments =
true;
1039 const bool show_function_name =
true;
1042 sc.line_entry.range.GetBaseAddress(),
1043 show_fullpaths, show_module, show_inlined_frames,
1044 show_function_arguments, show_function_name);
1050 size_t lines_to_back_up =
1055 ? sc.line_entry.column
1058 sc.comp_unit->GetPrimaryFile(), sc.line_entry.line, column,
1083 const bool show_inlines =
true;
1087 target->shared_from_this());
1108 bool check_inlines =
false;
1110 size_t num_matches = 0;
1116 if (module_file_spec) {
1118 matching_modules.
Clear();
1121 filename, 0, check_inlines,
1122 SymbolContextItem(eSymbolContextModule |
1123 eSymbolContextCompUnit),
1129 filename, 0, check_inlines,
1130 eSymbolContextModule | eSymbolContextCompUnit, sc_list);
1133 if (num_matches == 0) {
1139 if (num_matches > 1) {
1140 bool got_multiple =
false;
1146 if (test_cu != sc.comp_unit)
1147 got_multiple =
true;
1150 test_cu = sc.comp_unit;
1155 "Multiple source files found matching: \"%s.\"\n",
1165 const bool show_inlines =
true;
1169 target->shared_from_this());
1204#pragma mark CommandObjectMultiwordSource
1210 "Commands for examining "
1211 "source code described by "
1212 "debug information for the "
1213 "current target process.",
1214 "source <subcommand> [<subcommand-options>]") {
static llvm::raw_ostream & error(Stream &strm)
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
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 DoExecute(Args &command, CommandReturnObject &result) override
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
FileLineResolver m_breakpoint_locations
bool DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectSourceList(CommandInterpreter &interpreter)
void FindMatchingFunctions(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.
Options * GetOptions() override
void FindMatchingFunctionSymbols(Target *target, ConstString name, SymbolContextList &sc_list)
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) 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 FileSpec & GetPrimaryFile() const
Return the primary source file associated with this compile unit.
const FileSpecList & GetSupportFiles()
Get the compile unit's support file list.
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.
lldb::TargetSP GetSelectedTarget()
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.
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
Target * GetTargetPtr() const
Returns a pointer to the target 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)
const FileSpec & GetFileSpecAtIndex(size_t idx) const
Get file at index.
size_t FindFileIndex(size_t idx, const FileSpec &file, bool full) const
Find a file index.
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
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.
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.
@ eReturnStatusSuccessFinishResult
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.
FileSpec original_file
The original source file, from debug info.
bool IsValid() const
Check if a line entry object is valid.
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.
bool GetDescription(Stream *s, lldb::DescriptionLevel level, CompileUnit *cu, Target *target, bool show_address_only) const
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.