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 strm.
Printf(
"%starget #%u: %s", prefix_cstr ? prefix_cstr :
"", target_idx,
90 strm.
Printf(
"%sarch=", properties++ > 0 ?
", " :
" ( ");
96 strm.
Format(
"{0}platform={1}", properties++ > 0 ?
", " :
" ( ",
97 platform_sp->GetName());
100 bool show_process_status =
false;
103 StateType state = process_sp->GetState();
104 if (show_stopped_process_status)
108 strm.
Printf(
"%spid=%" PRIu64, properties++ > 0 ?
", " :
" ( ", pid);
109 strm.
Printf(
"%sstate=%s", properties++ > 0 ?
", " :
" ( ", state_cstr);
115 if (show_process_status) {
116 const bool only_threads_with_stop_reason =
true;
119 const uint32_t num_frames_with_source = 1;
120 const bool stop_format =
false;
121 process_sp->GetStatus(strm);
122 process_sp->GetThreadStatus(strm, only_threads_with_stop_reason,
123 start_frame, num_frames, num_frames_with_source,
129 bool show_stopped_process_status,
Stream &strm) {
134 for (
uint32_t i = 0; i < num_targets; ++i) {
137 bool is_selected = target_sp.get() == selected_target_sp.get();
139 show_stopped_process_status, strm);
146#define LLDB_OPTIONS_target_dependents
147#include "CommandOptions.inc"
156 return llvm::ArrayRef(g_target_dependents_options);
164 if (option_value.empty()) {
169 const char short_option =
170 g_target_dependents_options[option_idx].short_option;
171 if (short_option ==
'd') {
174 option_value, g_target_dependents_options[option_idx].enum_values, 0,
179 error.SetErrorStringWithFormat(
"unrecognized short option '%c'",
200#pragma mark CommandObjectTargetCreate
206 interpreter,
"target create",
207 "Create a target using the argument as the main executable.",
211 "Fullpath to a core file to use for this target."),
214 "Fullpath to a stand alone debug "
215 "symbols file for when debug symbols "
216 "are not in the executable."),
219 "Fullpath to the file on the remote host if debugging remotely.") {
229 arg.push_back(file_arg);
268 llvm::toString(file.takeError()));
273 if (argc == 1 || core_file || remote_file) {
282 llvm::toString(file.takeError()));
290 bool must_set_platform_path =
false;
297 debugger, file_path, arch_cstr,
306 auto on_error = llvm::make_scope_exit(
308 target_list.DeleteTarget(target_sp);
315 PlatformSP platform_sp = target_sp->GetPlatform();
319 file_spec.
SetFile(file_path, FileSpec::Style::native);
324 if (platform_sp && platform_sp->IsHost() &&
334 if (!platform_sp->GetFileExists(remote_file)) {
335 Status err = platform_sp->PutFile(file_spec, remote_file);
349 Status err = platform_sp->GetFile(remote_file, file_spec);
363 if (platform_sp->IsHost()) {
364 result.
AppendError(
"Supply a local file, not a remote file, "
365 "when debugging on the host.");
368 if (platform_sp->IsConnected() && !platform_sp->GetFileExists(remote_file)) {
369 result.
AppendError(
"remote --> local transfer without local "
370 "path is not implemented yet");
377 target_sp->SetProcessLaunchInfo(launch_info);
381 result.
AppendError(
"no platform found for target");
386 if (symfile || remote_file) {
387 ModuleSP module_sp(target_sp->GetExecutableModule());
390 module_sp->SetSymbolFileFileSpec(symfile);
392 std::string remote_path = remote_file.
GetPath();
393 target_sp->SetArg0(remote_path.c_str());
394 module_sp->SetPlatformFileSpec(remote_file);
399 if (must_set_platform_path) {
402 target_sp->GetOrCreateModule(main_module_spec,
true );
404 module_sp->SetPlatformFileSpec(remote_file);
410 target_sp->AppendExecutableSearchPaths(core_file_dir);
412 ProcessSP process_sp(target_sp->CreateProcess(
413 GetDebugger().GetListener(), llvm::StringRef(), &core_file,
false));
418 error = process_sp->LoadCore();
422 error.AsCString(
"can't find plug-in for core file"));
426 "Core file '{0}' ({1}) was loaded.\n", core_file.
GetPath(),
427 target_sp->GetArchitecture().GetArchitectureName());
433 "Unable to find process plug-in for core file '{0}'\n",
438 "Current executable set to '%s' (%s).\n",
440 target_sp->GetArchitecture().GetArchitectureName());
446 "argument, or use the --core option.\n",
463#pragma mark CommandObjectTargetList
469 interpreter,
"target list",
470 "List all current targets in the current debug session.", nullptr) {
479 bool show_stopped_process_status =
false;
481 show_stopped_process_status, strm) == 0) {
489#pragma mark CommandObjectTargetSelect
495 interpreter,
"target select",
496 "Select a target as the current target by target index.", nullptr) {
508 if (llvm::to_integer(target_idx_arg, target_idx)) {
511 if (target_idx < num_targets) {
514 bool show_stopped_process_status =
false;
518 if (num_targets > 0) {
520 "index %u is out of range, valid target indexes are 0 - %u\n",
521 target_idx, num_targets - 1);
524 "index %u is out of range since there are no active targets\n",
534 "'target select' takes a single argument: a target index\n");
540#pragma mark CommandObjectTargetDelete
546 "Delete one or more targets by target index.",
552 "Perform extra cleanup to minimize memory consumption after "
553 "deleting the target. "
554 "By default, LLDB will keep in memory any modules previously "
555 "loaded by the target as well "
556 "as all of its debug info. Specifying --clean will unload all of "
557 "these shared modules and "
558 "cause them to be reparsed again the next time the target is run",
574 std::vector<TargetSP> delete_target_list;
581 }
else if (argc > 0) {
584 if (num_targets == 0) {
589 for (
auto &entry : args.
entries()) {
591 if (entry.ref().getAsInteger(0, target_idx)) {
596 if (target_idx < num_targets) {
599 delete_target_list.push_back(target_sp);
605 "target indexes are 0 - %u\n",
606 target_idx, num_targets - 1);
609 "target index %u is out of range, the only valid index is 0\n",
620 delete_target_list.push_back(target_sp);
623 const size_t num_targets_to_delete = delete_target_list.size();
624 for (
size_t idx = 0; idx < num_targets_to_delete; ++idx) {
625 target_sp = delete_target_list[idx];
627 target_sp->Destroy();
632 const bool mandatory =
true;
651 interpreter,
"target show-launch-environment",
652 "Shows the environment being passed to the process when launched, "
653 "taking info account 3 settings: target.env-vars, "
654 "target.inherit-env and target.unset-env-vars.",
655 nullptr, eCommandRequiresTarget) {}
664 std::vector<Environment::value_type *> env_vector;
665 env_vector.reserve(env.size());
667 env_vector.push_back(&KV);
668 std::sort(env_vector.begin(), env_vector.end(),
669 [](Environment::value_type *a, Environment::value_type *b) {
670 return a->first() < b->first();
674 for (
auto &KV : env_vector)
675 strm.
Format(
"{0}={1}\n", KV->first(), KV->second);
682#pragma mark CommandObjectTargetVariable
691 "Read global variables for the current target, "
692 "before or while running a process.",
693 nullptr, eCommandRequiresTarget),
698 "A basename or fullpath to a file that contains "
699 "global variables. This option can be "
700 "specified multiple times."),
704 "A basename or fullpath to a shared library to use in the search "
706 "variables. This option can be specified multiple times.") {
716 arg.push_back(var_name_arg);
737 const char *root_name) {
740 if (!valobj_sp->GetTargetSP()->GetDisplayRuntimeSupportValues() &&
741 valobj_sp->IsRuntimeSupportValue())
744 switch (var_sp->GetScope()) {
775 bool show_fullpaths =
false;
776 bool show_module =
true;
777 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
787 valobj_sp->Dump(s, options);
792 size_t old_size = variable_list.
GetSize();
797 return variable_list.
GetSize() - old_size;
806 if (variable_list.
Empty())
810 s.
Format(
"Global variables for {0} in {1}:\n",
813 s.
Printf(
"Global variables for %s\n",
814 sc.
module_sp->GetFileSpec().GetPath().c_str());
820 for (VariableSP var_sp : variable_list) {
842 bool use_var_name =
false;
847 "error: invalid regular expression: '%s'\n", arg.c_str());
853 matches = variable_list.
GetSize();
858 matches = variable_list.
GetSize();
866 for (
uint32_t global_idx = 0; global_idx < matches; ++global_idx) {
869 ValueObjectSP valobj_sp(
877 use_var_name ? var_sp->GetName().GetCString()
884 const FileSpecList &compile_units =
886 const FileSpecList &shlibs =
889 const size_t num_compile_units = compile_units.
GetSize();
890 const size_t num_shlibs = shlibs.GetSize();
891 if (num_compile_units == 0 && num_shlibs == 0) {
892 bool success =
false;
899 const bool can_create =
true;
900 VariableListSP comp_unit_varlist_sp(
902 if (comp_unit_varlist_sp) {
903 size_t count = comp_unit_varlist_sp->GetSize();
915 "no global variables in current compile unit: {0}\n",
919 "no debug information for frame %u\n",
922 result.
AppendError(
"'target variable' takes one or more global "
923 "variable names as arguments\n");
928 if (num_shlibs > 0) {
929 for (
size_t shlib_idx = 0; shlib_idx < num_shlibs; ++shlib_idx) {
930 const FileSpec module_file(shlibs.GetFileSpecAtIndex(shlib_idx));
936 if (num_compile_units > 0) {
937 for (
size_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
938 module_sp->FindCompileUnits(
939 compile_units.GetFileSpecAtIndex(cu_idx), sc_list);
948 "target doesn't contain the specified shared library: %s\n",
949 module_file.
GetPath().c_str());
955 for (
size_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
957 compile_units.GetFileSpecAtIndex(cu_idx), sc_list);
963 for (
uint32_t sc_idx = 0; sc_idx < num_scs; ++sc_idx) {
966 const bool can_create =
true;
967 VariableListSP comp_unit_varlist_sp(
969 if (comp_unit_varlist_sp)
1002#pragma mark CommandObjectTargetModulesSearchPathsAdd
1008 "Add new image search paths substitution pairs to "
1009 "the current target.",
1010 nullptr, eCommandRequiresTarget) {
1029 arg.push_back(old_prefix_arg);
1030 arg.push_back(new_prefix_arg);
1042 result.
AppendError(
"add requires an even number of arguments\n");
1044 for (
size_t i = 0; i < argc; i += 2) {
1048 if (from[0] && to[0]) {
1052 "target modules search path adding ImageSearchPath "
1053 "pair: '%s' -> '%s'",
1056 bool last_pair = ((argc - i) == 2);
1058 from, to, last_pair);
1062 result.
AppendError(
"<path-prefix> can't be empty\n");
1064 result.
AppendError(
"<new-path-prefix> can't be empty\n");
1072#pragma mark CommandObjectTargetModulesSearchPathsClear
1078 "Clear all current image search path substitution "
1079 "pairs from the current target.",
1080 "target modules search-paths clear",
1081 eCommandRequiresTarget) {}
1095#pragma mark CommandObjectTargetModulesSearchPathsInsert
1101 "Insert a new image search path substitution pair "
1102 "into the current target at the specified index.",
1103 nullptr, eCommandRequiresTarget) {
1115 arg1.push_back(index_arg);
1131 arg2.push_back(old_prefix_arg);
1132 arg2.push_back(new_prefix_arg);
1149 const size_t num = list.
GetSize();
1151 for (
size_t i = 0; i < num; ++i) {
1155 strm << old_path <<
" -> " << new_path;
1165 if (argc >= 3 && argc & 1) {
1170 "<index> parameter is not an integer: '%s'.\n",
1179 for (
uint32_t i = 0; i < argc; i += 2, ++insert_idx) {
1183 if (from[0] && to[0]) {
1184 bool last_pair = ((argc - i) == 2);
1190 result.
AppendError(
"<path-prefix> can't be empty\n");
1192 result.
AppendError(
"<new-path-prefix> can't be empty\n");
1197 result.
AppendError(
"insert requires at least three arguments\n");
1204#pragma mark CommandObjectTargetModulesSearchPathsList
1210 "List all current image search path substitution "
1211 "pairs in the current target.",
1212 "target modules search-paths list",
1213 eCommandRequiresTarget) {}
1227#pragma mark CommandObjectTargetModulesSearchPathsQuery
1233 interpreter,
"target modules search-paths query",
1234 "Transform a path using the first applicable image search path.",
1235 nullptr, eCommandRequiresTarget) {
1245 arg.push_back(path_arg);
1257 result.
AppendError(
"query requires one argument\n");
1275 bool full_triple,
uint32_t width) {
1283 std::string arch_str = std::string(arch_strm.
GetString());
1286 strm.
Printf(
"%-*s", width, arch_str.c_str());
1307 file_spec, 0,
false, eSymbolContextCompUnit, sc_list);
1309 for (
uint32_t i = 0; i < num_matches; ++i) {
1323 strm <<
"No line table";
1332 if (file_spec_ptr) {
1334 std::string fullpath = file_spec_ptr->
GetPath();
1335 strm.
Printf(
"%-*s", width, fullpath.c_str());
1344 strm.
Printf(
"%-*s", width,
"");
1349 if (file_spec_ptr) {
1358 strm.
Printf(
"%-*s", width,
"");
1363 if (file_spec_ptr) {
1372 strm.
Printf(
"%-*s", width,
"");
1376 std::lock_guard<std::recursive_mutex> guard(module_list.
GetMutex());
1377 const size_t num_modules = module_list.
GetSize();
1378 if (num_modules == 0)
1381 size_t num_dumped = 0;
1382 strm.
Format(
"Dumping headers for {0} module(s).\n", num_modules);
1386 if (num_dumped++ > 0) {
1390 ObjectFile *objfile = module_sp->GetObjectFile();
1392 objfile->
Dump(&strm);
1394 strm.
Format(
"No object file for module: {0:F}\n",
1395 module_sp->GetFileSpec());
1405 Mangled::NamePreference name_preference) {
1410 sort_order, name_preference);
1418 strm.
Printf(
"Sections for '%s' (%s):\n",
1431 symbol_file->Dump(strm);
1439 const Address &so_addr,
bool verbose,
bool all_ranges,
1442 strm.
Indent(
" Address: ");
1447 strm.
Indent(
" Summary: ");
1464 bool verbose,
bool all_ranges) {
1473 else if (so_addr.
GetModule().get() != module)
1482 DumpAddress(exe_scope, so_addr, verbose, all_ranges, strm);
1513 const char *name,
bool name_is_regex,
1514 bool verbose,
bool all_ranges) {
1523 std::vector<uint32_t> match_indexes;
1526 if (name_is_regex) {
1535 if (num_matches > 0) {
1537 strm.
Printf(
"%u symbols match %s'%s' in ", num_matches,
1538 name_is_regex ?
"the regular expression " :
"", name);
1542 for (
uint32_t i = 0; i < num_matches; ++i) {
1572 bool verbose,
bool all_ranges) {
1577 for (
uint32_t i = 0; i < num_matches; ++i) {
1585 if (i != (num_matches - 1))
1594 const char *name,
bool name_is_regex,
1596 bool verbose,
bool all_ranges) {
1597 if (module && name && name[0]) {
1599 size_t num_matches = 0;
1600 if (name_is_regex) {
1602 module->
FindFunctions(function_name_regex, options, sc_list);
1606 eFunctionNameTypeAuto, options, sc_list);
1608 num_matches = sc_list.
GetSize();
1611 strm.
Printf(
"%" PRIu64
" match%s found in ", (uint64_t)num_matches,
1612 num_matches > 1 ?
"es" :
"");
1617 strm, sc_list, verbose, all_ranges);
1626 Module *module,
const char *name_cstr,
1627 bool name_is_regex) {
1629 if (module && name_cstr && name_cstr[0]) {
1631 bool name_is_fully_qualified =
false;
1634 llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
1635 module->
FindTypes(name, name_is_fully_qualified, max_num_matches,
1636 searched_symbol_files, type_list);
1638 if (type_list.
Empty())
1641 const uint64_t num_matches = type_list.
GetSize();
1644 strm.
Printf(
"%" PRIu64
" match%s found in ", num_matches,
1645 num_matches > 1 ?
"es" :
"");
1648 for (TypeSP type_sp : type_list.
Types()) {
1653 type_sp->GetFullCompilerType();
1656 TypeSP typedef_type_sp(type_sp);
1657 TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType());
1658 while (typedefed_type_sp) {
1660 strm.
Printf(
" typedef '%s': ",
1661 typedef_type_sp->GetName().GetCString());
1662 typedefed_type_sp->GetFullCompilerType();
1665 typedef_type_sp = typedefed_type_sp;
1666 typedefed_type_sp = typedef_type_sp->GetTypedefType();
1676 const char *name_cstr,
bool name_is_regex) {
1679 bool name_is_fully_qualified =
false;
1682 llvm::DenseSet<SymbolFile *> searched_symbol_files;
1683 module.
FindTypes(name, name_is_fully_qualified, max_num_matches,
1684 searched_symbol_files, type_list);
1686 if (type_list.
Empty())
1698 type_sp->GetFullCompilerType();
1701 TypeSP typedef_type_sp(type_sp);
1702 TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType());
1703 while (typedefed_type_sp) {
1705 strm.
Printf(
" typedef '%s': ",
1706 typedef_type_sp->GetName().GetCString());
1707 typedefed_type_sp->GetFullCompilerType();
1710 typedef_type_sp = typedefed_type_sp;
1711 typedefed_type_sp = typedef_type_sp->GetTypedefType();
1722 bool verbose,
bool all_ranges) {
1723 if (module && file_spec) {
1726 file_spec, line, check_inlines, eSymbolContextEverything, sc_list);
1727 if (num_matches > 0) {
1729 strm.
Printf(
"%u match%s found in ", num_matches,
1730 num_matches > 1 ?
"es" :
"");
1733 strm.
Printf(
":%u", line);
1739 strm, sc_list, verbose, all_ranges);
1748 bool check_global_list) {
1749 FileSpec module_file_spec(module_name);
1752 const size_t initial_size = module_list.
GetSize();
1754 if (check_global_list) {
1756 std::lock_guard<std::recursive_mutex> guard(
1760 for (
size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
1765 module_sp = module->shared_from_this();
1773 const size_t num_matches = module_list.
GetSize();
1777 if (num_matches == 0) {
1786 return module_list.
GetSize() - initial_size;
1789#pragma mark CommandObjectTargetModulesModuleAutoComplete
1812 arg.push_back(file_arg);
1829#pragma mark CommandObjectTargetModulesSourceFileAutoComplete
1839 const char *syntax,
uint32_t flags)
1850 arg.push_back(source_file_arg);
1867#pragma mark CommandObjectTargetModulesDumpObjfile
1874 interpreter,
"target modules dump objfile",
1875 "Dump the object file headers from one or more target modules.",
1876 nullptr, eCommandRequiresTarget) {}
1888 size_t num_dumped = 0;
1893 if (num_dumped == 0) {
1894 result.
AppendError(
"the target has no associated executable images");
1899 const char *arg_cstr;
1900 for (
int arg_idx = 0;
1903 size_t num_matched =
1905 if (num_matched == 0) {
1907 "Unable to find an image that matches '%s'.\n", arg_cstr);
1915 if (num_dumped > 0) {
1918 result.
AppendError(
"no matching executable images found");
1924#define LLDB_OPTIONS_target_modules_dump_symtab
1925#include "CommandOptions.inc"
1932 interpreter,
"target modules dump symtab",
1933 "Dump the symbol table from one or more target modules.", nullptr,
1934 eCommandRequiresTarget) {}
1951 switch (short_option) {
1964 llvm_unreachable(
"Unimplemented option");
1975 return llvm::ArrayRef(g_target_modules_dump_symtab_options);
1986 Mangled::NamePreference name_preference =
1988 : Mangled::ePreferDemangled);
1997 std::lock_guard<std::recursive_mutex> guard(module_list.
GetMutex());
1998 const size_t num_modules = module_list.
GetSize();
1999 if (num_modules > 0) {
2001 "Dumping symbol table for {0} modules.\n", num_modules);
2003 if (num_dumped > 0) {
2015 result.
AppendError(
"the target has no associated executable images");
2020 const char *arg_cstr;
2021 for (
int arg_idx = 0;
2025 const size_t num_matches =
2027 if (num_matches > 0) {
2028 for (ModuleSP module_sp : module_list.
Modules()) {
2030 if (num_dumped > 0) {
2044 "Unable to find an image that matches '%s'.\n", arg_cstr);
2051 result.
AppendError(
"no matching executable images found");
2059#pragma mark CommandObjectTargetModulesDumpSections
2068 interpreter,
"target modules dump sections",
2069 "Dump the sections from one or more target modules.",
2071 nullptr, eCommandRequiresTarget) {}
2087 if (num_modules == 0) {
2088 result.
AppendError(
"the target has no associated executable images");
2094 for (
size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
2104 const char *arg_cstr;
2105 for (
int arg_idx = 0;
2109 const size_t num_matches =
2111 if (num_matches > 0) {
2112 for (
size_t i = 0; i < num_matches; ++i) {
2124 std::lock_guard<std::recursive_mutex> guard(
2128 "Unable to find an image that matches '%s'.\n", arg_cstr);
2136 result.
AppendError(
"no matching executable images found");
2146 interpreter,
"target modules dump pcm-info",
2147 "Dump information about the given clang module (pcm).") {
2166 if (pcm_file.GetFileNameExtension().GetStringRef() !=
".pcm") {
2167 result.
AppendError(
"file must have a .pcm extension");
2176 clang::CompilerInstance compiler;
2177 compiler.createDiagnostics();
2179 const char *clang_args[] = {
"clang", pcm_path};
2180 compiler.setInvocation(clang::createInvocation(clang_args));
2182 clang::DumpModuleInfoAction dump_module_info;
2185 compiler.getPCHContainerOperations()->registerReader(
2186 std::make_unique<clang::ObjectFilePCHContainerReader>());
2188 if (compiler.ExecuteAction(dump_module_info))
2195#pragma mark CommandObjectTargetModulesDumpClangAST
2204 interpreter,
"target modules dump ast",
2205 "Dump the clang ast for a given module's symbol file.",
2207 nullptr, eCommandRequiresTarget) {}
2216 const size_t num_modules = module_list.
GetSize();
2217 if (num_modules == 0) {
2218 result.
AppendError(
"the target has no associated executable images");
2229 if (
SymbolFile *sf = module_sp->GetSymbolFile())
2239 const size_t num_matches =
2241 if (num_matches == 0) {
2243 std::lock_guard<std::recursive_mutex> guard(
2247 "Unable to find an image that matches '%s'.\n", arg.c_str());
2251 for (
size_t i = 0; i < num_matches; ++i) {
2264#pragma mark CommandObjectTargetModulesDumpSymfile
2273 interpreter,
"target modules dump symfile",
2274 "Dump the debug symbol file for one or more target modules.",
2276 nullptr, eCommandRequiresTarget) {}
2292 std::lock_guard<std::recursive_mutex> guard(target_modules.
GetMutex());
2293 const size_t num_modules = target_modules.
GetSize();
2294 if (num_modules == 0) {
2295 result.
AppendError(
"the target has no associated executable images");
2299 "Dumping debug symbols for {0} modules.\n", num_modules);
2308 const char *arg_cstr;
2309 for (
int arg_idx = 0;
2313 const size_t num_matches =
2315 if (num_matches > 0) {
2316 for (
size_t i = 0; i < num_matches; ++i) {
2327 "Unable to find an image that matches '%s'.\n", arg_cstr);
2334 result.
AppendError(
"no matching executable images found");
2340#pragma mark CommandObjectTargetModulesDumpLineTable
2341#define LLDB_OPTIONS_target_modules_dump
2342#include "CommandOptions.inc"
2351 interpreter,
"target modules dump line-table",
2352 "Dump the line table for one or more compilation units.", nullptr,
2353 eCommandRequiresTarget) {}
2369 result.
AppendError(
"file option must be specified.");
2373 const char *arg_cstr;
2374 for (
int arg_idx = 0;
2380 std::lock_guard<std::recursive_mutex> guard(target_modules.
GetMutex());
2381 if (target_modules.
GetSize() > 0) {
2393 if (num_dumped == 0)
2395 "No source filenames matched '%s'.\n", arg_cstr);
2397 total_num_dumped += num_dumped;
2402 if (total_num_dumped > 0)
2405 result.
AppendError(
"no source filenames matched any command arguments");
2416 assert(option_idx == 0 &&
"We only have one option.");
2427 return llvm::ArrayRef(g_target_modules_dump_options);
2436#pragma mark CommandObjectTargetModulesDump
2445 interpreter,
"target modules dump",
2446 "Commands for dumping information about one or more target "
2448 "target modules dump "
2449 "[objfile|symtab|sections|ast|symfile|line-table|pcm-info] "
2450 "[<file1> <file2> ...]") {
2464 "ast", CommandObjectSP(
2482 "Add a new module to the current target's modules.",
2483 "target modules add [<module>]",
2484 eCommandRequiresTarget),
2487 "Fullpath to a stand alone debug "
2488 "symbols file for when debug symbols "
2489 "are not in the executable.") {
2542 "Unable to create the executable or symbol file with "
2543 "UUID %s with path %s and symbol file %s",
2548 "Unable to create the executable or symbol file with "
2549 "UUID %s with path %s",
2555 "or symbol file with UUID %s",
2564 "Unable to locate the executable or symbol file with UUID %s",
2571 "one or more executable image paths must be specified");
2575 for (
auto &entry : args.
entries()) {
2576 if (entry.ref().empty())
2592 module_spec,
true , &
error));
2594 const char *error_cstr =
error.AsCString();
2606 std::string resolved_path = file_spec.
GetPath();
2607 if (resolved_path != entry.ref()) {
2609 "invalid module path '%s' with resolved path '%s'\n",
2610 entry.ref().str().c_str(), resolved_path.c_str());
2635 interpreter,
"target modules load",
2636 "Set the load addresses for one or more sections in a target "
2638 "target modules load [--file <module> --uuid <uuid>] <sect-name> "
2639 "<address> [<sect-name> <address> ....]",
2640 eCommandRequiresTarget),
2642 "Fullpath or basename for module to load.",
""),
2644 "Write file contents to the memory.", false, true),
2646 "Set PC to the entry point."
2647 " Only applicable with '--load' option.",
2650 "Set the load address for all sections to be the "
2651 "virtual address in the file plus the offset.",
2674 bool search_using_module_spec =
false;
2681 if (module_list.
GetSize() == 1) {
2682 search_using_module_spec =
true;
2690 search_using_module_spec =
true;
2692 const bool use_global_module_list =
true;
2695 target, arg_cstr, module_list, use_global_module_list);
2696 if (num_matches == 1) {
2699 }
else if (num_matches > 1) {
2700 search_using_module_spec =
false;
2702 "more than 1 module matched by name '%s'\n", arg_cstr);
2704 search_using_module_spec =
false;
2711 search_using_module_spec =
true;
2716 if (search_using_module_spec) {
2719 const size_t num_matches = matching_modules.
GetSize();
2722 if (num_matches == 1) {
2729 bool changed =
false;
2734 const bool slide_is_offset =
true;
2738 result.
AppendError(
"one or more section name + load "
2739 "address pair must be specified");
2744 result.
AppendError(
"The \"--slide <offset>\" option can't "
2745 "be used in conjunction with setting "
2746 "section load addresses.\n");
2750 for (
size_t i = 0; i < argc; i += 2) {
2753 if (sect_name && load_addr_cstr) {
2756 if (llvm::to_integer(load_addr_cstr, load_addr)) {
2757 SectionSP section_sp(
2760 if (section_sp->IsThreadSpecific()) {
2762 "thread specific sections are not yet "
2763 "supported (section '%s')\n",
2771 "section '%s' loaded at 0x%" PRIx64
"\n",
2772 sect_name, load_addr);
2776 "matches the section "
2783 "invalid load address string '%s'\n", load_addr_cstr);
2788 result.
AppendError(
"section names must be followed by "
2789 "a load address.\n");
2791 result.
AppendError(
"one or more section name + load "
2792 "address pair must be specified.\n");
2811 if (set_pc && !file_entry.
IsValid()) {
2812 result.
AppendError(
"No entry address in object file");
2815 std::vector<ObjectFile::LoadableData> loadables(
2817 if (loadables.size() == 0) {
2821 Status error = process->WriteObjectFile(std::move(loadables));
2827 ThreadList &thread_list = process->GetThreadList();
2828 RegisterContextSP reg_context(
2831 if (!reg_context->SetPC(file_entry_addr)) {
2850 if (module_spec_file) {
2851 module_spec_file->
GetPath(path,
sizeof(path));
2857 std::string uuid_str;
2866 if (num_matches > 1) {
2868 "multiple modules match%s%s%s%s:\n", path[0] ?
" file=" :
"",
2869 path, !uuid_str.empty() ?
" uuid=" :
"", uuid_str.c_str());
2870 for (
size_t i = 0; i < num_matches; ++i) {
2878 "no modules were found that match%s%s%s%s.\n",
2879 path[0] ?
" file=" :
"", path, !uuid_str.empty() ?
" uuid=" :
"",
2884 result.
AppendError(
"either the \"--file <module>\" or the \"--uuid "
2885 "<uuid>\" option must be specified.\n");
2899#pragma mark CommandObjectTargetModulesList
2901#define LLDB_OPTIONS_target_modules_list
2902#include "CommandOptions.inc"
2917 if (short_option ==
'g') {
2919 }
else if (short_option ==
'a') {
2923 unsigned long width = 0;
2924 option_arg.getAsInteger(0, width);
2937 return llvm::ArrayRef(g_target_modules_list_options);
2949 interpreter,
"target modules list",
2950 "List current executable and dependent shared library images.") {
2967 if (target ==
nullptr && !use_global_module_list) {
2968 result.
AppendError(
"invalid target, create a debug target using the "
2969 "'target create' command");
2985 ModuleSP module_sp(module_address.
GetModule());
2991 "Couldn't find module matching address: 0x%" PRIx64
".",
2996 "Couldn't find module containing address: 0x%" PRIx64
".",
3001 "Can only look up modules by address with a valid target.");
3006 size_t num_modules = 0;
3012 std::unique_lock<std::recursive_mutex> guard(
3018 if (use_global_module_list) {
3028 target, arg.c_str(), module_list, use_global_module_list);
3029 if (num_matches == 0) {
3038 module_list_ptr = &module_list;
3041 std::unique_lock<std::recursive_mutex> lock;
3042 if (module_list_ptr !=
nullptr) {
3044 std::unique_lock<std::recursive_mutex>(module_list_ptr->
GetMutex());
3046 num_modules = module_list_ptr->
GetSize();
3049 if (num_modules > 0) {
3050 for (
uint32_t image_idx = 0; image_idx < num_modules; ++image_idx) {
3053 if (module_list_ptr) {
3055 module = module_sp.get();
3058 module_sp = module->shared_from_this();
3061 const size_t indent = strm.
Printf(
"[%3u] ", image_idx);
3067 if (use_global_module_list)
3069 "the global module list has no matching modules");
3071 result.
AppendError(
"the target has no matching modules");
3073 if (use_global_module_list)
3074 result.
AppendError(
"the global module list is empty");
3077 "the target has no associated executable images");
3086 if (module ==
nullptr) {
3091 bool dump_object_name =
false;
3099 bool print_space =
false;
3100 for (
size_t i = 0; i < num_entries; ++i) {
3106 switch (format_char) {
3117 dump_object_name =
true;
3126 dump_object_name =
true;
3139 Address base_addr(objfile->GetBaseAddress());
3144 base_addr.
Dump(&strm, target,
3148 if (format_char ==
'o') {
3150 strm.
Printf(
"0x%*.*" PRIx64, addr_nibble_width,
3155 strm.
Printf(
"0x%*.*" PRIx64, addr_nibble_width,
3156 addr_nibble_width, load_addr);
3167 strm.
Printf(
"%*s", addr_nibble_width + 2,
"");
3172 size_t ref_count = 0;
3173 ModuleSP module_sp(module->shared_from_this());
3176 ref_count = module_sp.use_count() - 1;
3179 strm.
Printf(
"{%*" PRIu64
"}", width, (uint64_t)ref_count);
3181 strm.
Printf(
"{%" PRIu64
"}", (uint64_t)ref_count);
3188 symbol_file->GetObjectFile()->GetFileSpec();
3189 if (format_char ==
'S') {
3191 if (!symfile_spec || symfile_spec == module->
GetFileSpec()) {
3192 print_space =
false;
3196 strm.
Printf(
"\n%*s", indent,
"");
3199 dump_object_name =
true;
3202 strm.
Printf(
"%.*s", width,
"<NONE>");
3207 llvm::AlignStyle::Left, width));
3211 strm.
Printf(
"%p",
static_cast<void *
>(module));
3222 if (dump_object_name) {
3225 strm.
Printf(
"(%s)", object_name);
3233#pragma mark CommandObjectTargetModulesShowUnwind
3236#define LLDB_OPTIONS_target_modules_show_unwind
3237#include "CommandOptions.inc"
3262 switch (short_option) {
3264 m_str = std::string(option_arg);
3269 error.SetErrorStringWithFormat(
"invalid address string '%s'",
3270 option_arg.str().c_str());
3275 m_str = std::string(option_arg);
3280 llvm_unreachable(
"Unimplemented option");
3293 return llvm::ArrayRef(g_target_modules_show_unwind_options);
3306 interpreter,
"target modules show-unwind",
3307 "Show synthesized unwind instructions for a function.", nullptr,
3308 eCommandRequiresTarget | eCommandRequiresProcess |
3309 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
3321 abi = process->
GetABI().get();
3323 if (process ==
nullptr) {
3325 "You must have a process running to use this command.");
3331 result.
AppendError(
"The process must be paused to use this command.");
3337 result.
AppendError(
"The process must be paused to use this command.");
3349 function_options, sc_list);
3356 module_sp->ResolveSymbolContextForAddress(addr,
3357 eSymbolContextEverything, sc);
3364 "address-expression or function name option must be specified.");
3368 size_t num_matches = sc_list.
GetSize();
3369 if (num_matches == 0) {
3375 for (
uint32_t idx = 0; idx < num_matches; idx++) {
3383 if (!sc.
GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0,
3395 FuncUnwindersSP func_unwinders_sp(
3397 .GetUncachedFuncUnwindersContainingAddress(start_addr, sc));
3398 if (!func_unwinders_sp)
3402 "UNWIND PLANS for %s`%s (start addr 0x%" PRIx64
")\n",
3403 sc.
module_sp->GetPlatformFileSpec().GetFilename().AsCString(),
3409 for (
size_t i = 0; i < count; i++) {
3411 if (strcmp(funcname.
GetCString(), trap_func_name) == 0)
3414 "treated as a trap handler function via user setting.\n");
3418 const std::vector<ConstString> trap_handler_names(
3419 platform_sp->GetTrapHandlerSymbolNames());
3420 for (
ConstString trap_name : trap_handler_names) {
3421 if (trap_name == funcname) {
3424 "name is listed by the platform as a trap handler.\n");
3431 UnwindPlanSP non_callsite_unwind_plan =
3432 func_unwinders_sp->GetUnwindPlanAtNonCallSite(*target, *thread);
3433 if (non_callsite_unwind_plan) {
3435 "Asynchronous (not restricted to call-sites) UnwindPlan is '%s'\n",
3436 non_callsite_unwind_plan->GetSourceName().AsCString());
3438 UnwindPlanSP callsite_unwind_plan =
3439 func_unwinders_sp->GetUnwindPlanAtCallSite(*target, *thread);
3440 if (callsite_unwind_plan) {
3442 "Synchronous (restricted to call-sites) UnwindPlan is '%s'\n",
3443 callsite_unwind_plan->GetSourceName().AsCString());
3445 UnwindPlanSP fast_unwind_plan =
3446 func_unwinders_sp->GetUnwindPlanFastUnwind(*target, *thread);
3447 if (fast_unwind_plan) {
3449 "Fast UnwindPlan is '%s'\n",
3450 fast_unwind_plan->GetSourceName().AsCString());
3455 UnwindPlanSP assembly_sp =
3456 func_unwinders_sp->GetAssemblyUnwindPlan(*target, *thread);
3459 "Assembly language inspection UnwindPlan:\n");
3465 UnwindPlanSP of_unwind_sp =
3466 func_unwinders_sp->GetObjectFileUnwindPlan(*target);
3474 UnwindPlanSP of_unwind_augmented_sp =
3475 func_unwinders_sp->GetObjectFileAugmentedUnwindPlan(*target, *thread);
3476 if (of_unwind_augmented_sp) {
3484 func_unwinders_sp->GetEHFrameUnwindPlan(*target);
3492 UnwindPlanSP ehframe_augmented_sp =
3493 func_unwinders_sp->GetEHFrameAugmentedUnwindPlan(*target, *thread);
3494 if (ehframe_augmented_sp) {
3501 if (UnwindPlanSP plan_sp =
3502 func_unwinders_sp->GetDebugFrameUnwindPlan(*target)) {
3509 if (UnwindPlanSP plan_sp =
3510 func_unwinders_sp->GetDebugFrameAugmentedUnwindPlan(*target,
3518 UnwindPlanSP arm_unwind_sp =
3519 func_unwinders_sp->GetArmUnwindUnwindPlan(*target);
3520 if (arm_unwind_sp) {
3527 if (UnwindPlanSP symfile_plan_sp =
3528 func_unwinders_sp->GetSymbolFileUnwindPlan(*thread)) {
3535 UnwindPlanSP compact_unwind_sp =
3536 func_unwinders_sp->GetCompactUnwindUnwindPlan(*target);
3537 if (compact_unwind_sp) {
3544 if (fast_unwind_plan) {
3551 ABISP abi_sp = process->
GetABI();
3554 if (abi_sp->CreateDefaultUnwindPlan(arch_default)) {
3562 if (abi_sp->CreateFunctionEntryUnwindPlan(arch_entry)) {
3564 "Arch default at entry point UnwindPlan:\n");
3580#define LLDB_OPTIONS_target_modules_lookup
3581#include "CommandOptions.inc"
3608 switch (short_option) {
3616 if (option_arg.getAsInteger(0,
m_offset))
3617 error.SetErrorStringWithFormat(
"invalid offset string '%s'",
3618 option_arg.str().c_str());
3622 m_str = std::string(option_arg);
3637 error.SetErrorStringWithFormat(
"invalid line number string '%s'",
3638 option_arg.str().c_str());
3640 error.SetErrorString(
"zero is an invalid line number");
3645 m_str = std::string(option_arg);
3650 m_str = std::string(option_arg);
3655 m_str = std::string(option_arg);
3675 llvm_unreachable(
"Unimplemented option");
3699 "conjunction with --verbose.");
3705 return llvm::ArrayRef(g_target_modules_lookup_options);
3726 "Look up information within executable and "
3727 "dependent shared library images.",
3728 nullptr, eCommandRequiresTarget) {
3738 arg.push_back(file_arg);
3749 bool &syntax_error) {
3767 const SymbolContext &sym_ctx(frame->GetSymbolContext(eSymbolContextModule));
3797 eSymbolContextEverything |
3799 ?
static_cast<int>(eSymbolContextVariable)
3868 syntax_error =
true;
3879 bool syntax_error =
false;
3881 uint32_t num_successful_lookups = 0;
3888 ModuleSP current_module;
3895 num_successful_lookups++;
3905 std::lock_guard<std::recursive_mutex> guard(target_modules.
GetMutex());
3906 if (target_modules.
GetSize() == 0) {
3907 result.
AppendError(
"the target has no associated executable images");
3912 if (module_sp != current_module &&
3916 num_successful_lookups++;
3921 const char *arg_cstr;
3926 const size_t num_matches =
3928 if (num_matches > 0) {
3929 for (
size_t j = 0; j < num_matches; ++j) {
3934 num_successful_lookups++;
3940 "Unable to find an image that matches '%s'.\n", arg_cstr);
3944 if (num_successful_lookups > 0)
3954#pragma mark CommandObjectMultiwordImageSearchPaths
3963 interpreter,
"target modules search-paths",
3964 "Commands for managing module search paths for a target.",
3965 "target modules search-paths <subcommand> [<subcommand-options>]") {
3967 "add", CommandObjectSP(
3987#pragma mark CommandObjectTargetModules
3996 "Commands for accessing information for one or "
3997 "more target modules.",
3998 "target modules <sub-command> ...") {
4032 interpreter,
"target symbols add",
4033 "Add a debug symbol file to one of the target's current modules by "
4034 "specifying a path to a debug symbols file or by using the options "
4035 "to specify a module.",
4036 "target symbols add <cmd-options> [<symfile>]",
4037 eCommandRequiresTarget),
4041 "Locate the debug symbols for the shared library specified by "
4045 "Locate the debug symbols for the currently selected frame.", false,
4048 "Locate the debug symbols for every frame in "
4049 "the current call stack.",
4081 if (!symbol_fspec) {
4083 "one or more executable image paths must be specified");
4088 symbol_fspec.
GetPath(symfile_path,
sizeof(symfile_path));
4102 0, 0, symfile_module_specs)) {
4108 symfile_module_spec)) {
4112 symfile_uuid_module_spec.
GetUUID() = symfile_module_spec.
GetUUID();
4118 if (matching_modules.
IsEmpty()) {
4121 const size_t num_symfile_module_specs = symfile_module_specs.
GetSize();
4123 i < num_symfile_module_specs && matching_modules.
IsEmpty(); ++i) {
4125 i, symfile_module_spec)) {
4129 symfile_uuid_module_spec.
GetUUID() =
4130 symfile_module_spec.
GetUUID();
4141 if (matching_modules.
IsEmpty())
4144 while (matching_modules.
IsEmpty()) {
4148 if (!filename_no_extension)
4160 if (matching_modules.
GetSize() > 1) {
4162 "use the --uuid option to resolve the "
4168 if (matching_modules.
GetSize() == 1) {
4174 module_sp->SetSymbolFileFileSpec(symbol_fspec);
4180 if (object_file && object_file->
GetFileSpec() == symbol_fspec) {
4182 const FileSpec &module_fs = module_sp->GetFileSpec();
4184 "symbol file '%s' has been added to '%s'\n", symfile_path,
4190 module_list.
Append(module_sp);
4197 module_sp->LoadScriptingResourceInTarget(target,
error,
4201 "unable to load scripting data for module %s - error "
4203 module_sp->GetFileSpec()
4204 .GetFileNameStrippingExtension()
4207 else if (feedback_stream.
GetSize())
4216 module_sp->SetSymbolFileFileSpec(
FileSpec());
4221 ss_symfile_uuid <<
" (";
4223 ss_symfile_uuid <<
')';
4226 "symbol file '%s'%s does not match any existing module%s\n",
4227 symfile_path, ss_symfile_uuid.
GetData(),
4228 !llvm::sys::fs::is_regular_file(symbol_fspec.
GetPath())
4229 ?
"\n please specify the full path to the symbol file"
4256 error_strm.
PutCString(
"unable to find debug symbols for UUID ");
4275 module_spec.
GetFileSpec() = module_sp->GetFileSpec();
4277 module_spec.
GetUUID() = module_sp->GetUUID();
4286 "unable to find debug symbols for the executable file ");
4301 "a process must exist in order to use the --frame option");
4318 ModuleSP frame_module_sp(
4320 if (!frame_module_sp) {
4326 module_spec.
GetUUID() = frame_module_sp->GetUUID();
4330 module_spec.
GetFileSpec() = frame_module_sp->GetPlatformFileSpec();
4334 result.
AppendError(
"unable to find debug symbols for the current frame");
4347 "a process must exist in order to use the --stack option");
4364 bool symbols_found =
false;
4366 for (
uint32_t i = 0; i < frame_count; ++i) {
4369 ModuleSP frame_module_sp(
4370 frame_sp->GetSymbolContext(eSymbolContextModule).module_sp);
4371 if (!frame_module_sp)
4375 module_spec.
GetUUID() = frame_module_sp->GetUUID();
4378 frame_module_sp->GetPlatformFileSpec())) {
4380 module_spec.
GetFileSpec() = frame_module_sp->GetPlatformFileSpec();
4383 bool current_frame_flush =
false;
4385 symbols_found =
true;
4386 flush |= current_frame_flush;
4389 if (!symbols_found) {
4391 "unable to find debug symbols in the current call stack");
4403 const bool uuid_option_set =
4406 const bool frame_option_set =
4408 const bool stack_option_set =
4413 if (uuid_option_set)
4415 else if (file_option_set)
4417 else if (frame_option_set)
4419 else if (stack_option_set)
4422 result.
AppendError(
"one or more symbol file paths must be specified, "
4423 "or options must be specified");
4425 if (uuid_option_set) {
4426 result.
AppendError(
"specify either one or more paths to symbol files "
4427 "or use the --uuid option without arguments");
4428 }
else if (frame_option_set) {
4429 result.
AppendError(
"specify either one or more paths to symbol files "
4430 "or use the --frame option without arguments");
4431 }
else if (file_option_set && argc > 1) {
4432 result.
AppendError(
"specify at most one symbol file path when "
4433 "--shlib option is set");
4437 for (
auto &entry : args.
entries()) {
4438 if (!entry.ref().empty()) {
4440 symbol_file_spec.
SetFile(entry.ref(), FileSpec::Style::native);
4442 if (file_option_set) {
4449 ->ResolveSymbolFile(*target, module_spec, symfile_spec)
4454 bool symfile_exists =
4457 if (symfile_exists) {
4461 std::string resolved_symfile_path =
4463 if (resolved_symfile_path != entry.ref()) {
4465 "invalid module path '%s' with resolved path '%s'\n",
4466 entry.c_str(), resolved_symfile_path.c_str());
4493#pragma mark CommandObjectTargetSymbols
4502 interpreter,
"target symbols",
4503 "Commands for adding and managing debug symbol files.",
4504 "target symbols <sub-command> ...") {
4518#pragma mark CommandObjectTargetStopHookAdd
4521#define LLDB_OPTIONS_target_stop_hook_add
4522#include "CommandOptions.inc"
4534 return llvm::ArrayRef(g_target_stop_hook_add_options);
4540 const int short_option =
4541 g_target_stop_hook_add_options[option_idx].short_option;
4543 switch (short_option) {
4550 if (option_arg.getAsInteger(0,
m_line_end)) {
4551 error.SetErrorStringWithFormat(
"invalid end line number: \"%s\"",
4552 option_arg.str().c_str());
4559 bool value, success;
4564 error.SetErrorStringWithFormat(
4565 "invalid boolean value '%s' passed for -G option",
4566 option_arg.str().c_str());
4570 error.SetErrorStringWithFormat(
"invalid start line number: \"%s\"",
4571 option_arg.str().c_str());
4599 error.SetErrorStringWithFormat(
"invalid thread id string '%s'",
4600 option_arg.str().c_str());
4616 error.SetErrorStringWithFormat(
"invalid thread index string '%s'",
4617 option_arg.str().c_str());
4627 llvm_unreachable(
"Unimplemented option");