1 //===-- ProcessInfo.cpp -----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Target/ProcessInfo.h"
16 // Other libraries and framework includes
18 #include "lldb/Host/PosixApi.h"
19 #include "lldb/Utility/Stream.h"
21 #include "llvm/ADT/SmallString.h"
24 using namespace lldb_private;
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) {}
30 ProcessInfo::ProcessInfo(const char *name, const ArchSpec &arch,
32 : m_executable(name, false), m_arguments(), m_environment(),
33 m_uid(UINT32_MAX), m_gid(UINT32_MAX), m_arch(arch), m_pid(pid) {}
35 void ProcessInfo::Clear() {
38 m_environment.Clear();
42 m_pid = LLDB_INVALID_PROCESS_ID;
45 const char *ProcessInfo::GetName() const {
46 return m_executable.GetFilename().GetCString();
49 size_t ProcessInfo::GetNameLength() const {
50 return m_executable.GetFilename().GetLength();
53 void ProcessInfo::Dump(Stream &s, Platform *platform) const {
54 s << "Executable: " << GetName() << "\n";
62 s << "Environment:\n";
63 m_environment.Dump(s, "env");
66 void ProcessInfo::SetExecutableFile(const FileSpec &exe_file,
67 bool add_exe_file_as_first_arg) {
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);
81 llvm::StringRef ProcessInfo::GetArg0() const {
85 void ProcessInfo::SetArg0(llvm::StringRef arg) {
89 void ProcessInfo::SetArguments(char const **argv,
90 bool first_arg_is_executable) {
91 m_arguments.SetArguments(argv);
93 // Is the first argument the executable?
94 if (first_arg_is_executable) {
95 const char *first_arg = m_arguments.GetArgumentAtIndex(0);
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);
106 void ProcessInfo::SetArguments(const Args &args, bool first_arg_is_executable) {
107 // Copy all arguments
110 // Is the first argument the executable?
111 if (first_arg_is_executable) {
112 const char *first_arg = m_arguments.GetArgumentAtIndex(0);
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);