69#include "llvm/Support/PrettyStackTrace.h"
70#include "llvm/Support/Regex.h"
75#define DEFAULT_DISASM_BYTE_SIZE 32
78 std::lock_guard<std::recursive_mutex> guard(target.
GetAPIMutex());
82 const auto state = process_sp->GetState();
88 return Status(
"process is connected and already has a listener, pass "
93 return target.
Attach(attach_info,
nullptr);
155 return this->
operator bool();
157SBTarget::operator bool()
const {
160 return m_opaque_sp.get() !=
nullptr && m_opaque_sp->IsValid();
170 process_sp = target_sp->GetProcessSP();
171 sb_process.
SetSP(process_sp);
196 debugger.
reset(target_sp->GetDebugger().shared_from_this());
213 std::string json_str =
215 target_sp->GetDebugger(), target_sp.get(),
255 ProcessSP process_sp(target_sp->CreateProcess(
256 target_sp->GetDebugger().GetListener(),
"", &filespec,
false));
258 error.SetError(process_sp->LoadCore());
260 sb_process.
SetSP(process_sp);
262 error.SetErrorString(
"Failed to create the process");
265 error.SetErrorString(
"SBTarget is invalid");
271 const char *working_directory) {
280 if (
Module *exe_module = target_sp->GetExecutableModulePointer())
287 if (working_directory)
300 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
301 sb_error.
ref() = target_sp->Install(
nullptr);
307 char const **envp,
const char *stdin_path,
308 const char *stdout_path,
const char *stderr_path,
309 const char *working_directory,
310 uint32_t launch_flags,
313 stderr_path, working_directory, launch_flags,
314 stop_at_entry,
error);
321 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
324 launch_flags |= eLaunchFlagStopAtEntry;
326 if (getenv(
"LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
327 launch_flags |= eLaunchFlagDisableASLR;
330 process_sp = target_sp->GetProcessSP();
332 state = process_sp->GetState();
336 error.SetErrorString(
"process attach is in progress");
338 error.SetErrorString(
"a process is already being debugged");
348 error.SetErrorString(
"process is connected and already has a listener, "
349 "pass empty listener");
354 if (getenv(
"LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
355 launch_flags |= eLaunchFlagDisableSTDIO;
359 FileSpec(working_directory), launch_flags);
361 Module *exe_module = target_sp->GetExecutableModulePointer();
367 auto default_launch_info = target_sp->GetProcessLaunchInfo();
369 default_launch_info.GetArguments());
374 auto default_launch_info = target_sp->GetProcessLaunchInfo();
375 launch_info.
GetEnvironment() = default_launch_info.GetEnvironment();
381 error.SetError(target_sp->Launch(launch_info,
nullptr));
383 sb_process.
SetSP(target_sp->GetProcessSP());
385 error.SetErrorString(
"SBTarget is invalid");
398 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
401 ProcessSP process_sp = target_sp->GetProcessSP();
403 state = process_sp->GetState();
407 error.SetErrorString(
"process attach is in progress");
409 error.SetErrorString(
"a process is already being debugged");
418 Module *exe_module = target_sp->GetExecutableModulePointer();
423 const ArchSpec &arch_spec = target_sp->GetArchitecture();
427 error.SetError(target_sp->Launch(launch_info,
nullptr));
428 sb_launch_info.
set_ref(launch_info);
429 sb_process.
SetSP(target_sp->GetProcessSP());
431 error.SetErrorString(
"SBTarget is invalid");
447 PlatformSP platform_sp = target_sp->GetPlatform();
449 if (platform_sp && platform_sp->IsConnected()) {
452 if (platform_sp->GetProcessInfo(attach_pid, instance_info)) {
455 error.ref().SetErrorStringWithFormat(
456 "no process found with process ID %" PRIu64, attach_pid);
463 sb_process.
SetSP(target_sp->GetProcessSP());
465 error.SetErrorString(
"SBTarget is invalid");
488 if (target_sp->GetPlatform()->GetProcessInfo(pid, instance_info))
493 sb_process.
SetSP(target_sp->GetProcessSP());
495 error.SetErrorString(
"SBTarget is invalid");
511 if (name && target_sp) {
520 sb_process.
SetSP(target_sp->GetProcessSP());
522 error.SetErrorString(
"SBTarget is invalid");
528 const char *plugin_name,
537 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
540 target_sp->CreateProcess(listener.
m_opaque_sp, plugin_name,
nullptr,
543 process_sp = target_sp->CreateProcess(
544 target_sp->GetDebugger().GetListener(), plugin_name,
nullptr,
true);
547 sb_process.
SetSP(process_sp);
548 error.SetError(process_sp->ConnectRemote(url));
550 error.SetErrorString(
"unable to create lldb_private::Process");
553 error.SetErrorString(
"SBTarget is invalid");
565 Module *exe_module = target_sp->GetExecutableModulePointer();
570 return exe_file_spec;
598 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
599 if (target_sp->ResolveLoadAddress(vm_addr, addr))
616 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
617 if (target_sp->ResolveFileAddress(file_addr, addr))
633 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
634 if (target_sp->ResolveLoadAddress(vm_addr, addr))
646 uint32_t resolve_scope) {
650 SymbolContextItem scope =
static_cast<SymbolContextItem
>(resolve_scope);
654 target_sp->GetImages().ResolveSymbolContextForAddress(addr.
ref(), scope,
665 size_t bytes_read = 0;
668 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
670 target_sp->ReadMemory(addr.
ref(), buf, size, sb_error.
ref(),
true);
714 const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
720 if (target_sp && line != 0) {
721 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
725 const bool internal =
false;
726 const bool hardware =
false;
729 if (sb_module_list.
GetSize() > 0) {
730 module_list = sb_module_list.
get();
732 sb_bp = target_sp->CreateBreakpoint(
733 module_list, *sb_file_spec, line, column, offset, check_inlines,
734 skip_prologue, internal, hardware, move_to_nearest_code);
741 const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
743 bool move_to_nearest_code) {
745 move_to_nearest_code);
749 if (target_sp && line != 0) {
750 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
754 const bool internal =
false;
755 const bool hardware =
false;
757 if (sb_module_list.
GetSize() > 0) {
758 module_list = sb_module_list.
get();
760 sb_bp = target_sp->CreateBreakpoint(
761 module_list, *sb_file_spec, line, column, offset, check_inlines,
762 skip_prologue, internal, hardware,
770 const char *module_name) {
775 if (target_sp.get()) {
776 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
778 const bool internal =
false;
779 const bool hardware =
false;
782 if (module_name && module_name[0]) {
785 sb_bp = target_sp->CreateBreakpoint(
786 &module_spec_list,
nullptr, symbol_name, eFunctionNameTypeAuto,
789 sb_bp = target_sp->CreateBreakpoint(
790 nullptr,
nullptr, symbol_name, eFunctionNameTypeAuto,
804 lldb::FunctionNameType name_type_mask = eFunctionNameTypeAuto;
811 const char *symbol_name, uint32_t name_type_mask,
822 const char *symbol_name, uint32_t name_type_mask,
826 module_list, comp_unit_list);
830 if (target_sp && symbol_name && symbol_name[0]) {
831 const bool internal =
false;
832 const bool hardware =
false;
834 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
835 FunctionNameType mask =
static_cast<FunctionNameType
>(name_type_mask);
836 sb_bp = target_sp->CreateBreakpoint(module_list.
get(), comp_unit_list.
get(),
837 symbol_name, mask, symbol_language, 0,
838 skip_prologue, internal, hardware);
845 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
856 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
860 symbol_language, module_list, comp_unit_list);
868 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
872 symbol_language, offset, module_list, comp_unit_list);
876 if (target_sp && num_names > 0) {
877 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
878 const bool internal =
false;
879 const bool hardware =
false;
880 FunctionNameType mask =
static_cast<FunctionNameType
>(name_type_mask);
882 sb_bp = target_sp->CreateBreakpoint(
883 module_list.
get(), comp_unit_list.
get(), symbol_names, num_names, mask,
884 symbol_language, offset, skip_prologue, internal, hardware);
891 const char *module_name) {
896 if (module_name && module_name[0]) {
900 module_spec_list, comp_unit_list);
910 module_list, comp_unit_list);
914 const char *symbol_name_regex,
LanguageType symbol_language,
921 if (target_sp && symbol_name_regex && symbol_name_regex[0]) {
922 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
924 const bool internal =
false;
925 const bool hardware =
false;
928 sb_bp = target_sp->CreateFuncRegexBreakpoint(
929 module_list.
get(), comp_unit_list.
get(), std::move(regexp),
930 symbol_language, skip_prologue, internal, hardware);
942 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
943 const bool hardware =
false;
944 sb_bp = target_sp->CreateBreakpoint(address,
false, hardware);
960 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
961 const bool hardware =
false;
962 sb_bp = target_sp->CreateBreakpoint(sb_address.
ref(),
false, hardware);
971 const char *module_name) {
976 if (module_name && module_name[0]) {
982 source_file_list.
Append(source_file);
1007 if (target_sp && source_regex && source_regex[0]) {
1008 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1009 const bool hardware =
false;
1012 std::unordered_set<std::string> func_names_set;
1013 for (
size_t i = 0; i < func_names.
GetSize(); i++) {
1017 sb_bp = target_sp->CreateSourceRegexBreakpoint(
1018 module_list.
get(), source_file_list.
get(), func_names_set,
1019 std::move(regexp),
false, hardware, move_to_nearest_code);
1027 bool catch_bp,
bool throw_bp) {
1033 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1034 const bool hardware =
false;
1035 sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp,
1045 bool request_hardware) {
1052 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1057 target_sp->CreateScriptedBreakpoint(class_name,
1075 return target_sp->GetBreakpointList().GetSize();
1087 sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
1089 return sb_breakpoint;
1095 bool result =
false;
1098 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1099 result = target_sp->RemoveBreakpointByID(bp_id);
1111 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1112 sb_breakpoint = target_sp->GetBreakpointByID(bp_id);
1115 return sb_breakpoint;
1124 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1125 llvm::Expected<std::vector<BreakpointSP>> expected_vector =
1126 target_sp->GetBreakpointList().FindBreakpointsByName(name);
1127 if (!expected_vector) {
1129 "invalid breakpoint name: {0}");
1146 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1148 std::vector<std::string> name_vec;
1149 target_sp->GetBreakpointNames(name_vec);
1150 for (
const auto &name : name_vec)
1160 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1161 target_sp->DeleteBreakpointName(
ConstString(name));
1170 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1171 target_sp->EnableAllowedBreakpoints();
1182 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1183 target_sp->DisableAllowedBreakpoints();
1194 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1195 target_sp->RemoveAllowedBreakpoints();
1218 "BreakpointCreateFromFile called with invalid target.");
1221 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1225 std::vector<std::string> name_vector;
1226 size_t num_names = matching_names.
GetSize();
1227 for (
size_t i = 0; i < num_names; i++)
1230 sberr.
ref() = target_sp->CreateBreakpointsFromFile(source_file.
ref(),
1231 name_vector, bp_ids);
1235 size_t num_bkpts = bp_ids.
GetSize();
1236 for (
size_t i = 0; i < num_bkpts; i++) {
1249 sberr.
SetErrorString(
"BreakpointWriteToFile called with invalid target.");
1264 sberr.
SetErrorString(
"BreakpointWriteToFile called with invalid target.");
1268 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1271 sberr.
ref() = target_sp->SerializeBreakpointsToFile(dest_file.
ref(),
1272 bp_id_list, append);
1282 return target_sp->GetWatchpointList().GetSize();
1294 sb_watchpoint.
SetSP(target_sp->GetWatchpointList().GetByIndex(idx));
1296 return sb_watchpoint;
1302 bool result =
false;
1305 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1306 std::unique_lock<std::recursive_mutex> lock;
1307 target_sp->GetWatchpointList().GetListMutex(lock);
1308 result = target_sp->RemoveWatchpointByID(wp_id);
1321 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1322 std::unique_lock<std::recursive_mutex> lock;
1323 target_sp->GetWatchpointList().GetListMutex(lock);
1324 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1325 sb_watchpoint.
SetSP(watchpoint_sp);
1328 return sb_watchpoint;
1332 bool read,
bool modify,
1351 uint32_t watch_type = 0;
1358 if (watch_type == 0) {
1359 error.SetErrorString(
"Can't create a watchpoint that is neither read nor "
1360 "write nor modify.");
1361 return sb_watchpoint;
1364 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1370 target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1371 error.SetError(cw_error);
1372 sb_watchpoint.
SetSP(watchpoint_sp);
1375 return sb_watchpoint;
1383 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1384 std::unique_lock<std::recursive_mutex> lock;
1385 target_sp->GetWatchpointList().GetListMutex(lock);
1386 target_sp->EnableAllWatchpoints();
1397 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1398 std::unique_lock<std::recursive_mutex> lock;
1399 target_sp->GetWatchpointList().GetListMutex(lock);
1400 target_sp->DisableAllWatchpoints();
1420 sb_value.
SetSP(new_value_sp);
1438 sb_value.
SetSP(new_value_sp);
1448 if (
IsValid() && name && *name && expr && *expr) {
1454 sb_value.
SetSP(new_value_sp);
1463 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1464 std::unique_lock<std::recursive_mutex> lock;
1465 target_sp->GetWatchpointList().GetListMutex(lock);
1466 target_sp->RemoveAllWatchpoints();
1478 return error.SetErrorString(
"invalid target");
1480 llvm::StringRef srFrom = from, srTo = to;
1482 return error.SetErrorString(
"<from> path can't be empty");
1484 return error.SetErrorString(
"<to> path can't be empty");
1486 target_sp->GetImageSearchPathList().Append(srFrom, srTo,
true);
1490 const char *uuid_cstr) {
1493 return AddModule(path, triple, uuid_cstr,
nullptr);
1497 const char *uuid_cstr,
const char *symfile) {
1548 if (sb_module.
IsValid() && !target_sp->GetArchitecture().IsValid() &&
1549 sb_module.
GetSP()->GetArchitecture().IsValid())
1550 target_sp->SetArchitecture(sb_module.
GetSP()->GetArchitecture());
1559 target_sp->GetImages().AppendIfNeeded(module.
GetSP());
1572 num = target_sp->GetImages().GetSize();
1589 if (target_sp && sb_file_spec.
IsValid()) {
1592 sb_module.
SetSP(target_sp->GetImages().FindFirstModule(module_spec));
1602 if (target_sp && sb_file_spec.
IsValid())
1603 target_sp->GetImages().FindCompileUnits(*sb_file_spec, *sb_sc_list);
1612 return target_sp->GetArchitecture().GetByteOrder();
1623 std::string triple(target_sp->GetArchitecture().GetTriple().str());
1638 std::string abi_name(target_sp->GetABIName().str());
1658 return Status(
"Couldn't get internal target object.");
1660 return Status(target_sp->SetLabel(label));
1668 return target_sp->GetArchitecture().GetDataByteSize();
1678 return target_sp->GetArchitecture().GetCodeByteSize();
1688 return target_sp->GetMaximumNumberOfChildrenToDisplay();
1698 return target_sp->GetArchitecture().GetAddressByteSize();
1699 return sizeof(
void *);
1710 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1711 sb_module.
SetSP(module_sp);
1722 return target_sp->GetImages().Remove(module.
GetSP());
1743 target_sp->Dump(&strm, description_level);
1751 uint32_t name_type_mask) {
1755 if (!name || !name[0])
1766 FunctionNameType mask =
static_cast<FunctionNameType
>(name_type_mask);
1767 target_sp->GetImages().FindFunctions(
ConstString(name), mask,
1768 function_options, *sb_sc_list);
1773 uint32_t max_matches,
1778 if (name && name[0]) {
1779 llvm::StringRef name_ref(name);
1786 std::string regexstr;
1787 switch (matchtype) {
1790 function_options, *sb_sc_list);
1793 target_sp->GetImages().FindFunctions(
1795 function_options, *sb_sc_list);
1798 regexstr = llvm::Regex::escape(name) +
".*";
1800 function_options, *sb_sc_list);
1803 target_sp->GetImages().FindFunctions(
ConstString(name),
1804 eFunctionNameTypeAny,
1805 function_options, *sb_sc_list);
1817 if (typename_cstr && typename_cstr[0] && target_sp) {
1820 TypeQueryOptions::e_find_one);
1822 target_sp->GetImages().FindTypes(
nullptr, query, results);
1827 if (
auto process_sp = target_sp->GetProcessSP()) {
1828 for (
auto *runtime : process_sp->GetLanguageRuntimes()) {
1829 if (
auto vendor = runtime->GetDeclVendor()) {
1830 auto types = vendor->FindTypes(const_typename, 1);
1832 return SBType(types.front());
1838 for (
auto type_system_sp : target_sp->GetScratchTypeSystems())
1839 if (
auto type = type_system_sp->GetBuiltinTypeByName(const_typename))
1851 for (
auto type_system_sp : target_sp->GetScratchTypeSystems())
1852 if (
auto compiler_type = type_system_sp->GetBasicTypeFromAST(type))
1853 return SBType(compiler_type);
1863 if (typename_cstr && typename_cstr[0] && target_sp) {
1868 images.
FindTypes(
nullptr, query, results);
1873 if (
auto process_sp = target_sp->GetProcessSP()) {
1874 for (
auto *runtime : process_sp->GetLanguageRuntimes()) {
1875 if (
auto *vendor = runtime->GetDeclVendor()) {
1877 vendor->FindTypes(const_typename,
UINT32_MAX);
1878 for (
auto type : types)
1884 if (sb_type_list.
GetSize() == 0) {
1886 for (
auto type_system_sp : target_sp->GetScratchTypeSystems())
1887 if (
auto compiler_type =
1888 type_system_sp->GetBuiltinTypeByName(const_typename))
1892 return sb_type_list;
1896 uint32_t max_matches) {
1902 if (name && target_sp) {
1904 target_sp->GetImages().FindGlobalVariables(
ConstString(name), max_matches,
1906 if (!variable_list.
Empty()) {
1908 if (exe_scope ==
nullptr)
1909 exe_scope = target_sp.get();
1910 for (
const VariableSP &var_sp : variable_list) {
1919 return sb_value_list;
1923 uint32_t max_matches,
1930 if (name && target_sp) {
1931 llvm::StringRef name_ref(name);
1934 std::string regexstr;
1935 switch (matchtype) {
1937 target_sp->GetImages().FindGlobalVariables(
ConstString(name), max_matches,
1942 max_matches, variable_list);
1945 target_sp->GetImages().FindGlobalVariables(
1950 regexstr =
"^" + llvm::Regex::escape(name) +
".*";
1952 max_matches, variable_list);
1955 if (!variable_list.
Empty()) {
1957 if (exe_scope ==
nullptr)
1958 exe_scope = target_sp.get();
1959 for (
const VariableSP &var_sp : variable_list) {
1968 return sb_value_list;
1984 return source_manager;
1996 const char *flavor_string) {
2007 target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2008 bool force_live_memory =
true;
2011 const size_t bytes_read =
2013 error, force_live_memory, &load_addr);
2016 target_sp->GetArchitecture(),
nullptr, flavor_string, *addr_ptr,
2017 data.
GetBytes(), bytes_read, count, data_from_file));
2021 return sb_instructions;
2026 const char *flavor_string) {
2035 if (end_load_addr > start_load_addr) {
2039 const bool force_live_memory =
true;
2041 target_sp->GetArchitecture(),
nullptr, flavor_string, *target_sp,
2042 range, force_live_memory));
2045 return sb_instructions;
2058 const char *flavor_string,
const void *buf,
2068 if (base_addr.
get())
2069 addr = *base_addr.
get();
2071 const bool data_from_file =
true;
2074 target_sp->GetArchitecture(),
nullptr, flavor_string, addr, buf, size,
2078 return sb_instructions;
2092 const char *flavor_string,
const void *buf,
2108 sb_error.SetErrorStringWithFormat(
"invalid section");
2112 if (section_sp->IsThreadSpecific()) {
2114 "thread specific sections are not yet supported");
2116 ProcessSP process_sp(target_sp->GetProcessSP());
2117 if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) {
2118 ModuleSP module_sp(section_sp->GetModule());
2121 module_list.
Append(module_sp);
2122 target_sp->ModulesDidLoad(module_list);
2126 process_sp->Flush();
2145 sb_error.SetErrorStringWithFormat(
"invalid section");
2149 ProcessSP process_sp(target_sp->GetProcessSP());
2150 if (target_sp->SetSectionUnloaded(section_sp)) {
2151 ModuleSP module_sp(section_sp->GetModule());
2154 module_list.
Append(module_sp);
2155 target_sp->ModulesDidUnload(module_list,
false);
2159 process_sp->Flush();
2162 sb_error.SetErrorStringWithFormat(
"invalid section");
2166 sb_error.SetErrorStringWithFormat(
"invalid target");
2172 int64_t slide_offset) {
2175 if (slide_offset < 0) {
2177 sb_error.SetErrorStringWithFormat(
"slide must be positive");
2185 uint64_t slide_offset) {
2193 bool changed =
false;
2194 if (module_sp->SetLoadAddress(*target_sp, slide_offset,
true, changed)) {
2199 module_list.
Append(module_sp);
2200 target_sp->ModulesDidLoad(module_list);
2202 ProcessSP process_sp(target_sp->GetProcessSP());
2204 process_sp->Flush();
2208 sb_error.SetErrorStringWithFormat(
"invalid module");
2212 sb_error.SetErrorStringWithFormat(
"invalid target");
2227 ObjectFile *objfile = module_sp->GetObjectFile();
2231 ProcessSP process_sp(target_sp->GetProcessSP());
2233 bool changed =
false;
2234 const size_t num_sections = section_list->
GetSize();
2235 for (
size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
2238 changed |= target_sp->SetSectionUnloaded(section_sp);
2242 module_list.
Append(module_sp);
2243 target_sp->ModulesDidUnload(module_list,
false);
2245 ProcessSP process_sp(target_sp->GetProcessSP());
2247 process_sp->Flush();
2250 module_sp->GetFileSpec().GetPath(path,
sizeof(path));
2251 sb_error.SetErrorStringWithFormat(
"no sections in object file '%s'",
2255 module_sp->GetFileSpec().GetPath(path,
sizeof(path));
2256 sb_error.SetErrorStringWithFormat(
"no object file for module '%s'",
2260 sb_error.SetErrorStringWithFormat(
"invalid module");
2263 sb_error.SetErrorStringWithFormat(
"invalid target");
2273 if (name && name[0]) {
2276 target_sp->GetImages().FindSymbolsWithNameAndType(
2291 target_sp->GetPreferDynamicValue();
2301 Log *expr_log =
GetLog(LLDBLog::Expressions);
2307 if (expr ==
nullptr || expr[0] ==
'\0') {
2311 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
2326 error.SetErrorString(
"can't evaluate expressions when the "
2327 "process is running.");
2338 "** [SBTarget::EvaluateExpression] Expression result is "
2339 "%s, summary %s **",
2350 ProcessSP process_sp(target_sp->GetProcessSP());
2352 abi_sp = process_sp->GetABI();
2356 return abi_sp->GetRedZoneSize();
2372 return module_sp->IsLoadedInTarget(target_sp.get());
2409 return SBTrace(target_sp->GetTrace());
2420 if (llvm::Expected<lldb::TraceSP> trace_sp = target_sp->CreateTrace()) {
2423 error.SetErrorString(llvm::toString(trace_sp.takeError()).c_str());
2426 error.SetErrorString(
"missing target");
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT()
#define LLDB_INSTRUMENT_VA(...)
#define LLDB_LOGF(log,...)
#define LLDB_LOG_ERROR(log, error,...)
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()
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
This class handles the verbosity when dumping statistics.
const lldb_private::StatisticsOptions & ref() 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)
const char * GetLabel() const
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::SBWatchpoint WatchpointCreateByAddress(lldb::addr_t addr, size_t size, lldb::SBWatchpointOptions options, SBError &error)
lldb::SBStructuredData GetStatistics()
Returns a dump of the collected statistics.
lldb::SBModule GetModuleAtIndex(uint32_t idx)
SBError SetLabel(const char *label)
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.
friend class SBBreakpoint
lldb::SBBreakpoint BreakpointCreateByName(const char *symbol_name, const char *module_name=nullptr)
void DeleteBreakpointName(const char *name)
lldb::SBWatchpoint WatchAddress(lldb::addr_t addr, size_t size, bool read, bool modify, SBError &error)
SBProcess Attach(SBAttachInfo &attach_info, SBError &error)
bool EnableAllWatchpoints()
lldb::SBBreakpoint BreakpointCreateBySBAddress(SBAddress &address)
LLDB_DEPRECATED_FIXME("Use SetModuleLoadAddress(lldb::SBModule, uint64_t)", "SetModuleLoadAddress(lldb::SBModule, uint64_t)") lldb lldb::SBError SetModuleLoadAddress(lldb::SBModule module, uint64_t sections_offset)
Slide all file addresses for all module sections so that module appears to loaded at these slide addr...
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::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
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 SetWatchpointTypeWrite(lldb::WatchpointWriteType write_type)
Stop when the watched memory region is written to/modified.
lldb::WatchpointWriteType GetWatchpointTypeWrite() const
void SetWatchpointTypeRead(bool read)
Stop when the watched memory region is read.
bool GetWatchpointTypeRead() const
void SetSP(const lldb::WatchpointSP &sp)
static lldb::ABISP FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch)
A section + offset based address range class.
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)
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.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
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
Get the number of bytes in the data buffer.
static void SetCollectingStats(bool enable)
static bool GetCollectingStats()
static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target, const lldb_private::StatisticsOptions &options)
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)
static lldb::DisassemblerSP DisassembleRange(const ArchSpec &arch, const char *plugin_name, const char *flavor, Target &target, const AddressRange &disasm_range, bool force_live_memory=false)
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.
Process * GetProcessPtr() const
Returns a pointer to the process object.
void Append(const FileSpec &file)
Append a FileSpec object to the list.
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, const TypeQuery &query, lldb_private::TypeResults &results) const
Find types using a type-matching object that contains all search parameters.
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
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).
static bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec, Status &error, bool force_lookup=true, bool copy_executable=true)
void SetWaitForLaunch(bool b)
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()
void SetListener(const lldb::ListenerSP &listener_sp)
lldb::ListenerSP GetListener() const
bool UserIDIsValid() const
Environment & GetEnvironment()
bool IsScriptedProcess() const
void SetUserID(uint32_t uid)
ArchSpec & GetArchitecture()
uint32_t GetEffectiveUserID() const
bool TryLock(ProcessRunLock *lock)
A plug-in interface definition class for debugging a process.
ProcessRunLock & GetRunLock()
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(llvm::StringRef json_text)
static ModuleList GetModuleListFromEvent(const Event *event_ptr)
static const TargetEventData * GetEventDataFromEvent(const Event *event_ptr)
static lldb::TargetSP GetTargetFromEvent(const Event *event_ptr)
const lldb::ProcessSP & GetProcessSP() const
std::recursive_mutex & GetAPIMutex()
static llvm::StringRef GetStaticBroadcasterClass()
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)
TypeIterable Types() const
A class that contains all state required for type lookups.
This class tracks the state and results of a TypeQuery.
lldb::TypeSP GetFirstType() const
bool SetFromStringRef(llvm::StringRef str)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size, lldb::addr_t address=LLDB_INVALID_ADDRESS)
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 CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx, CompilerType type, bool do_deref=true)
Given an address either create a value object containing the value at that address,...
static lldb::ValueObjectSP CreateValueObjectFromData(llvm::StringRef name, const DataExtractor &data, const ExecutionContext &exe_ctx, CompilerType type)
uint8_t * GetBytes()
Get a pointer to the data.
#define LLDB_WATCH_TYPE_WRITE
#define LLDB_INVALID_BREAK_ID
#define LLDB_INVALID_WATCH_ID
#define LLDB_WATCH_TYPE_MODIFY
#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.
@ eMatchTypeRegexInsensitive
std::shared_ptr< lldb_private::ABI > ABISP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
@ eWatchpointWriteTypeOnModify
Stop on a write to the memory region that changes its value.
@ eWatchpointWriteTypeAlways
Stop on any write access to the memory region, even if the value doesn't change.
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::Platform > PlatformSP
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.
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
std::shared_ptr< lldb_private::Type > TypeSP
std::shared_ptr< lldb_private::Process > ProcessSP
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::Watchpoint > WatchpointSP
std::shared_ptr< lldb_private::Variable > VariableSP
std::shared_ptr< lldb_private::Section > SectionSP
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::Module > ModuleSP
Options used by Module::FindFunctions.
bool include_inlines
Include inlined functions.
bool include_symbols
Include the symbol table.