summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/lldb/source/Target/ProcessInfo.cpp
blob: 22da2c6a2a29e3cbfffa90acf3fa7da560193f45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//===-- ProcessInfo.cpp -----------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "lldb/Target/ProcessInfo.h"

// C Includes
#include <limits.h>

using namespace lldb;
using namespace lldb_private;

ProcessInfo::ProcessInfo () :
    m_executable (),
    m_arguments (),
    m_environment (),
    m_uid (UINT32_MAX),
    m_gid (UINT32_MAX),
    m_arch(),
    m_pid (LLDB_INVALID_PROCESS_ID)
{
}

ProcessInfo::ProcessInfo (const char *name, const ArchSpec &arch, lldb::pid_t pid) :
    m_executable (name, false),
    m_arguments (),
    m_environment(),
    m_uid (UINT32_MAX),
    m_gid (UINT32_MAX),
    m_arch (arch),
    m_pid (pid)
{
}

void
ProcessInfo::Clear ()
{
    m_executable.Clear();
    m_arguments.Clear();
    m_environment.Clear();
    m_uid = UINT32_MAX;
    m_gid = UINT32_MAX;
    m_arch.Clear();
    m_pid = LLDB_INVALID_PROCESS_ID;
}

const char *
ProcessInfo::GetName() const
{
    return m_executable.GetFilename().GetCString();
}

size_t
ProcessInfo::GetNameLength() const
{
    return m_executable.GetFilename().GetLength();
}

void
ProcessInfo::SetExecutableFile (const FileSpec &exe_file, bool add_exe_file_as_first_arg)
{
    if (exe_file)
    {
        m_executable = exe_file;
        if (add_exe_file_as_first_arg)
        {
            char filename[PATH_MAX];
            if (exe_file.GetPath(filename, sizeof(filename)))
                m_arguments.InsertArgumentAtIndex (0, filename);
        }
    }
    else
    {
        m_executable.Clear();
    }
}

const char *
ProcessInfo::GetArg0 () const
{
    if (m_arg0.empty())
        return NULL;
    return m_arg0.c_str();
}

void
ProcessInfo::SetArg0 (const char *arg)
{
    if (arg && arg[0])
        m_arg0 = arg;
    else
        m_arg0.clear();
}

void
ProcessInfo::SetArguments (char const **argv, bool first_arg_is_executable)
{
    m_arguments.SetArguments (argv);

    // Is the first argument the executable?
    if (first_arg_is_executable)
    {
        const char *first_arg = m_arguments.GetArgumentAtIndex (0);
        if (first_arg)
        {
            // Yes the first argument is an executable, set it as the executable
            // in the launch options. Don't resolve the file path as the path
            // could be a remote platform path
            const bool resolve = false;
            m_executable.SetFile(first_arg, resolve);
        }
    }
}
void
ProcessInfo::SetArguments (const Args& args, bool first_arg_is_executable)
{
    // Copy all arguments
    m_arguments = args;

    // Is the first argument the executable?
    if (first_arg_is_executable)
    {
        const char *first_arg = m_arguments.GetArgumentAtIndex (0);
        if (first_arg)
        {
            // Yes the first argument is an executable, set it as the executable
            // in the launch options. Don't resolve the file path as the path
            // could be a remote platform path
            const bool resolve = false;
            m_executable.SetFile(first_arg, resolve);
        }
    }
}
OpenPOWER on IntegriCloud