]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Target/ProcessInfo.cpp
Merge ^/head r304236 through r304536.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Target / ProcessInfo.cpp
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 // C Includes
11 // C++ Includes
12 #include <climits>
13
14 // Other libraries and framework includes
15 // Project includes
16 #include "lldb/Target/ProcessInfo.h"
17
18 #include "lldb/Core/Stream.h"
19
20 using namespace lldb;
21 using namespace lldb_private;
22
23 ProcessInfo::ProcessInfo () :
24     m_executable (),
25     m_arguments (),
26     m_environment (),
27     m_uid (UINT32_MAX),
28     m_gid (UINT32_MAX),
29     m_arch(),
30     m_pid (LLDB_INVALID_PROCESS_ID)
31 {
32 }
33
34 ProcessInfo::ProcessInfo (const char *name, const ArchSpec &arch, lldb::pid_t pid) :
35     m_executable (name, false),
36     m_arguments (),
37     m_environment(),
38     m_uid (UINT32_MAX),
39     m_gid (UINT32_MAX),
40     m_arch (arch),
41     m_pid (pid)
42 {
43 }
44
45 void
46 ProcessInfo::Clear ()
47 {
48     m_executable.Clear();
49     m_arguments.Clear();
50     m_environment.Clear();
51     m_uid = UINT32_MAX;
52     m_gid = UINT32_MAX;
53     m_arch.Clear();
54     m_pid = LLDB_INVALID_PROCESS_ID;
55 }
56
57 const char *
58 ProcessInfo::GetName() const
59 {
60     return m_executable.GetFilename().GetCString();
61 }
62
63 size_t
64 ProcessInfo::GetNameLength() const
65 {
66     return m_executable.GetFilename().GetLength();
67 }
68
69 void
70 ProcessInfo::Dump (Stream &s, Platform *platform) const
71 {
72     s << "Executable: " << GetName() << "\n";
73     s << "Triple: ";
74     m_arch.DumpTriple(s);
75     s << "\n";
76
77     s << "Arguments:\n";
78     m_arguments.Dump(s);
79
80     s << "Environment:\n";
81     m_environment.Dump(s, "env");
82 }
83
84 void
85 ProcessInfo::SetExecutableFile (const FileSpec &exe_file, bool add_exe_file_as_first_arg)
86 {
87     if (exe_file)
88     {
89         m_executable = exe_file;
90         if (add_exe_file_as_first_arg)
91         {
92             char filename[PATH_MAX];
93             if (exe_file.GetPath(filename, sizeof(filename)))
94                 m_arguments.InsertArgumentAtIndex (0, filename);
95         }
96     }
97     else
98     {
99         m_executable.Clear();
100     }
101 }
102
103 const char *
104 ProcessInfo::GetArg0 () const
105 {
106     return (m_arg0.empty() ? nullptr : m_arg0.c_str());
107 }
108
109 void
110 ProcessInfo::SetArg0 (const char *arg)
111 {
112     if (arg && arg[0])
113         m_arg0 = arg;
114     else
115         m_arg0.clear();
116 }
117
118 void
119 ProcessInfo::SetArguments (char const **argv, bool first_arg_is_executable)
120 {
121     m_arguments.SetArguments (argv);
122
123     // Is the first argument the executable?
124     if (first_arg_is_executable)
125     {
126         const char *first_arg = m_arguments.GetArgumentAtIndex (0);
127         if (first_arg)
128         {
129             // Yes the first argument is an executable, set it as the executable
130             // in the launch options. Don't resolve the file path as the path
131             // could be a remote platform path
132             const bool resolve = false;
133             m_executable.SetFile(first_arg, resolve);
134         }
135     }
136 }
137
138 void
139 ProcessInfo::SetArguments (const Args& args, bool first_arg_is_executable)
140 {
141     // Copy all arguments
142     m_arguments = args;
143
144     // Is the first argument the executable?
145     if (first_arg_is_executable)
146     {
147         const char *first_arg = m_arguments.GetArgumentAtIndex (0);
148         if (first_arg)
149         {
150             // Yes the first argument is an executable, set it as the executable
151             // in the launch options. Don't resolve the file path as the path
152             // could be a remote platform path
153             const bool resolve = false;
154             m_executable.SetFile(first_arg, resolve);
155         }
156     }
157 }