31 #pragma mark CommandObjectSourceInfo
33 #define LLDB_OPTIONS_source_info
34 #include "CommandOptions.inc"
46 const int short_option = GetDefinitions()[option_idx].short_option;
47 switch (short_option) {
49 if (option_arg.getAsInteger(0, start_line))
50 error.SetErrorStringWithFormat(
"invalid line number: '%s'",
51 option_arg.str().c_str());
55 if (option_arg.getAsInteger(0, end_line))
56 error.SetErrorStringWithFormat(
"invalid line number: '%s'",
57 option_arg.str().c_str());
61 if (option_arg.getAsInteger(0, num_lines))
62 error.SetErrorStringWithFormat(
"invalid line count: '%s'",
63 option_arg.str().c_str());
75 address = OptionArgParser::ToAddress(execution_context, option_arg,
82 llvm_unreachable(
"Unimplemented option");
100 return llvm::makeArrayRef(g_source_info_options);
117 interpreter,
"source info",
118 "Display source line information for the current target "
119 "process. Defaults to instruction pointer in current stack "
121 nullptr, eCommandRequiresTarget) {}
139 uint32_t start_line = m_options.start_line;
140 uint32_t end_line = m_options.end_line;
141 uint32_t num_lines = m_options.num_lines;
142 Target *target = m_exe_ctx.GetTargetPtr();
148 for (
uint32_t i = 0; i < num_scs; ++i) {
155 assert(module && cu);
161 if (!FileSpec::Match(file_spec, line_entry.
file))
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;
197 uint32_t start_line = m_options.start_line;
198 uint32_t end_line = m_options.end_line;
199 uint32_t num_lines = m_options.num_lines;
200 Target *target = m_exe_ctx.GetTargetPtr();
208 size_t file_idx = cu_file_list.FindFileIndex(0, file_spec, has_path);
212 cu_file_list.GetFileSpecAtIndex(file_idx);
218 bool cu_header_printed =
false;
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.
file);
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,
287 DumpFileLinesInCompUnit(strm, module, cu_sp.get(), file_spec);
302 size_t num_matches = 0;
303 assert(module_list.
GetSize() > 0);
304 Target *target = m_exe_ctx.GetTargetPtr();
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,
346 Address::DumpStyleModuleWithFileAddress);
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,
355 Address::DumpStyleModuleWithFileAddress);
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);
373 Target *target = m_exe_ctx.GetTargetPtr();
383 (m_module_list.GetSize() > 0) ? m_module_list : target->
GetImages();
384 module_list.
FindFunctions(name, eFunctionNameTypeAuto, function_options,
386 size_t num_matches = sc_list_funcs.
GetSize();
394 size_t num_symbol_matches = sc_list_symbols.
GetSize();
395 for (
size_t i = 0; i < num_symbol_matches; i++) {
408 if (num_matches == 0) {
410 m_options.symbol_name.c_str());
413 for (
size_t i = 0; i < num_matches; i++) {
416 bool context_found_for_symbol =
false;
432 addr += addr_byte_size) {
434 if (!GetSymbolContextsForAddress(module_list, addr, sc_list_lines,
440 context_found_for_symbol =
true;
443 if (!context_found_for_symbol)
445 " for matching symbol '%s'.\n",
448 if (sc_list_lines.
GetSize() == 0) {
450 " for any symbols matching '%s'.\n",
455 if (!DumpLinesInSymbolContexts(result.
GetOutputStream(), sc_list_lines,
456 module_list, file_spec)) {
458 "Unable to dump line information for symbol '%s'.\n",
467 Target *target = m_exe_ctx.GetTargetPtr();
471 if (!GetSymbolContextsForAddress(target->
GetImages(), m_options.address,
472 sc_list, error_strm)) {
479 module_list, file_spec)) {
490 FileSpec file_spec(m_options.file_name);
491 const char *filename = m_options.file_name.c_str();
492 Target *target = m_exe_ctx.GetTargetPtr();
494 (m_module_list.GetSize() > 0) ? m_module_list : target->
GetImages();
496 bool displayed_something =
false;
497 const size_t num_modules = module_list.
GetSize();
498 for (
uint32_t i = 0; i < num_modules; ++i) {
502 if (DumpFileLinesInModule(result.
GetOutputStream(), module, file_spec))
503 displayed_something =
true;
505 if (!displayed_something) {
515 StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
516 if (cur_frame ==
nullptr) {
518 "No selected frame to use to find the default source.");
521 result.
AppendError(
"No debug info for the selected frame.");
531 module_list, file_spec)) {
533 "No source line info available for the selected frame.");
545 GetCommandName().str().c_str());
549 Target *target = m_exe_ctx.GetTargetPtr();
550 if (target ==
nullptr) {
551 target = GetDebugger().GetSelectedTarget().get();
552 if (target ==
nullptr) {
553 result.
AppendError(
"invalid target, create a debug target using the "
554 "'target create' command.");
564 m_module_list.Clear();
565 if (!m_options.modules.empty()) {
566 for (
size_t i = 0, e = m_options.modules.size(); i < e; ++i) {
567 FileSpec module_file_spec(m_options.modules[i]);
568 if (module_file_spec) {
571 if (m_module_list.IsEmpty())
573 m_options.modules[i].c_str());
576 if (!m_module_list.GetSize()) {
581 result.
AppendError(
"The target has no associated executable images.");
586 if (!m_options.symbol_name.empty()) {
588 if (DumpLinesInFunctions(result))
594 if (DumpLinesForAddress(result))
598 }
else if (!m_options.file_name.empty()) {
600 if (DumpLinesForFile(result))
606 if (DumpLinesForFrame(result))
618 #pragma mark CommandObjectSourceList
620 #define LLDB_OPTIONS_source_list
621 #include "CommandOptions.inc"
633 const int short_option = GetDefinitions()[option_idx].short_option;
634 switch (short_option) {
636 if (option_arg.getAsInteger(0, start_line))
637 error.SetErrorStringWithFormat(
"invalid line number: '%s'",
638 option_arg.str().c_str());
642 if (option_arg.getAsInteger(0, num_lines))
643 error.SetErrorStringWithFormat(
"invalid line count: '%s'",
644 option_arg.str().c_str());
656 address = OptionArgParser::ToAddress(execution_context, option_arg,
674 error.SetErrorStringWithFormat(
675 "Invalid value for file:line specifier: %s",
686 llvm_unreachable(
"Unimplemented option");
699 show_bp_locs =
false;
705 return llvm::makeArrayRef(g_source_list_options);
723 "Display source code for the current target "
724 "process as specified by options.",
725 nullptr, eCommandRequiresTarget) {}
738 return e.
ref() ==
"-r" || e.
ref() ==
"--reverse";
740 if (iter == current_command_args.
end())
743 if (m_reverse_name.empty()) {
744 m_reverse_name = m_cmd_name;
745 m_reverse_name.append(
" -r");
747 return m_reverse_name;
756 : function(name), line_entry(line_entry) {}
797 Target *target = m_exe_ctx.GetTargetPtr();
804 if (sc.
block ==
nullptr) {
807 if (start_line == 0) {
809 "start of function: \"%s\".\n",
818 end_line = start_line + m_options.num_lines;
826 if (m_options.num_lines >= 10)
829 extra_lines = m_options.num_lines / 2;
831 if (start_line <= extra_lines)
834 line_no = start_line - extra_lines;
839 if (m_options.num_lines > end_line - line_no)
840 m_options.num_lines = end_line - line_no + extra_lines;
843 m_breakpoint_locations.Clear();
845 if (m_options.show_bp_locs) {
846 const bool show_inlines =
true;
847 m_breakpoint_locations.Reset(start_file, 0, show_inlines);
849 m_exe_ctx.GetTargetSP());
850 target_search_filter.
Search(m_breakpoint_locations);
858 start_file, line_no, column, 0, m_options.num_lines,
"",
862 "Could not find function info for: \"%s\".\n",
863 m_options.symbol_name.c_str());
878 if (m_options.num_lines == 0)
879 m_options.num_lines = 10;
885 const size_t num_modules = m_options.modules.size();
886 if (num_modules > 0) {
888 for (
size_t i = 0; i < num_modules; ++i) {
889 FileSpec module_file_spec(m_options.modules[i]);
890 if (module_file_spec) {
892 matching_modules.
Clear();
896 function_options, sc_list);
901 function_options, sc_list);
907 const size_t num_modules = m_options.modules.size();
908 if (num_modules > 0) {
910 for (
size_t i = 0; i < num_modules; ++i) {
911 FileSpec module_file_spec(m_options.modules[i]);
912 if (module_file_spec) {
914 matching_modules.
Clear();
931 GetCommandName().str().c_str());
935 Target *target = m_exe_ctx.GetTargetPtr();
937 if (!m_options.symbol_name.empty()) {
942 FindMatchingFunctions(target, name, sc_list);
943 size_t num_matches = sc_list.
GetSize();
948 FindMatchingFunctionSymbols(target, name, sc_list_symbols);
949 size_t num_symbol_matches = sc_list_symbols.
GetSize();
951 for (
size_t i = 0; i < num_symbol_matches; i++) {
966 if (num_matches == 0) {
968 m_options.symbol_name.c_str());
972 if (num_matches > 1) {
973 std::set<SourceInfo> source_match_set;
975 bool displayed_something =
false;
976 for (
size_t i = 0; i < num_matches; i++) {
983 if (source_match_set.find(source_info) == source_match_set.end()) {
984 source_match_set.insert(source_info);
985 if (DisplayFunctionSource(sc, source_info, result))
986 displayed_something =
true;
991 if (displayed_something)
1000 if (DisplayFunctionSource(sc, source_info, result)) {
1016 const size_t num_modules = module_list.
GetSize();
1017 for (
size_t i = 0; i < num_modules; ++i) {
1020 module_sp->ResolveFileAddress(m_options.address, so_addr)) {
1023 if (module_sp->ResolveSymbolContextForAddress(
1024 so_addr, eSymbolContextEverything, sc) &
1025 eSymbolContextLineEntry)
1032 "no modules have source information for file address 0x%" PRIx64
1042 ModuleSP module_sp(so_addr.
GetModule());
1046 if (module_sp->ResolveSymbolContextForAddress(
1047 so_addr, eSymbolContextEverything, sc) &
1048 eSymbolContextLineEntry) {
1051 so_addr.
Dump(&error_strm,
nullptr,
1052 Address::DumpStyleModuleWithFileAddress);
1054 "is no line table information "
1055 "available for this address.\n",
1064 "no modules contain load address 0x%" PRIx64
".\n",
1070 for (
uint32_t i = 0; i < num_matches; ++i) {
1074 if (m_options.show_bp_locs) {
1075 m_breakpoint_locations.Clear();
1076 const bool show_inlines =
true;
1080 target->shared_from_this());
1081 target_search_filter.
Search(m_breakpoint_locations);
1084 bool show_fullpaths =
true;
1085 bool show_module =
true;
1086 bool show_inlined_frames =
true;
1087 const bool show_function_arguments =
true;
1088 const bool show_function_name =
true;
1090 m_exe_ctx.GetBestExecutionContextScope(),
1092 show_fullpaths, show_module, show_inlined_frames,
1093 show_function_arguments, show_function_name);
1096 if (m_options.num_lines == 0)
1097 m_options.num_lines = 10;
1099 size_t lines_to_back_up =
1100 m_options.num_lines >= 10 ? 5 : m_options.num_lines / 2;
1108 lines_to_back_up, m_options.num_lines - lines_to_back_up,
"->",
1113 }
else if (m_options.file_name.empty()) {
1118 if (m_options.start_line == 0) {
1121 m_options.reverse, GetBreakpointLocations())) {
1125 if (m_options.num_lines == 0)
1126 m_options.num_lines = 10;
1128 if (m_options.show_bp_locs) {
1132 const bool show_inlines =
true;
1133 m_breakpoint_locations.Reset(last_file_sp->GetFileSpec(), 0,
1136 target->shared_from_this());
1137 target_search_filter.
Search(m_breakpoint_locations);
1140 m_breakpoint_locations.Clear();
1145 m_options.start_line,
1146 m_options.num_lines,
1155 const char *filename = m_options.file_name.c_str();
1157 bool check_inlines =
false;
1159 size_t num_matches = 0;
1161 if (!m_options.modules.empty()) {
1163 for (
size_t i = 0, e = m_options.modules.size(); i < e; ++i) {
1164 FileSpec module_file_spec(m_options.modules[i]);
1165 if (module_file_spec) {
1167 matching_modules.
Clear();
1170 filename, 0, check_inlines,
1171 SymbolContextItem(eSymbolContextModule |
1172 eSymbolContextCompUnit),
1178 filename, 0, check_inlines,
1179 eSymbolContextModule | eSymbolContextCompUnit, sc_list);
1182 if (num_matches == 0) {
1184 m_options.file_name.c_str());
1188 if (num_matches > 1) {
1189 bool got_multiple =
false;
1192 for (
unsigned i = 0; i < num_matches; i++) {
1198 got_multiple =
true;
1206 "Multiple source files found matching: \"%s.\"\n",
1207 m_options.file_name.c_str());
1215 if (m_options.show_bp_locs) {
1216 const bool show_inlines =
true;
1220 target->shared_from_this());
1221 target_search_filter.
Search(m_breakpoint_locations);
1223 m_breakpoint_locations.Clear();
1225 if (m_options.num_lines == 0)
1226 m_options.num_lines = 10;
1231 GetBreakpointLocations());
1236 m_options.file_name.c_str());
1245 if (m_breakpoint_locations.GetFileLineMatches().GetSize() > 0)
1246 return &m_breakpoint_locations.GetFileLineMatches();
1255 #pragma mark CommandObjectMultiwordSource
1258 CommandObjectMultiwordSource::CommandObjectMultiwordSource(
1261 "Commands for examining "
1262 "source code described by "
1263 "debug information for the "
1264 "current target process.",
1265 "source <subcommand> [<subcommand-options>]") {