1e996fd30SGreg Clayton //===-- PlatformLinux.cpp ---------------------------------------*- C++ -*-===// 2e996fd30SGreg Clayton // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e996fd30SGreg Clayton // 7e996fd30SGreg Clayton //===----------------------------------------------------------------------===// 8e996fd30SGreg Clayton 9e996fd30SGreg Clayton #include "PlatformLinux.h" 10b2f1fb29SVirgile Bello #include "lldb/Host/Config.h" 11e996fd30SGreg Clayton 12ecc11474SStephen Wilson #include <stdio.h> 13b2f1fb29SVirgile Bello #ifndef LLDB_DISABLE_POSIX 14ecc11474SStephen Wilson #include <sys/utsname.h> 15b2f1fb29SVirgile Bello #endif 16ecc11474SStephen Wilson 1728041352SGreg Clayton #include "lldb/Core/Debugger.h" 18ecc11474SStephen Wilson #include "lldb/Core/PluginManager.h" 1913b18261SZachary Turner #include "lldb/Host/HostInfo.h" 20e996fd30SGreg Clayton #include "lldb/Target/Process.h" 21b9c1b51eSKate Stone #include "lldb/Target/Target.h" 225713a05bSZachary Turner #include "lldb/Utility/FileSpec.h" 236f9e6901SZachary Turner #include "lldb/Utility/Log.h" 24d821c997SPavel Labath #include "lldb/Utility/State.h" 2597206d57SZachary Turner #include "lldb/Utility/Status.h" 26bf9a7730SZachary Turner #include "lldb/Utility/StreamString.h" 27e996fd30SGreg Clayton 2805097246SAdrian Prantl // Define these constants from Linux mman.h for use when targeting remote linux 2905097246SAdrian Prantl // systems even when host has different values. 3096ad3de5SRobert Flack #define MAP_PRIVATE 2 3196ad3de5SRobert Flack #define MAP_ANON 0x20 3296ad3de5SRobert Flack 33e996fd30SGreg Clayton using namespace lldb; 34e996fd30SGreg Clayton using namespace lldb_private; 35db264a6dSTamas Berghammer using namespace lldb_private::platform_linux; 36e996fd30SGreg Clayton 3728041352SGreg Clayton static uint32_t g_initialize_count = 0; 3828041352SGreg Clayton 39281961a8STodd Fiala //------------------------------------------------------------------ 40281961a8STodd Fiala 41b9c1b51eSKate Stone PlatformSP PlatformLinux::CreateInstance(bool force, const ArchSpec *arch) { 42db264a6dSTamas Berghammer Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); 430e92fbb5SPavel Labath LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force, 440e92fbb5SPavel Labath arch ? arch->GetArchitectureName() : "<null>", 450e92fbb5SPavel Labath arch ? arch->GetTriple().getTriple() : "<null>"); 46015d818bSTodd Fiala 47b3a40ba8SGreg Clayton bool create = force; 48a6682a41SJonas Devlieghere if (!create && arch && arch->IsValid()) { 49b3a40ba8SGreg Clayton const llvm::Triple &triple = arch->GetTriple(); 50b9c1b51eSKate Stone switch (triple.getOS()) { 5170512317SGreg Clayton case llvm::Triple::Linux: 52b1da257aSTed Woodward create = true; 5370512317SGreg Clayton break; 5470512317SGreg Clayton 55dbc6c0bbSGreg Clayton #if defined(__linux__) 5605097246SAdrian Prantl // Only accept "unknown" for the OS if the host is linux and it "unknown" 5705097246SAdrian Prantl // wasn't specified (it was just returned because it was NOT specified) 58015d818bSTodd Fiala case llvm::Triple::OSType::UnknownOS: 5970512317SGreg Clayton create = !arch->TripleOSWasSpecified(); 6070512317SGreg Clayton break; 61dbc6c0bbSGreg Clayton #endif 6270512317SGreg Clayton default: 6370512317SGreg Clayton break; 6470512317SGreg Clayton } 6570512317SGreg Clayton } 66015d818bSTodd Fiala 670e92fbb5SPavel Labath LLDB_LOG(log, "create = {0}", create); 68b9c1b51eSKate Stone if (create) { 69615eb7e6SGreg Clayton return PlatformSP(new PlatformLinux(false)); 70015d818bSTodd Fiala } 71615eb7e6SGreg Clayton return PlatformSP(); 72ecc11474SStephen Wilson } 73ecc11474SStephen Wilson 74b9c1b51eSKate Stone ConstString PlatformLinux::GetPluginNameStatic(bool is_host) { 75b9c1b51eSKate Stone if (is_host) { 7657abc5d6SGreg Clayton static ConstString g_host_name(Platform::GetHostPlatformName()); 7757abc5d6SGreg Clayton return g_host_name; 78b9c1b51eSKate Stone } else { 7957abc5d6SGreg Clayton static ConstString g_remote_name("remote-linux"); 8057abc5d6SGreg Clayton return g_remote_name; 8157abc5d6SGreg Clayton } 8228041352SGreg Clayton } 8328041352SGreg Clayton 84b9c1b51eSKate Stone const char *PlatformLinux::GetPluginDescriptionStatic(bool is_host) { 8528041352SGreg Clayton if (is_host) 8628041352SGreg Clayton return "Local Linux user platform plug-in."; 8728041352SGreg Clayton else 8828041352SGreg Clayton return "Remote Linux user platform plug-in."; 89ecc11474SStephen Wilson } 90ecc11474SStephen Wilson 91b9c1b51eSKate Stone ConstString PlatformLinux::GetPluginName() { 9257abc5d6SGreg Clayton return GetPluginNameStatic(IsHost()); 9357abc5d6SGreg Clayton } 9457abc5d6SGreg Clayton 95b9c1b51eSKate Stone void PlatformLinux::Initialize() { 963c4f89d7STamas Berghammer PlatformPOSIX::Initialize(); 973c4f89d7STamas Berghammer 98b9c1b51eSKate Stone if (g_initialize_count++ == 0) { 991c6a1ea9STamas Berghammer #if defined(__linux__) && !defined(__ANDROID__) 10028041352SGreg Clayton PlatformSP default_platform_sp(new PlatformLinux(true)); 10113b18261SZachary Turner default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture()); 102615eb7e6SGreg Clayton Platform::SetHostPlatform(default_platform_sp); 10328041352SGreg Clayton #endif 104b9c1b51eSKate Stone PluginManager::RegisterPlugin( 105b9c1b51eSKate Stone PlatformLinux::GetPluginNameStatic(false), 10628041352SGreg Clayton PlatformLinux::GetPluginDescriptionStatic(false), 107d65ac229SPavel Labath PlatformLinux::CreateInstance, nullptr); 108ecc11474SStephen Wilson } 109e996fd30SGreg Clayton } 110e996fd30SGreg Clayton 111b9c1b51eSKate Stone void PlatformLinux::Terminate() { 112b9c1b51eSKate Stone if (g_initialize_count > 0) { 113b9c1b51eSKate Stone if (--g_initialize_count == 0) { 11428041352SGreg Clayton PluginManager::UnregisterPlugin(PlatformLinux::CreateInstance); 115e996fd30SGreg Clayton } 11628041352SGreg Clayton } 1173c4f89d7STamas Berghammer 1183c4f89d7STamas Berghammer PlatformPOSIX::Terminate(); 11928041352SGreg Clayton } 120e996fd30SGreg Clayton 121e996fd30SGreg Clayton //------------------------------------------------------------------ 122e996fd30SGreg Clayton /// Default Constructor 123e996fd30SGreg Clayton //------------------------------------------------------------------ 124b9c1b51eSKate Stone PlatformLinux::PlatformLinux(bool is_host) 125b9c1b51eSKate Stone : PlatformPOSIX(is_host) // This is the local host platform 126b9c1b51eSKate Stone {} 127e996fd30SGreg Clayton 128222b937cSEugene Zelenko PlatformLinux::~PlatformLinux() = default; 129e996fd30SGreg Clayton 130b9c1b51eSKate Stone bool PlatformLinux::GetSupportedArchitectureAtIndex(uint32_t idx, 131b9c1b51eSKate Stone ArchSpec &arch) { 132b9c1b51eSKate Stone if (IsHost()) { 133e49b8e06SRobert Flack ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault); 134b9c1b51eSKate Stone if (hostArch.GetTriple().isOSLinux()) { 135b9c1b51eSKate Stone if (idx == 0) { 136e49b8e06SRobert Flack arch = hostArch; 137e49b8e06SRobert Flack return arch.IsValid(); 138b9c1b51eSKate Stone } else if (idx == 1) { 13905097246SAdrian Prantl // If the default host architecture is 64-bit, look for a 32-bit 14005097246SAdrian Prantl // variant 141b9c1b51eSKate Stone if (hostArch.IsValid() && hostArch.GetTriple().isArch64Bit()) { 142e49b8e06SRobert Flack arch = HostInfo::GetArchitecture(HostInfo::eArchKind32); 143e49b8e06SRobert Flack return arch.IsValid(); 144e49b8e06SRobert Flack } 145e49b8e06SRobert Flack } 146e49b8e06SRobert Flack } 147b9c1b51eSKate Stone } else { 148e49b8e06SRobert Flack if (m_remote_platform_sp) 149e49b8e06SRobert Flack return m_remote_platform_sp->GetSupportedArchitectureAtIndex(idx, arch); 150bb1e283cSTed Woodward 151bb1e283cSTed Woodward llvm::Triple triple; 152bb1e283cSTed Woodward // Set the OS to linux 153bb1e283cSTed Woodward triple.setOS(llvm::Triple::Linux); 154bb1e283cSTed Woodward // Set the architecture 155b9c1b51eSKate Stone switch (idx) { 156b9c1b51eSKate Stone case 0: 157b9c1b51eSKate Stone triple.setArchName("x86_64"); 158b9c1b51eSKate Stone break; 159b9c1b51eSKate Stone case 1: 160b9c1b51eSKate Stone triple.setArchName("i386"); 161b9c1b51eSKate Stone break; 162b9c1b51eSKate Stone case 2: 163b9c1b51eSKate Stone triple.setArchName("arm"); 164b9c1b51eSKate Stone break; 165b9c1b51eSKate Stone case 3: 166b9c1b51eSKate Stone triple.setArchName("aarch64"); 167b9c1b51eSKate Stone break; 168b9c1b51eSKate Stone case 4: 169b9c1b51eSKate Stone triple.setArchName("mips64"); 170b9c1b51eSKate Stone break; 171b9c1b51eSKate Stone case 5: 172b9c1b51eSKate Stone triple.setArchName("hexagon"); 173b9c1b51eSKate Stone break; 174b9c1b51eSKate Stone case 6: 175b9c1b51eSKate Stone triple.setArchName("mips"); 176b9c1b51eSKate Stone break; 177b9c1b51eSKate Stone case 7: 178b9c1b51eSKate Stone triple.setArchName("mips64el"); 179b9c1b51eSKate Stone break; 180b9c1b51eSKate Stone case 8: 181b9c1b51eSKate Stone triple.setArchName("mipsel"); 182b9c1b51eSKate Stone break; 183b9c1b51eSKate Stone case 9: 184b9c1b51eSKate Stone triple.setArchName("s390x"); 185b9c1b51eSKate Stone break; 186b9c1b51eSKate Stone default: 187b9c1b51eSKate Stone return false; 188bb1e283cSTed Woodward } 189b9c1b51eSKate Stone // Leave the vendor as "llvm::Triple:UnknownVendor" and don't specify the 19005097246SAdrian Prantl // vendor by calling triple.SetVendorName("unknown") so that it is a 19105097246SAdrian Prantl // "unspecified unknown". This means when someone calls 19205097246SAdrian Prantl // triple.GetVendorName() it will return an empty string which indicates 19305097246SAdrian Prantl // that the vendor can be set when two architectures are merged 194bb1e283cSTed Woodward 195bb1e283cSTed Woodward // Now set the triple into "arch" and return true 196bb1e283cSTed Woodward arch.SetTriple(triple); 197bb1e283cSTed Woodward return true; 198e49b8e06SRobert Flack } 199e996fd30SGreg Clayton return false; 200e996fd30SGreg Clayton } 201ecc11474SStephen Wilson 202b9c1b51eSKate Stone void PlatformLinux::GetStatus(Stream &strm) { 2033be69dacSDaniel Malea Platform::GetStatus(strm); 204ecc11474SStephen Wilson 205b2f1fb29SVirgile Bello #ifndef LLDB_DISABLE_POSIX 206b743a803SStephane Sezer // Display local kernel information only when we are running in host mode. 20705097246SAdrian Prantl // Otherwise, we would end up printing non-Linux information (when running on 20805097246SAdrian Prantl // Mac OS for example). 209b9c1b51eSKate Stone if (IsHost()) { 210b2f1fb29SVirgile Bello struct utsname un; 211b2f1fb29SVirgile Bello 2123be69dacSDaniel Malea if (uname(&un)) 2133be69dacSDaniel Malea return; 2143be69dacSDaniel Malea 2153be69dacSDaniel Malea strm.Printf(" Kernel: %s\n", un.sysname); 2163be69dacSDaniel Malea strm.Printf(" Release: %s\n", un.release); 2173be69dacSDaniel Malea strm.Printf(" Version: %s\n", un.version); 218b743a803SStephane Sezer } 219b2f1fb29SVirgile Bello #endif 220ecc11474SStephen Wilson } 221ecc11474SStephen Wilson 222348fb385STodd Fiala int32_t 223b9c1b51eSKate Stone PlatformLinux::GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) { 224348fb385STodd Fiala int32_t resume_count = 0; 22528041352SGreg Clayton 226348fb385STodd Fiala // Always resume past the initial stop when we use eLaunchFlagDebug 227b9c1b51eSKate Stone if (launch_info.GetFlags().Test(eLaunchFlagDebug)) { 228348fb385STodd Fiala // Resume past the stop for the final exec into the true inferior. 229348fb385STodd Fiala ++resume_count; 230348fb385STodd Fiala } 231015d818bSTodd Fiala 232348fb385STodd Fiala // If we're not launching a shell, we're done. 23310687b0eSZachary Turner const FileSpec &shell = launch_info.GetShell(); 23410687b0eSZachary Turner if (!shell) 235348fb385STodd Fiala return resume_count; 236348fb385STodd Fiala 23710687b0eSZachary Turner std::string shell_string = shell.GetPath(); 238348fb385STodd Fiala // We're in a shell, so for sure we have to resume past the shell exec. 239348fb385STodd Fiala ++resume_count; 240348fb385STodd Fiala 241348fb385STodd Fiala // Figure out what shell we're planning on using. 24210687b0eSZachary Turner const char *shell_name = strrchr(shell_string.c_str(), '/'); 243348fb385STodd Fiala if (shell_name == NULL) 24410687b0eSZachary Turner shell_name = shell_string.c_str(); 24528041352SGreg Clayton else 246348fb385STodd Fiala shell_name++; 247348fb385STodd Fiala 248b9c1b51eSKate Stone if (strcmp(shell_name, "csh") == 0 || strcmp(shell_name, "tcsh") == 0 || 249b9c1b51eSKate Stone strcmp(shell_name, "zsh") == 0 || strcmp(shell_name, "sh") == 0) { 250348fb385STodd Fiala // These shells seem to re-exec themselves. Add another resume. 251348fb385STodd Fiala ++resume_count; 252ecc11474SStephen Wilson } 25313e8e1c3SJohnny Chen 254348fb385STodd Fiala return resume_count; 255348fb385STodd Fiala } 256348fb385STodd Fiala 257b9c1b51eSKate Stone bool PlatformLinux::CanDebugProcess() { 258b9c1b51eSKate Stone if (IsHost()) { 259b36f9178SPavel Labath return true; 260b9c1b51eSKate Stone } else { 261015d818bSTodd Fiala // If we're connected, we can debug. 262015d818bSTodd Fiala return IsConnected(); 263015d818bSTodd Fiala } 264348fb385STodd Fiala } 265015d818bSTodd Fiala 266*6c0bbfc0SRaphael Isemann std::vector<std::string> 267*6c0bbfc0SRaphael Isemann PlatformLinux::GetSystemIncludeDirectories(lldb::LanguageType lang) { 268*6c0bbfc0SRaphael Isemann std::string sys_root = GetSDKRootDirectory().AsCString(""); 269*6c0bbfc0SRaphael Isemann switch (lang) { 270*6c0bbfc0SRaphael Isemann case lldb::eLanguageTypeC: 271*6c0bbfc0SRaphael Isemann case lldb::eLanguageTypeC89: 272*6c0bbfc0SRaphael Isemann case lldb::eLanguageTypeC99: 273*6c0bbfc0SRaphael Isemann case lldb::eLanguageTypeC11: 274*6c0bbfc0SRaphael Isemann case lldb::eLanguageTypeC_plus_plus: 275*6c0bbfc0SRaphael Isemann case lldb::eLanguageTypeC_plus_plus_03: 276*6c0bbfc0SRaphael Isemann case lldb::eLanguageTypeC_plus_plus_11: 277*6c0bbfc0SRaphael Isemann case lldb::eLanguageTypeC_plus_plus_14: 278*6c0bbfc0SRaphael Isemann case lldb::eLanguageTypeObjC_plus_plus: 279*6c0bbfc0SRaphael Isemann return {sys_root + "/usr/include/"}; 280*6c0bbfc0SRaphael Isemann default: 281*6c0bbfc0SRaphael Isemann return {}; 282*6c0bbfc0SRaphael Isemann } 283*6c0bbfc0SRaphael Isemann } 284*6c0bbfc0SRaphael Isemann 285b9c1b51eSKate Stone // For local debugging, Linux will override the debug logic to use llgs-launch 28605097246SAdrian Prantl // rather than lldb-launch, llgs-attach. This differs from current lldb- 28705097246SAdrian Prantl // launch, debugserver-attach approach on MacOSX. 28813e8e1c3SJohnny Chen lldb::ProcessSP 289b9c1b51eSKate Stone PlatformLinux::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, 290b9c1b51eSKate Stone Target *target, // Can be NULL, if NULL create a new 291b9c1b51eSKate Stone // target, else use existing one 29297206d57SZachary Turner Status &error) { 293db264a6dSTamas Berghammer Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); 2940e92fbb5SPavel Labath LLDB_LOG(log, "target {0}", target); 29528041352SGreg Clayton 296348fb385STodd Fiala // If we're a remote host, use standard behavior from parent class. 297348fb385STodd Fiala if (!IsHost()) 2988012cadbSGreg Clayton return PlatformPOSIX::DebugProcess(launch_info, debugger, target, error); 299348fb385STodd Fiala 300348fb385STodd Fiala // 301b9c1b51eSKate Stone // For local debugging, we'll insist on having ProcessGDBRemote create the 302b9c1b51eSKate Stone // process. 303348fb385STodd Fiala // 304348fb385STodd Fiala 305348fb385STodd Fiala ProcessSP process_sp; 306348fb385STodd Fiala 307348fb385STodd Fiala // Make sure we stop at the entry point 308348fb385STodd Fiala launch_info.GetFlags().Set(eLaunchFlagDebug); 309348fb385STodd Fiala 310348fb385STodd Fiala // We always launch the process we are going to debug in a separate process 31105097246SAdrian Prantl // group, since then we can handle ^C interrupts ourselves w/o having to 31205097246SAdrian Prantl // worry about the target getting them as well. 313348fb385STodd Fiala launch_info.SetLaunchInSeparateProcessGroup(true); 314348fb385STodd Fiala 315348fb385STodd Fiala // Ensure we have a target. 316b9c1b51eSKate Stone if (target == nullptr) { 3170e92fbb5SPavel Labath LLDB_LOG(log, "creating new target"); 318348fb385STodd Fiala TargetSP new_target_sp; 319f9a07e9fSJonas Devlieghere error = debugger.GetTargetList().CreateTarget( 320f9a07e9fSJonas Devlieghere debugger, "", "", eLoadDependentsNo, nullptr, new_target_sp); 321b9c1b51eSKate Stone if (error.Fail()) { 3220e92fbb5SPavel Labath LLDB_LOG(log, "failed to create new target: {0}", error); 323348fb385STodd Fiala return process_sp; 324348fb385STodd Fiala } 325348fb385STodd Fiala 32628041352SGreg Clayton target = new_target_sp.get(); 327b9c1b51eSKate Stone if (!target) { 328348fb385STodd Fiala error.SetErrorString("CreateTarget() returned nullptr"); 3290e92fbb5SPavel Labath LLDB_LOG(log, "error: {0}", error); 330348fb385STodd Fiala return process_sp; 331348fb385STodd Fiala } 332348fb385STodd Fiala } 333348fb385STodd Fiala 334348fb385STodd Fiala // Mark target as currently selected target. 33528041352SGreg Clayton debugger.GetTargetList().SetSelectedTarget(target); 33628041352SGreg Clayton 337348fb385STodd Fiala // Now create the gdb-remote process. 3380e92fbb5SPavel Labath LLDB_LOG(log, "having target create process with gdb-remote plugin"); 339cb8c6998SPavel Labath process_sp = 340cb8c6998SPavel Labath target->CreateProcess(launch_info.GetListener(), "gdb-remote", nullptr); 34128041352SGreg Clayton 342b9c1b51eSKate Stone if (!process_sp) { 343348fb385STodd Fiala error.SetErrorString("CreateProcess() failed for gdb-remote process"); 3440e92fbb5SPavel Labath LLDB_LOG(log, "error: {0}", error); 345348fb385STodd Fiala return process_sp; 346348fb385STodd Fiala } 347348fb385STodd Fiala 3480e92fbb5SPavel Labath LLDB_LOG(log, "successfully created process"); 349348fb385STodd Fiala // Adjust launch for a hijacker. 350348fb385STodd Fiala ListenerSP listener_sp; 351b9c1b51eSKate Stone if (!launch_info.GetHijackListener()) { 3520e92fbb5SPavel Labath LLDB_LOG(log, "setting up hijacker"); 353b9c1b51eSKate Stone listener_sp = 354b9c1b51eSKate Stone Listener::MakeListener("lldb.PlatformLinux.DebugProcess.hijack"); 355348fb385STodd Fiala launch_info.SetHijackListener(listener_sp); 356583bbb1dSJim Ingham process_sp->HijackProcessEvents(listener_sp); 357348fb385STodd Fiala } 358348fb385STodd Fiala 359348fb385STodd Fiala // Log file actions. 360b9c1b51eSKate Stone if (log) { 3610e92fbb5SPavel Labath LLDB_LOG(log, "launching process with the following file actions:"); 362348fb385STodd Fiala StreamString stream; 363348fb385STodd Fiala size_t i = 0; 364348fb385STodd Fiala const FileAction *file_action; 365b9c1b51eSKate Stone while ((file_action = launch_info.GetFileActionAtIndex(i++)) != nullptr) { 366348fb385STodd Fiala file_action->Dump(stream); 3670e92fbb5SPavel Labath LLDB_LOG(log, "{0}", stream.GetData()); 368348fb385STodd Fiala stream.Clear(); 369348fb385STodd Fiala } 370348fb385STodd Fiala } 371348fb385STodd Fiala 372348fb385STodd Fiala // Do the launch. 373348fb385STodd Fiala error = process_sp->Launch(launch_info); 374b9c1b51eSKate Stone if (error.Success()) { 375348fb385STodd Fiala // Handle the hijacking of process events. 376b9c1b51eSKate Stone if (listener_sp) { 377b9c1b51eSKate Stone const StateType state = process_sp->WaitForProcessToStop( 378e3e21cfcSPavel Labath llvm::None, NULL, false, listener_sp); 379348fb385STodd Fiala 3800e92fbb5SPavel Labath LLDB_LOG(log, "pid {0} state {0}", process_sp->GetID(), state); 381348fb385STodd Fiala } 382348fb385STodd Fiala 383b9c1b51eSKate Stone // Hook up process PTY if we have one (which we should for local debugging 384b9c1b51eSKate Stone // with llgs). 385348fb385STodd Fiala int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor(); 38607d6f881SPavel Labath if (pty_fd != PseudoTerminal::invalid_fd) { 387348fb385STodd Fiala process_sp->SetSTDIOFileDescriptor(pty_fd); 3880e92fbb5SPavel Labath LLDB_LOG(log, "hooked up STDIO pty to process"); 3890e92fbb5SPavel Labath } else 3900e92fbb5SPavel Labath LLDB_LOG(log, "not using process STDIO pty"); 391b9c1b51eSKate Stone } else { 3920e92fbb5SPavel Labath LLDB_LOG(log, "process launch failed: {0}", error); 393b9c1b51eSKate Stone // FIXME figure out appropriate cleanup here. Do we delete the target? Do 394b9c1b51eSKate Stone // we delete the process? Does our caller do that? 39528041352SGreg Clayton } 396348fb385STodd Fiala 39728041352SGreg Clayton return process_sp; 39813e8e1c3SJohnny Chen } 3992094dbf4SJason Molenda 400b9c1b51eSKate Stone void PlatformLinux::CalculateTrapHandlerSymbolNames() { 4012094dbf4SJason Molenda m_trap_handlers.push_back(ConstString("_sigtramp")); 4022094dbf4SJason Molenda } 403af245d11STodd Fiala 40437c40af7SEd Maste MmapArgList PlatformLinux::GetMmapArgumentList(const ArchSpec &arch, 40537c40af7SEd Maste addr_t addr, addr_t length, 40637c40af7SEd Maste unsigned prot, unsigned flags, 40737c40af7SEd Maste addr_t fd, addr_t offset) { 40896ad3de5SRobert Flack uint64_t flags_platform = 0; 409e0d8c422SMohit K. Bhakkad uint64_t map_anon = MAP_ANON; 410e0d8c422SMohit K. Bhakkad 411e0d8c422SMohit K. Bhakkad // To get correct flags for MIPS Architecture 412b9c1b51eSKate Stone if (arch.GetTriple().getArch() == llvm::Triple::mips64 || 413b9c1b51eSKate Stone arch.GetTriple().getArch() == llvm::Triple::mips64el || 414b9c1b51eSKate Stone arch.GetTriple().getArch() == llvm::Triple::mips || 415b9c1b51eSKate Stone arch.GetTriple().getArch() == llvm::Triple::mipsel) 416e0d8c422SMohit K. Bhakkad map_anon = 0x800; 417e0d8c422SMohit K. Bhakkad 41896ad3de5SRobert Flack if (flags & eMmapFlagsPrivate) 41996ad3de5SRobert Flack flags_platform |= MAP_PRIVATE; 42096ad3de5SRobert Flack if (flags & eMmapFlagsAnon) 421e0d8c422SMohit K. Bhakkad flags_platform |= map_anon; 42237c40af7SEd Maste 42337c40af7SEd Maste MmapArgList args({addr, length, prot, flags_platform, fd, offset}); 42437c40af7SEd Maste return args; 42596ad3de5SRobert Flack } 4266e25aeeaSEnrico Granata 427