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 
40b9c1b51eSKate Stone PlatformSP PlatformLinux::CreateInstance(bool force, const ArchSpec *arch) {
41db264a6dSTamas Berghammer   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
420e92fbb5SPavel Labath   LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
430e92fbb5SPavel Labath            arch ? arch->GetArchitectureName() : "<null>",
440e92fbb5SPavel Labath            arch ? arch->GetTriple().getTriple() : "<null>");
45015d818bSTodd Fiala 
46b3a40ba8SGreg Clayton   bool create = force;
47a6682a41SJonas Devlieghere   if (!create && arch && arch->IsValid()) {
48b3a40ba8SGreg Clayton     const llvm::Triple &triple = arch->GetTriple();
49b9c1b51eSKate Stone     switch (triple.getOS()) {
5070512317SGreg Clayton     case llvm::Triple::Linux:
51b1da257aSTed Woodward       create = true;
5270512317SGreg Clayton       break;
5370512317SGreg Clayton 
54dbc6c0bbSGreg Clayton #if defined(__linux__)
5505097246SAdrian Prantl     // Only accept "unknown" for the OS if the host is linux and it "unknown"
5605097246SAdrian Prantl     // wasn't specified (it was just returned because it was NOT specified)
57015d818bSTodd Fiala     case llvm::Triple::OSType::UnknownOS:
5870512317SGreg Clayton       create = !arch->TripleOSWasSpecified();
5970512317SGreg Clayton       break;
60dbc6c0bbSGreg Clayton #endif
6170512317SGreg Clayton     default:
6270512317SGreg Clayton       break;
6370512317SGreg Clayton     }
6470512317SGreg Clayton   }
65015d818bSTodd Fiala 
660e92fbb5SPavel Labath   LLDB_LOG(log, "create = {0}", create);
67b9c1b51eSKate Stone   if (create) {
68615eb7e6SGreg Clayton     return PlatformSP(new PlatformLinux(false));
69015d818bSTodd Fiala   }
70615eb7e6SGreg Clayton   return PlatformSP();
71ecc11474SStephen Wilson }
72ecc11474SStephen Wilson 
73b9c1b51eSKate Stone ConstString PlatformLinux::GetPluginNameStatic(bool is_host) {
74b9c1b51eSKate Stone   if (is_host) {
7557abc5d6SGreg Clayton     static ConstString g_host_name(Platform::GetHostPlatformName());
7657abc5d6SGreg Clayton     return g_host_name;
77b9c1b51eSKate Stone   } else {
7857abc5d6SGreg Clayton     static ConstString g_remote_name("remote-linux");
7957abc5d6SGreg Clayton     return g_remote_name;
8057abc5d6SGreg Clayton   }
8128041352SGreg Clayton }
8228041352SGreg Clayton 
83b9c1b51eSKate Stone const char *PlatformLinux::GetPluginDescriptionStatic(bool is_host) {
8428041352SGreg Clayton   if (is_host)
8528041352SGreg Clayton     return "Local Linux user platform plug-in.";
8628041352SGreg Clayton   else
8728041352SGreg Clayton     return "Remote Linux user platform plug-in.";
88ecc11474SStephen Wilson }
89ecc11474SStephen Wilson 
90b9c1b51eSKate Stone ConstString PlatformLinux::GetPluginName() {
9157abc5d6SGreg Clayton   return GetPluginNameStatic(IsHost());
9257abc5d6SGreg Clayton }
9357abc5d6SGreg Clayton 
94b9c1b51eSKate Stone void PlatformLinux::Initialize() {
953c4f89d7STamas Berghammer   PlatformPOSIX::Initialize();
963c4f89d7STamas Berghammer 
97b9c1b51eSKate Stone   if (g_initialize_count++ == 0) {
981c6a1ea9STamas Berghammer #if defined(__linux__) && !defined(__ANDROID__)
9928041352SGreg Clayton     PlatformSP default_platform_sp(new PlatformLinux(true));
10013b18261SZachary Turner     default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
101615eb7e6SGreg Clayton     Platform::SetHostPlatform(default_platform_sp);
10228041352SGreg Clayton #endif
103b9c1b51eSKate Stone     PluginManager::RegisterPlugin(
104b9c1b51eSKate Stone         PlatformLinux::GetPluginNameStatic(false),
10528041352SGreg Clayton         PlatformLinux::GetPluginDescriptionStatic(false),
106d65ac229SPavel Labath         PlatformLinux::CreateInstance, nullptr);
107ecc11474SStephen Wilson   }
108e996fd30SGreg Clayton }
109e996fd30SGreg Clayton 
110b9c1b51eSKate Stone void PlatformLinux::Terminate() {
111b9c1b51eSKate Stone   if (g_initialize_count > 0) {
112b9c1b51eSKate Stone     if (--g_initialize_count == 0) {
11328041352SGreg Clayton       PluginManager::UnregisterPlugin(PlatformLinux::CreateInstance);
114e996fd30SGreg Clayton     }
11528041352SGreg Clayton   }
1163c4f89d7STamas Berghammer 
1173c4f89d7STamas Berghammer   PlatformPOSIX::Terminate();
11828041352SGreg Clayton }
119e996fd30SGreg Clayton 
120e996fd30SGreg Clayton /// Default Constructor
121b9c1b51eSKate Stone PlatformLinux::PlatformLinux(bool is_host)
122b9c1b51eSKate Stone     : PlatformPOSIX(is_host) // This is the local host platform
123b9c1b51eSKate Stone {}
124e996fd30SGreg Clayton 
125222b937cSEugene Zelenko PlatformLinux::~PlatformLinux() = default;
126e996fd30SGreg Clayton 
127b9c1b51eSKate Stone bool PlatformLinux::GetSupportedArchitectureAtIndex(uint32_t idx,
128b9c1b51eSKate Stone                                                     ArchSpec &arch) {
129b9c1b51eSKate Stone   if (IsHost()) {
130e49b8e06SRobert Flack     ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
131b9c1b51eSKate Stone     if (hostArch.GetTriple().isOSLinux()) {
132b9c1b51eSKate Stone       if (idx == 0) {
133e49b8e06SRobert Flack         arch = hostArch;
134e49b8e06SRobert Flack         return arch.IsValid();
135b9c1b51eSKate Stone       } else if (idx == 1) {
13605097246SAdrian Prantl         // If the default host architecture is 64-bit, look for a 32-bit
13705097246SAdrian Prantl         // variant
138b9c1b51eSKate Stone         if (hostArch.IsValid() && hostArch.GetTriple().isArch64Bit()) {
139e49b8e06SRobert Flack           arch = HostInfo::GetArchitecture(HostInfo::eArchKind32);
140e49b8e06SRobert Flack           return arch.IsValid();
141e49b8e06SRobert Flack         }
142e49b8e06SRobert Flack       }
143e49b8e06SRobert Flack     }
144b9c1b51eSKate Stone   } else {
145e49b8e06SRobert Flack     if (m_remote_platform_sp)
146e49b8e06SRobert Flack       return m_remote_platform_sp->GetSupportedArchitectureAtIndex(idx, arch);
147bb1e283cSTed Woodward 
148bb1e283cSTed Woodward     llvm::Triple triple;
149bb1e283cSTed Woodward     // Set the OS to linux
150bb1e283cSTed Woodward     triple.setOS(llvm::Triple::Linux);
151bb1e283cSTed Woodward     // Set the architecture
152b9c1b51eSKate Stone     switch (idx) {
153b9c1b51eSKate Stone     case 0:
154b9c1b51eSKate Stone       triple.setArchName("x86_64");
155b9c1b51eSKate Stone       break;
156b9c1b51eSKate Stone     case 1:
157b9c1b51eSKate Stone       triple.setArchName("i386");
158b9c1b51eSKate Stone       break;
159b9c1b51eSKate Stone     case 2:
160b9c1b51eSKate Stone       triple.setArchName("arm");
161b9c1b51eSKate Stone       break;
162b9c1b51eSKate Stone     case 3:
163b9c1b51eSKate Stone       triple.setArchName("aarch64");
164b9c1b51eSKate Stone       break;
165b9c1b51eSKate Stone     case 4:
166b9c1b51eSKate Stone       triple.setArchName("mips64");
167b9c1b51eSKate Stone       break;
168b9c1b51eSKate Stone     case 5:
169b9c1b51eSKate Stone       triple.setArchName("hexagon");
170b9c1b51eSKate Stone       break;
171b9c1b51eSKate Stone     case 6:
172b9c1b51eSKate Stone       triple.setArchName("mips");
173b9c1b51eSKate Stone       break;
174b9c1b51eSKate Stone     case 7:
175b9c1b51eSKate Stone       triple.setArchName("mips64el");
176b9c1b51eSKate Stone       break;
177b9c1b51eSKate Stone     case 8:
178b9c1b51eSKate Stone       triple.setArchName("mipsel");
179b9c1b51eSKate Stone       break;
180b9c1b51eSKate Stone     case 9:
181b9c1b51eSKate Stone       triple.setArchName("s390x");
182b9c1b51eSKate Stone       break;
183b9c1b51eSKate Stone     default:
184b9c1b51eSKate Stone       return false;
185bb1e283cSTed Woodward     }
186b9c1b51eSKate Stone     // Leave the vendor as "llvm::Triple:UnknownVendor" and don't specify the
18705097246SAdrian Prantl     // vendor by calling triple.SetVendorName("unknown") so that it is a
18805097246SAdrian Prantl     // "unspecified unknown". This means when someone calls
18905097246SAdrian Prantl     // triple.GetVendorName() it will return an empty string which indicates
19005097246SAdrian Prantl     // that the vendor can be set when two architectures are merged
191bb1e283cSTed Woodward 
192bb1e283cSTed Woodward     // Now set the triple into "arch" and return true
193bb1e283cSTed Woodward     arch.SetTriple(triple);
194bb1e283cSTed Woodward     return true;
195e49b8e06SRobert Flack   }
196e996fd30SGreg Clayton   return false;
197e996fd30SGreg Clayton }
198ecc11474SStephen Wilson 
199b9c1b51eSKate Stone void PlatformLinux::GetStatus(Stream &strm) {
2003be69dacSDaniel Malea   Platform::GetStatus(strm);
201ecc11474SStephen Wilson 
202b2f1fb29SVirgile Bello #ifndef LLDB_DISABLE_POSIX
203b743a803SStephane Sezer   // Display local kernel information only when we are running in host mode.
20405097246SAdrian Prantl   // Otherwise, we would end up printing non-Linux information (when running on
20505097246SAdrian Prantl   // Mac OS for example).
206b9c1b51eSKate Stone   if (IsHost()) {
207b2f1fb29SVirgile Bello     struct utsname un;
208b2f1fb29SVirgile Bello 
2093be69dacSDaniel Malea     if (uname(&un))
2103be69dacSDaniel Malea       return;
2113be69dacSDaniel Malea 
2123be69dacSDaniel Malea     strm.Printf("    Kernel: %s\n", un.sysname);
2133be69dacSDaniel Malea     strm.Printf("   Release: %s\n", un.release);
2143be69dacSDaniel Malea     strm.Printf("   Version: %s\n", un.version);
215b743a803SStephane Sezer   }
216b2f1fb29SVirgile Bello #endif
217ecc11474SStephen Wilson }
218ecc11474SStephen Wilson 
219348fb385STodd Fiala int32_t
220b9c1b51eSKate Stone PlatformLinux::GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) {
221348fb385STodd Fiala   int32_t resume_count = 0;
22228041352SGreg Clayton 
223348fb385STodd Fiala   // Always resume past the initial stop when we use eLaunchFlagDebug
224b9c1b51eSKate Stone   if (launch_info.GetFlags().Test(eLaunchFlagDebug)) {
225348fb385STodd Fiala     // Resume past the stop for the final exec into the true inferior.
226348fb385STodd Fiala     ++resume_count;
227348fb385STodd Fiala   }
228015d818bSTodd Fiala 
229348fb385STodd Fiala   // If we're not launching a shell, we're done.
23010687b0eSZachary Turner   const FileSpec &shell = launch_info.GetShell();
23110687b0eSZachary Turner   if (!shell)
232348fb385STodd Fiala     return resume_count;
233348fb385STodd Fiala 
23410687b0eSZachary Turner   std::string shell_string = shell.GetPath();
235348fb385STodd Fiala   // We're in a shell, so for sure we have to resume past the shell exec.
236348fb385STodd Fiala   ++resume_count;
237348fb385STodd Fiala 
238348fb385STodd Fiala   // Figure out what shell we're planning on using.
23910687b0eSZachary Turner   const char *shell_name = strrchr(shell_string.c_str(), '/');
240348fb385STodd Fiala   if (shell_name == NULL)
24110687b0eSZachary Turner     shell_name = shell_string.c_str();
24228041352SGreg Clayton   else
243348fb385STodd Fiala     shell_name++;
244348fb385STodd Fiala 
245b9c1b51eSKate Stone   if (strcmp(shell_name, "csh") == 0 || strcmp(shell_name, "tcsh") == 0 ||
246b9c1b51eSKate Stone       strcmp(shell_name, "zsh") == 0 || strcmp(shell_name, "sh") == 0) {
247348fb385STodd Fiala     // These shells seem to re-exec themselves.  Add another resume.
248348fb385STodd Fiala     ++resume_count;
249ecc11474SStephen Wilson   }
25013e8e1c3SJohnny Chen 
251348fb385STodd Fiala   return resume_count;
252348fb385STodd Fiala }
253348fb385STodd Fiala 
254b9c1b51eSKate Stone bool PlatformLinux::CanDebugProcess() {
255b9c1b51eSKate Stone   if (IsHost()) {
256b36f9178SPavel Labath     return true;
257b9c1b51eSKate Stone   } else {
258015d818bSTodd Fiala     // If we're connected, we can debug.
259015d818bSTodd Fiala     return IsConnected();
260015d818bSTodd Fiala   }
261348fb385STodd Fiala }
262015d818bSTodd Fiala 
2636c0bbfc0SRaphael Isemann std::vector<std::string>
2646c0bbfc0SRaphael Isemann PlatformLinux::GetSystemIncludeDirectories(lldb::LanguageType lang) {
2656c0bbfc0SRaphael Isemann   std::string sys_root = GetSDKRootDirectory().AsCString("");
2666c0bbfc0SRaphael Isemann   switch (lang) {
2676c0bbfc0SRaphael Isemann   case lldb::eLanguageTypeC:
2686c0bbfc0SRaphael Isemann   case lldb::eLanguageTypeC89:
2696c0bbfc0SRaphael Isemann   case lldb::eLanguageTypeC99:
2706c0bbfc0SRaphael Isemann   case lldb::eLanguageTypeC11:
2716c0bbfc0SRaphael Isemann   case lldb::eLanguageTypeC_plus_plus:
2726c0bbfc0SRaphael Isemann   case lldb::eLanguageTypeC_plus_plus_03:
2736c0bbfc0SRaphael Isemann   case lldb::eLanguageTypeC_plus_plus_11:
2746c0bbfc0SRaphael Isemann   case lldb::eLanguageTypeC_plus_plus_14:
2756c0bbfc0SRaphael Isemann   case lldb::eLanguageTypeObjC_plus_plus:
2766c0bbfc0SRaphael Isemann     return {sys_root + "/usr/include/"};
2776c0bbfc0SRaphael Isemann   default:
2786c0bbfc0SRaphael Isemann     return {};
2796c0bbfc0SRaphael Isemann   }
2806c0bbfc0SRaphael Isemann }
2816c0bbfc0SRaphael Isemann 
282b9c1b51eSKate Stone // For local debugging, Linux will override the debug logic to use llgs-launch
28305097246SAdrian Prantl // rather than lldb-launch, llgs-attach.  This differs from current lldb-
28405097246SAdrian Prantl // launch, debugserver-attach approach on MacOSX.
28513e8e1c3SJohnny Chen lldb::ProcessSP
286b9c1b51eSKate Stone PlatformLinux::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
287b9c1b51eSKate Stone                             Target *target, // Can be NULL, if NULL create a new
288b9c1b51eSKate Stone                                             // target, else use existing one
28997206d57SZachary Turner                             Status &error) {
290db264a6dSTamas Berghammer   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
2910e92fbb5SPavel Labath   LLDB_LOG(log, "target {0}", target);
29228041352SGreg Clayton 
293348fb385STodd Fiala   // If we're a remote host, use standard behavior from parent class.
294348fb385STodd Fiala   if (!IsHost())
2958012cadbSGreg Clayton     return PlatformPOSIX::DebugProcess(launch_info, debugger, target, error);
296348fb385STodd Fiala 
297348fb385STodd Fiala   //
298b9c1b51eSKate Stone   // For local debugging, we'll insist on having ProcessGDBRemote create the
299b9c1b51eSKate Stone   // process.
300348fb385STodd Fiala   //
301348fb385STodd Fiala 
302348fb385STodd Fiala   ProcessSP process_sp;
303348fb385STodd Fiala 
304348fb385STodd Fiala   // Make sure we stop at the entry point
305348fb385STodd Fiala   launch_info.GetFlags().Set(eLaunchFlagDebug);
306348fb385STodd Fiala 
307348fb385STodd Fiala   // We always launch the process we are going to debug in a separate process
30805097246SAdrian Prantl   // group, since then we can handle ^C interrupts ourselves w/o having to
30905097246SAdrian Prantl   // worry about the target getting them as well.
310348fb385STodd Fiala   launch_info.SetLaunchInSeparateProcessGroup(true);
311348fb385STodd Fiala 
312348fb385STodd Fiala   // Ensure we have a target.
313b9c1b51eSKate Stone   if (target == nullptr) {
3140e92fbb5SPavel Labath     LLDB_LOG(log, "creating new target");
315348fb385STodd Fiala     TargetSP new_target_sp;
316f9a07e9fSJonas Devlieghere     error = debugger.GetTargetList().CreateTarget(
317f9a07e9fSJonas Devlieghere         debugger, "", "", eLoadDependentsNo, nullptr, new_target_sp);
318b9c1b51eSKate Stone     if (error.Fail()) {
3190e92fbb5SPavel Labath       LLDB_LOG(log, "failed to create new target: {0}", error);
320348fb385STodd Fiala       return process_sp;
321348fb385STodd Fiala     }
322348fb385STodd Fiala 
32328041352SGreg Clayton     target = new_target_sp.get();
324b9c1b51eSKate Stone     if (!target) {
325348fb385STodd Fiala       error.SetErrorString("CreateTarget() returned nullptr");
3260e92fbb5SPavel Labath       LLDB_LOG(log, "error: {0}", error);
327348fb385STodd Fiala       return process_sp;
328348fb385STodd Fiala     }
329348fb385STodd Fiala   }
330348fb385STodd Fiala 
331348fb385STodd Fiala   // Mark target as currently selected target.
33228041352SGreg Clayton   debugger.GetTargetList().SetSelectedTarget(target);
33328041352SGreg Clayton 
334348fb385STodd Fiala   // Now create the gdb-remote process.
3350e92fbb5SPavel Labath   LLDB_LOG(log, "having target create process with gdb-remote plugin");
336cb8c6998SPavel Labath   process_sp =
337cb8c6998SPavel Labath       target->CreateProcess(launch_info.GetListener(), "gdb-remote", nullptr);
33828041352SGreg Clayton 
339b9c1b51eSKate Stone   if (!process_sp) {
340348fb385STodd Fiala     error.SetErrorString("CreateProcess() failed for gdb-remote process");
3410e92fbb5SPavel Labath     LLDB_LOG(log, "error: {0}", error);
342348fb385STodd Fiala     return process_sp;
343348fb385STodd Fiala   }
344348fb385STodd Fiala 
3450e92fbb5SPavel Labath   LLDB_LOG(log, "successfully created process");
346348fb385STodd Fiala   // Adjust launch for a hijacker.
347348fb385STodd Fiala   ListenerSP listener_sp;
348b9c1b51eSKate Stone   if (!launch_info.GetHijackListener()) {
3490e92fbb5SPavel Labath     LLDB_LOG(log, "setting up hijacker");
350b9c1b51eSKate Stone     listener_sp =
351b9c1b51eSKate Stone         Listener::MakeListener("lldb.PlatformLinux.DebugProcess.hijack");
352348fb385STodd Fiala     launch_info.SetHijackListener(listener_sp);
353583bbb1dSJim Ingham     process_sp->HijackProcessEvents(listener_sp);
354348fb385STodd Fiala   }
355348fb385STodd Fiala 
356348fb385STodd Fiala   // Log file actions.
357b9c1b51eSKate Stone   if (log) {
3580e92fbb5SPavel Labath     LLDB_LOG(log, "launching process with the following file actions:");
359348fb385STodd Fiala     StreamString stream;
360348fb385STodd Fiala     size_t i = 0;
361348fb385STodd Fiala     const FileAction *file_action;
362b9c1b51eSKate Stone     while ((file_action = launch_info.GetFileActionAtIndex(i++)) != nullptr) {
363348fb385STodd Fiala       file_action->Dump(stream);
3640e92fbb5SPavel Labath       LLDB_LOG(log, "{0}", stream.GetData());
365348fb385STodd Fiala       stream.Clear();
366348fb385STodd Fiala     }
367348fb385STodd Fiala   }
368348fb385STodd Fiala 
369348fb385STodd Fiala   // Do the launch.
370348fb385STodd Fiala   error = process_sp->Launch(launch_info);
371b9c1b51eSKate Stone   if (error.Success()) {
372348fb385STodd Fiala     // Handle the hijacking of process events.
373b9c1b51eSKate Stone     if (listener_sp) {
374b9c1b51eSKate Stone       const StateType state = process_sp->WaitForProcessToStop(
375e3e21cfcSPavel Labath           llvm::None, NULL, false, listener_sp);
376348fb385STodd Fiala 
3770e92fbb5SPavel Labath       LLDB_LOG(log, "pid {0} state {0}", process_sp->GetID(), state);
378348fb385STodd Fiala     }
379348fb385STodd Fiala 
380b9c1b51eSKate Stone     // Hook up process PTY if we have one (which we should for local debugging
381b9c1b51eSKate Stone     // with llgs).
382348fb385STodd Fiala     int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor();
38307d6f881SPavel Labath     if (pty_fd != PseudoTerminal::invalid_fd) {
384348fb385STodd Fiala       process_sp->SetSTDIOFileDescriptor(pty_fd);
3850e92fbb5SPavel Labath       LLDB_LOG(log, "hooked up STDIO pty to process");
3860e92fbb5SPavel Labath     } else
3870e92fbb5SPavel Labath       LLDB_LOG(log, "not using process STDIO pty");
388b9c1b51eSKate Stone   } else {
3890e92fbb5SPavel Labath     LLDB_LOG(log, "process launch failed: {0}", error);
390b9c1b51eSKate Stone     // FIXME figure out appropriate cleanup here.  Do we delete the target? Do
391b9c1b51eSKate Stone     // we delete the process?  Does our caller do that?
39228041352SGreg Clayton   }
393348fb385STodd Fiala 
39428041352SGreg Clayton   return process_sp;
39513e8e1c3SJohnny Chen }
3962094dbf4SJason Molenda 
397b9c1b51eSKate Stone void PlatformLinux::CalculateTrapHandlerSymbolNames() {
3982094dbf4SJason Molenda   m_trap_handlers.push_back(ConstString("_sigtramp"));
3992094dbf4SJason Molenda }
400af245d11STodd Fiala 
40137c40af7SEd Maste MmapArgList PlatformLinux::GetMmapArgumentList(const ArchSpec &arch,
40237c40af7SEd Maste                                                addr_t addr, addr_t length,
40337c40af7SEd Maste                                                unsigned prot, unsigned flags,
40437c40af7SEd Maste                                                addr_t fd, addr_t offset) {
40596ad3de5SRobert Flack   uint64_t flags_platform = 0;
406*ddb93b63SFangrui Song   uint64_t map_anon = arch.IsMIPS() ? 0x800 : MAP_ANON;
407e0d8c422SMohit K. Bhakkad 
40896ad3de5SRobert Flack   if (flags & eMmapFlagsPrivate)
40996ad3de5SRobert Flack     flags_platform |= MAP_PRIVATE;
41096ad3de5SRobert Flack   if (flags & eMmapFlagsAnon)
411e0d8c422SMohit K. Bhakkad     flags_platform |= map_anon;
41237c40af7SEd Maste 
41337c40af7SEd Maste   MmapArgList args({addr, length, prot, flags_platform, fd, offset});
41437c40af7SEd Maste   return args;
41596ad3de5SRobert Flack }
4166e25aeeaSEnrico Granata 
417