blob: 1adb93333fc8af4cbcda8c3f560f5a4558107356 [file] [log] [blame]
Todd Fiala6d6b55d2014-06-30 00:30:53 +00001//===-- 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
Todd Fiala6d6b55d2014-06-30 00:30:53 +000010// C Includes
Eugene Zelenkod70a6e72016-02-18 18:52:47 +000011// C++ Includes
12#include <climits>
13
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Target/ProcessInfo.h"
Todd Fiala6d6b55d2014-06-30 00:30:53 +000017
18using namespace lldb;
19using namespace lldb_private;
20
21ProcessInfo::ProcessInfo () :
22 m_executable (),
23 m_arguments (),
24 m_environment (),
25 m_uid (UINT32_MAX),
26 m_gid (UINT32_MAX),
27 m_arch(),
28 m_pid (LLDB_INVALID_PROCESS_ID)
29{
30}
31
32ProcessInfo::ProcessInfo (const char *name, const ArchSpec &arch, lldb::pid_t pid) :
33 m_executable (name, false),
34 m_arguments (),
35 m_environment(),
36 m_uid (UINT32_MAX),
37 m_gid (UINT32_MAX),
38 m_arch (arch),
39 m_pid (pid)
40{
41}
42
43void
44ProcessInfo::Clear ()
45{
46 m_executable.Clear();
47 m_arguments.Clear();
48 m_environment.Clear();
49 m_uid = UINT32_MAX;
50 m_gid = UINT32_MAX;
51 m_arch.Clear();
52 m_pid = LLDB_INVALID_PROCESS_ID;
53}
54
55const char *
56ProcessInfo::GetName() const
57{
58 return m_executable.GetFilename().GetCString();
59}
60
61size_t
62ProcessInfo::GetNameLength() const
63{
64 return m_executable.GetFilename().GetLength();
65}
66
67void
68ProcessInfo::SetExecutableFile (const FileSpec &exe_file, bool add_exe_file_as_first_arg)
69{
70 if (exe_file)
71 {
72 m_executable = exe_file;
73 if (add_exe_file_as_first_arg)
74 {
75 char filename[PATH_MAX];
76 if (exe_file.GetPath(filename, sizeof(filename)))
77 m_arguments.InsertArgumentAtIndex (0, filename);
78 }
79 }
80 else
81 {
82 m_executable.Clear();
83 }
84}
85
86const char *
87ProcessInfo::GetArg0 () const
88{
Eugene Zelenkod70a6e72016-02-18 18:52:47 +000089 return (m_arg0.empty() ? nullptr : m_arg0.c_str());
Todd Fiala6d6b55d2014-06-30 00:30:53 +000090}
91
92void
93ProcessInfo::SetArg0 (const char *arg)
94{
95 if (arg && arg[0])
96 m_arg0 = arg;
97 else
98 m_arg0.clear();
99}
100
101void
102ProcessInfo::SetArguments (char const **argv, bool first_arg_is_executable)
103{
104 m_arguments.SetArguments (argv);
105
106 // Is the first argument the executable?
107 if (first_arg_is_executable)
108 {
109 const char *first_arg = m_arguments.GetArgumentAtIndex (0);
110 if (first_arg)
111 {
112 // Yes the first argument is an executable, set it as the executable
113 // in the launch options. Don't resolve the file path as the path
114 // could be a remote platform path
115 const bool resolve = false;
116 m_executable.SetFile(first_arg, resolve);
117 }
118 }
119}
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000120
Todd Fiala6d6b55d2014-06-30 00:30:53 +0000121void
122ProcessInfo::SetArguments (const Args& args, bool first_arg_is_executable)
123{
124 // Copy all arguments
125 m_arguments = args;
126
127 // Is the first argument the executable?
128 if (first_arg_is_executable)
129 {
130 const char *first_arg = m_arguments.GetArgumentAtIndex (0);
131 if (first_arg)
132 {
133 // Yes the first argument is an executable, set it as the executable
134 // in the launch options. Don't resolve the file path as the path
135 // could be a remote platform path
136 const bool resolve = false;
137 m_executable.SetFile(first_arg, resolve);
138 }
139 }
140}