1 //===-- ProcessInfo.cpp -----------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Target/ProcessInfo.h" 11 12 // C Includes 13 // C++ Includes 14 #include <climits> 15 16 // Other libraries and framework includes 17 // Project includes 18 #include "lldb/Core/Stream.h" 19 #include "lldb/Host/PosixApi.h" 20 21 #include "llvm/ADT/SmallString.h" 22 23 using namespace lldb; 24 using namespace lldb_private; 25 26 ProcessInfo::ProcessInfo() 27 : m_executable(), m_arguments(), m_environment(), m_uid(UINT32_MAX), 28 m_gid(UINT32_MAX), m_arch(), m_pid(LLDB_INVALID_PROCESS_ID) {} 29 30 ProcessInfo::ProcessInfo(const char *name, const ArchSpec &arch, 31 lldb::pid_t pid) 32 : m_executable(name, false), m_arguments(), m_environment(), 33 m_uid(UINT32_MAX), m_gid(UINT32_MAX), m_arch(arch), m_pid(pid) {} 34 35 void ProcessInfo::Clear() { 36 m_executable.Clear(); 37 m_arguments.Clear(); 38 m_environment.Clear(); 39 m_uid = UINT32_MAX; 40 m_gid = UINT32_MAX; 41 m_arch.Clear(); 42 m_pid = LLDB_INVALID_PROCESS_ID; 43 } 44 45 const char *ProcessInfo::GetName() const { 46 return m_executable.GetFilename().GetCString(); 47 } 48 49 size_t ProcessInfo::GetNameLength() const { 50 return m_executable.GetFilename().GetLength(); 51 } 52 53 void ProcessInfo::Dump(Stream &s, Platform *platform) const { 54 s << "Executable: " << GetName() << "\n"; 55 s << "Triple: "; 56 m_arch.DumpTriple(s); 57 s << "\n"; 58 59 s << "Arguments:\n"; 60 m_arguments.Dump(s); 61 62 s << "Environment:\n"; 63 m_environment.Dump(s, "env"); 64 } 65 66 void ProcessInfo::SetExecutableFile(const FileSpec &exe_file, 67 bool add_exe_file_as_first_arg) { 68 if (exe_file) { 69 m_executable = exe_file; 70 if (add_exe_file_as_first_arg) { 71 llvm::SmallString<PATH_MAX> filename; 72 exe_file.GetPath(filename); 73 if (!filename.empty()) 74 m_arguments.InsertArgumentAtIndex(0, filename); 75 } 76 } else { 77 m_executable.Clear(); 78 } 79 } 80 81 llvm::StringRef ProcessInfo::GetArg0() const { 82 return m_arg0; 83 } 84 85 void ProcessInfo::SetArg0(llvm::StringRef arg) { 86 m_arg0 = arg; 87 } 88 89 void ProcessInfo::SetArguments(char const **argv, 90 bool first_arg_is_executable) { 91 m_arguments.SetArguments(argv); 92 93 // Is the first argument the executable? 94 if (first_arg_is_executable) { 95 const char *first_arg = m_arguments.GetArgumentAtIndex(0); 96 if (first_arg) { 97 // Yes the first argument is an executable, set it as the executable 98 // in the launch options. Don't resolve the file path as the path 99 // could be a remote platform path 100 const bool resolve = false; 101 m_executable.SetFile(first_arg, resolve); 102 } 103 } 104 } 105 106 void ProcessInfo::SetArguments(const Args &args, bool first_arg_is_executable) { 107 // Copy all arguments 108 m_arguments = args; 109 110 // Is the first argument the executable? 111 if (first_arg_is_executable) { 112 const char *first_arg = m_arguments.GetArgumentAtIndex(0); 113 if (first_arg) { 114 // Yes the first argument is an executable, set it as the executable 115 // in the launch options. Don't resolve the file path as the path 116 // could be a remote platform path 117 const bool resolve = false; 118 m_executable.SetFile(first_arg, resolve); 119 } 120 } 121 } 122