59#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
60#include "clang/Frontend/CompilerInstance.h"
61#include "clang/Frontend/CompilerInvocation.h"
62#include "clang/Frontend/FrontendActions.h"
63#include "llvm/ADT/ScopeExit.h"
64#include "llvm/Support/FileSystem.h"
65#include "llvm/Support/FormatAdapters.h"
72 const char *prefix_cstr,
73 bool show_stopped_process_status,
Stream &strm) {
78 bool exe_valid =
false;
83 ::strcpy(exe_path,
"<none>");
85 std::string formatted_label =
"";
86 const std::string &label = target->
GetLabel();
88 formatted_label =
" (" + label +
")";
91 strm.
Printf(
"%starget #%u%s: %s", prefix_cstr ? prefix_cstr :
"", target_idx,
92 formatted_label.data(), exe_path);
94 uint32_t properties = 0;
96 strm.
Printf(
"%sarch=", properties++ > 0 ?
", " :
" ( ");
102 strm.
Format(
"{0}platform={1}", properties++ > 0 ?
", " :
" ( ",
103 platform_sp->GetName());
106 bool show_process_status =
false;
109 StateType state = process_sp->GetState();
110 if (show_stopped_process_status)
114 strm.
Printf(
"%spid=%" PRIu64, properties++ > 0 ?
", " :
" ( ", pid);
115 strm.
Printf(
"%sstate=%s", properties++ > 0 ?
", " :
" ( ", state_cstr);
121 if (show_process_status) {
122 const bool only_threads_with_stop_reason =
true;
123 const uint32_t start_frame = 0;
124 const uint32_t num_frames = 1;
125 const uint32_t num_frames_with_source = 1;
126 const bool stop_format =
false;
127 process_sp->GetStatus(strm);
128 process_sp->GetThreadStatus(strm, only_threads_with_stop_reason,
129 start_frame, num_frames, num_frames_with_source,
135 bool show_stopped_process_status,
Stream &strm) {
140 for (uint32_t i = 0; i < num_targets; ++i) {
143 bool is_selected = target_sp.get() == selected_target_sp.get();
145 show_stopped_process_status, strm);
152#define LLDB_OPTIONS_target_dependents
153#include "CommandOptions.inc"
162 return llvm::ArrayRef(g_target_dependents_options);
170 if (option_value.empty()) {
175 const char short_option =
176 g_target_dependents_options[option_idx].short_option;
177 if (short_option ==
'd') {
180 option_value, g_target_dependents_options[option_idx].enum_values, 0,
185 error.SetErrorStringWithFormat(
"unrecognized short option '%c'",
206#pragma mark CommandObjectTargetCreate
212 interpreter,
"target create",
213 "Create a target using the argument as the main executable.",
217 "Fullpath to a core file to use for this target."),
219 "Optional name for this target.", nullptr),
222 "Fullpath to a stand alone debug "
223 "symbols file for when debug symbols "
224 "are not in the executable."),
227 "Fullpath to the file on the remote host if debugging remotely.") {
237 arg.push_back(file_arg);
276 llvm::toString(file.takeError()));
281 if (argc == 1 || core_file || remote_file) {
290 llvm::toString(file.takeError()));
298 bool must_set_platform_path =
false;
305 debugger, file_path, arch_cstr,
314 const llvm::StringRef label =
316 if (!label.empty()) {
317 if (
auto E = target_sp->SetLabel(label))
322 auto on_error = llvm::make_scope_exit(
324 target_list.DeleteTarget(target_sp);
331 PlatformSP platform_sp = target_sp->GetPlatform();
335 file_spec.
SetFile(file_path, FileSpec::Style::native);
340 if (platform_sp && platform_sp->IsHost() &&
350 if (!platform_sp->GetFileExists(remote_file)) {
351 Status err = platform_sp->PutFile(file_spec, remote_file);
365 Status err = platform_sp->GetFile(remote_file, file_spec);
379 if (platform_sp->IsHost()) {
380 result.
AppendError(
"Supply a local file, not a remote file, "
381 "when debugging on the host.");
384 if (platform_sp->IsConnected() && !platform_sp->GetFileExists(remote_file)) {
385 result.
AppendError(
"remote --> local transfer without local "
386 "path is not implemented yet");
393 target_sp->SetProcessLaunchInfo(launch_info);
397 result.
AppendError(
"no platform found for target");
402 if (symfile || remote_file) {
403 ModuleSP module_sp(target_sp->GetExecutableModule());
406 module_sp->SetSymbolFileFileSpec(symfile);
408 std::string remote_path = remote_file.
GetPath();
409 target_sp->SetArg0(remote_path.c_str());
410 module_sp->SetPlatformFileSpec(remote_file);
415 if (must_set_platform_path) {
418 target_sp->GetOrCreateModule(main_module_spec,
true );
420 module_sp->SetPlatformFileSpec(remote_file);
426 target_sp->AppendExecutableSearchPaths(core_file_dir);
428 ProcessSP process_sp(target_sp->CreateProcess(
429 GetDebugger().GetListener(), llvm::StringRef(), &core_file,
false));
434 error = process_sp->LoadCore();
438 error.AsCString(
"can't find plug-in for core file"));
442 "Core file '{0}' ({1}) was loaded.\n", core_file.
GetPath(),
443 target_sp->GetArchitecture().GetArchitectureName());
449 "Unable to find process plug-in for core file '{0}'\n",
454 "Current executable set to '%s' (%s).\n",
456 target_sp->GetArchitecture().GetArchitectureName());
462 "argument, or use the --core option.\n",
480#pragma mark CommandObjectTargetList
486 interpreter,
"target list",
487 "List all current targets in the current debug session.", nullptr) {
496 bool show_stopped_process_status =
false;
498 show_stopped_process_status, strm) == 0) {
506#pragma mark CommandObjectTargetSelect
512 interpreter,
"target select",
513 "Select a target as the current target by target index.", nullptr) {
527 if (llvm::to_integer(target_identifier, target_idx)) {
528 if (target_idx < num_targets) {
531 bool show_stopped_process_status =
false;
535 if (num_targets > 0) {
537 "index %u is out of range, valid target indexes are 0 - %u\n",
538 target_idx, num_targets - 1);
541 "index %u is out of range since there are no active targets\n",
546 for (
size_t i = 0; i < num_targets; i++) {
548 const std::string &label = target_sp->GetLabel();
549 if (!label.empty() && label == target_identifier) {
559 bool show_stopped_process_status =
false;
569 "'target select' takes a single argument: a target index\n");
575#pragma mark CommandObjectTargetDelete
581 "Delete one or more targets by target index.",
587 "Perform extra cleanup to minimize memory consumption after "
588 "deleting the target. "
589 "By default, LLDB will keep in memory any modules previously "
590 "loaded by the target as well "
591 "as all of its debug info. Specifying --clean will unload all of "
592 "these shared modules and "
593 "cause them to be reparsed again the next time the target is run",
609 std::vector<TargetSP> delete_target_list;
616 }
else if (argc > 0) {
619 if (num_targets == 0) {
624 for (
auto &entry : args.
entries()) {
626 if (entry.ref().getAsInteger(0, target_idx)) {
631 if (target_idx < num_targets) {
634 delete_target_list.push_back(target_sp);
640 "target indexes are 0 - %u\n",
641 target_idx, num_targets - 1);
644 "target index %u is out of range, the only valid index is 0\n",
655 delete_target_list.push_back(target_sp);
658 const size_t num_targets_to_delete = delete_target_list.size();
659 for (
size_t idx = 0; idx < num_targets_to_delete; ++idx) {
660 target_sp = delete_target_list[idx];
662 target_sp->Destroy();
667 const bool mandatory =
true;
671 (uint32_t)num_targets_to_delete);
686 interpreter,
"target show-launch-environment",
687 "Shows the environment being passed to the process when launched, "
688 "taking info account 3 settings: target.env-vars, "
689 "target.inherit-env and target.unset-env-vars.",
690 nullptr, eCommandRequiresTarget) {}
699 std::vector<Environment::value_type *> env_vector;
700 env_vector.reserve(env.size());
702 env_vector.push_back(&KV);
703 std::sort(env_vector.begin(), env_vector.end(),
704 [](Environment::value_type *a, Environment::value_type *b) {
705 return a->first() < b->first();
709 for (
auto &KV : env_vector)
710 strm.
Format(
"{0}={1}\n", KV->first(), KV->second);
717#pragma mark CommandObjectTargetVariable
726 "Read global variables for the current target, "
727 "before or while running a process.",
728 nullptr, eCommandRequiresTarget),
733 "A basename or fullpath to a file that contains "
734 "global variables. This option can be "
735 "specified multiple times."),
739 "A basename or fullpath to a shared library to use in the search "
741 "variables. This option can be specified multiple times.") {
751 arg.push_back(var_name_arg);
772 const char *root_name) {
775 if (!valobj_sp->GetTargetSP()->GetDisplayRuntimeSupportValues() &&
776 valobj_sp->IsRuntimeSupportValue())
779 switch (var_sp->GetScope()) {
810 bool show_fullpaths =
false;
811 bool show_module =
true;
812 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
822 valobj_sp->Dump(s, options);
827 size_t old_size = variable_list.
GetSize();
832 return variable_list.
GetSize() - old_size;
841 if (variable_list.
Empty())
845 s.
Format(
"Global variables for {0} in {1}:\n",
848 s.
Printf(
"Global variables for %s\n",
849 sc.
module_sp->GetFileSpec().GetPath().c_str());
877 bool use_var_name =
false;
882 "error: invalid regular expression: '%s'\n", arg.c_str());
888 matches = variable_list.
GetSize();
893 matches = variable_list.
GetSize();
901 for (uint32_t global_idx = 0; global_idx < matches; ++global_idx) {
912 use_var_name ? var_sp->GetName().GetCString()
924 const size_t num_compile_units = compile_units.
GetSize();
925 const size_t num_shlibs = shlibs.
GetSize();
926 if (num_compile_units == 0 && num_shlibs == 0) {
927 bool success =
false;
934 const bool can_create =
true;
937 if (comp_unit_varlist_sp) {
938 size_t count = comp_unit_varlist_sp->GetSize();
950 "no global variables in current compile unit: {0}\n",
954 "no debug information for frame %u\n",
957 result.
AppendError(
"'target variable' takes one or more global "
958 "variable names as arguments\n");
963 if (num_shlibs > 0) {
964 for (
size_t shlib_idx = 0; shlib_idx < num_shlibs; ++shlib_idx) {
971 if (num_compile_units > 0) {
972 for (
size_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
973 module_sp->FindCompileUnits(
983 "target doesn't contain the specified shared library: %s\n",
984 module_file.
GetPath().c_str());
990 for (
size_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
997 const bool can_create =
true;
999 sc.comp_unit->GetVariableList(can_create));
1000 if (comp_unit_varlist_sp)
1002 }
else if (sc.module_sp) {
1005 llvm::StringRef(
"."));
1007 sc.module_sp->FindGlobalVariables(all_globals_regex,
UINT32_MAX,
1029#pragma mark CommandObjectTargetModulesSearchPathsAdd
1035 "Add new image search paths substitution pairs to "
1036 "the current target.",
1037 nullptr, eCommandRequiresTarget) {
1056 arg.push_back(old_prefix_arg);
1057 arg.push_back(new_prefix_arg);
1069 result.
AppendError(
"add requires an even number of arguments\n");
1071 for (
size_t i = 0; i < argc; i += 2) {
1075 if (from[0] && to[0]) {
1079 "target modules search path adding ImageSearchPath "
1080 "pair: '%s' -> '%s'",
1083 bool last_pair = ((argc - i) == 2);
1085 from, to, last_pair);
1089 result.
AppendError(
"<path-prefix> can't be empty\n");
1091 result.
AppendError(
"<new-path-prefix> can't be empty\n");
1099#pragma mark CommandObjectTargetModulesSearchPathsClear
1105 "Clear all current image search path substitution "
1106 "pairs from the current target.",
1107 "target modules search-paths clear",
1108 eCommandRequiresTarget) {}
1122#pragma mark CommandObjectTargetModulesSearchPathsInsert
1128 "Insert a new image search path substitution pair "
1129 "into the current target at the specified index.",
1130 nullptr, eCommandRequiresTarget) {
1142 arg1.push_back(index_arg);
1158 arg2.push_back(old_prefix_arg);
1159 arg2.push_back(new_prefix_arg);
1176 const size_t num = list.
GetSize();
1178 for (
size_t i = 0; i < num; ++i) {
1182 strm << old_path <<
" -> " << new_path;
1192 if (argc >= 3 && argc & 1) {
1193 uint32_t insert_idx;
1197 "<index> parameter is not an integer: '%s'.\n",
1206 for (uint32_t i = 0; i < argc; i += 2, ++insert_idx) {
1210 if (from[0] && to[0]) {
1211 bool last_pair = ((argc - i) == 2);
1217 result.
AppendError(
"<path-prefix> can't be empty\n");
1219 result.
AppendError(
"<new-path-prefix> can't be empty\n");
1224 result.
AppendError(
"insert requires at least three arguments\n");
1231#pragma mark CommandObjectTargetModulesSearchPathsList
1237 "List all current image search path substitution "
1238 "pairs in the current target.",
1239 "target modules search-paths list",
1240 eCommandRequiresTarget) {}
1254#pragma mark CommandObjectTargetModulesSearchPathsQuery
1260 interpreter,
"target modules search-paths query",
1261 "Transform a path using the first applicable image search path.",
1262 nullptr, eCommandRequiresTarget) {
1272 arg.push_back(path_arg);
1284 result.
AppendError(
"query requires one argument\n");
1302 bool full_triple, uint32_t width) {
1310 std::string arch_str = std::string(arch_strm.
GetString());
1313 strm.
Printf(
"%-*s", width, arch_str.c_str());
1330 uint32_t num_matches = 0;
1334 file_spec, 0,
false, eSymbolContextCompUnit, sc_list);
1336 bool first_module =
true;
1341 strm <<
"Line table for " << sc.comp_unit->GetPrimaryFile() <<
" in `"
1343 LineTable *line_table = sc.comp_unit->GetLineTable();
1349 strm <<
"No line table";
1351 first_module =
false;
1359 if (file_spec_ptr) {
1361 std::string fullpath = file_spec_ptr->
GetPath();
1362 strm.
Printf(
"%-*s", width, fullpath.c_str());
1371 strm.
Printf(
"%-*s", width,
"");
1376 if (file_spec_ptr) {
1385 strm.
Printf(
"%-*s", width,
"");
1390 if (file_spec_ptr) {
1399 strm.
Printf(
"%-*s", width,
"");
1403 std::lock_guard<std::recursive_mutex> guard(module_list.
GetMutex());
1404 const size_t num_modules = module_list.
GetSize();
1405 if (num_modules == 0)
1408 size_t num_dumped = 0;
1409 strm.
Format(
"Dumping headers for {0} module(s).\n", num_modules);
1413 if (num_dumped++ > 0) {
1417 ObjectFile *objfile = module_sp->GetObjectFile();
1419 objfile->
Dump(&strm);
1421 strm.
Format(
"No object file for module: {0:F}\n",
1422 module_sp->GetFileSpec());
1437 sort_order, name_preference);
1445 strm.
Printf(
"Sections for '%s' (%s):\n",
1458 symbol_file->Dump(strm);
1466 const Address &so_addr,
bool verbose,
bool all_ranges,
1469 strm.
Indent(
" Address: ");
1474 strm.
Indent(
" Summary: ");
1489 Module *module, uint32_t resolve_mask,
1491 bool verbose,
bool all_ranges) {
1500 else if (so_addr.
GetModule().get() != module)
1509 DumpAddress(exe_scope, so_addr, verbose, all_ranges, strm);
1518 const char *name,
bool name_is_regex,
1519 bool verbose,
bool all_ranges) {
1528 std::vector<uint32_t> match_indexes;
1530 uint32_t num_matches = 0;
1531 if (name_is_regex) {
1540 if (num_matches > 0) {
1542 strm.
Printf(
"%u symbols match %s'%s' in ", num_matches,
1543 name_is_regex ?
"the regular expression " :
"", name);
1547 for (uint32_t i = 0; i < num_matches; ++i) {
1578 bool verbose,
bool all_ranges) {
1580 bool first_module =
true;
1587 sc.GetAddressRange(eSymbolContextEverything, 0,
true, range);
1590 first_module =
false;
1597 const char *name,
bool name_is_regex,
1599 bool verbose,
bool all_ranges) {
1600 if (module && name && name[0]) {
1602 size_t num_matches = 0;
1603 if (name_is_regex) {
1605 module->
FindFunctions(function_name_regex, options, sc_list);
1609 eFunctionNameTypeAuto, options, sc_list);
1611 num_matches = sc_list.
GetSize();
1614 strm.
Printf(
"%" PRIu64
" match%s found in ", (uint64_t)num_matches,
1615 num_matches > 1 ?
"es" :
"");
1620 strm, sc_list, verbose, all_ranges);
1629 Module *module,
const char *name_cstr,
1630 bool name_is_regex) {
1632 if (module && name_cstr && name_cstr[0]) {
1634 bool name_is_fully_qualified =
false;
1637 llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
1638 module->
FindTypes(name, name_is_fully_qualified, max_num_matches,
1639 searched_symbol_files, type_list);
1641 if (type_list.
Empty())
1644 const uint64_t num_matches = type_list.
GetSize();
1647 strm.
Printf(
"%" PRIu64
" match%s found in ", num_matches,
1648 num_matches > 1 ?
"es" :
"");
1656 type_sp->GetFullCompilerType();
1659 TypeSP typedef_type_sp(type_sp);
1660 TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType());
1661 while (typedefed_type_sp) {
1663 strm.
Printf(
" typedef '%s': ",
1664 typedef_type_sp->GetName().GetCString());
1665 typedefed_type_sp->GetFullCompilerType();
1668 typedef_type_sp = typedefed_type_sp;
1669 typedefed_type_sp = typedef_type_sp->GetTypedefType();
1679 const char *name_cstr,
bool name_is_regex) {
1682 bool name_is_fully_qualified =
false;
1685 llvm::DenseSet<SymbolFile *> searched_symbol_files;
1686 module.
FindTypes(name, name_is_fully_qualified, max_num_matches,
1687 searched_symbol_files, type_list);
1689 if (type_list.
Empty())
1701 type_sp->GetFullCompilerType();
1704 TypeSP typedef_type_sp(type_sp);
1705 TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType());
1706 while (typedefed_type_sp) {
1708 strm.
Printf(
" typedef '%s': ",
1709 typedef_type_sp->GetName().GetCString());
1710 typedefed_type_sp->GetFullCompilerType();
1713 typedef_type_sp = typedefed_type_sp;
1714 typedefed_type_sp = typedef_type_sp->GetTypedefType();
1724 uint32_t line,
bool check_inlines,
1725 bool verbose,
bool all_ranges) {
1726 if (module && file_spec) {
1729 file_spec, line, check_inlines, eSymbolContextEverything, sc_list);
1730 if (num_matches > 0) {
1732 strm.
Printf(
"%u match%s found in ", num_matches,
1733 num_matches > 1 ?
"es" :
"");
1736 strm.
Printf(
":%u", line);
1742 strm, sc_list, verbose, all_ranges);
1751 bool check_global_list) {
1752 FileSpec module_file_spec(module_name);
1755 const size_t initial_size = module_list.
GetSize();
1757 if (check_global_list) {
1759 std::lock_guard<std::recursive_mutex> guard(
1763 for (
size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
1768 module_sp = module->shared_from_this();
1776 const size_t num_matches = module_list.
GetSize();
1780 if (num_matches == 0) {
1789 return module_list.
GetSize() - initial_size;
1792#pragma mark CommandObjectTargetModulesModuleAutoComplete
1815 arg.push_back(file_arg);
1831#pragma mark CommandObjectTargetModulesSourceFileAutoComplete
1841 const char *syntax, uint32_t flags)
1852 arg.push_back(source_file_arg);
1868#pragma mark CommandObjectTargetModulesDumpObjfile
1875 interpreter,
"target modules dump objfile",
1876 "Dump the object file headers from one or more target modules.",
1877 nullptr, eCommandRequiresTarget) {}
1889 size_t num_dumped = 0;
1894 if (num_dumped == 0) {
1895 result.
AppendError(
"the target has no associated executable images");
1900 const char *arg_cstr;
1901 for (
int arg_idx = 0;
1904 size_t num_matched =
1906 if (num_matched == 0) {
1908 "Unable to find an image that matches '%s'.\n", arg_cstr);
1916 if (num_dumped > 0) {
1919 result.
AppendError(
"no matching executable images found");
1925#define LLDB_OPTIONS_target_modules_dump_symtab
1926#include "CommandOptions.inc"
1933 interpreter,
"target modules dump symtab",
1934 "Dump the symbol table from one or more target modules.", nullptr,
1935 eCommandRequiresTarget) {}
1952 switch (short_option) {
1965 llvm_unreachable(
"Unimplemented option");
1976 return llvm::ArrayRef(g_target_modules_dump_symtab_options);
1986 uint32_t num_dumped = 0;
1998 std::lock_guard<std::recursive_mutex> guard(module_list.
GetMutex());
1999 const size_t num_modules = module_list.
GetSize();
2000 if (num_modules > 0) {
2002 "Dumping symbol table for {0} modules.\n", num_modules);
2004 if (num_dumped > 0) {
2009 "Interrupted in dump all symtabs with {0} "
2010 "of {1} dumped.", num_dumped, num_modules))
2019 result.
AppendError(
"the target has no associated executable images");
2024 const char *arg_cstr;
2025 for (
int arg_idx = 0;
2029 const size_t num_matches =
2031 if (num_matches > 0) {
2034 if (num_dumped > 0) {
2039 "Interrupted in dump symtab list with {0} of {1} dumped.",
2040 num_dumped, num_matches))
2051 "Unable to find an image that matches '%s'.\n", arg_cstr);
2058 result.
AppendError(
"no matching executable images found");
2066#pragma mark CommandObjectTargetModulesDumpSections
2075 interpreter,
"target modules dump sections",
2076 "Dump the sections from one or more target modules.",
2078 nullptr, eCommandRequiresTarget) {}
2085 uint32_t num_dumped = 0;
2094 if (num_modules == 0) {
2095 result.
AppendError(
"the target has no associated executable images");
2101 for (
size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
2103 "Interrupted in dump all sections with {0} of {1} dumped",
2104 image_idx, num_modules))
2114 const char *arg_cstr;
2115 for (
int arg_idx = 0;
2119 const size_t num_matches =
2121 if (num_matches > 0) {
2122 for (
size_t i = 0; i < num_matches; ++i) {
2124 "Interrupted in dump section list with {0} of {1} dumped.",
2137 std::lock_guard<std::recursive_mutex> guard(
2141 "Unable to find an image that matches '%s'.\n", arg_cstr);
2149 result.
AppendError(
"no matching executable images found");
2159 interpreter,
"target modules dump pcm-info",
2160 "Dump information about the given clang module (pcm).") {
2179 if (pcm_file.GetFileNameExtension() !=
".pcm") {
2180 result.
AppendError(
"file must have a .pcm extension");
2189 clang::CompilerInstance compiler;
2190 compiler.createDiagnostics();
2192 const char *clang_args[] = {
"clang", pcm_path};
2193 compiler.setInvocation(clang::createInvocation(clang_args));
2197 std::shared_ptr<llvm::raw_ostream> Out(
2199 clang::DumpModuleInfoAction dump_module_info(Out);
2201 compiler.getPCHContainerOperations()->registerReader(
2202 std::make_unique<clang::ObjectFilePCHContainerReader>());
2204 if (compiler.ExecuteAction(dump_module_info))
2211#pragma mark CommandObjectTargetModulesDumpClangAST
2220 interpreter,
"target modules dump ast",
2221 "Dump the clang ast for a given module's symbol file.",
2223 nullptr, eCommandRequiresTarget) {}
2232 const size_t num_modules = module_list.
GetSize();
2233 if (num_modules == 0) {
2234 result.
AppendError(
"the target has no associated executable images");
2245 if (
SymbolFile *sf = module_sp->GetSymbolFile())
2255 const size_t num_matches =
2257 if (num_matches == 0) {
2259 std::lock_guard<std::recursive_mutex> guard(
2263 "Unable to find an image that matches '%s'.\n", arg.c_str());
2267 for (
size_t i = 0; i < num_matches; ++i) {
2269 "Interrupted in dump clang ast list with {0} of {1} dumped.",
2283#pragma mark CommandObjectTargetModulesDumpSymfile
2292 interpreter,
"target modules dump symfile",
2293 "Dump the debug symbol file for one or more target modules.",
2295 nullptr, eCommandRequiresTarget) {}
2302 uint32_t num_dumped = 0;
2311 std::lock_guard<std::recursive_mutex> guard(target_modules.
GetMutex());
2312 const size_t num_modules = target_modules.
GetSize();
2313 if (num_modules == 0) {
2314 result.
AppendError(
"the target has no associated executable images");
2318 "Dumping debug symbols for {0} modules.\n", num_modules);
2321 "debug symbols with {0} of {1} modules dumped",
2322 num_dumped, num_modules))
2330 const char *arg_cstr;
2331 for (
int arg_idx = 0;
2335 const size_t num_matches =
2337 if (num_matches > 0) {
2338 for (
size_t i = 0; i < num_matches; ++i) {
2340 "of {1} requested modules",
2351 "Unable to find an image that matches '%s'.\n", arg_cstr);
2358 result.
AppendError(
"no matching executable images found");
2364#pragma mark CommandObjectTargetModulesDumpLineTable
2365#define LLDB_OPTIONS_target_modules_dump
2366#include "CommandOptions.inc"
2375 interpreter,
"target modules dump line-table",
2376 "Dump the line table for one or more compilation units.", nullptr,
2377 eCommandRequiresTarget) {}
2386 uint32_t total_num_dumped = 0;
2393 result.
AppendError(
"file option must be specified.");
2397 const char *arg_cstr;
2398 for (
int arg_idx = 0;
2404 std::lock_guard<std::recursive_mutex> guard(target_modules.
GetMutex());
2405 size_t num_modules = target_modules.
GetSize();
2406 if (num_modules > 0) {
2407 uint32_t num_dumped = 0;
2410 "Interrupted in dump all line tables with "
2411 "{0} of {1} dumped", num_dumped,
2422 if (num_dumped == 0)
2424 "No source filenames matched '%s'.\n", arg_cstr);
2426 total_num_dumped += num_dumped;
2431 if (total_num_dumped > 0)
2434 result.
AppendError(
"no source filenames matched any command arguments");
2445 assert(option_idx == 0 &&
"We only have one option.");
2456 return llvm::ArrayRef(g_target_modules_dump_options);
2465#pragma mark CommandObjectTargetModulesDump
2474 interpreter,
"target modules dump",
2475 "Commands for dumping information about one or more target "
2477 "target modules dump "
2478 "[objfile|symtab|sections|ast|symfile|line-table|pcm-info] "
2479 "[<file1> <file2> ...]") {
2511 "Add a new module to the current target's modules.",
2512 "target modules add [<module>]",
2513 eCommandRequiresTarget),
2516 "Fullpath to a stand alone debug "
2517 "symbols file for when debug symbols "
2518 "are not in the executable.") {
2570 "Unable to create the executable or symbol file with "
2571 "UUID %s with path %s and symbol file %s",
2576 "Unable to create the executable or symbol file with "
2577 "UUID %s with path %s",
2583 "or symbol file with UUID %s",
2592 "Unable to locate the executable or symbol file with UUID %s",
2599 "one or more executable image paths must be specified");
2603 for (
auto &entry : args.
entries()) {
2604 if (entry.ref().empty())
2620 module_spec,
true , &
error));
2622 const char *error_cstr =
error.AsCString();
2634 std::string resolved_path = file_spec.
GetPath();
2635 if (resolved_path != entry.ref()) {
2637 "invalid module path '%s' with resolved path '%s'\n",
2638 entry.ref().str().c_str(), resolved_path.c_str());
2663 interpreter,
"target modules load",
2664 "Set the load addresses for one or more sections in a target "
2666 "target modules load [--file <module> --uuid <uuid>] <sect-name> "
2667 "<address> [<sect-name> <address> ....]",
2668 eCommandRequiresTarget),
2670 "Fullpath or basename for module to load.",
""),
2672 "Write file contents to the memory.", false, true),
2674 "Set PC to the entry point."
2675 " Only applicable with '--load' option.",
2678 "Set the load address for all sections to be the "
2679 "virtual address in the file plus the offset.",
2702 bool search_using_module_spec =
false;
2709 if (module_list.
GetSize() == 1) {
2710 search_using_module_spec =
true;
2718 search_using_module_spec =
true;
2720 const bool use_global_module_list =
true;
2723 target, arg_cstr, module_list, use_global_module_list);
2724 if (num_matches == 1) {
2727 }
else if (num_matches > 1) {
2728 search_using_module_spec =
false;
2730 "more than 1 module matched by name '%s'\n", arg_cstr);
2732 search_using_module_spec =
false;
2739 search_using_module_spec =
true;
2744 if (search_using_module_spec) {
2747 const size_t num_matches = matching_modules.
GetSize();
2750 if (num_matches == 1) {
2757 bool changed =
false;
2762 const bool slide_is_offset =
true;
2766 result.
AppendError(
"one or more section name + load "
2767 "address pair must be specified");
2772 result.
AppendError(
"The \"--slide <offset>\" option can't "
2773 "be used in conjunction with setting "
2774 "section load addresses.\n");
2778 for (
size_t i = 0; i < argc; i += 2) {
2781 if (sect_name && load_addr_cstr) {
2784 if (llvm::to_integer(load_addr_cstr, load_addr)) {
2788 if (section_sp->IsThreadSpecific()) {
2790 "thread specific sections are not yet "
2791 "supported (section '%s')\n",
2799 "section '%s' loaded at 0x%" PRIx64
"\n",
2800 sect_name, load_addr);
2804 "matches the section "
2811 "invalid load address string '%s'\n", load_addr_cstr);
2816 result.
AppendError(
"section names must be followed by "
2817 "a load address.\n");
2819 result.
AppendError(
"one or more section name + load "
2820 "address pair must be specified.\n");
2839 if (set_pc && !file_entry.
IsValid()) {
2840 result.
AppendError(
"No entry address in object file");
2843 std::vector<ObjectFile::LoadableData> loadables(
2845 if (loadables.size() == 0) {
2849 Status error = process->WriteObjectFile(std::move(loadables));
2855 ThreadList &thread_list = process->GetThreadList();
2859 if (!reg_context->SetPC(file_entry_addr)) {
2878 if (module_spec_file) {
2879 module_spec_file->
GetPath(path,
sizeof(path));
2885 std::string uuid_str;
2894 if (num_matches > 1) {
2896 "multiple modules match%s%s%s%s:\n", path[0] ?
" file=" :
"",
2897 path, !uuid_str.empty() ?
" uuid=" :
"", uuid_str.c_str());
2898 for (
size_t i = 0; i < num_matches; ++i) {
2906 "no modules were found that match%s%s%s%s.\n",
2907 path[0] ?
" file=" :
"", path, !uuid_str.empty() ?
" uuid=" :
"",
2912 result.
AppendError(
"either the \"--file <module>\" or the \"--uuid "
2913 "<uuid>\" option must be specified.\n");
2927#pragma mark CommandObjectTargetModulesList
2929#define LLDB_OPTIONS_target_modules_list
2930#include "CommandOptions.inc"
2945 if (short_option ==
'g') {
2947 }
else if (short_option ==
'a') {
2951 unsigned long width = 0;
2952 option_arg.getAsInteger(0, width);
2965 return llvm::ArrayRef(g_target_modules_list_options);
2977 interpreter,
"target modules list",
2978 "List current executable and dependent shared library images.") {
2995 if (target ==
nullptr && !use_global_module_list) {
2996 result.
AppendError(
"invalid target, create a debug target using the "
2997 "'target create' command");
3001 uint32_t addr_byte_size =
3019 "Couldn't find module matching address: 0x%" PRIx64
".",
3024 "Couldn't find module containing address: 0x%" PRIx64
".",
3029 "Can only look up modules by address with a valid target.");
3034 size_t num_modules = 0;
3040 std::unique_lock<std::recursive_mutex> guard(
3046 if (use_global_module_list) {
3056 target, arg.c_str(), module_list, use_global_module_list);
3057 if (num_matches == 0) {
3066 module_list_ptr = &module_list;
3069 std::unique_lock<std::recursive_mutex> lock;
3070 if (module_list_ptr !=
nullptr) {
3072 std::unique_lock<std::recursive_mutex>(module_list_ptr->
GetMutex());
3074 num_modules = module_list_ptr->
GetSize();
3077 if (num_modules > 0) {
3078 for (uint32_t image_idx = 0; image_idx < num_modules; ++image_idx) {
3081 if (module_list_ptr) {
3083 module = module_sp.get();
3086 module_sp = module->shared_from_this();
3089 const size_t indent = strm.
Printf(
"[%3u] ", image_idx);
3095 if (use_global_module_list)
3097 "the global module list has no matching modules");
3099 result.
AppendError(
"the target has no matching modules");
3101 if (use_global_module_list)
3102 result.
AppendError(
"the global module list is empty");
3105 "the target has no associated executable images");
3114 if (module ==
nullptr) {
3119 bool dump_object_name =
false;
3127 bool print_space =
false;
3128 for (
size_t i = 0; i < num_entries; ++i) {
3134 switch (format_char) {
3145 dump_object_name =
true;
3154 dump_object_name =
true;
3161 uint32_t addr_nibble_width =
3167 Address base_addr(objfile->GetBaseAddress());
3172 base_addr.
Dump(&strm, target,
3176 if (format_char ==
'o') {
3178 strm.
Printf(
"0x%*.*" PRIx64, addr_nibble_width,
3183 strm.
Printf(
"0x%*.*" PRIx64, addr_nibble_width,
3184 addr_nibble_width, load_addr);
3195 strm.
Printf(
"%*s", addr_nibble_width + 2,
"");
3200 size_t ref_count = 0;
3201 ModuleSP module_sp(module->shared_from_this());
3204 ref_count = module_sp.use_count() - 1;
3207 strm.
Printf(
"{%*" PRIu64
"}", width, (uint64_t)ref_count);
3209 strm.
Printf(
"{%" PRIu64
"}", (uint64_t)ref_count);
3216 symbol_file->GetObjectFile()->GetFileSpec();
3217 if (format_char ==
'S') {
3219 if (!symfile_spec || symfile_spec == module->
GetFileSpec()) {
3220 print_space =
false;
3224 strm.
Printf(
"\n%*s", indent,
"");
3227 dump_object_name =
true;
3230 strm.
Printf(
"%.*s", width,
"<NONE>");
3235 llvm::AlignStyle::Left, width));
3239 strm.
Printf(
"%p",
static_cast<void *
>(module));
3250 if (dump_object_name) {
3253 strm.
Printf(
"(%s)", object_name);
3261#pragma mark CommandObjectTargetModulesShowUnwind
3264#define LLDB_OPTIONS_target_modules_show_unwind
3265#include "CommandOptions.inc"
3290 switch (short_option) {
3292 m_str = std::string(option_arg);
3297 error.SetErrorStringWithFormat(
"invalid address string '%s'",
3298 option_arg.str().c_str());
3303 m_str = std::string(option_arg);
3308 llvm_unreachable(
"Unimplemented option");
3321 return llvm::ArrayRef(g_target_modules_show_unwind_options);
3334 interpreter,
"target modules show-unwind",
3335 "Show synthesized unwind instructions for a function.", nullptr,
3336 eCommandRequiresTarget | eCommandRequiresProcess |
3337 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
3349 abi = process->
GetABI().get();
3351 if (process ==
nullptr) {
3353 "You must have a process running to use this command.");
3359 result.
AppendError(
"The process must be paused to use this command.");
3365 result.
AppendError(
"The process must be paused to use this command.");
3377 function_options, sc_list);
3384 module_sp->ResolveSymbolContextForAddress(addr,
3385 eSymbolContextEverything, sc);
3392 "address-expression or function name option must be specified.");
3403 if (sc.symbol ==
nullptr && sc.function ==
nullptr)
3405 if (!sc.module_sp || sc.module_sp->GetObjectFile() ==
nullptr)
3408 if (!sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0,
3421 sc.module_sp->GetUnwindTable()
3422 .GetUncachedFuncUnwindersContainingAddress(start_addr, sc));
3423 if (!func_unwinders_sp)
3427 "UNWIND PLANS for %s`%s (start addr 0x%" PRIx64
")\n",
3428 sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(),
3434 for (
size_t i = 0; i < count; i++) {
3436 if (strcmp(funcname.
GetCString(), trap_func_name) == 0)
3439 "treated as a trap handler function via user setting.\n");
3443 const std::vector<ConstString> trap_handler_names(
3444 platform_sp->GetTrapHandlerSymbolNames());
3445 for (
ConstString trap_name : trap_handler_names) {
3446 if (trap_name == funcname) {
3449 "name is listed by the platform as a trap handler.\n");
3457 func_unwinders_sp->GetUnwindPlanAtNonCallSite(*target, *thread);
3458 if (non_callsite_unwind_plan) {
3460 "Asynchronous (not restricted to call-sites) UnwindPlan is '%s'\n",
3461 non_callsite_unwind_plan->GetSourceName().AsCString());
3464 func_unwinders_sp->GetUnwindPlanAtCallSite(*target, *thread);
3465 if (callsite_unwind_plan) {
3467 "Synchronous (restricted to call-sites) UnwindPlan is '%s'\n",
3468 callsite_unwind_plan->GetSourceName().AsCString());
3471 func_unwinders_sp->GetUnwindPlanFastUnwind(*target, *thread);
3472 if (fast_unwind_plan) {
3474 "Fast UnwindPlan is '%s'\n",
3475 fast_unwind_plan->GetSourceName().AsCString());
3481 func_unwinders_sp->GetAssemblyUnwindPlan(*target, *thread);
3484 "Assembly language inspection UnwindPlan:\n");
3491 func_unwinders_sp->GetObjectFileUnwindPlan(*target);
3500 func_unwinders_sp->GetObjectFileAugmentedUnwindPlan(*target, *thread);
3501 if (of_unwind_augmented_sp) {
3509 func_unwinders_sp->GetEHFrameUnwindPlan(*target);
3518 func_unwinders_sp->GetEHFrameAugmentedUnwindPlan(*target, *thread);
3519 if (ehframe_augmented_sp) {
3527 func_unwinders_sp->GetDebugFrameUnwindPlan(*target)) {
3535 func_unwinders_sp->GetDebugFrameAugmentedUnwindPlan(*target,
3544 func_unwinders_sp->GetArmUnwindUnwindPlan(*target);
3545 if (arm_unwind_sp) {
3553 func_unwinders_sp->GetSymbolFileUnwindPlan(*thread)) {
3561 func_unwinders_sp->GetCompactUnwindUnwindPlan(*target);
3562 if (compact_unwind_sp) {
3569 if (fast_unwind_plan) {
3579 if (abi_sp->CreateDefaultUnwindPlan(arch_default)) {
3587 if (abi_sp->CreateFunctionEntryUnwindPlan(arch_entry)) {
3589 "Arch default at entry point UnwindPlan:\n");
3605#define LLDB_OPTIONS_target_modules_lookup
3606#include "CommandOptions.inc"
3633 switch (short_option) {
3641 if (option_arg.getAsInteger(0,
m_offset))
3642 error.SetErrorStringWithFormat(
"invalid offset string '%s'",
3643 option_arg.str().c_str());
3647 m_str = std::string(option_arg);
3662 error.SetErrorStringWithFormat(
"invalid line number string '%s'",
3663 option_arg.str().c_str());
3665 error.SetErrorString(
"zero is an invalid line number");
3670 m_str = std::string(option_arg);
3675 m_str = std::string(option_arg);
3680 m_str = std::string(option_arg);
3700 llvm_unreachable(
"Unimplemented option");
3724 "conjunction with --verbose.");
3730 return llvm::ArrayRef(g_target_modules_lookup_options);
3751 "Look up information within executable and "
3752 "dependent shared library images.",
3753 nullptr, eCommandRequiresTarget) {
3763 arg.push_back(file_arg);
3774 bool &syntax_error) {
3792 const SymbolContext &sym_ctx(frame->GetSymbolContext(eSymbolContextModule));
3822 eSymbolContextEverything |
3824 ?
static_cast<int>(eSymbolContextVariable)
3893 syntax_error =
true;
3904 bool syntax_error =
false;
3906 uint32_t num_successful_lookups = 0;
3920 num_successful_lookups++;
3930 std::lock_guard<std::recursive_mutex> guard(target_modules.
GetMutex());
3931 if (target_modules.
GetSize() == 0) {
3932 result.
AppendError(
"the target has no associated executable images");
3937 if (module_sp != current_module &&
3941 num_successful_lookups++;
3946 const char *arg_cstr;
3951 const size_t num_matches =
3953 if (num_matches > 0) {
3954 for (
size_t j = 0; j < num_matches; ++j) {
3959 num_successful_lookups++;
3965 "Unable to find an image that matches '%s'.\n", arg_cstr);
3969 if (num_successful_lookups > 0)
3979#pragma mark CommandObjectMultiwordImageSearchPaths
3988 interpreter,
"target modules search-paths",
3989 "Commands for managing module search paths for a target.",
3990 "target modules search-paths <subcommand> [<subcommand-options>]") {
4012#pragma mark CommandObjectTargetModules
4021 "Commands for accessing information for one or "
4022 "more target modules.",
4023 "target modules <sub-command> ...") {
4057 interpreter,
"target symbols add",
4058 "Add a debug symbol file to one of the target's current modules by "
4059 "specifying a path to a debug symbols file or by using the options "
4060 "to specify a module.",
4061 "target symbols add <cmd-options> [<symfile>]",
4062 eCommandRequiresTarget),
4066 "Locate the debug symbols for the shared library specified by "
4070 "Locate the debug symbols for the currently selected frame.", false,
4073 "Locate the debug symbols for every frame in "
4074 "the current call stack.",
4105 if (!symbol_fspec) {
4107 "one or more executable image paths must be specified");
4112 symbol_fspec.
GetPath(symfile_path,
sizeof(symfile_path));
4126 0, 0, symfile_module_specs)) {
4132 symfile_module_spec)) {
4136 symfile_uuid_module_spec.
GetUUID() = symfile_module_spec.
GetUUID();
4142 if (matching_modules.
IsEmpty()) {
4145 const size_t num_symfile_module_specs = symfile_module_specs.
GetSize();
4147 i < num_symfile_module_specs && matching_modules.
IsEmpty(); ++i) {
4149 i, symfile_module_spec)) {
4153 symfile_uuid_module_spec.
GetUUID() =
4154 symfile_module_spec.
GetUUID();
4165 if (matching_modules.
IsEmpty())
4168 while (matching_modules.
IsEmpty()) {
4172 if (!filename_no_extension)
4184 if (matching_modules.
GetSize() > 1) {
4186 "use the --uuid option to resolve the "
4192 if (matching_modules.
GetSize() == 1) {
4198 module_sp->SetSymbolFileFileSpec(symbol_fspec);
4204 if (object_file && object_file->
GetFileSpec() == symbol_fspec) {
4206 const FileSpec &module_fs = module_sp->GetFileSpec();
4208 "symbol file '%s' has been added to '%s'\n", symfile_path,
4214 module_list.
Append(module_sp);
4221 module_sp->LoadScriptingResourceInTarget(target,
error,
4225 "unable to load scripting data for module %s - error "
4227 module_sp->GetFileSpec()
4228 .GetFileNameStrippingExtension()
4231 else if (feedback_stream.
GetSize())
4240 module_sp->SetSymbolFileFileSpec(
FileSpec());
4245 ss_symfile_uuid <<
" (";
4247 ss_symfile_uuid <<
')';
4250 "symbol file '%s'%s does not match any existing module%s\n",
4251 symfile_path, ss_symfile_uuid.
GetData(),
4252 !llvm::sys::fs::is_regular_file(symbol_fspec.
GetPath())
4253 ?
"\n please specify the full path to the symbol file"
4280 error_strm.
PutCString(
"unable to find debug symbols for UUID ");
4299 module_spec.
GetFileSpec() = module_sp->GetFileSpec();
4301 module_spec.
GetUUID() = module_sp->GetUUID();
4310 "unable to find debug symbols for the executable file ");
4325 "a process must exist in order to use the --frame option");
4344 if (!frame_module_sp) {
4350 module_spec.
GetUUID() = frame_module_sp->GetUUID();
4354 module_spec.
GetFileSpec() = frame_module_sp->GetPlatformFileSpec();
4358 result.
AppendError(
"unable to find debug symbols for the current frame");
4371 "a process must exist in order to use the --stack option");
4388 bool symbols_found =
false;
4390 for (uint32_t i = 0; i < frame_count; ++i) {
4394 frame_sp->GetSymbolContext(eSymbolContextModule).module_sp);
4395 if (!frame_module_sp)
4399 module_spec.
GetUUID() = frame_module_sp->GetUUID();
4402 frame_module_sp->GetPlatformFileSpec())) {
4404 module_spec.
GetFileSpec() = frame_module_sp->GetPlatformFileSpec();
4407 bool current_frame_flush =
false;
4409 symbols_found =
true;
4410 flush |= current_frame_flush;
4413 if (!symbols_found) {
4415 "unable to find debug symbols in the current call stack");
4427 const bool uuid_option_set =
4430 const bool frame_option_set =
4432 const bool stack_option_set =
4437 if (uuid_option_set)
4439 else if (file_option_set)
4441 else if (frame_option_set)
4443 else if (stack_option_set)
4446 result.
AppendError(
"one or more symbol file paths must be specified, "
4447 "or options must be specified");
4449 if (uuid_option_set) {
4450 result.
AppendError(
"specify either one or more paths to symbol files "
4451 "or use the --uuid option without arguments");
4452 }
else if (frame_option_set) {
4453 result.
AppendError(
"specify either one or more paths to symbol files "
4454 "or use the --frame option without arguments");
4455 }
else if (file_option_set && argc > 1) {
4456 result.
AppendError(
"specify at most one symbol file path when "
4457 "--shlib option is set");
4461 for (
auto &entry : args.
entries()) {
4462 if (!entry.ref().empty()) {
4464 symbol_file_spec.
SetFile(entry.ref(), FileSpec::Style::native);
4466 if (file_option_set) {
4473 ->ResolveSymbolFile(*target, module_spec, symfile_spec)
4478 bool symfile_exists =
4481 if (symfile_exists) {
4485 std::string resolved_symfile_path =
4487 if (resolved_symfile_path != entry.ref()) {
4489 "invalid module path '%s' with resolved path '%s'\n",
4490 entry.c_str(), resolved_symfile_path.c_str());
4517#pragma mark CommandObjectTargetSymbols
4526 interpreter,
"target symbols",
4527 "Commands for adding and managing debug symbol files.",
4528 "target symbols <sub-command> ...") {
4542#pragma mark CommandObjectTargetStopHookAdd
4545#define LLDB_OPTIONS_target_stop_hook_add
4546#include "CommandOptions.inc"
4558 return llvm::ArrayRef(g_target_stop_hook_add_options);
4564 const int short_option =
4565 g_target_stop_hook_add_options[option_idx].short_option;
4567 switch (short_option) {
4574 if (option_arg.getAsInteger(0,
m_line_end)) {
4575 error.SetErrorStringWithFormat(
"invalid end line number: \"%s\"",
4576 option_arg.str().c_str());
4583 bool value, success;
4588 error.SetErrorStringWithFormat(
4589 "invalid boolean value '%s' passed for -G option",
4590 option_arg.str().c_str());
4594 error.SetErrorStringWithFormat(
"invalid start line number: \"%s\"",
4595 option_arg.str().c_str());
4623 error.SetErrorStringWithFormat(
"invalid thread id string '%s'",
4624 option_arg.str().c_str());
4640 error.SetErrorStringWithFormat(
"invalid thread index string '%s'",
4641 option_arg.str().c_str());