180814287SRaphael Isemann //===-- SBAttachInfo.cpp --------------------------------------------------===//
271d08b3fSOleksiy Vyalov //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
671d08b3fSOleksiy Vyalov //
771d08b3fSOleksiy Vyalov //===----------------------------------------------------------------------===//
871d08b3fSOleksiy Vyalov 
971d08b3fSOleksiy Vyalov #include "lldb/API/SBAttachInfo.h"
10bd4bf82aSJonas Devlieghere #include "Utils.h"
1171d08b3fSOleksiy Vyalov #include "lldb/API/SBFileSpec.h"
1271d08b3fSOleksiy Vyalov #include "lldb/API/SBListener.h"
1371d08b3fSOleksiy Vyalov #include "lldb/Target/Process.h"
14*1755f5b1SJonas Devlieghere #include "lldb/Utility/Instrumentation.h"
1571d08b3fSOleksiy Vyalov 
1671d08b3fSOleksiy Vyalov using namespace lldb;
1771d08b3fSOleksiy Vyalov using namespace lldb_private;
1871d08b3fSOleksiy Vyalov 
SBAttachInfo()19baf5664fSJonas Devlieghere SBAttachInfo::SBAttachInfo() : m_opaque_sp(new ProcessAttachInfo()) {
20*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
21baf5664fSJonas Devlieghere }
2271d08b3fSOleksiy Vyalov 
SBAttachInfo(lldb::pid_t pid)23b9c1b51eSKate Stone SBAttachInfo::SBAttachInfo(lldb::pid_t pid)
24b9c1b51eSKate Stone     : m_opaque_sp(new ProcessAttachInfo()) {
25*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, pid);
26baf5664fSJonas Devlieghere 
2771d08b3fSOleksiy Vyalov   m_opaque_sp->SetProcessID(pid);
2871d08b3fSOleksiy Vyalov }
2971d08b3fSOleksiy Vyalov 
SBAttachInfo(const char * path,bool wait_for)30b9c1b51eSKate Stone SBAttachInfo::SBAttachInfo(const char *path, bool wait_for)
31b9c1b51eSKate Stone     : m_opaque_sp(new ProcessAttachInfo()) {
32*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, path, wait_for);
33baf5664fSJonas Devlieghere 
3471d08b3fSOleksiy Vyalov   if (path && path[0])
358f3be7a3SJonas Devlieghere     m_opaque_sp->GetExecutableFile().SetFile(path, FileSpec::Style::native);
3671d08b3fSOleksiy Vyalov   m_opaque_sp->SetWaitForLaunch(wait_for);
3771d08b3fSOleksiy Vyalov }
3871d08b3fSOleksiy Vyalov 
SBAttachInfo(const char * path,bool wait_for,bool async)39b9c1b51eSKate Stone SBAttachInfo::SBAttachInfo(const char *path, bool wait_for, bool async)
40b9c1b51eSKate Stone     : m_opaque_sp(new ProcessAttachInfo()) {
41*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, path, wait_for, async);
42baf5664fSJonas Devlieghere 
43b3788eafSGreg Clayton   if (path && path[0])
448f3be7a3SJonas Devlieghere     m_opaque_sp->GetExecutableFile().SetFile(path, FileSpec::Style::native);
45b3788eafSGreg Clayton   m_opaque_sp->SetWaitForLaunch(wait_for);
46b3788eafSGreg Clayton   m_opaque_sp->SetAsync(async);
47b3788eafSGreg Clayton }
48b3788eafSGreg Clayton 
SBAttachInfo(const SBAttachInfo & rhs)49b9c1b51eSKate Stone SBAttachInfo::SBAttachInfo(const SBAttachInfo &rhs)
50b9c1b51eSKate Stone     : m_opaque_sp(new ProcessAttachInfo()) {
51*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, rhs);
52baf5664fSJonas Devlieghere 
53bd4bf82aSJonas Devlieghere   m_opaque_sp = clone(rhs.m_opaque_sp);
5471d08b3fSOleksiy Vyalov }
5571d08b3fSOleksiy Vyalov 
56866b7a65SJonas Devlieghere SBAttachInfo::~SBAttachInfo() = default;
5771d08b3fSOleksiy Vyalov 
ref()58b9c1b51eSKate Stone lldb_private::ProcessAttachInfo &SBAttachInfo::ref() { return *m_opaque_sp; }
5971d08b3fSOleksiy Vyalov 
operator =(const SBAttachInfo & rhs)60b9c1b51eSKate Stone SBAttachInfo &SBAttachInfo::operator=(const SBAttachInfo &rhs) {
61*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, rhs);
62baf5664fSJonas Devlieghere 
6371d08b3fSOleksiy Vyalov   if (this != &rhs)
64bd4bf82aSJonas Devlieghere     m_opaque_sp = clone(rhs.m_opaque_sp);
65d232abc3SJonas Devlieghere   return *this;
6671d08b3fSOleksiy Vyalov }
6771d08b3fSOleksiy Vyalov 
GetProcessID()68baf5664fSJonas Devlieghere lldb::pid_t SBAttachInfo::GetProcessID() {
69*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
70baf5664fSJonas Devlieghere 
71baf5664fSJonas Devlieghere   return m_opaque_sp->GetProcessID();
72baf5664fSJonas Devlieghere }
7371d08b3fSOleksiy Vyalov 
SetProcessID(lldb::pid_t pid)74b9c1b51eSKate Stone void SBAttachInfo::SetProcessID(lldb::pid_t pid) {
75*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, pid);
76baf5664fSJonas Devlieghere 
7771d08b3fSOleksiy Vyalov   m_opaque_sp->SetProcessID(pid);
7871d08b3fSOleksiy Vyalov }
7971d08b3fSOleksiy Vyalov 
GetResumeCount()80b9c1b51eSKate Stone uint32_t SBAttachInfo::GetResumeCount() {
81*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
82baf5664fSJonas Devlieghere 
8371d08b3fSOleksiy Vyalov   return m_opaque_sp->GetResumeCount();
8471d08b3fSOleksiy Vyalov }
8571d08b3fSOleksiy Vyalov 
SetResumeCount(uint32_t c)86b9c1b51eSKate Stone void SBAttachInfo::SetResumeCount(uint32_t c) {
87*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, c);
88baf5664fSJonas Devlieghere 
8971d08b3fSOleksiy Vyalov   m_opaque_sp->SetResumeCount(c);
9071d08b3fSOleksiy Vyalov }
9171d08b3fSOleksiy Vyalov 
GetProcessPluginName()92b9c1b51eSKate Stone const char *SBAttachInfo::GetProcessPluginName() {
93*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
94baf5664fSJonas Devlieghere 
9571d08b3fSOleksiy Vyalov   return m_opaque_sp->GetProcessPluginName();
9671d08b3fSOleksiy Vyalov }
9771d08b3fSOleksiy Vyalov 
SetProcessPluginName(const char * plugin_name)98b9c1b51eSKate Stone void SBAttachInfo::SetProcessPluginName(const char *plugin_name) {
99*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, plugin_name);
100baf5664fSJonas Devlieghere 
10171d08b3fSOleksiy Vyalov   return m_opaque_sp->SetProcessPluginName(plugin_name);
10271d08b3fSOleksiy Vyalov }
10371d08b3fSOleksiy Vyalov 
SetExecutable(const char * path)104b9c1b51eSKate Stone void SBAttachInfo::SetExecutable(const char *path) {
105*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, path);
106baf5664fSJonas Devlieghere 
10771d08b3fSOleksiy Vyalov   if (path && path[0])
1088f3be7a3SJonas Devlieghere     m_opaque_sp->GetExecutableFile().SetFile(path, FileSpec::Style::native);
10971d08b3fSOleksiy Vyalov   else
11071d08b3fSOleksiy Vyalov     m_opaque_sp->GetExecutableFile().Clear();
11171d08b3fSOleksiy Vyalov }
11271d08b3fSOleksiy Vyalov 
SetExecutable(SBFileSpec exe_file)113b9c1b51eSKate Stone void SBAttachInfo::SetExecutable(SBFileSpec exe_file) {
114*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, exe_file);
115baf5664fSJonas Devlieghere 
11671d08b3fSOleksiy Vyalov   if (exe_file.IsValid())
11771d08b3fSOleksiy Vyalov     m_opaque_sp->GetExecutableFile() = exe_file.ref();
11871d08b3fSOleksiy Vyalov   else
11971d08b3fSOleksiy Vyalov     m_opaque_sp->GetExecutableFile().Clear();
12071d08b3fSOleksiy Vyalov }
12171d08b3fSOleksiy Vyalov 
GetWaitForLaunch()122b9c1b51eSKate Stone bool SBAttachInfo::GetWaitForLaunch() {
123*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
124baf5664fSJonas Devlieghere 
12571d08b3fSOleksiy Vyalov   return m_opaque_sp->GetWaitForLaunch();
12671d08b3fSOleksiy Vyalov }
12771d08b3fSOleksiy Vyalov 
SetWaitForLaunch(bool b)128b9c1b51eSKate Stone void SBAttachInfo::SetWaitForLaunch(bool b) {
129*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, b);
130baf5664fSJonas Devlieghere 
13171d08b3fSOleksiy Vyalov   m_opaque_sp->SetWaitForLaunch(b);
13271d08b3fSOleksiy Vyalov }
13371d08b3fSOleksiy Vyalov 
SetWaitForLaunch(bool b,bool async)134b9c1b51eSKate Stone void SBAttachInfo::SetWaitForLaunch(bool b, bool async) {
135*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, b, async);
136baf5664fSJonas Devlieghere 
137b3788eafSGreg Clayton   m_opaque_sp->SetWaitForLaunch(b);
138b3788eafSGreg Clayton   m_opaque_sp->SetAsync(async);
139b3788eafSGreg Clayton }
140b3788eafSGreg Clayton 
GetIgnoreExisting()141b9c1b51eSKate Stone bool SBAttachInfo::GetIgnoreExisting() {
142*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
143baf5664fSJonas Devlieghere 
14471d08b3fSOleksiy Vyalov   return m_opaque_sp->GetIgnoreExisting();
14571d08b3fSOleksiy Vyalov }
14671d08b3fSOleksiy Vyalov 
SetIgnoreExisting(bool b)147b9c1b51eSKate Stone void SBAttachInfo::SetIgnoreExisting(bool b) {
148*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, b);
149baf5664fSJonas Devlieghere 
15071d08b3fSOleksiy Vyalov   m_opaque_sp->SetIgnoreExisting(b);
15171d08b3fSOleksiy Vyalov }
15271d08b3fSOleksiy Vyalov 
GetUserID()153baf5664fSJonas Devlieghere uint32_t SBAttachInfo::GetUserID() {
154*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
15571d08b3fSOleksiy Vyalov 
156baf5664fSJonas Devlieghere   return m_opaque_sp->GetUserID();
157baf5664fSJonas Devlieghere }
15871d08b3fSOleksiy Vyalov 
GetGroupID()159baf5664fSJonas Devlieghere uint32_t SBAttachInfo::GetGroupID() {
160*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
16171d08b3fSOleksiy Vyalov 
162baf5664fSJonas Devlieghere   return m_opaque_sp->GetGroupID();
163baf5664fSJonas Devlieghere }
16471d08b3fSOleksiy Vyalov 
UserIDIsValid()165baf5664fSJonas Devlieghere bool SBAttachInfo::UserIDIsValid() {
166*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
16771d08b3fSOleksiy Vyalov 
168baf5664fSJonas Devlieghere   return m_opaque_sp->UserIDIsValid();
169baf5664fSJonas Devlieghere }
170baf5664fSJonas Devlieghere 
GroupIDIsValid()171baf5664fSJonas Devlieghere bool SBAttachInfo::GroupIDIsValid() {
172*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
173baf5664fSJonas Devlieghere 
174baf5664fSJonas Devlieghere   return m_opaque_sp->GroupIDIsValid();
175baf5664fSJonas Devlieghere }
176baf5664fSJonas Devlieghere 
SetUserID(uint32_t uid)177baf5664fSJonas Devlieghere void SBAttachInfo::SetUserID(uint32_t uid) {
178*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, uid);
179baf5664fSJonas Devlieghere 
180baf5664fSJonas Devlieghere   m_opaque_sp->SetUserID(uid);
181baf5664fSJonas Devlieghere }
182baf5664fSJonas Devlieghere 
SetGroupID(uint32_t gid)183baf5664fSJonas Devlieghere void SBAttachInfo::SetGroupID(uint32_t gid) {
184*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, gid);
185baf5664fSJonas Devlieghere 
186baf5664fSJonas Devlieghere   m_opaque_sp->SetGroupID(gid);
187baf5664fSJonas Devlieghere }
18871d08b3fSOleksiy Vyalov 
GetEffectiveUserID()189b9c1b51eSKate Stone uint32_t SBAttachInfo::GetEffectiveUserID() {
190*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
191baf5664fSJonas Devlieghere 
19271d08b3fSOleksiy Vyalov   return m_opaque_sp->GetEffectiveUserID();
19371d08b3fSOleksiy Vyalov }
19471d08b3fSOleksiy Vyalov 
GetEffectiveGroupID()195b9c1b51eSKate Stone uint32_t SBAttachInfo::GetEffectiveGroupID() {
196*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
197baf5664fSJonas Devlieghere 
19871d08b3fSOleksiy Vyalov   return m_opaque_sp->GetEffectiveGroupID();
19971d08b3fSOleksiy Vyalov }
20071d08b3fSOleksiy Vyalov 
EffectiveUserIDIsValid()201b9c1b51eSKate Stone bool SBAttachInfo::EffectiveUserIDIsValid() {
202*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
203baf5664fSJonas Devlieghere 
20471d08b3fSOleksiy Vyalov   return m_opaque_sp->EffectiveUserIDIsValid();
20571d08b3fSOleksiy Vyalov }
20671d08b3fSOleksiy Vyalov 
EffectiveGroupIDIsValid()207b9c1b51eSKate Stone bool SBAttachInfo::EffectiveGroupIDIsValid() {
208*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
209baf5664fSJonas Devlieghere 
21071d08b3fSOleksiy Vyalov   return m_opaque_sp->EffectiveGroupIDIsValid();
21171d08b3fSOleksiy Vyalov }
21271d08b3fSOleksiy Vyalov 
SetEffectiveUserID(uint32_t uid)213b9c1b51eSKate Stone void SBAttachInfo::SetEffectiveUserID(uint32_t uid) {
214*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, uid);
215baf5664fSJonas Devlieghere 
21671d08b3fSOleksiy Vyalov   m_opaque_sp->SetEffectiveUserID(uid);
21771d08b3fSOleksiy Vyalov }
21871d08b3fSOleksiy Vyalov 
SetEffectiveGroupID(uint32_t gid)219b9c1b51eSKate Stone void SBAttachInfo::SetEffectiveGroupID(uint32_t gid) {
220*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, gid);
221baf5664fSJonas Devlieghere 
22271d08b3fSOleksiy Vyalov   m_opaque_sp->SetEffectiveGroupID(gid);
22371d08b3fSOleksiy Vyalov }
22471d08b3fSOleksiy Vyalov 
GetParentProcessID()225b9c1b51eSKate Stone lldb::pid_t SBAttachInfo::GetParentProcessID() {
226*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
227baf5664fSJonas Devlieghere 
22871d08b3fSOleksiy Vyalov   return m_opaque_sp->GetParentProcessID();
22971d08b3fSOleksiy Vyalov }
23071d08b3fSOleksiy Vyalov 
SetParentProcessID(lldb::pid_t pid)231b9c1b51eSKate Stone void SBAttachInfo::SetParentProcessID(lldb::pid_t pid) {
232*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, pid);
233baf5664fSJonas Devlieghere 
23471d08b3fSOleksiy Vyalov   m_opaque_sp->SetParentProcessID(pid);
23571d08b3fSOleksiy Vyalov }
23671d08b3fSOleksiy Vyalov 
ParentProcessIDIsValid()237b9c1b51eSKate Stone bool SBAttachInfo::ParentProcessIDIsValid() {
238*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
239baf5664fSJonas Devlieghere 
24071d08b3fSOleksiy Vyalov   return m_opaque_sp->ParentProcessIDIsValid();
24171d08b3fSOleksiy Vyalov }
24271d08b3fSOleksiy Vyalov 
GetListener()243b9c1b51eSKate Stone SBListener SBAttachInfo::GetListener() {
244*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
245baf5664fSJonas Devlieghere 
246d232abc3SJonas Devlieghere   return SBListener(m_opaque_sp->GetListener());
24771d08b3fSOleksiy Vyalov }
24871d08b3fSOleksiy Vyalov 
SetListener(SBListener & listener)249b9c1b51eSKate Stone void SBAttachInfo::SetListener(SBListener &listener) {
250*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, listener);
251baf5664fSJonas Devlieghere 
25271d08b3fSOleksiy Vyalov   m_opaque_sp->SetListener(listener.GetSP());
25371d08b3fSOleksiy Vyalov }
254