1e996fd30SGreg Clayton //===-- PlatformLinux.cpp ---------------------------------------*- C++ -*-===// 2e996fd30SGreg Clayton // 3e996fd30SGreg Clayton // The LLVM Compiler Infrastructure 4e996fd30SGreg Clayton // 5e996fd30SGreg Clayton // This file is distributed under the University of Illinois Open Source 6e996fd30SGreg Clayton // License. See LICENSE.TXT for details. 7e996fd30SGreg Clayton // 8e996fd30SGreg Clayton //===----------------------------------------------------------------------===// 9e996fd30SGreg Clayton 10e996fd30SGreg Clayton #include "PlatformLinux.h" 11b2f1fb29SVirgile Bello #include "lldb/Host/Config.h" 12e996fd30SGreg Clayton 13e996fd30SGreg Clayton // C Includes 14ecc11474SStephen Wilson #include <stdio.h> 15b2f1fb29SVirgile Bello #ifndef LLDB_DISABLE_POSIX 16ecc11474SStephen Wilson #include <sys/utsname.h> 17b2f1fb29SVirgile Bello #endif 18ecc11474SStephen Wilson 19e996fd30SGreg Clayton // C++ Includes 20e996fd30SGreg Clayton // Other libraries and framework includes 21e996fd30SGreg Clayton // Project includes 222586e94bSJason Molenda #include "lldb/Breakpoint/BreakpointLocation.h" 2328041352SGreg Clayton #include "lldb/Core/Debugger.h" 24348fb385STodd Fiala #include "lldb/Core/Error.h" 25015d818bSTodd Fiala #include "lldb/Core/Log.h" 26e996fd30SGreg Clayton #include "lldb/Core/Module.h" 27e996fd30SGreg Clayton #include "lldb/Core/ModuleList.h" 281f746071SGreg Clayton #include "lldb/Core/ModuleSpec.h" 29ecc11474SStephen Wilson #include "lldb/Core/PluginManager.h" 30348fb385STodd Fiala #include "lldb/Core/State.h" 31e996fd30SGreg Clayton #include "lldb/Core/StreamString.h" 32e996fd30SGreg Clayton #include "lldb/Host/FileSpec.h" 3313b18261SZachary Turner #include "lldb/Host/HostInfo.h" 34348fb385STodd Fiala #include "lldb/Interpreter/OptionValueProperties.h" 35348fb385STodd Fiala #include "lldb/Interpreter/Property.h" 36ecc11474SStephen Wilson #include "lldb/Target/Target.h" 37e996fd30SGreg Clayton #include "lldb/Target/Process.h" 38e996fd30SGreg Clayton 39a868c13cSBruce Mitchener // Define these constants from Linux mman.h for use when targeting 4096ad3de5SRobert Flack // remote linux systems even when host has different values. 4196ad3de5SRobert Flack #define MAP_PRIVATE 2 4296ad3de5SRobert Flack #define MAP_ANON 0x20 4396ad3de5SRobert Flack 44e996fd30SGreg Clayton using namespace lldb; 45e996fd30SGreg Clayton using namespace lldb_private; 46db264a6dSTamas Berghammer using namespace lldb_private::platform_linux; 47e996fd30SGreg Clayton 4828041352SGreg Clayton static uint32_t g_initialize_count = 0; 4928041352SGreg Clayton 50281961a8STodd Fiala //------------------------------------------------------------------ 51281961a8STodd Fiala /// Code to handle the PlatformLinux settings 52281961a8STodd Fiala //------------------------------------------------------------------ 53281961a8STodd Fiala 54348fb385STodd Fiala namespace 55348fb385STodd Fiala { 56db264a6dSTamas Berghammer class PlatformLinuxProperties : public Properties 57db264a6dSTamas Berghammer { 58db264a6dSTamas Berghammer public: 59db264a6dSTamas Berghammer PlatformLinuxProperties(); 60db264a6dSTamas Berghammer 61*222b937cSEugene Zelenko ~PlatformLinuxProperties() override = default; 62*222b937cSEugene Zelenko 63*222b937cSEugene Zelenko static ConstString& 64*222b937cSEugene Zelenko GetSettingName (); 65db264a6dSTamas Berghammer 66db264a6dSTamas Berghammer private: 67db264a6dSTamas Berghammer static const PropertyDefinition* 68db264a6dSTamas Berghammer GetStaticPropertyDefinitions(); 69db264a6dSTamas Berghammer }; 70db264a6dSTamas Berghammer 71db264a6dSTamas Berghammer typedef std::shared_ptr<PlatformLinuxProperties> PlatformLinuxPropertiesSP; 72db264a6dSTamas Berghammer 73db264a6dSTamas Berghammer } // anonymous namespace 74db264a6dSTamas Berghammer 75db264a6dSTamas Berghammer PlatformLinuxProperties::PlatformLinuxProperties() : 76db264a6dSTamas Berghammer Properties () 77db264a6dSTamas Berghammer { 78db264a6dSTamas Berghammer m_collection_sp.reset (new OptionValueProperties(GetSettingName ())); 79db264a6dSTamas Berghammer m_collection_sp->Initialize (GetStaticPropertyDefinitions ()); 80db264a6dSTamas Berghammer } 81db264a6dSTamas Berghammer 82db264a6dSTamas Berghammer ConstString& 83db264a6dSTamas Berghammer PlatformLinuxProperties::GetSettingName () 84db264a6dSTamas Berghammer { 85db264a6dSTamas Berghammer static ConstString g_setting_name("linux"); 86db264a6dSTamas Berghammer return g_setting_name; 87db264a6dSTamas Berghammer } 88db264a6dSTamas Berghammer 89348fb385STodd Fiala const PropertyDefinition* 90db264a6dSTamas Berghammer PlatformLinuxProperties::GetStaticPropertyDefinitions() 91348fb385STodd Fiala { 92281961a8STodd Fiala static PropertyDefinition 93281961a8STodd Fiala g_properties[] = 94281961a8STodd Fiala { 95281961a8STodd Fiala { NULL , OptionValue::eTypeInvalid, false, 0 , NULL, NULL, NULL } 96281961a8STodd Fiala }; 97281961a8STodd Fiala 98348fb385STodd Fiala return g_properties; 99348fb385STodd Fiala } 100281961a8STodd Fiala 101281961a8STodd Fiala static const PlatformLinuxPropertiesSP & 102281961a8STodd Fiala GetGlobalProperties() 103281961a8STodd Fiala { 104281961a8STodd Fiala static PlatformLinuxPropertiesSP g_settings_sp; 105281961a8STodd Fiala if (!g_settings_sp) 106281961a8STodd Fiala g_settings_sp.reset (new PlatformLinuxProperties ()); 107281961a8STodd Fiala return g_settings_sp; 108281961a8STodd Fiala } 109281961a8STodd Fiala 110281961a8STodd Fiala void 111db264a6dSTamas Berghammer PlatformLinux::DebuggerInitialize (Debugger &debugger) 112281961a8STodd Fiala { 113281961a8STodd Fiala if (!PluginManager::GetSettingForPlatformPlugin (debugger, PlatformLinuxProperties::GetSettingName())) 114281961a8STodd Fiala { 115281961a8STodd Fiala const bool is_global_setting = true; 116281961a8STodd Fiala PluginManager::CreateSettingForPlatformPlugin (debugger, 117281961a8STodd Fiala GetGlobalProperties()->GetValueProperties(), 118281961a8STodd Fiala ConstString ("Properties for the PlatformLinux plug-in."), 119281961a8STodd Fiala is_global_setting); 120281961a8STodd Fiala } 121281961a8STodd Fiala } 122281961a8STodd Fiala 123281961a8STodd Fiala //------------------------------------------------------------------ 124281961a8STodd Fiala 125615eb7e6SGreg Clayton PlatformSP 126b3a40ba8SGreg Clayton PlatformLinux::CreateInstance (bool force, const ArchSpec *arch) 127ecc11474SStephen Wilson { 128db264a6dSTamas Berghammer Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM)); 129015d818bSTodd Fiala if (log) 130015d818bSTodd Fiala { 131015d818bSTodd Fiala const char *arch_name; 132015d818bSTodd Fiala if (arch && arch->GetArchitectureName ()) 133015d818bSTodd Fiala arch_name = arch->GetArchitectureName (); 134015d818bSTodd Fiala else 135015d818bSTodd Fiala arch_name = "<null>"; 136015d818bSTodd Fiala 137015d818bSTodd Fiala const char *triple_cstr = arch ? arch->GetTriple ().getTriple ().c_str() : "<null>"; 138015d818bSTodd Fiala 139015d818bSTodd Fiala log->Printf ("PlatformLinux::%s(force=%s, arch={%s,%s})", __FUNCTION__, force ? "true" : "false", arch_name, triple_cstr); 140015d818bSTodd Fiala } 141015d818bSTodd Fiala 142b3a40ba8SGreg Clayton bool create = force; 143b3a40ba8SGreg Clayton if (create == false && arch && arch->IsValid()) 144b3a40ba8SGreg Clayton { 145b3a40ba8SGreg Clayton const llvm::Triple &triple = arch->GetTriple(); 14670512317SGreg Clayton switch (triple.getOS()) 14770512317SGreg Clayton { 14870512317SGreg Clayton case llvm::Triple::Linux: 149b1da257aSTed Woodward create = true; 15070512317SGreg Clayton break; 15170512317SGreg Clayton 152dbc6c0bbSGreg Clayton #if defined(__linux__) 153dbc6c0bbSGreg Clayton // Only accept "unknown" for the OS if the host is linux and 1546a7f3338SBruce Mitchener // it "unknown" wasn't specified (it was just returned because it 155dbc6c0bbSGreg Clayton // was NOT specified) 156015d818bSTodd Fiala case llvm::Triple::OSType::UnknownOS: 15770512317SGreg Clayton create = !arch->TripleOSWasSpecified(); 15870512317SGreg Clayton break; 159dbc6c0bbSGreg Clayton #endif 16070512317SGreg Clayton default: 16170512317SGreg Clayton break; 16270512317SGreg Clayton } 16370512317SGreg Clayton } 164015d818bSTodd Fiala 165b3a40ba8SGreg Clayton if (create) 166015d818bSTodd Fiala { 167015d818bSTodd Fiala if (log) 168015d818bSTodd Fiala log->Printf ("PlatformLinux::%s() creating remote-linux platform", __FUNCTION__); 169615eb7e6SGreg Clayton return PlatformSP(new PlatformLinux(false)); 170015d818bSTodd Fiala } 171015d818bSTodd Fiala 172015d818bSTodd Fiala if (log) 173015d818bSTodd Fiala log->Printf ("PlatformLinux::%s() aborting creation of remote-linux platform", __FUNCTION__); 174015d818bSTodd Fiala 175615eb7e6SGreg Clayton return PlatformSP(); 176ecc11474SStephen Wilson } 177ecc11474SStephen Wilson 178db264a6dSTamas Berghammer ConstString 17957abc5d6SGreg Clayton PlatformLinux::GetPluginNameStatic (bool is_host) 180ecc11474SStephen Wilson { 18128041352SGreg Clayton if (is_host) 18257abc5d6SGreg Clayton { 18357abc5d6SGreg Clayton static ConstString g_host_name(Platform::GetHostPlatformName ()); 18457abc5d6SGreg Clayton return g_host_name; 18557abc5d6SGreg Clayton } 18628041352SGreg Clayton else 18757abc5d6SGreg Clayton { 18857abc5d6SGreg Clayton static ConstString g_remote_name("remote-linux"); 18957abc5d6SGreg Clayton return g_remote_name; 19057abc5d6SGreg Clayton } 19128041352SGreg Clayton } 19228041352SGreg Clayton 19328041352SGreg Clayton const char * 19428041352SGreg Clayton PlatformLinux::GetPluginDescriptionStatic (bool is_host) 19528041352SGreg Clayton { 19628041352SGreg Clayton if (is_host) 19728041352SGreg Clayton return "Local Linux user platform plug-in."; 19828041352SGreg Clayton else 19928041352SGreg Clayton return "Remote Linux user platform plug-in."; 200ecc11474SStephen Wilson } 201ecc11474SStephen Wilson 202db264a6dSTamas Berghammer ConstString 20357abc5d6SGreg Clayton PlatformLinux::GetPluginName() 20457abc5d6SGreg Clayton { 20557abc5d6SGreg Clayton return GetPluginNameStatic(IsHost()); 20657abc5d6SGreg Clayton } 20757abc5d6SGreg Clayton 208e996fd30SGreg Clayton void 209e996fd30SGreg Clayton PlatformLinux::Initialize () 210e996fd30SGreg Clayton { 2113c4f89d7STamas Berghammer PlatformPOSIX::Initialize (); 2123c4f89d7STamas Berghammer 21328041352SGreg Clayton if (g_initialize_count++ == 0) 214ecc11474SStephen Wilson { 2151c6a1ea9STamas Berghammer #if defined(__linux__) && !defined(__ANDROID__) 21628041352SGreg Clayton PlatformSP default_platform_sp (new PlatformLinux(true)); 21713b18261SZachary Turner default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture()); 218615eb7e6SGreg Clayton Platform::SetHostPlatform (default_platform_sp); 21928041352SGreg Clayton #endif 22057abc5d6SGreg Clayton PluginManager::RegisterPlugin(PlatformLinux::GetPluginNameStatic(false), 22128041352SGreg Clayton PlatformLinux::GetPluginDescriptionStatic(false), 222281961a8STodd Fiala PlatformLinux::CreateInstance, 223281961a8STodd Fiala PlatformLinux::DebuggerInitialize); 224ecc11474SStephen Wilson } 225e996fd30SGreg Clayton } 226e996fd30SGreg Clayton 227e996fd30SGreg Clayton void 228e996fd30SGreg Clayton PlatformLinux::Terminate () 229e996fd30SGreg Clayton { 23028041352SGreg Clayton if (g_initialize_count > 0) 23128041352SGreg Clayton { 23228041352SGreg Clayton if (--g_initialize_count == 0) 23328041352SGreg Clayton { 23428041352SGreg Clayton PluginManager::UnregisterPlugin (PlatformLinux::CreateInstance); 235e996fd30SGreg Clayton } 23628041352SGreg Clayton } 2373c4f89d7STamas Berghammer 2383c4f89d7STamas Berghammer PlatformPOSIX::Terminate (); 23928041352SGreg Clayton } 240e996fd30SGreg Clayton 241e996fd30SGreg Clayton Error 2428012cadbSGreg Clayton PlatformLinux::ResolveExecutable (const ModuleSpec &ms, 243ea5e0cc3SGreg Clayton lldb::ModuleSP &exe_module_sp, 244ea5e0cc3SGreg Clayton const FileSpecList *module_search_paths_ptr) 245e996fd30SGreg Clayton { 246e996fd30SGreg Clayton Error error; 247e996fd30SGreg Clayton // Nothing special to do here, just use the actual file and architecture 248e996fd30SGreg Clayton 24928041352SGreg Clayton char exe_path[PATH_MAX]; 2508012cadbSGreg Clayton ModuleSpec resolved_module_spec (ms); 251e996fd30SGreg Clayton 25228041352SGreg Clayton if (IsHost()) 25328041352SGreg Clayton { 25428041352SGreg Clayton // If we have "ls" as the exe_file, resolve the executable location based on 255e996fd30SGreg Clayton // the current path variables 2568012cadbSGreg Clayton if (!resolved_module_spec.GetFileSpec().Exists()) 25728041352SGreg Clayton { 2588012cadbSGreg Clayton resolved_module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path)); 2598012cadbSGreg Clayton resolved_module_spec.GetFileSpec().SetFile(exe_path, true); 26028041352SGreg Clayton } 26128041352SGreg Clayton 2628012cadbSGreg Clayton if (!resolved_module_spec.GetFileSpec().Exists()) 2638012cadbSGreg Clayton resolved_module_spec.GetFileSpec().ResolveExecutableLocation (); 264e996fd30SGreg Clayton 2658012cadbSGreg Clayton if (resolved_module_spec.GetFileSpec().Exists()) 26628041352SGreg Clayton error.Clear(); 26728041352SGreg Clayton else 26828041352SGreg Clayton { 2698012cadbSGreg Clayton error.SetErrorStringWithFormat("unable to find executable for '%s'", resolved_module_spec.GetFileSpec().GetPath().c_str()); 27028041352SGreg Clayton } 27128041352SGreg Clayton } 27228041352SGreg Clayton else 27328041352SGreg Clayton { 27428041352SGreg Clayton if (m_remote_platform_sp) 27528041352SGreg Clayton { 276a3f245ffSOleksiy Vyalov error = GetCachedExecutable (resolved_module_spec, exe_module_sp, module_search_paths_ptr, *m_remote_platform_sp); 27728041352SGreg Clayton } 27828041352SGreg Clayton else 27928041352SGreg Clayton { 28028041352SGreg Clayton // We may connect to a process and use the provided executable (Don't use local $PATH). 281e996fd30SGreg Clayton 2828012cadbSGreg Clayton if (resolved_module_spec.GetFileSpec().Exists()) 28328041352SGreg Clayton error.Clear(); 28428041352SGreg Clayton else 28528041352SGreg Clayton error.SetErrorStringWithFormat("the platform is not currently connected, and '%s' doesn't exist in the system root.", exe_path); 28628041352SGreg Clayton } 28728041352SGreg Clayton } 28828041352SGreg Clayton 28928041352SGreg Clayton if (error.Success()) 290e996fd30SGreg Clayton { 2918012cadbSGreg Clayton if (resolved_module_spec.GetArchitecture().IsValid()) 292e996fd30SGreg Clayton { 2938012cadbSGreg Clayton error = ModuleList::GetSharedModule (resolved_module_spec, 294e996fd30SGreg Clayton exe_module_sp, 295e996fd30SGreg Clayton NULL, 2960c90ef47SGreg Clayton NULL, 297e996fd30SGreg Clayton NULL); 2989f0013d8SMichael Sartain if (error.Fail()) 2999f0013d8SMichael Sartain { 3009f0013d8SMichael Sartain // If we failed, it may be because the vendor and os aren't known. If that is the 3019f0013d8SMichael Sartain // case, try setting them to the host architecture and give it another try. 3028012cadbSGreg Clayton llvm::Triple &module_triple = resolved_module_spec.GetArchitecture().GetTriple(); 3039f0013d8SMichael Sartain bool is_vendor_specified = (module_triple.getVendor() != llvm::Triple::UnknownVendor); 3049f0013d8SMichael Sartain bool is_os_specified = (module_triple.getOS() != llvm::Triple::UnknownOS); 3059f0013d8SMichael Sartain if (!is_vendor_specified || !is_os_specified) 3069f0013d8SMichael Sartain { 30713b18261SZachary Turner const llvm::Triple &host_triple = HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple(); 3089f0013d8SMichael Sartain 3099f0013d8SMichael Sartain if (!is_vendor_specified) 3109f0013d8SMichael Sartain module_triple.setVendorName (host_triple.getVendorName()); 3119f0013d8SMichael Sartain if (!is_os_specified) 3129f0013d8SMichael Sartain module_triple.setOSName (host_triple.getOSName()); 3139f0013d8SMichael Sartain 3148012cadbSGreg Clayton error = ModuleList::GetSharedModule (resolved_module_spec, 3159f0013d8SMichael Sartain exe_module_sp, 3169f0013d8SMichael Sartain NULL, 3179f0013d8SMichael Sartain NULL, 3189f0013d8SMichael Sartain NULL); 3199f0013d8SMichael Sartain } 3209f0013d8SMichael Sartain } 321e996fd30SGreg Clayton 322e635db49SSean Callanan // TODO find out why exe_module_sp might be NULL 323e635db49SSean Callanan if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL) 324e996fd30SGreg Clayton { 325e996fd30SGreg Clayton exe_module_sp.reset(); 326b5ad4ec7SGreg Clayton error.SetErrorStringWithFormat ("'%s' doesn't contain the architecture %s", 3278012cadbSGreg Clayton resolved_module_spec.GetFileSpec().GetPath().c_str(), 3288012cadbSGreg Clayton resolved_module_spec.GetArchitecture().GetArchitectureName()); 329e996fd30SGreg Clayton } 330e996fd30SGreg Clayton } 331e996fd30SGreg Clayton else 332e996fd30SGreg Clayton { 333e996fd30SGreg Clayton // No valid architecture was specified, ask the platform for 334e996fd30SGreg Clayton // the architectures that we should be using (in the correct order) 335e996fd30SGreg Clayton // and see if we can find a match that way 336e996fd30SGreg Clayton StreamString arch_names; 3378012cadbSGreg Clayton for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, resolved_module_spec.GetArchitecture()); ++idx) 338e996fd30SGreg Clayton { 3398012cadbSGreg Clayton error = ModuleList::GetSharedModule (resolved_module_spec, 340e996fd30SGreg Clayton exe_module_sp, 341e996fd30SGreg Clayton NULL, 3420c90ef47SGreg Clayton NULL, 343e996fd30SGreg Clayton NULL); 344e996fd30SGreg Clayton // Did we find an executable using one of the 345e996fd30SGreg Clayton if (error.Success()) 346e996fd30SGreg Clayton { 347e996fd30SGreg Clayton if (exe_module_sp && exe_module_sp->GetObjectFile()) 348e996fd30SGreg Clayton break; 349e996fd30SGreg Clayton else 350e996fd30SGreg Clayton error.SetErrorToGenericError(); 351e996fd30SGreg Clayton } 352e996fd30SGreg Clayton 353e996fd30SGreg Clayton if (idx > 0) 354e996fd30SGreg Clayton arch_names.PutCString (", "); 3558012cadbSGreg Clayton arch_names.PutCString (resolved_module_spec.GetArchitecture().GetArchitectureName()); 356e996fd30SGreg Clayton } 357e996fd30SGreg Clayton 358e996fd30SGreg Clayton if (error.Fail() || !exe_module_sp) 359e996fd30SGreg Clayton { 3608012cadbSGreg Clayton if (resolved_module_spec.GetFileSpec().Readable()) 36139945dccSGreg Clayton { 362b5ad4ec7SGreg Clayton error.SetErrorStringWithFormat ("'%s' doesn't contain any '%s' platform architectures: %s", 3638012cadbSGreg Clayton resolved_module_spec.GetFileSpec().GetPath().c_str(), 36457abc5d6SGreg Clayton GetPluginName().GetCString(), 365e996fd30SGreg Clayton arch_names.GetString().c_str()); 366e996fd30SGreg Clayton } 36739945dccSGreg Clayton else 36839945dccSGreg Clayton { 3698012cadbSGreg Clayton error.SetErrorStringWithFormat("'%s' is not readable", resolved_module_spec.GetFileSpec().GetPath().c_str()); 37039945dccSGreg Clayton } 37139945dccSGreg Clayton } 372e996fd30SGreg Clayton } 373e996fd30SGreg Clayton } 374e996fd30SGreg Clayton 375e996fd30SGreg Clayton return error; 376e996fd30SGreg Clayton } 377e996fd30SGreg Clayton 378e996fd30SGreg Clayton Error 379fc995725SSteve Pucci PlatformLinux::GetFileWithUUID (const FileSpec &platform_file, 38028041352SGreg Clayton const UUID *uuid_ptr, FileSpec &local_file) 381e996fd30SGreg Clayton { 38228041352SGreg Clayton if (IsRemote()) 38328041352SGreg Clayton { 38428041352SGreg Clayton if (m_remote_platform_sp) 385fc995725SSteve Pucci return m_remote_platform_sp->GetFileWithUUID (platform_file, uuid_ptr, local_file); 38628041352SGreg Clayton } 38728041352SGreg Clayton 388e996fd30SGreg Clayton // Default to the local case 389e996fd30SGreg Clayton local_file = platform_file; 390e996fd30SGreg Clayton return Error(); 391e996fd30SGreg Clayton } 392e996fd30SGreg Clayton 393e996fd30SGreg Clayton //------------------------------------------------------------------ 394e996fd30SGreg Clayton /// Default Constructor 395e996fd30SGreg Clayton //------------------------------------------------------------------ 39628041352SGreg Clayton PlatformLinux::PlatformLinux (bool is_host) : 397015d818bSTodd Fiala PlatformPOSIX(is_host) // This is the local host platform 398e996fd30SGreg Clayton { 399e996fd30SGreg Clayton } 400e996fd30SGreg Clayton 401e996fd30SGreg Clayton //------------------------------------------------------------------ 402e996fd30SGreg Clayton /// Destructor. 403e996fd30SGreg Clayton /// 404e996fd30SGreg Clayton /// The destructor is virtual since this class is designed to be 405e996fd30SGreg Clayton /// inherited from by the plug-in instance. 406e996fd30SGreg Clayton //------------------------------------------------------------------ 407*222b937cSEugene Zelenko PlatformLinux::~PlatformLinux() = default; 408e996fd30SGreg Clayton 409e996fd30SGreg Clayton bool 41013e8e1c3SJohnny Chen PlatformLinux::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info) 411e996fd30SGreg Clayton { 41228041352SGreg Clayton bool success = false; 41328041352SGreg Clayton if (IsHost()) 41428041352SGreg Clayton { 41528041352SGreg Clayton success = Platform::GetProcessInfo (pid, process_info); 41628041352SGreg Clayton } 41728041352SGreg Clayton else 41828041352SGreg Clayton { 41928041352SGreg Clayton if (m_remote_platform_sp) 42028041352SGreg Clayton success = m_remote_platform_sp->GetProcessInfo (pid, process_info); 42128041352SGreg Clayton } 42228041352SGreg Clayton return success; 423e996fd30SGreg Clayton } 424e996fd30SGreg Clayton 4258e6ec453SStephane Sezer uint32_t 4268e6ec453SStephane Sezer PlatformLinux::FindProcesses (const ProcessInstanceInfoMatch &match_info, 4278e6ec453SStephane Sezer ProcessInstanceInfoList &process_infos) 4288e6ec453SStephane Sezer { 4298e6ec453SStephane Sezer uint32_t match_count = 0; 4308e6ec453SStephane Sezer if (IsHost()) 4318e6ec453SStephane Sezer { 4328e6ec453SStephane Sezer // Let the base class figure out the host details 4338e6ec453SStephane Sezer match_count = Platform::FindProcesses (match_info, process_infos); 4348e6ec453SStephane Sezer } 4358e6ec453SStephane Sezer else 4368e6ec453SStephane Sezer { 4378e6ec453SStephane Sezer // If we are remote, we can only return results if we are connected 4388e6ec453SStephane Sezer if (m_remote_platform_sp) 4398e6ec453SStephane Sezer match_count = m_remote_platform_sp->FindProcesses (match_info, process_infos); 4408e6ec453SStephane Sezer } 4418e6ec453SStephane Sezer return match_count; 4428e6ec453SStephane Sezer } 4438e6ec453SStephane Sezer 444e996fd30SGreg Clayton bool 445e996fd30SGreg Clayton PlatformLinux::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch) 446e996fd30SGreg Clayton { 447e49b8e06SRobert Flack if (IsHost()) 448e49b8e06SRobert Flack { 449e49b8e06SRobert Flack ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault); 450e49b8e06SRobert Flack if (hostArch.GetTriple().isOSLinux()) 451e49b8e06SRobert Flack { 452e49b8e06SRobert Flack if (idx == 0) 453e49b8e06SRobert Flack { 454e49b8e06SRobert Flack arch = hostArch; 455e49b8e06SRobert Flack return arch.IsValid(); 456e49b8e06SRobert Flack } 457e49b8e06SRobert Flack else if (idx == 1) 458e49b8e06SRobert Flack { 459e49b8e06SRobert Flack // If the default host architecture is 64-bit, look for a 32-bit variant 460e49b8e06SRobert Flack if (hostArch.IsValid() && hostArch.GetTriple().isArch64Bit()) 461e49b8e06SRobert Flack { 462e49b8e06SRobert Flack arch = HostInfo::GetArchitecture(HostInfo::eArchKind32); 463e49b8e06SRobert Flack return arch.IsValid(); 464e49b8e06SRobert Flack } 465e49b8e06SRobert Flack } 466e49b8e06SRobert Flack } 467e49b8e06SRobert Flack } 468e49b8e06SRobert Flack else 469e49b8e06SRobert Flack { 470e49b8e06SRobert Flack if (m_remote_platform_sp) 471e49b8e06SRobert Flack return m_remote_platform_sp->GetSupportedArchitectureAtIndex(idx, arch); 472bb1e283cSTed Woodward 473bb1e283cSTed Woodward llvm::Triple triple; 474bb1e283cSTed Woodward // Set the OS to linux 475bb1e283cSTed Woodward triple.setOS(llvm::Triple::Linux); 476bb1e283cSTed Woodward // Set the architecture 477bb1e283cSTed Woodward switch (idx) 478bb1e283cSTed Woodward { 479bb1e283cSTed Woodward case 0: triple.setArchName("x86_64"); break; 480bb1e283cSTed Woodward case 1: triple.setArchName("i386"); break; 481bb1e283cSTed Woodward case 2: triple.setArchName("arm"); break; 482bb1e283cSTed Woodward case 3: triple.setArchName("aarch64"); break; 483bb1e283cSTed Woodward case 4: triple.setArchName("mips64"); break; 484bb1e283cSTed Woodward case 5: triple.setArchName("hexagon"); break; 485bb1e283cSTed Woodward case 6: triple.setArchName("mips"); break; 486ce815e45SSagar Thakur case 7: triple.setArchName("mips64el"); break; 487ce815e45SSagar Thakur case 8: triple.setArchName("mipsel"); break; 488bb1e283cSTed Woodward default: return false; 489bb1e283cSTed Woodward } 490bb1e283cSTed Woodward // Leave the vendor as "llvm::Triple:UnknownVendor" and don't specify the vendor by 491bb1e283cSTed Woodward // calling triple.SetVendorName("unknown") so that it is a "unspecified unknown". 492bb1e283cSTed Woodward // This means when someone calls triple.GetVendorName() it will return an empty string 493bb1e283cSTed Woodward // which indicates that the vendor can be set when two architectures are merged 494bb1e283cSTed Woodward 495bb1e283cSTed Woodward // Now set the triple into "arch" and return true 496bb1e283cSTed Woodward arch.SetTriple(triple); 497bb1e283cSTed Woodward return true; 498e49b8e06SRobert Flack } 499e996fd30SGreg Clayton return false; 500e996fd30SGreg Clayton } 501ecc11474SStephen Wilson 502ecc11474SStephen Wilson void 503ecc11474SStephen Wilson PlatformLinux::GetStatus (Stream &strm) 504ecc11474SStephen Wilson { 5053be69dacSDaniel Malea Platform::GetStatus(strm); 506ecc11474SStephen Wilson 507b2f1fb29SVirgile Bello #ifndef LLDB_DISABLE_POSIX 508b743a803SStephane Sezer // Display local kernel information only when we are running in host mode. 509b743a803SStephane Sezer // Otherwise, we would end up printing non-Linux information (when running 510b743a803SStephane Sezer // on Mac OS for example). 511b743a803SStephane Sezer if (IsHost()) 512b743a803SStephane Sezer { 513b2f1fb29SVirgile Bello struct utsname un; 514b2f1fb29SVirgile Bello 5153be69dacSDaniel Malea if (uname(&un)) 5163be69dacSDaniel Malea return; 5173be69dacSDaniel Malea 5183be69dacSDaniel Malea strm.Printf (" Kernel: %s\n", un.sysname); 5193be69dacSDaniel Malea strm.Printf (" Release: %s\n", un.release); 5203be69dacSDaniel Malea strm.Printf (" Version: %s\n", un.version); 521b743a803SStephane Sezer } 522b2f1fb29SVirgile Bello #endif 523ecc11474SStephen Wilson } 524ecc11474SStephen Wilson 525ecc11474SStephen Wilson size_t 526ecc11474SStephen Wilson PlatformLinux::GetSoftwareBreakpointTrapOpcode (Target &target, 527ecc11474SStephen Wilson BreakpointSite *bp_site) 528ecc11474SStephen Wilson { 529ecc11474SStephen Wilson ArchSpec arch = target.GetArchitecture(); 53028041352SGreg Clayton const uint8_t *trap_opcode = NULL; 53128041352SGreg Clayton size_t trap_opcode_size = 0; 532ecc11474SStephen Wilson 533906e9acfSGreg Clayton switch (arch.GetMachine()) 534ecc11474SStephen Wilson { 535ecc11474SStephen Wilson default: 536ecc11474SStephen Wilson assert(false && "CPU type not supported!"); 537ecc11474SStephen Wilson break; 538ecc11474SStephen Wilson 5392afc5966STodd Fiala case llvm::Triple::aarch64: 5402afc5966STodd Fiala { 5412afc5966STodd Fiala static const uint8_t g_aarch64_opcode[] = { 0x00, 0x00, 0x20, 0xd4 }; 5422afc5966STodd Fiala trap_opcode = g_aarch64_opcode; 5432afc5966STodd Fiala trap_opcode_size = sizeof(g_aarch64_opcode); 5442afc5966STodd Fiala } 5452afc5966STodd Fiala break; 546906e9acfSGreg Clayton case llvm::Triple::x86: 547906e9acfSGreg Clayton case llvm::Triple::x86_64: 54828041352SGreg Clayton { 54928041352SGreg Clayton static const uint8_t g_i386_breakpoint_opcode[] = { 0xCC }; 55028041352SGreg Clayton trap_opcode = g_i386_breakpoint_opcode; 55128041352SGreg Clayton trap_opcode_size = sizeof(g_i386_breakpoint_opcode); 55228041352SGreg Clayton } 553ecc11474SStephen Wilson break; 554906e9acfSGreg Clayton case llvm::Triple::hexagon: 5558006d319SDeepak Panickal { 5568006d319SDeepak Panickal static const uint8_t g_hex_opcode[] = { 0x0c, 0xdb, 0x00, 0x54 }; 5578006d319SDeepak Panickal trap_opcode = g_hex_opcode; 5588006d319SDeepak Panickal trap_opcode_size = sizeof(g_hex_opcode); 5598006d319SDeepak Panickal } 5608006d319SDeepak Panickal break; 5612586e94bSJason Molenda case llvm::Triple::arm: 5622586e94bSJason Molenda { 5632586e94bSJason Molenda // The ARM reference recommends the use of 0xe7fddefe and 0xdefe 5642586e94bSJason Molenda // but the linux kernel does otherwise. 5652586e94bSJason Molenda static const uint8_t g_arm_breakpoint_opcode[] = { 0xf0, 0x01, 0xf0, 0xe7 }; 5662586e94bSJason Molenda static const uint8_t g_thumb_breakpoint_opcode[] = { 0x01, 0xde }; 5672586e94bSJason Molenda 5682586e94bSJason Molenda lldb::BreakpointLocationSP bp_loc_sp (bp_site->GetOwnerAtIndex (0)); 5692586e94bSJason Molenda AddressClass addr_class = eAddressClassUnknown; 5702586e94bSJason Molenda 5712586e94bSJason Molenda if (bp_loc_sp) 57276011b63STamas Berghammer { 5732586e94bSJason Molenda addr_class = bp_loc_sp->GetAddress ().GetAddressClass (); 5742586e94bSJason Molenda 57576011b63STamas Berghammer if (addr_class == eAddressClassUnknown && 57676011b63STamas Berghammer (bp_loc_sp->GetAddress ().GetFileAddress () & 1)) 57776011b63STamas Berghammer { 57876011b63STamas Berghammer addr_class = eAddressClassCodeAlternateISA; 57976011b63STamas Berghammer } 58076011b63STamas Berghammer } 58176011b63STamas Berghammer 58276011b63STamas Berghammer if (addr_class == eAddressClassCodeAlternateISA) 5832586e94bSJason Molenda { 5842586e94bSJason Molenda trap_opcode = g_thumb_breakpoint_opcode; 5852586e94bSJason Molenda trap_opcode_size = sizeof(g_thumb_breakpoint_opcode); 5862586e94bSJason Molenda } 5872586e94bSJason Molenda else 5882586e94bSJason Molenda { 5892586e94bSJason Molenda trap_opcode = g_arm_breakpoint_opcode; 5902586e94bSJason Molenda trap_opcode_size = sizeof(g_arm_breakpoint_opcode); 5912586e94bSJason Molenda } 5922586e94bSJason Molenda } 5932586e94bSJason Molenda break; 594794a4d5aSBhushan D. Attarde case llvm::Triple::mips: 595c9335a3fSMohit K. Bhakkad case llvm::Triple::mips64: 596c9335a3fSMohit K. Bhakkad { 597c9335a3fSMohit K. Bhakkad static const uint8_t g_hex_opcode[] = { 0x00, 0x00, 0x00, 0x0d }; 598c9335a3fSMohit K. Bhakkad trap_opcode = g_hex_opcode; 599c9335a3fSMohit K. Bhakkad trap_opcode_size = sizeof(g_hex_opcode); 600c9335a3fSMohit K. Bhakkad } 601c9335a3fSMohit K. Bhakkad break; 602794a4d5aSBhushan D. Attarde case llvm::Triple::mipsel: 6032c2acf96SMohit K. Bhakkad case llvm::Triple::mips64el: 6042c2acf96SMohit K. Bhakkad { 6052c2acf96SMohit K. Bhakkad static const uint8_t g_hex_opcode[] = { 0x0d, 0x00, 0x00, 0x00 }; 6062c2acf96SMohit K. Bhakkad trap_opcode = g_hex_opcode; 6072c2acf96SMohit K. Bhakkad trap_opcode_size = sizeof(g_hex_opcode); 6082c2acf96SMohit K. Bhakkad } 6092c2acf96SMohit K. Bhakkad break; 610ecc11474SStephen Wilson } 611ecc11474SStephen Wilson 61228041352SGreg Clayton if (bp_site->SetTrapOpcode(trap_opcode, trap_opcode_size)) 61328041352SGreg Clayton return trap_opcode_size; 61428041352SGreg Clayton return 0; 61528041352SGreg Clayton } 61628041352SGreg Clayton 617348fb385STodd Fiala int32_t 618348fb385STodd Fiala PlatformLinux::GetResumeCountForLaunchInfo (ProcessLaunchInfo &launch_info) 61928041352SGreg Clayton { 620348fb385STodd Fiala int32_t resume_count = 0; 62128041352SGreg Clayton 622348fb385STodd Fiala // Always resume past the initial stop when we use eLaunchFlagDebug 623348fb385STodd Fiala if (launch_info.GetFlags ().Test (eLaunchFlagDebug)) 62428041352SGreg Clayton { 625348fb385STodd Fiala // Resume past the stop for the final exec into the true inferior. 626348fb385STodd Fiala ++resume_count; 627348fb385STodd Fiala } 628015d818bSTodd Fiala 629348fb385STodd Fiala // If we're not launching a shell, we're done. 63010687b0eSZachary Turner const FileSpec &shell = launch_info.GetShell(); 63110687b0eSZachary Turner if (!shell) 632348fb385STodd Fiala return resume_count; 633348fb385STodd Fiala 63410687b0eSZachary Turner std::string shell_string = shell.GetPath(); 635348fb385STodd Fiala // We're in a shell, so for sure we have to resume past the shell exec. 636348fb385STodd Fiala ++resume_count; 637348fb385STodd Fiala 638348fb385STodd Fiala // Figure out what shell we're planning on using. 63910687b0eSZachary Turner const char *shell_name = strrchr (shell_string.c_str(), '/'); 640348fb385STodd Fiala if (shell_name == NULL) 64110687b0eSZachary Turner shell_name = shell_string.c_str(); 64228041352SGreg Clayton else 643348fb385STodd Fiala shell_name++; 644348fb385STodd Fiala 645348fb385STodd Fiala if (strcmp (shell_name, "csh") == 0 646348fb385STodd Fiala || strcmp (shell_name, "tcsh") == 0 647348fb385STodd Fiala || strcmp (shell_name, "zsh") == 0 648348fb385STodd Fiala || strcmp (shell_name, "sh") == 0) 64928041352SGreg Clayton { 650348fb385STodd Fiala // These shells seem to re-exec themselves. Add another resume. 651348fb385STodd Fiala ++resume_count; 652ecc11474SStephen Wilson } 65313e8e1c3SJohnny Chen 654348fb385STodd Fiala return resume_count; 655348fb385STodd Fiala } 656348fb385STodd Fiala 657348fb385STodd Fiala bool 658015d818bSTodd Fiala PlatformLinux::CanDebugProcess () 659015d818bSTodd Fiala { 660015d818bSTodd Fiala if (IsHost ()) 661348fb385STodd Fiala { 662b36f9178SPavel Labath return true; 663348fb385STodd Fiala } 664348fb385STodd Fiala else 665348fb385STodd Fiala { 666015d818bSTodd Fiala // If we're connected, we can debug. 667015d818bSTodd Fiala return IsConnected (); 668015d818bSTodd Fiala } 669348fb385STodd Fiala } 670015d818bSTodd Fiala 671348fb385STodd Fiala // For local debugging, Linux will override the debug logic to use llgs-launch rather than 672348fb385STodd Fiala // lldb-launch, llgs-attach. This differs from current lldb-launch, debugserver-attach 673348fb385STodd Fiala // approach on MacOSX. 67413e8e1c3SJohnny Chen lldb::ProcessSP 675348fb385STodd Fiala PlatformLinux::DebugProcess (ProcessLaunchInfo &launch_info, 67613e8e1c3SJohnny Chen Debugger &debugger, 677348fb385STodd Fiala Target *target, // Can be NULL, if NULL create a new target, else use existing one 67813e8e1c3SJohnny Chen Error &error) 67913e8e1c3SJohnny Chen { 680db264a6dSTamas Berghammer Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM)); 681348fb385STodd Fiala if (log) 682348fb385STodd Fiala log->Printf ("PlatformLinux::%s entered (target %p)", __FUNCTION__, static_cast<void*>(target)); 68328041352SGreg Clayton 684348fb385STodd Fiala // If we're a remote host, use standard behavior from parent class. 685348fb385STodd Fiala if (!IsHost ()) 6868012cadbSGreg Clayton return PlatformPOSIX::DebugProcess (launch_info, debugger, target, error); 687348fb385STodd Fiala 688348fb385STodd Fiala // 689348fb385STodd Fiala // For local debugging, we'll insist on having ProcessGDBRemote create the process. 690348fb385STodd Fiala // 691348fb385STodd Fiala 692348fb385STodd Fiala ProcessSP process_sp; 693348fb385STodd Fiala 694348fb385STodd Fiala // Make sure we stop at the entry point 695348fb385STodd Fiala launch_info.GetFlags ().Set (eLaunchFlagDebug); 696348fb385STodd Fiala 697348fb385STodd Fiala // We always launch the process we are going to debug in a separate process 698348fb385STodd Fiala // group, since then we can handle ^C interrupts ourselves w/o having to worry 699348fb385STodd Fiala // about the target getting them as well. 700348fb385STodd Fiala launch_info.SetLaunchInSeparateProcessGroup(true); 701348fb385STodd Fiala 702348fb385STodd Fiala // Ensure we have a target. 703348fb385STodd Fiala if (target == nullptr) 704348fb385STodd Fiala { 705348fb385STodd Fiala if (log) 706348fb385STodd Fiala log->Printf ("PlatformLinux::%s creating new target", __FUNCTION__); 707348fb385STodd Fiala 708348fb385STodd Fiala TargetSP new_target_sp; 70928041352SGreg Clayton error = debugger.GetTargetList().CreateTarget (debugger, 710348fb385STodd Fiala nullptr, 711348fb385STodd Fiala nullptr, 71228041352SGreg Clayton false, 713348fb385STodd Fiala nullptr, 71428041352SGreg Clayton new_target_sp); 715348fb385STodd Fiala if (error.Fail ()) 716348fb385STodd Fiala { 717348fb385STodd Fiala if (log) 718348fb385STodd Fiala log->Printf ("PlatformLinux::%s failed to create new target: %s", __FUNCTION__, error.AsCString ()); 719348fb385STodd Fiala return process_sp; 720348fb385STodd Fiala } 721348fb385STodd Fiala 72228041352SGreg Clayton target = new_target_sp.get(); 723348fb385STodd Fiala if (!target) 724348fb385STodd Fiala { 725348fb385STodd Fiala error.SetErrorString ("CreateTarget() returned nullptr"); 726348fb385STodd Fiala if (log) 727348fb385STodd Fiala log->Printf ("PlatformLinux::%s failed: %s", __FUNCTION__, error.AsCString ()); 728348fb385STodd Fiala return process_sp; 729348fb385STodd Fiala } 73028041352SGreg Clayton } 73128041352SGreg Clayton else 73228041352SGreg Clayton { 733348fb385STodd Fiala if (log) 734348fb385STodd Fiala log->Printf ("PlatformLinux::%s using provided target", __FUNCTION__); 735348fb385STodd Fiala } 736348fb385STodd Fiala 737348fb385STodd Fiala // Mark target as currently selected target. 73828041352SGreg Clayton debugger.GetTargetList().SetSelectedTarget(target); 73928041352SGreg Clayton 740348fb385STodd Fiala // Now create the gdb-remote process. 741348fb385STodd Fiala if (log) 742348fb385STodd Fiala log->Printf ("PlatformLinux::%s having target create process with gdb-remote plugin", __FUNCTION__); 7438012cadbSGreg Clayton process_sp = target->CreateProcess (launch_info.GetListenerForProcess(debugger), "gdb-remote", nullptr); 74428041352SGreg Clayton 745348fb385STodd Fiala if (!process_sp) 746348fb385STodd Fiala { 747348fb385STodd Fiala error.SetErrorString ("CreateProcess() failed for gdb-remote process"); 748348fb385STodd Fiala if (log) 749348fb385STodd Fiala log->Printf ("PlatformLinux::%s failed: %s", __FUNCTION__, error.AsCString ()); 750348fb385STodd Fiala return process_sp; 751348fb385STodd Fiala } 752348fb385STodd Fiala else 753348fb385STodd Fiala { 754348fb385STodd Fiala if (log) 755348fb385STodd Fiala log->Printf ("PlatformLinux::%s successfully created process", __FUNCTION__); 756348fb385STodd Fiala } 757348fb385STodd Fiala 758348fb385STodd Fiala // Adjust launch for a hijacker. 759348fb385STodd Fiala ListenerSP listener_sp; 760348fb385STodd Fiala if (!launch_info.GetHijackListener ()) 761348fb385STodd Fiala { 762348fb385STodd Fiala if (log) 763348fb385STodd Fiala log->Printf ("PlatformLinux::%s setting up hijacker", __FUNCTION__); 764348fb385STodd Fiala 765348fb385STodd Fiala listener_sp.reset (new Listener("lldb.PlatformLinux.DebugProcess.hijack")); 766348fb385STodd Fiala launch_info.SetHijackListener (listener_sp); 767348fb385STodd Fiala process_sp->HijackProcessEvents (listener_sp.get ()); 768348fb385STodd Fiala } 769348fb385STodd Fiala 770348fb385STodd Fiala // Log file actions. 771348fb385STodd Fiala if (log) 772348fb385STodd Fiala { 773348fb385STodd Fiala log->Printf ("PlatformLinux::%s launching process with the following file actions:", __FUNCTION__); 774348fb385STodd Fiala 775348fb385STodd Fiala StreamString stream; 776348fb385STodd Fiala size_t i = 0; 777348fb385STodd Fiala const FileAction *file_action; 778348fb385STodd Fiala while ((file_action = launch_info.GetFileActionAtIndex (i++)) != nullptr) 779348fb385STodd Fiala { 780348fb385STodd Fiala file_action->Dump (stream); 781348fb385STodd Fiala log->PutCString (stream.GetString().c_str ()); 782348fb385STodd Fiala stream.Clear(); 783348fb385STodd Fiala } 784348fb385STodd Fiala } 785348fb385STodd Fiala 786348fb385STodd Fiala // Do the launch. 787348fb385STodd Fiala error = process_sp->Launch(launch_info); 788348fb385STodd Fiala if (error.Success ()) 789348fb385STodd Fiala { 790348fb385STodd Fiala // Handle the hijacking of process events. 791348fb385STodd Fiala if (listener_sp) 792348fb385STodd Fiala { 793348fb385STodd Fiala const StateType state = process_sp->WaitForProcessToStop (NULL, NULL, false, listener_sp.get()); 794348fb385STodd Fiala 795348fb385STodd Fiala if (state == eStateStopped) 796348fb385STodd Fiala { 797348fb385STodd Fiala if (log) 798348fb385STodd Fiala log->Printf ("PlatformLinux::%s pid %" PRIu64 " state %s\n", 799348fb385STodd Fiala __FUNCTION__, process_sp->GetID (), StateAsCString (state)); 800348fb385STodd Fiala } 801348fb385STodd Fiala else 802348fb385STodd Fiala { 803348fb385STodd Fiala if (log) 804348fb385STodd Fiala log->Printf ("PlatformLinux::%s pid %" PRIu64 " state is not stopped - %s\n", 805348fb385STodd Fiala __FUNCTION__, process_sp->GetID (), StateAsCString (state)); 806348fb385STodd Fiala } 807348fb385STodd Fiala } 808348fb385STodd Fiala 809348fb385STodd Fiala // Hook up process PTY if we have one (which we should for local debugging with llgs). 810348fb385STodd Fiala int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor(); 811348fb385STodd Fiala if (pty_fd != lldb_utility::PseudoTerminal::invalid_fd) 812348fb385STodd Fiala { 813348fb385STodd Fiala process_sp->SetSTDIOFileDescriptor(pty_fd); 814348fb385STodd Fiala if (log) 815348fb385STodd Fiala log->Printf ("PlatformLinux::%s pid %" PRIu64 " hooked up STDIO pty to process", __FUNCTION__, process_sp->GetID ()); 816348fb385STodd Fiala } 817348fb385STodd Fiala else 818348fb385STodd Fiala { 819348fb385STodd Fiala if (log) 820348fb385STodd Fiala log->Printf ("PlatformLinux::%s pid %" PRIu64 " not using process STDIO pty", __FUNCTION__, process_sp->GetID ()); 82128041352SGreg Clayton } 82228041352SGreg Clayton } 82328041352SGreg Clayton else 82428041352SGreg Clayton { 825348fb385STodd Fiala if (log) 826348fb385STodd Fiala log->Printf ("PlatformLinux::%s process launch failed: %s", __FUNCTION__, error.AsCString ()); 827348fb385STodd Fiala // FIXME figure out appropriate cleanup here. Do we delete the target? Do we delete the process? Does our caller do that? 82828041352SGreg Clayton } 829348fb385STodd Fiala 83028041352SGreg Clayton return process_sp; 83113e8e1c3SJohnny Chen } 8322094dbf4SJason Molenda 8332094dbf4SJason Molenda void 8342094dbf4SJason Molenda PlatformLinux::CalculateTrapHandlerSymbolNames () 8352094dbf4SJason Molenda { 8362094dbf4SJason Molenda m_trap_handlers.push_back (ConstString ("_sigtramp")); 8372094dbf4SJason Molenda } 838af245d11STodd Fiala 83996ad3de5SRobert Flack uint64_t 840e0d8c422SMohit K. Bhakkad PlatformLinux::ConvertMmapFlagsToPlatform(const ArchSpec &arch, unsigned flags) 84196ad3de5SRobert Flack { 84296ad3de5SRobert Flack uint64_t flags_platform = 0; 843e0d8c422SMohit K. Bhakkad uint64_t map_anon = MAP_ANON; 844e0d8c422SMohit K. Bhakkad 845e0d8c422SMohit K. Bhakkad // To get correct flags for MIPS Architecture 846e0d8c422SMohit K. Bhakkad if (arch.GetTriple ().getArch () == llvm::Triple::mips64 847e0d8c422SMohit K. Bhakkad || arch.GetTriple ().getArch () == llvm::Triple::mips64el 848e0d8c422SMohit K. Bhakkad || arch.GetTriple ().getArch () == llvm::Triple::mips 849e0d8c422SMohit K. Bhakkad || arch.GetTriple ().getArch () == llvm::Triple::mipsel) 850e0d8c422SMohit K. Bhakkad map_anon = 0x800; 851e0d8c422SMohit K. Bhakkad 85296ad3de5SRobert Flack if (flags & eMmapFlagsPrivate) 85396ad3de5SRobert Flack flags_platform |= MAP_PRIVATE; 85496ad3de5SRobert Flack if (flags & eMmapFlagsAnon) 855e0d8c422SMohit K. Bhakkad flags_platform |= map_anon; 85696ad3de5SRobert Flack return flags_platform; 85796ad3de5SRobert Flack } 8586e25aeeaSEnrico Granata 8596e25aeeaSEnrico Granata ConstString 8606e25aeeaSEnrico Granata PlatformLinux::GetFullNameForDylib (ConstString basename) 8616e25aeeaSEnrico Granata { 8626e25aeeaSEnrico Granata if (basename.IsEmpty()) 8636e25aeeaSEnrico Granata return basename; 8646e25aeeaSEnrico Granata 8656e25aeeaSEnrico Granata StreamString stream; 8666e25aeeaSEnrico Granata stream.Printf("lib%s.so", basename.GetCString()); 8676e25aeeaSEnrico Granata return ConstString(stream.GetData()); 8686e25aeeaSEnrico Granata } 869