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) {}
150 for (
uint32_t i = 0; i < num_scs; ++i) {
157 assert(module && cu);
165 if (start_line > 0 && line_entry.
line < start_line)
167 if (end_line > 0 && line_entry.
line > end_line)
169 if (num_lines > 0 && num_matches > num_lines)
174 assert(module_file_name);
175 if (module_file_name != last_module_file_name) {
178 strm <<
"Lines found in module `" << module_file_name <<
"\n";
184 last_module_file_name = module_file_name;
210 size_t file_idx = cu_file_list.FindFileIndex(0, file_spec, has_path);
214 cu_file_list.GetFileSpecAtIndex(file_idx);
220 bool cu_header_printed =
false;
228 start_idx = cu->
FindLineEntry(start_idx, line, &cu_file_spec,
234 if (end_line > 0 && line_entry.
line > end_line)
239 line = line_entry.
line;
242 if (num_lines > 0 && num_matches > num_lines)
244 assert(cu_file_spec == line_entry.
file);
245 if (!cu_header_printed) {
248 strm <<
"Lines found for file " << file_spec_name
249 <<
" in compilation unit "
251 << module_file_name <<
"\n";
252 cu_header_printed =
true;
260 start_idx = cu->
FindLineEntry(start_idx, line, &cu_file_spec,
304 size_t num_matches = 0;
305 assert(module_list.
GetSize() > 0);
310 const size_t num_modules = module_list.
GetSize();
311 for (
size_t i = 0; i < num_modules; ++i) {
315 if (module_sp->ResolveFileAddress(addr, so_addr)) {
318 if (module_sp->ResolveSymbolContextForAddress(
319 so_addr, eSymbolContextEverything, sc) &
320 eSymbolContextLineEntry) {
326 if (num_matches == 0)
327 error_strm.
Printf(
"Source information for file address 0x%" PRIx64
328 " not found in any modules.\n",
340 if (module_sp->ResolveSymbolContextForAddress(
341 so_addr, eSymbolContextEverything, sc) &
342 eSymbolContextLineEntry) {
347 so_addr.
Dump(&addr_strm,
nullptr,
350 "Address 0x%" PRIx64
" resolves to %s, but there is"
351 " no source information available for this address.\n",
356 so_addr.
Dump(&addr_strm,
nullptr,
358 error_strm.
Printf(
"Address 0x%" PRIx64
359 " resolves to %s, but it cannot"
360 " be found in any modules.\n",
364 error_strm.
Printf(
"Unable to resolve address 0x%" PRIx64
".\n", addr);
386 module_list.
FindFunctions(name, eFunctionNameTypeAuto, function_options,
388 size_t num_matches = sc_list_funcs.
GetSize();
396 size_t num_symbol_matches = sc_list_symbols.
GetSize();
397 for (
size_t i = 0; i < num_symbol_matches; i++) {
410 if (num_matches == 0) {
415 for (
size_t i = 0; i < num_matches; i++) {
418 bool context_found_for_symbol =
false;
434 addr += addr_byte_size) {
442 context_found_for_symbol =
true;
445 if (!context_found_for_symbol)
447 " for matching symbol '%s'.\n",
450 if (sc_list_lines.
GetSize() == 0) {
452 " for any symbols matching '%s'.\n",
458 module_list, file_spec)) {
460 "Unable to dump line information for symbol '%s'.\n",
474 sc_list, error_strm)) {
481 module_list, file_spec)) {
498 bool displayed_something =
false;
499 const size_t num_modules = module_list.
GetSize();
500 for (
uint32_t i = 0; i < num_modules; ++i) {
505 displayed_something =
true;
507 if (!displayed_something) {
518 if (cur_frame ==
nullptr) {
520 "No selected frame to use to find the default source.");
523 result.
AppendError(
"No debug info for the selected frame.");
533 module_list, file_spec)) {
535 "No source line info available for the selected frame.");
544 if (target ==
nullptr) {
546 if (target ==
nullptr) {
547 result.
AppendError(
"invalid target, create a debug target using the "
548 "'target create' command.");
562 if (module_file_spec) {
575 result.
AppendError(
"The target has no associated executable images.");
612#pragma mark CommandObjectSourceList
614#define LLDB_OPTIONS_source_list
615#include "CommandOptions.inc"
627 const int short_option =
GetDefinitions()[option_idx].short_option;
628 switch (short_option) {
631 error.SetErrorStringWithFormat(
"invalid line number: '%s'",
632 option_arg.str().c_str());
636 if (option_arg.getAsInteger(0,
num_lines))
637 error.SetErrorStringWithFormat(
"invalid line count: '%s'",
638 option_arg.str().c_str());
654 modules.push_back(std::string(option_arg));
668 error.SetErrorStringWithFormat(
669 "Invalid value for file:line specifier: %s",
680 llvm_unreachable(
"Unimplemented option");
699 return llvm::ArrayRef(g_source_list_options);
717 "Display source code for the current target "
718 "process as specified by options.",
719 nullptr, eCommandRequiresTarget) {}
732 return e.
ref() ==
"-r" || e.
ref() ==
"--reverse";
734 if (iter == current_command_args.
end())
798 if (sc.
block ==
nullptr) {
801 if (start_line == 0) {
803 "start of function: \"%s\".\n",
825 if (start_line <= extra_lines)
828 line_no = start_line - extra_lines;
840 const bool show_inlines =
true;
856 "Could not find function info for: \"%s\".\n",
880 if (num_modules > 0) {
882 for (
size_t i = 0; i < num_modules; ++i) {
884 if (module_file_spec) {
886 matching_modules.
Clear();
890 function_options, sc_list);
895 function_options, sc_list);
902 if (num_modules > 0) {
904 for (
size_t i = 0; i < num_modules; ++i) {
906 if (module_file_spec) {
908 matching_modules.
Clear();
929 size_t num_matches = sc_list.
GetSize();
935 size_t num_symbol_matches = sc_list_symbols.
GetSize();
937 for (
size_t i = 0; i < num_symbol_matches; i++) {
952 if (num_matches == 0) {
958 if (num_matches > 1) {
959 std::set<SourceInfo> source_match_set;
961 bool displayed_something =
false;
962 for (
size_t i = 0; i < num_matches; i++) {
969 if (source_match_set.find(source_info) == source_match_set.end()) {
970 source_match_set.insert(source_info);
972 displayed_something =
true;
977 if (displayed_something)
1002 const size_t num_modules = module_list.
GetSize();
1003 for (
size_t i = 0; i < num_modules; ++i) {
1009 if (module_sp->ResolveSymbolContextForAddress(
1010 so_addr, eSymbolContextEverything, sc) &
1011 eSymbolContextLineEntry)
1018 "no modules have source information for file address 0x%" PRIx64
1028 ModuleSP module_sp(so_addr.
GetModule());
1032 if (module_sp->ResolveSymbolContextForAddress(
1033 so_addr, eSymbolContextEverything, sc) &
1034 eSymbolContextLineEntry) {
1037 so_addr.
Dump(&error_strm,
nullptr,
1040 "is no line table information "
1041 "available for this address.\n",
1050 "no modules contain load address 0x%" PRIx64
".\n",
1056 for (
uint32_t i = 0; i < num_matches; ++i) {
1062 const bool show_inlines =
true;
1066 target->shared_from_this());
1070 bool show_fullpaths =
true;
1071 bool show_module =
true;
1072 bool show_inlined_frames =
true;
1073 const bool show_function_arguments =
true;
1074 const bool show_function_name =
true;
1078 show_fullpaths, show_module, show_inlined_frames,
1079 show_function_arguments, show_function_name);
1085 size_t lines_to_back_up =
1118 const bool show_inlines =
true;
1122 target->shared_from_this());
1143 bool check_inlines =
false;
1145 size_t num_matches = 0;
1151 if (module_file_spec) {
1153 matching_modules.
Clear();
1156 filename, 0, check_inlines,
1157 SymbolContextItem(eSymbolContextModule |
1158 eSymbolContextCompUnit),
1164 filename, 0, check_inlines,
1165 eSymbolContextModule | eSymbolContextCompUnit, sc_list);
1168 if (num_matches == 0) {
1174 if (num_matches > 1) {
1175 bool got_multiple =
false;
1178 for (
unsigned i = 0; i < num_matches; i++) {
1184 got_multiple =
true;
1192 "Multiple source files found matching: \"%s.\"\n",
1202 const bool show_inlines =
true;
1206 target->shared_from_this());
1241#pragma mark CommandObjectMultiwordSource
1247 "Commands for examining "
1248 "source code described by "
1249 "debug information for the "
1250 "current target process.",
1251 "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)
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.
bool DumpStopContext(Stream *s, ExecutionContextScope *exe_scope, const Address &so_addr, bool show_fullpaths, bool show_module, bool show_inlined_frames, bool show_function_arguments, bool show_function_name) const
Dump the stop context in this object to a Stream.
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.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
void Clear(bool clear_target)
Clear the object's state.
bool GetAddressRange(uint32_t scope, uint32_t range_idx, bool use_inline_block_range, AddressRange &range) const
Get the address range contained within a symbol context.
Symbol * symbol
The Symbol for a given query.
LineEntry line_entry
The LineEntry for a given query.
bool ValueIsAddress() const
Address & GetAddressRef()
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.
uint16_t column
The column number of the source line, or zero if there is no column information.
bool IsValid() const
Check if a line entry object is valid.
FileSpec file
The source file, possibly mapped by the target.source-map setting.
AddressRange range
The section offset address range for this line entry.
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)