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