68#include "llvm/Support/PrettyStackTrace.h"
69#include "llvm/Support/Regex.h"
74#define DEFAULT_DISASM_BYTE_SIZE 32
77 std::lock_guard<std::recursive_mutex> guard(target.
GetAPIMutex());
81 const auto state = process_sp->GetState();
87 return Status(
"process is connected and already has a listener, pass "
92 return target.
Attach(attach_info,
nullptr);
154 return this->
operator bool();
156SBTarget::operator bool()
const {
159 return m_opaque_sp.get() !=
nullptr && m_opaque_sp->IsValid();
166 ProcessSP process_sp;
167 TargetSP target_sp(
GetSP());
169 process_sp = target_sp->GetProcessSP();
170 sb_process.
SetSP(process_sp);
179 TargetSP target_sp(
GetSP());
193 TargetSP target_sp(
GetSP());
195 debugger.
reset(target_sp->GetDebugger().shared_from_this());
203 TargetSP target_sp(
GetSP());
206 std::string json_str =
207 llvm::formatv(
"{0:2}",
209 target_sp.get())).str();
217 TargetSP target_sp(
GetSP());
226 TargetSP target_sp(
GetSP());
243 TargetSP target_sp(
GetSP());
247 ProcessSP process_sp(target_sp->CreateProcess(
248 target_sp->GetDebugger().GetListener(),
"", &filespec,
false));
250 error.SetError(process_sp->LoadCore());
252 sb_process.
SetSP(process_sp);
254 error.SetErrorString(
"Failed to create the process");
257 error.SetErrorString(
"SBTarget is invalid");
263 const char *working_directory) {
266 TargetSP target_sp =
GetSP();
272 if (
Module *exe_module = target_sp->GetExecutableModulePointer())
279 if (working_directory)
290 TargetSP target_sp(
GetSP());
292 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
293 sb_error.
ref() = target_sp->Install(
nullptr);
299 char const **envp,
const char *stdin_path,
300 const char *stdout_path,
const char *stderr_path,
301 const char *working_directory,
305 stderr_path, working_directory, launch_flags,
306 stop_at_entry,
error);
309 ProcessSP process_sp;
310 TargetSP target_sp(
GetSP());
313 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
316 launch_flags |= eLaunchFlagStopAtEntry;
318 if (getenv(
"LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
319 launch_flags |= eLaunchFlagDisableASLR;
322 process_sp = target_sp->GetProcessSP();
324 state = process_sp->GetState();
328 error.SetErrorString(
"process attach is in progress");
330 error.SetErrorString(
"a process is already being debugged");
340 error.SetErrorString(
"process is connected and already has a listener, "
341 "pass empty listener");
346 if (getenv(
"LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
347 launch_flags |= eLaunchFlagDisableSTDIO;
351 FileSpec(working_directory), launch_flags);
353 Module *exe_module = target_sp->GetExecutableModulePointer();
359 auto default_launch_info = target_sp->GetProcessLaunchInfo();
361 default_launch_info.GetArguments());
366 auto default_launch_info = target_sp->GetProcessLaunchInfo();
367 launch_info.
GetEnvironment() = default_launch_info.GetEnvironment();
373 error.SetError(target_sp->Launch(launch_info,
nullptr));
375 sb_process.
SetSP(target_sp->GetProcessSP());
377 error.SetErrorString(
"SBTarget is invalid");
387 TargetSP target_sp(
GetSP());
390 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
393 ProcessSP process_sp = target_sp->GetProcessSP();
395 state = process_sp->GetState();
399 error.SetErrorString(
"process attach is in progress");
401 error.SetErrorString(
"a process is already being debugged");
410 Module *exe_module = target_sp->GetExecutableModulePointer();
415 const ArchSpec &arch_spec = target_sp->GetArchitecture();
419 error.SetError(target_sp->Launch(launch_info,
nullptr));
420 sb_launch_info.
set_ref(launch_info);
421 sb_process.
SetSP(target_sp->GetProcessSP());
423 error.SetErrorString(
"SBTarget is invalid");
433 TargetSP target_sp(
GetSP());
438 PlatformSP platform_sp = target_sp->GetPlatform();
440 if (platform_sp && platform_sp->IsConnected()) {
443 if (platform_sp->GetProcessInfo(attach_pid, instance_info)) {
446 error.ref().SetErrorStringWithFormat(
447 "no process found with process ID %" PRIu64, attach_pid);
454 sb_process.
SetSP(target_sp->GetProcessSP());
456 error.SetErrorString(
"SBTarget is invalid");
470 TargetSP target_sp(
GetSP());
479 if (target_sp->GetPlatform()->GetProcessInfo(pid, instance_info))
484 sb_process.
SetSP(target_sp->GetProcessSP());
486 error.SetErrorString(
"SBTarget is invalid");
500 TargetSP target_sp(
GetSP());
502 if (name && target_sp) {
511 sb_process.
SetSP(target_sp->GetProcessSP());
513 error.SetErrorString(
"SBTarget is invalid");
519 const char *plugin_name,
524 ProcessSP process_sp;
525 TargetSP target_sp(
GetSP());
528 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
531 target_sp->CreateProcess(listener.
m_opaque_sp, plugin_name,
nullptr,
534 process_sp = target_sp->CreateProcess(
535 target_sp->GetDebugger().GetListener(), plugin_name,
nullptr,
true);
538 sb_process.
SetSP(process_sp);
539 error.SetError(process_sp->ConnectRemote(url));
541 error.SetErrorString(
"unable to create lldb_private::Process");
544 error.SetErrorString(
"SBTarget is invalid");
554 TargetSP target_sp(
GetSP());
556 Module *exe_module = target_sp->GetExecutableModulePointer();
561 return exe_file_spec;
587 TargetSP target_sp(
GetSP());
589 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
590 if (target_sp->ResolveLoadAddress(vm_addr, addr))
605 TargetSP target_sp(
GetSP());
607 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
608 if (target_sp->ResolveFileAddress(file_addr, addr))
622 TargetSP target_sp(
GetSP());
624 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
625 if (target_sp->ResolveLoadAddress(vm_addr, addr))
641 SymbolContextItem scope =
static_cast<SymbolContextItem
>(resolve_scope);
643 TargetSP target_sp(
GetSP());
645 target_sp->GetImages().ResolveSymbolContextForAddress(addr.
ref(), scope,
656 size_t bytes_read = 0;
657 TargetSP target_sp(
GetSP());
659 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
661 target_sp->ReadMemory(addr.
ref(), buf, size, sb_error.
ref(),
true);
710 TargetSP target_sp(
GetSP());
711 if (target_sp && line != 0) {
712 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
716 const bool internal =
false;
717 const bool hardware =
false;
719 const FileSpecList *module_list =
nullptr;
720 if (sb_module_list.
GetSize() > 0) {
721 module_list = sb_module_list.
get();
723 sb_bp = target_sp->CreateBreakpoint(
724 module_list, *sb_file_spec, line, column, offset, check_inlines,
725 skip_prologue, internal, hardware, move_to_nearest_code);
734 bool move_to_nearest_code) {
736 move_to_nearest_code);
739 TargetSP target_sp(
GetSP());
740 if (target_sp && line != 0) {
741 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
745 const bool internal =
false;
746 const bool hardware =
false;
747 const FileSpecList *module_list =
nullptr;
748 if (sb_module_list.
GetSize() > 0) {
749 module_list = sb_module_list.
get();
751 sb_bp = target_sp->CreateBreakpoint(
752 module_list, *sb_file_spec, line, column, offset, check_inlines,
753 skip_prologue, internal, hardware,
761 const char *module_name) {
765 TargetSP target_sp(
GetSP());
766 if (target_sp.get()) {
767 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
769 const bool internal =
false;
770 const bool hardware =
false;
773 if (module_name && module_name[0]) {
774 FileSpecList module_spec_list;
775 module_spec_list.Append(
FileSpec(module_name));
776 sb_bp = target_sp->CreateBreakpoint(
777 &module_spec_list,
nullptr, symbol_name, eFunctionNameTypeAuto,
780 sb_bp = target_sp->CreateBreakpoint(
781 nullptr,
nullptr, symbol_name, eFunctionNameTypeAuto,
795 lldb::FunctionNameType name_type_mask = eFunctionNameTypeAuto;
802 const char *symbol_name,
uint32_t name_type_mask,
813 const char *symbol_name,
uint32_t name_type_mask,
817 module_list, comp_unit_list);
820 TargetSP target_sp(
GetSP());
821 if (target_sp && symbol_name && symbol_name[0]) {
822 const bool internal =
false;
823 const bool hardware =
false;
825 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
826 FunctionNameType mask =
static_cast<FunctionNameType
>(name_type_mask);
827 sb_bp = target_sp->CreateBreakpoint(module_list.
get(), comp_unit_list.
get(),
828 symbol_name, mask, symbol_language, 0,
829 skip_prologue, internal, hardware);
851 symbol_language, module_list, comp_unit_list);
863 symbol_language, offset, module_list, comp_unit_list);
866 TargetSP target_sp(
GetSP());
867 if (target_sp && num_names > 0) {
868 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
869 const bool internal =
false;
870 const bool hardware =
false;
871 FunctionNameType mask =
static_cast<FunctionNameType
>(name_type_mask);
873 sb_bp = target_sp->CreateBreakpoint(
874 module_list.
get(), comp_unit_list.
get(), symbol_names, num_names, mask,
875 symbol_language, offset, skip_prologue, internal, hardware);
882 const char *module_name) {
887 if (module_name && module_name[0]) {
891 module_spec_list, comp_unit_list);
901 module_list, comp_unit_list);
905 const char *symbol_name_regex,
LanguageType symbol_language,
911 TargetSP target_sp(
GetSP());
912 if (target_sp && symbol_name_regex && symbol_name_regex[0]) {
913 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
915 const bool internal =
false;
916 const bool hardware =
false;
919 sb_bp = target_sp->CreateFuncRegexBreakpoint(
920 module_list.
get(), comp_unit_list.
get(), std::move(regexp),
921 symbol_language, skip_prologue, internal, hardware);
931 TargetSP target_sp(
GetSP());
933 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
934 const bool hardware =
false;
935 sb_bp = target_sp->CreateBreakpoint(address,
false, hardware);
945 TargetSP target_sp(
GetSP());
951 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
952 const bool hardware =
false;
953 sb_bp = target_sp->CreateBreakpoint(sb_address.
ref(),
false, hardware);
962 const char *module_name) {
967 if (module_name && module_name[0]) {
973 source_file_list.
Append(source_file);
997 TargetSP target_sp(
GetSP());
998 if (target_sp && source_regex && source_regex[0]) {
999 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1000 const bool hardware =
false;
1003 std::unordered_set<std::string> func_names_set;
1004 for (
size_t i = 0; i < func_names.
GetSize(); i++) {
1008 sb_bp = target_sp->CreateSourceRegexBreakpoint(
1009 module_list.
get(), source_file_list.
get(), func_names_set,
1010 std::move(regexp),
false, hardware, move_to_nearest_code);
1018 bool catch_bp,
bool throw_bp) {
1022 TargetSP target_sp(
GetSP());
1024 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1025 const bool hardware =
false;
1026 sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp,
1036 bool request_hardware) {
1041 TargetSP target_sp(
GetSP());
1043 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1048 target_sp->CreateScriptedBreakpoint(class_name,
1063 TargetSP target_sp(
GetSP());
1066 return target_sp->GetBreakpointList().GetSize();
1075 TargetSP target_sp(
GetSP());
1078 sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
1080 return sb_breakpoint;
1086 bool result =
false;
1087 TargetSP target_sp(
GetSP());
1089 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1090 result = target_sp->RemoveBreakpointByID(bp_id);
1100 TargetSP target_sp(
GetSP());
1102 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1103 sb_breakpoint = target_sp->GetBreakpointByID(bp_id);
1106 return sb_breakpoint;
1113 TargetSP target_sp(
GetSP());
1115 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1116 llvm::Expected<std::vector<BreakpointSP>> expected_vector =
1117 target_sp->GetBreakpointList().FindBreakpointsByName(name);
1118 if (!expected_vector) {
1119 LLDB_LOG(
GetLog(LLDBLog::Breakpoints),
"invalid breakpoint name: {}",
1120 llvm::toString(expected_vector.takeError()));
1123 for (BreakpointSP bkpt_sp : *expected_vector) {
1135 TargetSP target_sp(
GetSP());
1137 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1139 std::vector<std::string> name_vec;
1140 target_sp->GetBreakpointNames(name_vec);
1141 for (
auto name : name_vec)
1149 TargetSP target_sp(
GetSP());
1151 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1152 target_sp->DeleteBreakpointName(
ConstString(name));
1159 TargetSP target_sp(
GetSP());
1161 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1162 target_sp->EnableAllowedBreakpoints();
1171 TargetSP target_sp(
GetSP());
1173 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1174 target_sp->DisableAllowedBreakpoints();
1183 TargetSP target_sp(
GetSP());
1185 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1186 target_sp->RemoveAllowedBreakpoints();
1206 TargetSP target_sp(
GetSP());
1209 "BreakpointCreateFromFile called with invalid target.");
1212 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1216 std::vector<std::string> name_vector;
1217 size_t num_names = matching_names.
GetSize();
1218 for (
size_t i = 0; i < num_names; i++)
1221 sberr.
ref() = target_sp->CreateBreakpointsFromFile(source_file.
ref(),
1222 name_vector, bp_ids);
1226 size_t num_bkpts = bp_ids.
GetSize();
1227 for (
size_t i = 0; i < num_bkpts; i++) {
1238 TargetSP target_sp(
GetSP());
1240 sberr.
SetErrorString(
"BreakpointWriteToFile called with invalid target.");
1253 TargetSP target_sp(
GetSP());
1255 sberr.
SetErrorString(
"BreakpointWriteToFile called with invalid target.");
1259 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1262 sberr.
ref() = target_sp->SerializeBreakpointsToFile(dest_file.
ref(),
1263 bp_id_list, append);
1270 TargetSP target_sp(
GetSP());
1273 return target_sp->GetWatchpointList().GetSize();
1282 TargetSP target_sp(
GetSP());
1285 sb_watchpoint.
SetSP(target_sp->GetWatchpointList().GetByIndex(idx));
1287 return sb_watchpoint;
1293 bool result =
false;
1294 TargetSP target_sp(
GetSP());
1296 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1297 std::unique_lock<std::recursive_mutex> lock;
1298 target_sp->GetWatchpointList().GetListMutex(lock);
1299 result = target_sp->RemoveWatchpointByID(wp_id);
1309 lldb::WatchpointSP watchpoint_sp;
1310 TargetSP target_sp(
GetSP());
1312 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1313 std::unique_lock<std::recursive_mutex> lock;
1314 target_sp->GetWatchpointList().GetListMutex(lock);
1315 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1316 sb_watchpoint.
SetSP(watchpoint_sp);
1319 return sb_watchpoint;
1323 bool read,
bool write,
1328 lldb::WatchpointSP watchpoint_sp;
1329 TargetSP target_sp(
GetSP());
1332 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1338 if (watch_type == 0) {
1339 error.SetErrorString(
1340 "Can't create a watchpoint that is neither read nor write.");
1341 return sb_watchpoint;
1349 target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1350 error.SetError(cw_error);
1351 sb_watchpoint.
SetSP(watchpoint_sp);
1354 return sb_watchpoint;
1360 TargetSP target_sp(
GetSP());
1362 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1363 std::unique_lock<std::recursive_mutex> lock;
1364 target_sp->GetWatchpointList().GetListMutex(lock);
1365 target_sp->EnableAllWatchpoints();
1374 TargetSP target_sp(
GetSP());
1376 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1377 std::unique_lock<std::recursive_mutex> lock;
1378 target_sp->GetWatchpointList().GetListMutex(lock);
1379 target_sp->DisableAllWatchpoints();
1390 lldb::ValueObjectSP new_value_sp;
1399 sb_value.
SetSP(new_value_sp);
1408 lldb::ValueObjectSP new_value_sp;
1410 DataExtractorSP extractor(*data);
1417 sb_value.
SetSP(new_value_sp);
1426 lldb::ValueObjectSP new_value_sp;
1427 if (
IsValid() && name && *name && expr && *expr) {
1433 sb_value.
SetSP(new_value_sp);
1440 TargetSP target_sp(
GetSP());
1442 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1443 std::unique_lock<std::recursive_mutex> lock;
1444 target_sp->GetWatchpointList().GetListMutex(lock);
1445 target_sp->RemoveAllWatchpoints();
1455 TargetSP target_sp(
GetSP());
1457 return error.SetErrorString(
"invalid target");
1459 llvm::StringRef srFrom = from, srTo = to;
1461 return error.SetErrorString(
"<from> path can't be empty");
1463 return error.SetErrorString(
"<to> path can't be empty");
1465 target_sp->GetImageSearchPathList().Append(srFrom, srTo,
true);
1469 const char *uuid_cstr) {
1472 return AddModule(path, triple, uuid_cstr,
nullptr);
1476 const char *uuid_cstr,
const char *symfile) {
1480 TargetSP target_sp(
GetSP());
1491 target_sp->GetPlatform().get(), triple);
1498 sb_module.
SetSP(target_sp->GetOrCreateModule(module_spec,
true ));
1507 TargetSP target_sp(
GetSP());
1517 TargetSP target_sp(
GetSP());
1519 target_sp->GetImages().AppendIfNeeded(module.
GetSP());
1529 TargetSP target_sp(
GetSP());
1532 num = target_sp->GetImages().GetSize();
1548 TargetSP target_sp(
GetSP());
1549 if (target_sp && sb_file_spec.
IsValid()) {
1552 sb_module.
SetSP(target_sp->GetImages().FindFirstModule(module_spec));
1561 const TargetSP target_sp(
GetSP());
1562 if (target_sp && sb_file_spec.
IsValid())
1563 target_sp->GetImages().FindCompileUnits(*sb_file_spec, *sb_sc_list);
1570 TargetSP target_sp(
GetSP());
1572 return target_sp->GetArchitecture().GetByteOrder();
1579 TargetSP target_sp(
GetSP());
1581 std::string triple(target_sp->GetArchitecture().GetTriple().str());
1594 TargetSP target_sp(
GetSP());
1596 std::string abi_name(target_sp->GetABIName().str());
1606 TargetSP target_sp(
GetSP());
1608 return target_sp->GetArchitecture().GetDataByteSize();
1616 TargetSP target_sp(
GetSP());
1618 return target_sp->GetArchitecture().GetCodeByteSize();
1626 TargetSP target_sp(
GetSP());
1628 return target_sp->GetMaximumNumberOfChildrenToDisplay();
1636 TargetSP target_sp(
GetSP());
1638 return target_sp->GetArchitecture().GetAddressByteSize();
1639 return sizeof(
void *);
1647 TargetSP target_sp(
GetSP());
1650 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1651 sb_module.
SetSP(module_sp);
1660 TargetSP target_sp(
GetSP());
1662 return target_sp->GetImages().Remove(module.
GetSP());
1669 TargetSP target_sp(
GetSP());
1681 TargetSP target_sp(
GetSP());
1683 target_sp->Dump(&strm, description_level);
1695 if (!name || !name[0])
1698 TargetSP target_sp(
GetSP());
1706 FunctionNameType mask =
static_cast<FunctionNameType
>(name_type_mask);
1707 target_sp->GetImages().FindFunctions(
ConstString(name), mask,
1708 function_options, *sb_sc_list);
1718 if (name && name[0]) {
1719 llvm::StringRef name_ref(name);
1720 TargetSP target_sp(
GetSP());
1726 std::string regexstr;
1727 switch (matchtype) {
1730 function_options, *sb_sc_list);
1733 regexstr = llvm::Regex::escape(name) +
".*";
1735 function_options, *sb_sc_list);
1738 target_sp->GetImages().FindFunctions(
ConstString(name),
1739 eFunctionNameTypeAny,
1740 function_options, *sb_sc_list);
1751 TargetSP target_sp(
GetSP());
1752 if (typename_cstr && typename_cstr[0] && target_sp) {
1755 const bool exact_match =
false;
1757 const ModuleList &module_list = target_sp->GetImages();
1758 size_t count = module_list.
GetSize();
1759 for (
size_t idx = 0; idx < count; idx++) {
1763 module_sp->FindFirstType(sc, const_typename, exact_match));
1770 if (
auto process_sp = target_sp->GetProcessSP()) {
1771 for (
auto *runtime : process_sp->GetLanguageRuntimes()) {
1772 if (
auto vendor = runtime->GetDeclVendor()) {
1773 auto types = vendor->FindTypes(const_typename, 1);
1775 return SBType(types.front());
1781 for (
auto type_system_sp : target_sp->GetScratchTypeSystems())
1782 if (
auto type = type_system_sp->GetBuiltinTypeByName(const_typename))
1792 TargetSP target_sp(
GetSP());
1794 for (
auto type_system_sp : target_sp->GetScratchTypeSystems())
1795 if (
auto compiler_type = type_system_sp->GetBasicTypeFromAST(type))
1796 return SBType(compiler_type);
1805 TargetSP target_sp(
GetSP());
1806 if (typename_cstr && typename_cstr[0] && target_sp) {
1809 bool exact_match =
false;
1811 llvm::DenseSet<SymbolFile *> searched_symbol_files;
1813 searched_symbol_files, type_list);
1815 for (
size_t idx = 0; idx < type_list.
GetSize(); idx++) {
1822 if (
auto process_sp = target_sp->GetProcessSP()) {
1823 for (
auto *runtime : process_sp->GetLanguageRuntimes()) {
1824 if (
auto *vendor = runtime->GetDeclVendor()) {
1826 vendor->FindTypes(const_typename,
UINT32_MAX);
1827 for (
auto type : types)
1833 if (sb_type_list.
GetSize() == 0) {
1835 for (
auto type_system_sp : target_sp->GetScratchTypeSystems())
1836 if (
auto compiler_type =
1837 type_system_sp->GetBuiltinTypeByName(const_typename))
1841 return sb_type_list;
1850 TargetSP target_sp(
GetSP());
1851 if (name && target_sp) {
1853 target_sp->GetImages().FindGlobalVariables(
ConstString(name), max_matches,
1855 if (!variable_list.
Empty()) {
1857 if (exe_scope ==
nullptr)
1858 exe_scope = target_sp.get();
1859 for (
const VariableSP &var_sp : variable_list) {
1860 lldb::ValueObjectSP valobj_sp(
1868 return sb_value_list;
1878 TargetSP target_sp(
GetSP());
1879 if (name && target_sp) {
1880 llvm::StringRef name_ref(name);
1883 std::string regexstr;
1884 switch (matchtype) {
1886 target_sp->GetImages().FindGlobalVariables(
ConstString(name), max_matches,
1891 max_matches, variable_list);
1894 regexstr = llvm::Regex::escape(name) +
".*";
1896 max_matches, variable_list);
1899 if (!variable_list.
Empty()) {
1901 if (exe_scope ==
nullptr)
1902 exe_scope = target_sp.get();
1903 for (
const VariableSP &var_sp : variable_list) {
1904 lldb::ValueObjectSP valobj_sp(
1912 return sb_value_list;
1928 return source_manager;
1940 const char *flavor_string) {
1945 TargetSP target_sp(
GetSP());
1951 target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
1952 bool force_live_memory =
true;
1955 const size_t bytes_read =
1956 target_sp->ReadMemory(*addr_ptr, data.GetBytes(), data.
GetByteSize(),
1957 error, force_live_memory, &load_addr);
1960 target_sp->GetArchitecture(),
nullptr, flavor_string, *addr_ptr,
1961 data.GetBytes(), bytes_read, count, data_from_file));
1965 return sb_instructions;
1978 const char *flavor_string,
const void *buf,
1984 TargetSP target_sp(
GetSP());
1988 if (base_addr.
get())
1989 addr = *base_addr.
get();
1991 const bool data_from_file =
true;
1994 target_sp->GetArchitecture(),
nullptr, flavor_string, addr, buf, size,
1998 return sb_instructions;
2012 const char *flavor_string,
const void *buf,
2025 TargetSP target_sp(
GetSP());
2030 SectionSP section_sp(section.
GetSP());
2032 if (section_sp->IsThreadSpecific()) {
2034 "thread specific sections are not yet supported");
2036 ProcessSP process_sp(target_sp->GetProcessSP());
2037 if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) {
2038 ModuleSP module_sp(section_sp->GetModule());
2041 module_list.
Append(module_sp);
2042 target_sp->ModulesDidLoad(module_list);
2046 process_sp->Flush();
2062 TargetSP target_sp(
GetSP());
2067 SectionSP section_sp(section.
GetSP());
2069 ProcessSP process_sp(target_sp->GetProcessSP());
2070 if (target_sp->SetSectionUnloaded(section_sp)) {
2071 ModuleSP module_sp(section_sp->GetModule());
2074 module_list.
Append(module_sp);
2075 target_sp->ModulesDidUnload(module_list,
false);
2079 process_sp->Flush();
2092 int64_t slide_offset) {
2097 TargetSP target_sp(
GetSP());
2099 ModuleSP module_sp(module.
GetSP());
2101 bool changed =
false;
2102 if (module_sp->SetLoadAddress(*target_sp, slide_offset,
true, changed)) {
2107 module_list.
Append(module_sp);
2108 target_sp->ModulesDidLoad(module_list);
2110 ProcessSP process_sp(target_sp->GetProcessSP());
2112 process_sp->Flush();
2131 TargetSP target_sp(
GetSP());
2133 ModuleSP module_sp(module.
GetSP());
2135 ObjectFile *objfile = module_sp->GetObjectFile();
2139 ProcessSP process_sp(target_sp->GetProcessSP());
2141 bool changed =
false;
2142 const size_t num_sections = section_list->
GetSize();
2143 for (
size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
2146 changed |= target_sp->SetSectionUnloaded(section_sp);
2150 module_list.
Append(module_sp);
2151 target_sp->ModulesDidUnload(module_list,
false);
2153 ProcessSP process_sp(target_sp->GetProcessSP());
2155 process_sp->Flush();
2158 module_sp->GetFileSpec().GetPath(path,
sizeof(path));
2163 module_sp->GetFileSpec().GetPath(path,
sizeof(path));
2181 if (name && name[0]) {
2182 TargetSP target_sp(
GetSP());
2184 target_sp->GetImages().FindSymbolsWithNameAndType(
2193 TargetSP target_sp(
GetSP());
2199 target_sp->GetPreferDynamicValue();
2209 Log *expr_log =
GetLog(LLDBLog::Expressions);
2211 ValueObjectSP expr_value_sp;
2212 TargetSP target_sp(
GetSP());
2215 if (expr ==
nullptr || expr[0] ==
'\0') {
2219 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
2233 "** [SBTarget::EvaluateExpression] Expression result is "
2234 "%s, summary %s **",
2242 TargetSP target_sp(
GetSP());
2245 ProcessSP process_sp(target_sp->GetProcessSP());
2247 abi_sp = process_sp->GetABI();
2251 return abi_sp->GetRedZoneSize();
2259 TargetSP target_sp(
GetSP());
2263 ModuleSP module_sp(module.
GetSP());
2267 return module_sp->IsLoadedInTarget(target_sp.get());
2274 TargetSP target_sp(
GetSP());
2283 TargetSP target_sp(
GetSP());
2290 TargetSP target_sp(
GetSP());
2301 TargetSP target_sp(
GetSP());
2304 return SBTrace(target_sp->GetTrace());
2311 TargetSP target_sp(
GetSP());
2315 if (llvm::Expected<lldb::TraceSP> trace_sp = target_sp->CreateTrace()) {
2318 error.SetErrorString(llvm::toString(trace_sp.takeError()).c_str());
2321 error.SetErrorString(
"missing target");
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT()
#define LLDB_INSTRUMENT_VA(...)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
static Status AttachToProcess(ProcessAttachInfo &attach_info, Target &target)
lldb_private::Address * get()
addr_t GetLoadAddress(const lldb::SBTarget &target) const
lldb_private::Address & ref()
lldb_private::ProcessAttachInfo & ref()
void CopyToBreakpointIDList(lldb_private::BreakpointIDList &bp_id_list)
void AppendByID(lldb::break_id_t id)
void reset(const lldb::DebuggerSP &debugger_sp)
void SetErrorString(const char *err_str)
lldb_private::Status & ref()
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
lldb_private::Event * get() const
void SetFetchDynamicValue(lldb::DynamicValueType dynamic=lldb::eDynamicCanRunTarget)
lldb_private::EvaluateExpressionOptions & ref() const
void SetUnwindOnError(bool unwind=true)
lldb::DynamicValueType GetFetchDynamicValue() const
const lldb_private::FileSpecList * get() const
void Append(const SBFileSpec &sb_file)
void SetFileSpec(const lldb_private::FileSpec &fspec)
const lldb_private::FileSpec & ref() const
void SetDisassembler(const lldb::DisassemblerSP &opaque_sp)
void SetWorkingDirectory(const char *working_dir)
void SetExecutableFile(SBFileSpec exe_file, bool add_as_first_arg)
Set the executable file that will be used to launch the process and optionally set it as the first ar...
void set_ref(const lldb_private::ProcessLaunchInfo &info)
void SetEnvironmentEntries(const char **envp, bool append)
Update this object with the given environment variables.
const lldb_private::ProcessLaunchInfo & ref() const
void SetArguments(const char **argv, bool append)
lldb::ListenerSP m_opaque_sp
std::unique_ptr< lldb_private::ModuleSpec > m_opaque_up
void SetSP(const ModuleSP &module_sp)
void SetSP(const lldb::ProcessSP &process_sp)
lldb::SectionSP GetSP() const
lldb_private::Stream & ref()
void AppendString(const char *str)
const char * GetStringAtIndex(size_t idx)
StructuredDataImplUP m_impl_up
lldb_private::SymbolContext & ref()
SBSourceManager GetSourceManager()
bool AddModule(lldb::SBModule &module)
bool DisableAllBreakpoints()
uint32_t GetNumWatchpoints() const
bool GetDescription(lldb::SBStream &description, lldb::DescriptionLevel description_level)
lldb::SBError ClearSectionLoadAddress(lldb::SBSection section)
Clear the base load address for a module section.
bool DeleteWatchpoint(lldb::watch_id_t watch_id)
lldb::ByteOrder GetByteOrder()
uint32_t GetNumBreakpoints() const
lldb::SBInstructionList GetInstructionsWithFlavor(lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
void SetCollectingStats(bool v)
Sets whether we should collect statistics on lldb or not.
bool BreakpointDelete(break_id_t break_id)
void SetSP(const lldb::TargetSP &target_sp)
bool IsLoaded(const lldb::SBModule &module) const
static lldb::SBModule GetModuleAtIndexFromEvent(const uint32_t idx, const lldb::SBEvent &event)
bool GetCollectingStats()
Returns whether statistics collection are enabled.
lldb::SBBreakpoint BreakpointCreateByAddress(addr_t address)
lldb::SBValue CreateValueFromExpression(const char *name, const char *expr)
lldb::SBSymbolContextList FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype)
Find global functions by their name with pattern matching.
lldb::SBBreakpoint BreakpointCreateByRegex(const char *symbol_name_regex, const char *module_name=nullptr)
lldb::SBTrace GetTrace()
Get a SBTrace object the can manage the processor trace information of this target.
const lldb::SBTarget & operator=(const lldb::SBTarget &rhs)
static bool EventIsTargetEvent(const lldb::SBEvent &event)
lldb::SBAddress ResolvePastLoadAddress(uint32_t stop_id, lldb::addr_t vm_addr)
Resolve a current load address into a section offset address using the process stop ID to identify a ...
bool DisableAllWatchpoints()
lldb::addr_t GetStackRedZoneSize()
lldb::SBBreakpoint GetBreakpointAtIndex(uint32_t idx) const
SBError Install()
Install any binaries that need to be installed.
lldb::SBSymbolContextList FindCompileUnits(const lldb::SBFileSpec &sb_file_spec)
Find compile units related to *this target and passed source file.
lldb::SBAddress ResolveLoadAddress(lldb::addr_t vm_addr)
Resolve a current load address into a section offset address.
lldb::SBStructuredData GetStatistics()
Returns a dump of the collected statistics.
lldb::SBModule GetModuleAtIndex(uint32_t idx)
lldb::SBValueList FindGlobalVariables(const char *name, uint32_t max_matches)
Find global and static variables by name.
lldb::SBType GetBasicType(lldb::BasicType type)
lldb::SBFileSpec GetExecutable()
const char * GetABIName()
lldb::SBError SetSectionLoadAddress(lldb::SBSection section, lldb::addr_t section_base_addr)
Set the base load address for a module section.
lldb::SBProcess ConnectRemote(SBListener &listener, const char *url, const char *plugin_name, SBError &error)
Connect to a remote debug server with url.
lldb::SBBreakpoint BreakpointCreateByName(const char *symbol_name, const char *module_name=nullptr)
void DeleteBreakpointName(const char *name)
SBProcess Attach(SBAttachInfo &attach_info, SBError &error)
bool EnableAllWatchpoints()
lldb::SBBreakpoint BreakpointCreateBySBAddress(SBAddress &address)
lldb::SBProcess GetProcess()
SBSymbolContext ResolveSymbolContextForAddress(const SBAddress &addr, uint32_t resolve_scope)
lldb::SBProcess AttachToProcessWithID(SBListener &listener, lldb::pid_t pid, lldb::SBError &error)
Attach to process with pid.
lldb::SBPlatform GetPlatform()
Return the platform object associated with the target.
lldb::SBBreakpoint BreakpointCreateByLocation(const char *file, uint32_t line)
lldb::SBBreakpoint BreakpointCreateForException(lldb::LanguageType language, bool catch_bp, bool throw_bp)
uint32_t GetNumModules() const
lldb::TargetSP GetSP() const
uint32_t GetDataByteSize()
Architecture data byte width accessor.
uint32_t GetMaximumNumberOfChildrenToDisplay() const
Gets the target.max-children-count value It should be used to limit the number of children of large d...
bool DeleteAllWatchpoints()
lldb::SBInstructionList GetInstructions(lldb::SBAddress base_addr, const void *buf, size_t size)
lldb::SBProcess Launch(SBListener &listener, char const **argv, char const **envp, const char *stdin_path, const char *stdout_path, const char *stderr_path, const char *working_directory, uint32_t launch_flags, bool stop_at_entry, lldb::SBError &error)
Launch a new process.
bool RemoveModule(lldb::SBModule module)
lldb::SBWatchpoint WatchAddress(lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
lldb::SBSymbolContextList FindFunctions(const char *name, uint32_t name_type_mask=lldb::eFunctionNameTypeAny)
Find functions by name.
lldb::SBValue FindFirstGlobalVariable(const char *name)
Find the first global (or static) variable by name.
lldb::SBValue EvaluateExpression(const char *expr)
lldb::SBBreakpoint BreakpointCreateFromScript(const char *class_name, SBStructuredData &extra_args, const SBFileSpecList &module_list, const SBFileSpecList &file_list, bool request_hardware=false)
Create a breakpoint using a scripted resolver.
static const char * GetBroadcasterClassName()
SBEnvironment GetEnvironment()
Return the environment variables that would be used to launch a new process.
lldb::SBTypeList FindTypes(const char *type)
lldb::SBValue CreateValueFromAddress(const char *name, lldb::SBAddress addr, lldb::SBType type)
static lldb::SBTarget GetTargetFromEvent(const lldb::SBEvent &event)
lldb::SBError BreakpointsCreateFromFile(SBFileSpec &source_file, SBBreakpointList &new_bps)
Read breakpoints from source_file and return the newly created breakpoints in bkpt_list.
uint32_t GetAddressByteSize()
bool operator==(const lldb::SBTarget &rhs) const
bool operator!=(const lldb::SBTarget &rhs) const
lldb::TargetSP m_opaque_sp
lldb::SBWatchpoint GetWatchpointAtIndex(uint32_t idx) const
lldb::SBLaunchInfo GetLaunchInfo() const
lldb::SBSymbolContextList FindSymbols(const char *name, lldb::SymbolType type=eSymbolTypeAny)
void AppendImageSearchPath(const char *from, const char *to, lldb::SBError &error)
lldb::SBTrace CreateTrace(SBError &error)
Create a Trace object for the current target using the using the default supported tracing technology...
lldb::SBBreakpoint BreakpointCreateBySourceRegex(const char *source_regex, const SBFileSpec &source_file, const char *module_name=nullptr)
bool DeleteAllBreakpoints()
lldb::SBValue CreateValueFromData(const char *name, lldb::SBData data, lldb::SBType type)
lldb::SBBroadcaster GetBroadcaster() const
lldb::SBError SetModuleLoadAddress(lldb::SBModule module, int64_t sections_offset)
Slide all file addresses for all module sections so that module appears to loaded at these slide addr...
bool FindBreakpointsByName(const char *name, SBBreakpointList &bkpt_list)
size_t ReadMemory(const SBAddress addr, void *buf, size_t size, lldb::SBError &error)
Read target memory.
lldb::SBBreakpoint BreakpointCreateByNames(const char *symbol_name[], uint32_t num_names, uint32_t name_type_mask, const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list)
SBProcess LaunchSimple(const char **argv, const char **envp, const char *working_directory)
Launch a new process with sensible defaults.
lldb::SBModule FindModule(const lldb::SBFileSpec &file_spec)
lldb::SBBreakpoint FindBreakpointByID(break_id_t break_id)
lldb::SBInstructionList ReadInstructions(lldb::SBAddress base_addr, uint32_t count)
void GetBreakpointNames(SBStringList &names)
lldb::SBDebugger GetDebugger() const
lldb::SBError BreakpointsWriteToFile(SBFileSpec &dest_file)
Write breakpoints to dest_file.
lldb::SBWatchpoint FindWatchpointByID(lldb::watch_id_t watch_id)
lldb::SBAddress ResolveFileAddress(lldb::addr_t file_addr)
Resolve a current file address into a section offset address.
void SetLaunchInfo(const lldb::SBLaunchInfo &launch_info)
lldb::SBError ClearModuleLoadAddress(lldb::SBModule module)
Clear the section base load addresses for all sections in a module.
lldb::SBType FindFirstType(const char *type)
uint32_t GetCodeByteSize()
Architecture code byte width accessor.
lldb::SBProcess AttachToProcessWithName(SBListener &listener, const char *name, bool wait_for, lldb::SBError &error)
Attach to process with name.
SBProcess LoadCore(const char *core_file)
static uint32_t GetNumModulesFromEvent(const lldb::SBEvent &event)
bool EnableAllBreakpoints()
void Append(lldb::SBType type)
void Append(const lldb::SBValue &val_obj)
lldb::SBValue GetValueAtIndex(uint32_t idx) const
void SetSP(const lldb::ValueObjectSP &sp)
const char * GetSummary()
void SetSP(const lldb::WatchpointSP &sp)
static lldb::ABISP FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch)
A section + offset based address class.
void SetRawAddress(lldb::addr_t addr)
An architecture specification class.
bool IsValid() const
Tests if this ArchSpec is valid.
void AppendArguments(const Args &rhs)
const BreakpointID & GetBreakpointIDAtIndex(size_t index) const
lldb::break_id_t GetBreakpointID() const
Generic representation of a type in a programming language.
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
const char * GetCString() const
Get the string value as a C string.
A subclass of DataBuffer that stores a data buffer on the heap.
lldb::offset_t GetByteSize() const override
static void SetCollectingStats(bool enable)
static bool GetCollectingStats()
static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target)
Get metrics associated with one or all targets in a debugger in JSON format.
static lldb::DisassemblerSP DisassembleBytes(const ArchSpec &arch, const char *plugin_name, const char *flavor, const Address &start, const void *bytes, size_t length, uint32_t max_num_instructions, bool data_from_file)
Execution context objects refer to objects in the execution of the program that is being debugged.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
Target * GetTargetPtr() const
Returns a pointer to the target object.
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
static FileSystem & Instance()
A collection class for Module objects.
void FindTypes(Module *search_first, ConstString name, bool name_is_fully_qualified, size_t max_matches, llvm::DenseSet< SymbolFile * > &searched_symbol_files, TypeList &types) const
Find types by name.
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
size_t GetSize() const
Gets the size of the module list.
ArchSpec & GetArchitecture()
FileSpec & GetSymbolFileSpec()
A class that describes an executable image and its associated object and symbol files.
const FileSpec & GetPlatformFileSpec() const
Get accessor for the module platform file specification.
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
A plug-in interface definition class for object file parsers.
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
void SetListener(const lldb::ListenerSP &listener_sp)
void SetWaitForLaunch(bool b)
lldb::ListenerSP GetListener() const
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
bool ProcessIDIsValid() const
lldb::pid_t GetProcessID() const
void SetProcessID(lldb::pid_t pid)
FileSpec & GetExecutableFile()
bool UserIDIsValid() const
Environment & GetEnvironment()
void SetUserID(uint32_t uid)
ArchSpec & GetArchitecture()
uint32_t GetEffectiveUserID() const
void SetListener(const lldb::ListenerSP &listener_sp)
lldb::SectionSP GetSectionAtIndex(size_t idx) const
This base class provides an interface to stack frames.
A stream class that can stream formatted output to a file.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
std::shared_ptr< Object > ObjectSP
static ObjectSP ParseJSON(const std::string &json_text)
Defines a symbol context baton that can be handed other debug core functions.
static ModuleList GetModuleListFromEvent(const Event *event_ptr)
static const TargetEventData * GetEventDataFromEvent(const Event *event_ptr)
static lldb::TargetSP GetTargetFromEvent(const Event *event_ptr)
static ConstString & GetStaticBroadcasterClass()
const lldb::ProcessSP & GetProcessSP() const
std::recursive_mutex & GetAPIMutex()
Status Attach(ProcessAttachInfo &attach_info, Stream *stream)
lldb::ExpressionResults EvaluateExpression(llvm::StringRef expression, ExecutionContextScope *exe_scope, lldb::ValueObjectSP &result_valobj_sp, const EvaluateExpressionOptions &options=EvaluateExpressionOptions(), std::string *fixed_expression=nullptr, ValueObject *ctx_obj=nullptr)
lldb::TypeSP GetTypeAtIndex(uint32_t idx)
bool SetFromStringRef(llvm::StringRef str)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp)
static lldb::ValueObjectSP CreateValueObjectFromExpression(llvm::StringRef name, llvm::StringRef expression, const ExecutionContext &exe_ctx)
static lldb::ValueObjectSP CreateValueObjectFromData(llvm::StringRef name, const DataExtractor &data, const ExecutionContext &exe_ctx, CompilerType type)
static lldb::ValueObjectSP CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx, CompilerType type)
#define LLDB_WATCH_TYPE_WRITE
#define LLDB_INVALID_BREAK_ID
#define LLDB_INVALID_WATCH_ID
#define LLDB_WATCH_TYPE_READ
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
MatchType
String matching algorithm used by SBTarget.
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
StateType
Process and Thread States.
@ eStateConnected
Process is connected to remote debug services, but not launched or attached to anything yet.
@ eStateAttaching
Process is currently trying to attach.
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
ByteOrder
Byte ordering definitions.
Options used by Module::FindFunctions.
bool include_inlines
Include inlined functions.
bool include_symbols
Include the symbol table.