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 static ConstString& 60db264a6dSTamas Berghammer GetSettingName (); 61db264a6dSTamas Berghammer 62db264a6dSTamas Berghammer PlatformLinuxProperties(); 63db264a6dSTamas Berghammer 64db264a6dSTamas Berghammer virtual 65db264a6dSTamas Berghammer ~PlatformLinuxProperties() = default; 66db264a6dSTamas Berghammer 67db264a6dSTamas Berghammer private: 68db264a6dSTamas Berghammer static const PropertyDefinition* 69db264a6dSTamas Berghammer GetStaticPropertyDefinitions(); 70db264a6dSTamas Berghammer }; 71db264a6dSTamas Berghammer 72db264a6dSTamas Berghammer typedef std::shared_ptr<PlatformLinuxProperties> PlatformLinuxPropertiesSP; 73db264a6dSTamas Berghammer 74db264a6dSTamas Berghammer } // anonymous namespace 75db264a6dSTamas Berghammer 76db264a6dSTamas Berghammer PlatformLinuxProperties::PlatformLinuxProperties() : 77db264a6dSTamas Berghammer Properties () 78db264a6dSTamas Berghammer { 79db264a6dSTamas Berghammer m_collection_sp.reset (new OptionValueProperties(GetSettingName ())); 80db264a6dSTamas Berghammer m_collection_sp->Initialize (GetStaticPropertyDefinitions ()); 81db264a6dSTamas Berghammer } 82db264a6dSTamas Berghammer 83db264a6dSTamas Berghammer ConstString& 84db264a6dSTamas Berghammer PlatformLinuxProperties::GetSettingName () 85db264a6dSTamas Berghammer { 86db264a6dSTamas Berghammer static ConstString g_setting_name("linux"); 87db264a6dSTamas Berghammer return g_setting_name; 88db264a6dSTamas Berghammer } 89db264a6dSTamas Berghammer 90348fb385STodd Fiala const PropertyDefinition* 91db264a6dSTamas Berghammer PlatformLinuxProperties::GetStaticPropertyDefinitions() 92348fb385STodd Fiala { 93281961a8STodd Fiala static PropertyDefinition 94281961a8STodd Fiala g_properties[] = 95281961a8STodd Fiala { 96281961a8STodd Fiala { NULL , OptionValue::eTypeInvalid, false, 0 , NULL, NULL, NULL } 97281961a8STodd Fiala }; 98281961a8STodd Fiala 99348fb385STodd Fiala return g_properties; 100348fb385STodd Fiala } 101281961a8STodd Fiala 102281961a8STodd Fiala static const PlatformLinuxPropertiesSP & 103281961a8STodd Fiala GetGlobalProperties() 104281961a8STodd Fiala { 105281961a8STodd Fiala static PlatformLinuxPropertiesSP g_settings_sp; 106281961a8STodd Fiala if (!g_settings_sp) 107281961a8STodd Fiala g_settings_sp.reset (new PlatformLinuxProperties ()); 108281961a8STodd Fiala return g_settings_sp; 109281961a8STodd Fiala } 110281961a8STodd Fiala 111281961a8STodd Fiala void 112db264a6dSTamas Berghammer PlatformLinux::DebuggerInitialize (Debugger &debugger) 113281961a8STodd Fiala { 114281961a8STodd Fiala if (!PluginManager::GetSettingForPlatformPlugin (debugger, PlatformLinuxProperties::GetSettingName())) 115281961a8STodd Fiala { 116281961a8STodd Fiala const bool is_global_setting = true; 117281961a8STodd Fiala PluginManager::CreateSettingForPlatformPlugin (debugger, 118281961a8STodd Fiala GetGlobalProperties()->GetValueProperties(), 119281961a8STodd Fiala ConstString ("Properties for the PlatformLinux plug-in."), 120281961a8STodd Fiala is_global_setting); 121281961a8STodd Fiala } 122281961a8STodd Fiala } 123281961a8STodd Fiala 124281961a8STodd Fiala 125281961a8STodd Fiala //------------------------------------------------------------------ 126281961a8STodd Fiala 127615eb7e6SGreg Clayton PlatformSP 128b3a40ba8SGreg Clayton PlatformLinux::CreateInstance (bool force, const ArchSpec *arch) 129ecc11474SStephen Wilson { 130db264a6dSTamas Berghammer Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM)); 131015d818bSTodd Fiala if (log) 132015d818bSTodd Fiala { 133015d818bSTodd Fiala const char *arch_name; 134015d818bSTodd Fiala if (arch && arch->GetArchitectureName ()) 135015d818bSTodd Fiala arch_name = arch->GetArchitectureName (); 136015d818bSTodd Fiala else 137015d818bSTodd Fiala arch_name = "<null>"; 138015d818bSTodd Fiala 139015d818bSTodd Fiala const char *triple_cstr = arch ? arch->GetTriple ().getTriple ().c_str() : "<null>"; 140015d818bSTodd Fiala 141015d818bSTodd Fiala log->Printf ("PlatformLinux::%s(force=%s, arch={%s,%s})", __FUNCTION__, force ? "true" : "false", arch_name, triple_cstr); 142015d818bSTodd Fiala } 143015d818bSTodd Fiala 144b3a40ba8SGreg Clayton bool create = force; 145b3a40ba8SGreg Clayton if (create == false && arch && arch->IsValid()) 146b3a40ba8SGreg Clayton { 147b3a40ba8SGreg Clayton const llvm::Triple &triple = arch->GetTriple(); 14870512317SGreg Clayton switch (triple.getOS()) 14970512317SGreg Clayton { 15070512317SGreg Clayton case llvm::Triple::Linux: 151b1da257aSTed Woodward create = true; 15270512317SGreg Clayton break; 15370512317SGreg Clayton 154dbc6c0bbSGreg Clayton #if defined(__linux__) 155dbc6c0bbSGreg Clayton // Only accept "unknown" for the OS if the host is linux and 1566a7f3338SBruce Mitchener // it "unknown" wasn't specified (it was just returned because it 157dbc6c0bbSGreg Clayton // was NOT specified) 158015d818bSTodd Fiala case llvm::Triple::OSType::UnknownOS: 15970512317SGreg Clayton create = !arch->TripleOSWasSpecified(); 16070512317SGreg Clayton break; 161dbc6c0bbSGreg Clayton #endif 16270512317SGreg Clayton default: 16370512317SGreg Clayton break; 16470512317SGreg Clayton } 16570512317SGreg Clayton } 166015d818bSTodd Fiala 167b3a40ba8SGreg Clayton if (create) 168015d818bSTodd Fiala { 169015d818bSTodd Fiala if (log) 170015d818bSTodd Fiala log->Printf ("PlatformLinux::%s() creating remote-linux platform", __FUNCTION__); 171615eb7e6SGreg Clayton return PlatformSP(new PlatformLinux(false)); 172015d818bSTodd Fiala } 173015d818bSTodd Fiala 174015d818bSTodd Fiala if (log) 175015d818bSTodd Fiala log->Printf ("PlatformLinux::%s() aborting creation of remote-linux platform", __FUNCTION__); 176015d818bSTodd Fiala 177615eb7e6SGreg Clayton return PlatformSP(); 178ecc11474SStephen Wilson } 179ecc11474SStephen Wilson 180ecc11474SStephen Wilson 181db264a6dSTamas Berghammer ConstString 18257abc5d6SGreg Clayton PlatformLinux::GetPluginNameStatic (bool is_host) 183ecc11474SStephen Wilson { 18428041352SGreg Clayton if (is_host) 18557abc5d6SGreg Clayton { 18657abc5d6SGreg Clayton static ConstString g_host_name(Platform::GetHostPlatformName ()); 18757abc5d6SGreg Clayton return g_host_name; 18857abc5d6SGreg Clayton } 18928041352SGreg Clayton else 19057abc5d6SGreg Clayton { 19157abc5d6SGreg Clayton static ConstString g_remote_name("remote-linux"); 19257abc5d6SGreg Clayton return g_remote_name; 19357abc5d6SGreg Clayton } 19428041352SGreg Clayton } 19528041352SGreg Clayton 19628041352SGreg Clayton const char * 19728041352SGreg Clayton PlatformLinux::GetPluginDescriptionStatic (bool is_host) 19828041352SGreg Clayton { 19928041352SGreg Clayton if (is_host) 20028041352SGreg Clayton return "Local Linux user platform plug-in."; 20128041352SGreg Clayton else 20228041352SGreg Clayton return "Remote Linux user platform plug-in."; 203ecc11474SStephen Wilson } 204ecc11474SStephen Wilson 205db264a6dSTamas Berghammer ConstString 20657abc5d6SGreg Clayton PlatformLinux::GetPluginName() 20757abc5d6SGreg Clayton { 20857abc5d6SGreg Clayton return GetPluginNameStatic(IsHost()); 20957abc5d6SGreg Clayton } 21057abc5d6SGreg Clayton 211e996fd30SGreg Clayton void 212e996fd30SGreg Clayton PlatformLinux::Initialize () 213e996fd30SGreg Clayton { 2143c4f89d7STamas Berghammer PlatformPOSIX::Initialize (); 2153c4f89d7STamas Berghammer 21628041352SGreg Clayton if (g_initialize_count++ == 0) 217ecc11474SStephen Wilson { 2181c6a1ea9STamas Berghammer #if defined(__linux__) && !defined(__ANDROID__) 21928041352SGreg Clayton PlatformSP default_platform_sp (new PlatformLinux(true)); 22013b18261SZachary Turner default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture()); 221615eb7e6SGreg Clayton Platform::SetHostPlatform (default_platform_sp); 22228041352SGreg Clayton #endif 22357abc5d6SGreg Clayton PluginManager::RegisterPlugin(PlatformLinux::GetPluginNameStatic(false), 22428041352SGreg Clayton PlatformLinux::GetPluginDescriptionStatic(false), 225281961a8STodd Fiala PlatformLinux::CreateInstance, 226281961a8STodd Fiala PlatformLinux::DebuggerInitialize); 227ecc11474SStephen Wilson } 228e996fd30SGreg Clayton } 229e996fd30SGreg Clayton 230e996fd30SGreg Clayton void 231e996fd30SGreg Clayton PlatformLinux::Terminate () 232e996fd30SGreg Clayton { 23328041352SGreg Clayton if (g_initialize_count > 0) 23428041352SGreg Clayton { 23528041352SGreg Clayton if (--g_initialize_count == 0) 23628041352SGreg Clayton { 23728041352SGreg Clayton PluginManager::UnregisterPlugin (PlatformLinux::CreateInstance); 238e996fd30SGreg Clayton } 23928041352SGreg Clayton } 2403c4f89d7STamas Berghammer 2413c4f89d7STamas Berghammer PlatformPOSIX::Terminate (); 24228041352SGreg Clayton } 243e996fd30SGreg Clayton 244e996fd30SGreg Clayton Error 2458012cadbSGreg Clayton PlatformLinux::ResolveExecutable (const ModuleSpec &ms, 246ea5e0cc3SGreg Clayton lldb::ModuleSP &exe_module_sp, 247ea5e0cc3SGreg Clayton const FileSpecList *module_search_paths_ptr) 248e996fd30SGreg Clayton { 249e996fd30SGreg Clayton Error error; 250e996fd30SGreg Clayton // Nothing special to do here, just use the actual file and architecture 251e996fd30SGreg Clayton 25228041352SGreg Clayton char exe_path[PATH_MAX]; 2538012cadbSGreg Clayton ModuleSpec resolved_module_spec (ms); 254e996fd30SGreg Clayton 25528041352SGreg Clayton if (IsHost()) 25628041352SGreg Clayton { 25728041352SGreg Clayton // If we have "ls" as the exe_file, resolve the executable location based on 258e996fd30SGreg Clayton // the current path variables 2598012cadbSGreg Clayton if (!resolved_module_spec.GetFileSpec().Exists()) 26028041352SGreg Clayton { 2618012cadbSGreg Clayton resolved_module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path)); 2628012cadbSGreg Clayton resolved_module_spec.GetFileSpec().SetFile(exe_path, true); 26328041352SGreg Clayton } 26428041352SGreg Clayton 2658012cadbSGreg Clayton if (!resolved_module_spec.GetFileSpec().Exists()) 2668012cadbSGreg Clayton resolved_module_spec.GetFileSpec().ResolveExecutableLocation (); 267e996fd30SGreg Clayton 2688012cadbSGreg Clayton if (resolved_module_spec.GetFileSpec().Exists()) 26928041352SGreg Clayton error.Clear(); 27028041352SGreg Clayton else 27128041352SGreg Clayton { 2728012cadbSGreg Clayton error.SetErrorStringWithFormat("unable to find executable for '%s'", resolved_module_spec.GetFileSpec().GetPath().c_str()); 27328041352SGreg Clayton } 27428041352SGreg Clayton } 27528041352SGreg Clayton else 27628041352SGreg Clayton { 27728041352SGreg Clayton if (m_remote_platform_sp) 27828041352SGreg Clayton { 279a3f245ffSOleksiy Vyalov error = GetCachedExecutable (resolved_module_spec, exe_module_sp, module_search_paths_ptr, *m_remote_platform_sp); 28028041352SGreg Clayton } 28128041352SGreg Clayton else 28228041352SGreg Clayton { 28328041352SGreg Clayton // We may connect to a process and use the provided executable (Don't use local $PATH). 284e996fd30SGreg Clayton 2858012cadbSGreg Clayton if (resolved_module_spec.GetFileSpec().Exists()) 28628041352SGreg Clayton error.Clear(); 28728041352SGreg Clayton else 28828041352SGreg Clayton error.SetErrorStringWithFormat("the platform is not currently connected, and '%s' doesn't exist in the system root.", exe_path); 28928041352SGreg Clayton } 29028041352SGreg Clayton } 29128041352SGreg Clayton 29228041352SGreg Clayton if (error.Success()) 293e996fd30SGreg Clayton { 2948012cadbSGreg Clayton if (resolved_module_spec.GetArchitecture().IsValid()) 295e996fd30SGreg Clayton { 2968012cadbSGreg Clayton error = ModuleList::GetSharedModule (resolved_module_spec, 297e996fd30SGreg Clayton exe_module_sp, 298e996fd30SGreg Clayton NULL, 2990c90ef47SGreg Clayton NULL, 300e996fd30SGreg Clayton NULL); 3019f0013d8SMichael Sartain if (error.Fail()) 3029f0013d8SMichael Sartain { 3039f0013d8SMichael Sartain // If we failed, it may be because the vendor and os aren't known. If that is the 3049f0013d8SMichael Sartain // case, try setting them to the host architecture and give it another try. 3058012cadbSGreg Clayton llvm::Triple &module_triple = resolved_module_spec.GetArchitecture().GetTriple(); 3069f0013d8SMichael Sartain bool is_vendor_specified = (module_triple.getVendor() != llvm::Triple::UnknownVendor); 3079f0013d8SMichael Sartain bool is_os_specified = (module_triple.getOS() != llvm::Triple::UnknownOS); 3089f0013d8SMichael Sartain if (!is_vendor_specified || !is_os_specified) 3099f0013d8SMichael Sartain { 31013b18261SZachary Turner const llvm::Triple &host_triple = HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple(); 3119f0013d8SMichael Sartain 3129f0013d8SMichael Sartain if (!is_vendor_specified) 3139f0013d8SMichael Sartain module_triple.setVendorName (host_triple.getVendorName()); 3149f0013d8SMichael Sartain if (!is_os_specified) 3159f0013d8SMichael Sartain module_triple.setOSName (host_triple.getOSName()); 3169f0013d8SMichael Sartain 3178012cadbSGreg Clayton error = ModuleList::GetSharedModule (resolved_module_spec, 3189f0013d8SMichael Sartain exe_module_sp, 3199f0013d8SMichael Sartain NULL, 3209f0013d8SMichael Sartain NULL, 3219f0013d8SMichael Sartain NULL); 3229f0013d8SMichael Sartain } 3239f0013d8SMichael Sartain } 324e996fd30SGreg Clayton 325e635db49SSean Callanan // TODO find out why exe_module_sp might be NULL 326e635db49SSean Callanan if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL) 327e996fd30SGreg Clayton { 328e996fd30SGreg Clayton exe_module_sp.reset(); 329b5ad4ec7SGreg Clayton error.SetErrorStringWithFormat ("'%s' doesn't contain the architecture %s", 3308012cadbSGreg Clayton resolved_module_spec.GetFileSpec().GetPath().c_str(), 3318012cadbSGreg Clayton resolved_module_spec.GetArchitecture().GetArchitectureName()); 332e996fd30SGreg Clayton } 333e996fd30SGreg Clayton } 334e996fd30SGreg Clayton else 335e996fd30SGreg Clayton { 336e996fd30SGreg Clayton // No valid architecture was specified, ask the platform for 337e996fd30SGreg Clayton // the architectures that we should be using (in the correct order) 338e996fd30SGreg Clayton // and see if we can find a match that way 339e996fd30SGreg Clayton StreamString arch_names; 3408012cadbSGreg Clayton for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, resolved_module_spec.GetArchitecture()); ++idx) 341e996fd30SGreg Clayton { 3428012cadbSGreg Clayton error = ModuleList::GetSharedModule (resolved_module_spec, 343e996fd30SGreg Clayton exe_module_sp, 344e996fd30SGreg Clayton NULL, 3450c90ef47SGreg Clayton NULL, 346e996fd30SGreg Clayton NULL); 347e996fd30SGreg Clayton // Did we find an executable using one of the 348e996fd30SGreg Clayton if (error.Success()) 349e996fd30SGreg Clayton { 350e996fd30SGreg Clayton if (exe_module_sp && exe_module_sp->GetObjectFile()) 351e996fd30SGreg Clayton break; 352e996fd30SGreg Clayton else 353e996fd30SGreg Clayton error.SetErrorToGenericError(); 354e996fd30SGreg Clayton } 355e996fd30SGreg Clayton 356e996fd30SGreg Clayton if (idx > 0) 357e996fd30SGreg Clayton arch_names.PutCString (", "); 3588012cadbSGreg Clayton arch_names.PutCString (resolved_module_spec.GetArchitecture().GetArchitectureName()); 359e996fd30SGreg Clayton } 360e996fd30SGreg Clayton 361e996fd30SGreg Clayton if (error.Fail() || !exe_module_sp) 362e996fd30SGreg Clayton { 3638012cadbSGreg Clayton if (resolved_module_spec.GetFileSpec().Readable()) 36439945dccSGreg Clayton { 365b5ad4ec7SGreg Clayton error.SetErrorStringWithFormat ("'%s' doesn't contain any '%s' platform architectures: %s", 3668012cadbSGreg Clayton resolved_module_spec.GetFileSpec().GetPath().c_str(), 36757abc5d6SGreg Clayton GetPluginName().GetCString(), 368e996fd30SGreg Clayton arch_names.GetString().c_str()); 369e996fd30SGreg Clayton } 37039945dccSGreg Clayton else 37139945dccSGreg Clayton { 3728012cadbSGreg Clayton error.SetErrorStringWithFormat("'%s' is not readable", resolved_module_spec.GetFileSpec().GetPath().c_str()); 37339945dccSGreg Clayton } 37439945dccSGreg Clayton } 375e996fd30SGreg Clayton } 376e996fd30SGreg Clayton } 377e996fd30SGreg Clayton 378e996fd30SGreg Clayton return error; 379e996fd30SGreg Clayton } 380e996fd30SGreg Clayton 381e996fd30SGreg Clayton Error 382fc995725SSteve Pucci PlatformLinux::GetFileWithUUID (const FileSpec &platform_file, 38328041352SGreg Clayton const UUID *uuid_ptr, FileSpec &local_file) 384e996fd30SGreg Clayton { 38528041352SGreg Clayton if (IsRemote()) 38628041352SGreg Clayton { 38728041352SGreg Clayton if (m_remote_platform_sp) 388fc995725SSteve Pucci return m_remote_platform_sp->GetFileWithUUID (platform_file, uuid_ptr, local_file); 38928041352SGreg Clayton } 39028041352SGreg Clayton 391e996fd30SGreg Clayton // Default to the local case 392e996fd30SGreg Clayton local_file = platform_file; 393e996fd30SGreg Clayton return Error(); 394e996fd30SGreg Clayton } 395e996fd30SGreg Clayton 396e996fd30SGreg Clayton 397e996fd30SGreg Clayton //------------------------------------------------------------------ 398e996fd30SGreg Clayton /// Default Constructor 399e996fd30SGreg Clayton //------------------------------------------------------------------ 40028041352SGreg Clayton PlatformLinux::PlatformLinux (bool is_host) : 401015d818bSTodd Fiala PlatformPOSIX(is_host) // This is the local host platform 402e996fd30SGreg Clayton { 403e996fd30SGreg Clayton } 404e996fd30SGreg Clayton 405e996fd30SGreg Clayton //------------------------------------------------------------------ 406e996fd30SGreg Clayton /// Destructor. 407e996fd30SGreg Clayton /// 408e996fd30SGreg Clayton /// The destructor is virtual since this class is designed to be 409e996fd30SGreg Clayton /// inherited from by the plug-in instance. 410e996fd30SGreg Clayton //------------------------------------------------------------------ 411e996fd30SGreg Clayton PlatformLinux::~PlatformLinux() 412e996fd30SGreg Clayton { 413e996fd30SGreg Clayton } 414e996fd30SGreg Clayton 415e996fd30SGreg Clayton bool 41613e8e1c3SJohnny Chen PlatformLinux::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info) 417e996fd30SGreg Clayton { 41828041352SGreg Clayton bool success = false; 41928041352SGreg Clayton if (IsHost()) 42028041352SGreg Clayton { 42128041352SGreg Clayton success = Platform::GetProcessInfo (pid, process_info); 42228041352SGreg Clayton } 42328041352SGreg Clayton else 42428041352SGreg Clayton { 42528041352SGreg Clayton if (m_remote_platform_sp) 42628041352SGreg Clayton success = m_remote_platform_sp->GetProcessInfo (pid, process_info); 42728041352SGreg Clayton } 42828041352SGreg Clayton return success; 429e996fd30SGreg Clayton } 430e996fd30SGreg Clayton 4318e6ec453SStephane Sezer uint32_t 4328e6ec453SStephane Sezer PlatformLinux::FindProcesses (const ProcessInstanceInfoMatch &match_info, 4338e6ec453SStephane Sezer ProcessInstanceInfoList &process_infos) 4348e6ec453SStephane Sezer { 4358e6ec453SStephane Sezer uint32_t match_count = 0; 4368e6ec453SStephane Sezer if (IsHost()) 4378e6ec453SStephane Sezer { 4388e6ec453SStephane Sezer // Let the base class figure out the host details 4398e6ec453SStephane Sezer match_count = Platform::FindProcesses (match_info, process_infos); 4408e6ec453SStephane Sezer } 4418e6ec453SStephane Sezer else 4428e6ec453SStephane Sezer { 4438e6ec453SStephane Sezer // If we are remote, we can only return results if we are connected 4448e6ec453SStephane Sezer if (m_remote_platform_sp) 4458e6ec453SStephane Sezer match_count = m_remote_platform_sp->FindProcesses (match_info, process_infos); 4468e6ec453SStephane Sezer } 4478e6ec453SStephane Sezer return match_count; 4488e6ec453SStephane Sezer } 4498e6ec453SStephane Sezer 450e996fd30SGreg Clayton bool 451e996fd30SGreg Clayton PlatformLinux::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch) 452e996fd30SGreg Clayton { 453e49b8e06SRobert Flack if (IsHost()) 454e49b8e06SRobert Flack { 455e49b8e06SRobert Flack ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault); 456e49b8e06SRobert Flack if (hostArch.GetTriple().isOSLinux()) 457e49b8e06SRobert Flack { 458e49b8e06SRobert Flack if (idx == 0) 459e49b8e06SRobert Flack { 460e49b8e06SRobert Flack arch = hostArch; 461e49b8e06SRobert Flack return arch.IsValid(); 462e49b8e06SRobert Flack } 463e49b8e06SRobert Flack else if (idx == 1) 464e49b8e06SRobert Flack { 465e49b8e06SRobert Flack // If the default host architecture is 64-bit, look for a 32-bit variant 466e49b8e06SRobert Flack if (hostArch.IsValid() && hostArch.GetTriple().isArch64Bit()) 467e49b8e06SRobert Flack { 468e49b8e06SRobert Flack arch = HostInfo::GetArchitecture(HostInfo::eArchKind32); 469e49b8e06SRobert Flack return arch.IsValid(); 470e49b8e06SRobert Flack } 471e49b8e06SRobert Flack } 472e49b8e06SRobert Flack } 473e49b8e06SRobert Flack } 474e49b8e06SRobert Flack else 475e49b8e06SRobert Flack { 476e49b8e06SRobert Flack if (m_remote_platform_sp) 477e49b8e06SRobert Flack return m_remote_platform_sp->GetSupportedArchitectureAtIndex(idx, arch); 478bb1e283cSTed Woodward 479bb1e283cSTed Woodward llvm::Triple triple; 480bb1e283cSTed Woodward // Set the OS to linux 481bb1e283cSTed Woodward triple.setOS(llvm::Triple::Linux); 482bb1e283cSTed Woodward // Set the architecture 483bb1e283cSTed Woodward switch (idx) 484bb1e283cSTed Woodward { 485bb1e283cSTed Woodward case 0: triple.setArchName("x86_64"); break; 486bb1e283cSTed Woodward case 1: triple.setArchName("i386"); break; 487bb1e283cSTed Woodward case 2: triple.setArchName("arm"); break; 488bb1e283cSTed Woodward case 3: triple.setArchName("aarch64"); break; 489bb1e283cSTed Woodward case 4: triple.setArchName("mips64"); break; 490bb1e283cSTed Woodward case 5: triple.setArchName("hexagon"); break; 491bb1e283cSTed Woodward case 6: triple.setArchName("mips"); break; 492ce815e45SSagar Thakur case 7: triple.setArchName("mips64el"); break; 493ce815e45SSagar Thakur case 8: triple.setArchName("mipsel"); break; 494bb1e283cSTed Woodward default: return false; 495bb1e283cSTed Woodward } 496bb1e283cSTed Woodward // Leave the vendor as "llvm::Triple:UnknownVendor" and don't specify the vendor by 497bb1e283cSTed Woodward // calling triple.SetVendorName("unknown") so that it is a "unspecified unknown". 498bb1e283cSTed Woodward // This means when someone calls triple.GetVendorName() it will return an empty string 499bb1e283cSTed Woodward // which indicates that the vendor can be set when two architectures are merged 500bb1e283cSTed Woodward 501bb1e283cSTed Woodward // Now set the triple into "arch" and return true 502bb1e283cSTed Woodward arch.SetTriple(triple); 503bb1e283cSTed Woodward return true; 504e49b8e06SRobert Flack } 505e996fd30SGreg Clayton return false; 506e996fd30SGreg Clayton } 507ecc11474SStephen Wilson 508ecc11474SStephen Wilson void 509ecc11474SStephen Wilson PlatformLinux::GetStatus (Stream &strm) 510ecc11474SStephen Wilson { 5113be69dacSDaniel Malea Platform::GetStatus(strm); 512ecc11474SStephen Wilson 513b2f1fb29SVirgile Bello #ifndef LLDB_DISABLE_POSIX 514b743a803SStephane Sezer // Display local kernel information only when we are running in host mode. 515b743a803SStephane Sezer // Otherwise, we would end up printing non-Linux information (when running 516b743a803SStephane Sezer // on Mac OS for example). 517b743a803SStephane Sezer if (IsHost()) 518b743a803SStephane Sezer { 519b2f1fb29SVirgile Bello struct utsname un; 520b2f1fb29SVirgile Bello 5213be69dacSDaniel Malea if (uname(&un)) 5223be69dacSDaniel Malea return; 5233be69dacSDaniel Malea 5243be69dacSDaniel Malea strm.Printf (" Kernel: %s\n", un.sysname); 5253be69dacSDaniel Malea strm.Printf (" Release: %s\n", un.release); 5263be69dacSDaniel Malea strm.Printf (" Version: %s\n", un.version); 527b743a803SStephane Sezer } 528b2f1fb29SVirgile Bello #endif 529ecc11474SStephen Wilson } 530ecc11474SStephen Wilson 531ecc11474SStephen Wilson size_t 532ecc11474SStephen Wilson PlatformLinux::GetSoftwareBreakpointTrapOpcode (Target &target, 533ecc11474SStephen Wilson BreakpointSite *bp_site) 534ecc11474SStephen Wilson { 535ecc11474SStephen Wilson ArchSpec arch = target.GetArchitecture(); 53628041352SGreg Clayton const uint8_t *trap_opcode = NULL; 53728041352SGreg Clayton size_t trap_opcode_size = 0; 538ecc11474SStephen Wilson 539906e9acfSGreg Clayton switch (arch.GetMachine()) 540ecc11474SStephen Wilson { 541ecc11474SStephen Wilson default: 542ecc11474SStephen Wilson assert(false && "CPU type not supported!"); 543ecc11474SStephen Wilson break; 544ecc11474SStephen Wilson 5452afc5966STodd Fiala case llvm::Triple::aarch64: 5462afc5966STodd Fiala { 5472afc5966STodd Fiala static const uint8_t g_aarch64_opcode[] = { 0x00, 0x00, 0x20, 0xd4 }; 5482afc5966STodd Fiala trap_opcode = g_aarch64_opcode; 5492afc5966STodd Fiala trap_opcode_size = sizeof(g_aarch64_opcode); 5502afc5966STodd Fiala } 5512afc5966STodd Fiala break; 552906e9acfSGreg Clayton case llvm::Triple::x86: 553906e9acfSGreg Clayton case llvm::Triple::x86_64: 55428041352SGreg Clayton { 55528041352SGreg Clayton static const uint8_t g_i386_breakpoint_opcode[] = { 0xCC }; 55628041352SGreg Clayton trap_opcode = g_i386_breakpoint_opcode; 55728041352SGreg Clayton trap_opcode_size = sizeof(g_i386_breakpoint_opcode); 55828041352SGreg Clayton } 559ecc11474SStephen Wilson break; 560906e9acfSGreg Clayton case llvm::Triple::hexagon: 5618006d319SDeepak Panickal { 5628006d319SDeepak Panickal static const uint8_t g_hex_opcode[] = { 0x0c, 0xdb, 0x00, 0x54 }; 5638006d319SDeepak Panickal trap_opcode = g_hex_opcode; 5648006d319SDeepak Panickal trap_opcode_size = sizeof(g_hex_opcode); 5658006d319SDeepak Panickal } 5668006d319SDeepak Panickal break; 5672586e94bSJason Molenda case llvm::Triple::arm: 5682586e94bSJason Molenda { 5692586e94bSJason Molenda // The ARM reference recommends the use of 0xe7fddefe and 0xdefe 5702586e94bSJason Molenda // but the linux kernel does otherwise. 5712586e94bSJason Molenda static const uint8_t g_arm_breakpoint_opcode[] = { 0xf0, 0x01, 0xf0, 0xe7 }; 5722586e94bSJason Molenda static const uint8_t g_thumb_breakpoint_opcode[] = { 0x01, 0xde }; 5732586e94bSJason Molenda 5742586e94bSJason Molenda lldb::BreakpointLocationSP bp_loc_sp (bp_site->GetOwnerAtIndex (0)); 5752586e94bSJason Molenda AddressClass addr_class = eAddressClassUnknown; 5762586e94bSJason Molenda 5772586e94bSJason Molenda if (bp_loc_sp) 578*76011b63STamas Berghammer { 5792586e94bSJason Molenda addr_class = bp_loc_sp->GetAddress ().GetAddressClass (); 5802586e94bSJason Molenda 581*76011b63STamas Berghammer if (addr_class == eAddressClassUnknown && 582*76011b63STamas Berghammer (bp_loc_sp->GetAddress ().GetFileAddress () & 1)) 583*76011b63STamas Berghammer { 584*76011b63STamas Berghammer addr_class = eAddressClassCodeAlternateISA; 585*76011b63STamas Berghammer } 586*76011b63STamas Berghammer } 587*76011b63STamas Berghammer 588*76011b63STamas Berghammer if (addr_class == eAddressClassCodeAlternateISA) 5892586e94bSJason Molenda { 5902586e94bSJason Molenda trap_opcode = g_thumb_breakpoint_opcode; 5912586e94bSJason Molenda trap_opcode_size = sizeof(g_thumb_breakpoint_opcode); 5922586e94bSJason Molenda } 5932586e94bSJason Molenda else 5942586e94bSJason Molenda { 5952586e94bSJason Molenda trap_opcode = g_arm_breakpoint_opcode; 5962586e94bSJason Molenda trap_opcode_size = sizeof(g_arm_breakpoint_opcode); 5972586e94bSJason Molenda } 5982586e94bSJason Molenda } 5992586e94bSJason Molenda break; 600794a4d5aSBhushan D. Attarde case llvm::Triple::mips: 601c9335a3fSMohit K. Bhakkad case llvm::Triple::mips64: 602c9335a3fSMohit K. Bhakkad { 603c9335a3fSMohit K. Bhakkad static const uint8_t g_hex_opcode[] = { 0x00, 0x00, 0x00, 0x0d }; 604c9335a3fSMohit K. Bhakkad trap_opcode = g_hex_opcode; 605c9335a3fSMohit K. Bhakkad trap_opcode_size = sizeof(g_hex_opcode); 606c9335a3fSMohit K. Bhakkad } 607c9335a3fSMohit K. Bhakkad break; 608794a4d5aSBhushan D. Attarde case llvm::Triple::mipsel: 6092c2acf96SMohit K. Bhakkad case llvm::Triple::mips64el: 6102c2acf96SMohit K. Bhakkad { 6112c2acf96SMohit K. Bhakkad static const uint8_t g_hex_opcode[] = { 0x0d, 0x00, 0x00, 0x00 }; 6122c2acf96SMohit K. Bhakkad trap_opcode = g_hex_opcode; 6132c2acf96SMohit K. Bhakkad trap_opcode_size = sizeof(g_hex_opcode); 6142c2acf96SMohit K. Bhakkad } 6152c2acf96SMohit K. Bhakkad break; 616ecc11474SStephen Wilson } 617ecc11474SStephen Wilson 61828041352SGreg Clayton if (bp_site->SetTrapOpcode(trap_opcode, trap_opcode_size)) 61928041352SGreg Clayton return trap_opcode_size; 62028041352SGreg Clayton return 0; 62128041352SGreg Clayton } 62228041352SGreg Clayton 623348fb385STodd Fiala int32_t 624348fb385STodd Fiala PlatformLinux::GetResumeCountForLaunchInfo (ProcessLaunchInfo &launch_info) 62528041352SGreg Clayton { 626348fb385STodd Fiala int32_t resume_count = 0; 62728041352SGreg Clayton 628348fb385STodd Fiala // Always resume past the initial stop when we use eLaunchFlagDebug 629348fb385STodd Fiala if (launch_info.GetFlags ().Test (eLaunchFlagDebug)) 63028041352SGreg Clayton { 631348fb385STodd Fiala // Resume past the stop for the final exec into the true inferior. 632348fb385STodd Fiala ++resume_count; 633348fb385STodd Fiala } 634015d818bSTodd Fiala 635348fb385STodd Fiala // If we're not launching a shell, we're done. 63610687b0eSZachary Turner const FileSpec &shell = launch_info.GetShell(); 63710687b0eSZachary Turner if (!shell) 638348fb385STodd Fiala return resume_count; 639348fb385STodd Fiala 64010687b0eSZachary Turner std::string shell_string = shell.GetPath(); 641348fb385STodd Fiala // We're in a shell, so for sure we have to resume past the shell exec. 642348fb385STodd Fiala ++resume_count; 643348fb385STodd Fiala 644348fb385STodd Fiala // Figure out what shell we're planning on using. 64510687b0eSZachary Turner const char *shell_name = strrchr (shell_string.c_str(), '/'); 646348fb385STodd Fiala if (shell_name == NULL) 64710687b0eSZachary Turner shell_name = shell_string.c_str(); 64828041352SGreg Clayton else 649348fb385STodd Fiala shell_name++; 650348fb385STodd Fiala 651348fb385STodd Fiala if (strcmp (shell_name, "csh") == 0 652348fb385STodd Fiala || strcmp (shell_name, "tcsh") == 0 653348fb385STodd Fiala || strcmp (shell_name, "zsh") == 0 654348fb385STodd Fiala || strcmp (shell_name, "sh") == 0) 65528041352SGreg Clayton { 656348fb385STodd Fiala // These shells seem to re-exec themselves. Add another resume. 657348fb385STodd Fiala ++resume_count; 658ecc11474SStephen Wilson } 65913e8e1c3SJohnny Chen 660348fb385STodd Fiala return resume_count; 661348fb385STodd Fiala } 662348fb385STodd Fiala 663348fb385STodd Fiala bool 664015d818bSTodd Fiala PlatformLinux::CanDebugProcess () 665015d818bSTodd Fiala { 666015d818bSTodd Fiala if (IsHost ()) 667348fb385STodd Fiala { 668b36f9178SPavel Labath return true; 669348fb385STodd Fiala } 670348fb385STodd Fiala else 671348fb385STodd Fiala { 672015d818bSTodd Fiala // If we're connected, we can debug. 673015d818bSTodd Fiala return IsConnected (); 674015d818bSTodd Fiala } 675348fb385STodd Fiala } 676015d818bSTodd Fiala 677348fb385STodd Fiala // For local debugging, Linux will override the debug logic to use llgs-launch rather than 678348fb385STodd Fiala // lldb-launch, llgs-attach. This differs from current lldb-launch, debugserver-attach 679348fb385STodd Fiala // approach on MacOSX. 68013e8e1c3SJohnny Chen lldb::ProcessSP 681348fb385STodd Fiala PlatformLinux::DebugProcess (ProcessLaunchInfo &launch_info, 68213e8e1c3SJohnny Chen Debugger &debugger, 683348fb385STodd Fiala Target *target, // Can be NULL, if NULL create a new target, else use existing one 68413e8e1c3SJohnny Chen Error &error) 68513e8e1c3SJohnny Chen { 686db264a6dSTamas Berghammer Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM)); 687348fb385STodd Fiala if (log) 688348fb385STodd Fiala log->Printf ("PlatformLinux::%s entered (target %p)", __FUNCTION__, static_cast<void*>(target)); 68928041352SGreg Clayton 690348fb385STodd Fiala // If we're a remote host, use standard behavior from parent class. 691348fb385STodd Fiala if (!IsHost ()) 6928012cadbSGreg Clayton return PlatformPOSIX::DebugProcess (launch_info, debugger, target, error); 693348fb385STodd Fiala 694348fb385STodd Fiala // 695348fb385STodd Fiala // For local debugging, we'll insist on having ProcessGDBRemote create the process. 696348fb385STodd Fiala // 697348fb385STodd Fiala 698348fb385STodd Fiala ProcessSP process_sp; 699348fb385STodd Fiala 700348fb385STodd Fiala // Make sure we stop at the entry point 701348fb385STodd Fiala launch_info.GetFlags ().Set (eLaunchFlagDebug); 702348fb385STodd Fiala 703348fb385STodd Fiala // We always launch the process we are going to debug in a separate process 704348fb385STodd Fiala // group, since then we can handle ^C interrupts ourselves w/o having to worry 705348fb385STodd Fiala // about the target getting them as well. 706348fb385STodd Fiala launch_info.SetLaunchInSeparateProcessGroup(true); 707348fb385STodd Fiala 708348fb385STodd Fiala // Ensure we have a target. 709348fb385STodd Fiala if (target == nullptr) 710348fb385STodd Fiala { 711348fb385STodd Fiala if (log) 712348fb385STodd Fiala log->Printf ("PlatformLinux::%s creating new target", __FUNCTION__); 713348fb385STodd Fiala 714348fb385STodd Fiala TargetSP new_target_sp; 71528041352SGreg Clayton error = debugger.GetTargetList().CreateTarget (debugger, 716348fb385STodd Fiala nullptr, 717348fb385STodd Fiala nullptr, 71828041352SGreg Clayton false, 719348fb385STodd Fiala nullptr, 72028041352SGreg Clayton new_target_sp); 721348fb385STodd Fiala if (error.Fail ()) 722348fb385STodd Fiala { 723348fb385STodd Fiala if (log) 724348fb385STodd Fiala log->Printf ("PlatformLinux::%s failed to create new target: %s", __FUNCTION__, error.AsCString ()); 725348fb385STodd Fiala return process_sp; 726348fb385STodd Fiala } 727348fb385STodd Fiala 72828041352SGreg Clayton target = new_target_sp.get(); 729348fb385STodd Fiala if (!target) 730348fb385STodd Fiala { 731348fb385STodd Fiala error.SetErrorString ("CreateTarget() returned nullptr"); 732348fb385STodd Fiala if (log) 733348fb385STodd Fiala log->Printf ("PlatformLinux::%s failed: %s", __FUNCTION__, error.AsCString ()); 734348fb385STodd Fiala return process_sp; 735348fb385STodd Fiala } 73628041352SGreg Clayton } 73728041352SGreg Clayton else 73828041352SGreg Clayton { 739348fb385STodd Fiala if (log) 740348fb385STodd Fiala log->Printf ("PlatformLinux::%s using provided target", __FUNCTION__); 741348fb385STodd Fiala } 742348fb385STodd Fiala 743348fb385STodd Fiala // Mark target as currently selected target. 74428041352SGreg Clayton debugger.GetTargetList().SetSelectedTarget(target); 74528041352SGreg Clayton 746348fb385STodd Fiala // Now create the gdb-remote process. 747348fb385STodd Fiala if (log) 748348fb385STodd Fiala log->Printf ("PlatformLinux::%s having target create process with gdb-remote plugin", __FUNCTION__); 7498012cadbSGreg Clayton process_sp = target->CreateProcess (launch_info.GetListenerForProcess(debugger), "gdb-remote", nullptr); 75028041352SGreg Clayton 751348fb385STodd Fiala if (!process_sp) 752348fb385STodd Fiala { 753348fb385STodd Fiala error.SetErrorString ("CreateProcess() failed for gdb-remote process"); 754348fb385STodd Fiala if (log) 755348fb385STodd Fiala log->Printf ("PlatformLinux::%s failed: %s", __FUNCTION__, error.AsCString ()); 756348fb385STodd Fiala return process_sp; 757348fb385STodd Fiala } 758348fb385STodd Fiala else 759348fb385STodd Fiala { 760348fb385STodd Fiala if (log) 761348fb385STodd Fiala log->Printf ("PlatformLinux::%s successfully created process", __FUNCTION__); 762348fb385STodd Fiala } 763348fb385STodd Fiala 764348fb385STodd Fiala // Adjust launch for a hijacker. 765348fb385STodd Fiala ListenerSP listener_sp; 766348fb385STodd Fiala if (!launch_info.GetHijackListener ()) 767348fb385STodd Fiala { 768348fb385STodd Fiala if (log) 769348fb385STodd Fiala log->Printf ("PlatformLinux::%s setting up hijacker", __FUNCTION__); 770348fb385STodd Fiala 771348fb385STodd Fiala listener_sp.reset (new Listener("lldb.PlatformLinux.DebugProcess.hijack")); 772348fb385STodd Fiala launch_info.SetHijackListener (listener_sp); 773348fb385STodd Fiala process_sp->HijackProcessEvents (listener_sp.get ()); 774348fb385STodd Fiala } 775348fb385STodd Fiala 776348fb385STodd Fiala // Log file actions. 777348fb385STodd Fiala if (log) 778348fb385STodd Fiala { 779348fb385STodd Fiala log->Printf ("PlatformLinux::%s launching process with the following file actions:", __FUNCTION__); 780348fb385STodd Fiala 781348fb385STodd Fiala StreamString stream; 782348fb385STodd Fiala size_t i = 0; 783348fb385STodd Fiala const FileAction *file_action; 784348fb385STodd Fiala while ((file_action = launch_info.GetFileActionAtIndex (i++)) != nullptr) 785348fb385STodd Fiala { 786348fb385STodd Fiala file_action->Dump (stream); 787348fb385STodd Fiala log->PutCString (stream.GetString().c_str ()); 788348fb385STodd Fiala stream.Clear(); 789348fb385STodd Fiala } 790348fb385STodd Fiala } 791348fb385STodd Fiala 792348fb385STodd Fiala // Do the launch. 793348fb385STodd Fiala error = process_sp->Launch(launch_info); 794348fb385STodd Fiala if (error.Success ()) 795348fb385STodd Fiala { 796348fb385STodd Fiala // Handle the hijacking of process events. 797348fb385STodd Fiala if (listener_sp) 798348fb385STodd Fiala { 799348fb385STodd Fiala const StateType state = process_sp->WaitForProcessToStop (NULL, NULL, false, listener_sp.get()); 800348fb385STodd Fiala 801348fb385STodd Fiala if (state == eStateStopped) 802348fb385STodd Fiala { 803348fb385STodd Fiala if (log) 804348fb385STodd Fiala log->Printf ("PlatformLinux::%s pid %" PRIu64 " state %s\n", 805348fb385STodd Fiala __FUNCTION__, process_sp->GetID (), StateAsCString (state)); 806348fb385STodd Fiala } 807348fb385STodd Fiala else 808348fb385STodd Fiala { 809348fb385STodd Fiala if (log) 810348fb385STodd Fiala log->Printf ("PlatformLinux::%s pid %" PRIu64 " state is not stopped - %s\n", 811348fb385STodd Fiala __FUNCTION__, process_sp->GetID (), StateAsCString (state)); 812348fb385STodd Fiala } 813348fb385STodd Fiala } 814348fb385STodd Fiala 815348fb385STodd Fiala // Hook up process PTY if we have one (which we should for local debugging with llgs). 816348fb385STodd Fiala int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor(); 817348fb385STodd Fiala if (pty_fd != lldb_utility::PseudoTerminal::invalid_fd) 818348fb385STodd Fiala { 819348fb385STodd Fiala process_sp->SetSTDIOFileDescriptor(pty_fd); 820348fb385STodd Fiala if (log) 821348fb385STodd Fiala log->Printf ("PlatformLinux::%s pid %" PRIu64 " hooked up STDIO pty to process", __FUNCTION__, process_sp->GetID ()); 822348fb385STodd Fiala } 823348fb385STodd Fiala else 824348fb385STodd Fiala { 825348fb385STodd Fiala if (log) 826348fb385STodd Fiala log->Printf ("PlatformLinux::%s pid %" PRIu64 " not using process STDIO pty", __FUNCTION__, process_sp->GetID ()); 82728041352SGreg Clayton } 82828041352SGreg Clayton } 82928041352SGreg Clayton else 83028041352SGreg Clayton { 831348fb385STodd Fiala if (log) 832348fb385STodd Fiala log->Printf ("PlatformLinux::%s process launch failed: %s", __FUNCTION__, error.AsCString ()); 833348fb385STodd Fiala // FIXME figure out appropriate cleanup here. Do we delete the target? Do we delete the process? Does our caller do that? 83428041352SGreg Clayton } 835348fb385STodd Fiala 83628041352SGreg Clayton return process_sp; 83713e8e1c3SJohnny Chen } 8382094dbf4SJason Molenda 8392094dbf4SJason Molenda void 8402094dbf4SJason Molenda PlatformLinux::CalculateTrapHandlerSymbolNames () 8412094dbf4SJason Molenda { 8422094dbf4SJason Molenda m_trap_handlers.push_back (ConstString ("_sigtramp")); 8432094dbf4SJason Molenda } 844af245d11STodd Fiala 84596ad3de5SRobert Flack uint64_t 846e0d8c422SMohit K. Bhakkad PlatformLinux::ConvertMmapFlagsToPlatform(const ArchSpec &arch, unsigned flags) 84796ad3de5SRobert Flack { 84896ad3de5SRobert Flack uint64_t flags_platform = 0; 849e0d8c422SMohit K. Bhakkad uint64_t map_anon = MAP_ANON; 850e0d8c422SMohit K. Bhakkad 851e0d8c422SMohit K. Bhakkad // To get correct flags for MIPS Architecture 852e0d8c422SMohit K. Bhakkad if (arch.GetTriple ().getArch () == llvm::Triple::mips64 853e0d8c422SMohit K. Bhakkad || arch.GetTriple ().getArch () == llvm::Triple::mips64el 854e0d8c422SMohit K. Bhakkad || arch.GetTriple ().getArch () == llvm::Triple::mips 855e0d8c422SMohit K. Bhakkad || arch.GetTriple ().getArch () == llvm::Triple::mipsel) 856e0d8c422SMohit K. Bhakkad map_anon = 0x800; 857e0d8c422SMohit K. Bhakkad 85896ad3de5SRobert Flack if (flags & eMmapFlagsPrivate) 85996ad3de5SRobert Flack flags_platform |= MAP_PRIVATE; 86096ad3de5SRobert Flack if (flags & eMmapFlagsAnon) 861e0d8c422SMohit K. Bhakkad flags_platform |= map_anon; 86296ad3de5SRobert Flack return flags_platform; 86396ad3de5SRobert Flack } 8646e25aeeaSEnrico Granata 8656e25aeeaSEnrico Granata ConstString 8666e25aeeaSEnrico Granata PlatformLinux::GetFullNameForDylib (ConstString basename) 8676e25aeeaSEnrico Granata { 8686e25aeeaSEnrico Granata if (basename.IsEmpty()) 8696e25aeeaSEnrico Granata return basename; 8706e25aeeaSEnrico Granata 8716e25aeeaSEnrico Granata StreamString stream; 8726e25aeeaSEnrico Granata stream.Printf("lib%s.so", basename.GetCString()); 8736e25aeeaSEnrico Granata return ConstString(stream.GetData()); 8746e25aeeaSEnrico Granata } 875