LLDB mainline
SBAttachInfo.cpp
Go to the documentation of this file.
1//===-- SBAttachInfo.cpp --------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "Utils.h"
11#include "lldb/API/SBFileSpec.h"
12#include "lldb/API/SBListener.h"
14#include "lldb/Target/Process.h"
17
18using namespace lldb;
19using namespace lldb_private;
20
23}
24
26 : m_opaque_sp(new ProcessAttachInfo()) {
27 LLDB_INSTRUMENT_VA(this, pid);
28
29 m_opaque_sp->SetProcessID(pid);
30}
31
32SBAttachInfo::SBAttachInfo(const char *path, bool wait_for)
33 : m_opaque_sp(new ProcessAttachInfo()) {
34 LLDB_INSTRUMENT_VA(this, path, wait_for);
35
36 if (path && path[0])
37 m_opaque_sp->GetExecutableFile().SetFile(path, FileSpec::Style::native);
38 m_opaque_sp->SetWaitForLaunch(wait_for);
39}
40
41SBAttachInfo::SBAttachInfo(const char *path, bool wait_for, bool async)
42 : m_opaque_sp(new ProcessAttachInfo()) {
43 LLDB_INSTRUMENT_VA(this, path, wait_for, async);
44
45 if (path && path[0])
46 m_opaque_sp->GetExecutableFile().SetFile(path, FileSpec::Style::native);
47 m_opaque_sp->SetWaitForLaunch(wait_for);
48 m_opaque_sp->SetAsync(async);
49}
50
52 : m_opaque_sp(new ProcessAttachInfo()) {
53 LLDB_INSTRUMENT_VA(this, rhs);
54
56}
57
59
61
63 LLDB_INSTRUMENT_VA(this, rhs);
64
65 if (this != &rhs)
67 return *this;
68}
69
72
73 return m_opaque_sp->GetProcessID();
74}
75
77 LLDB_INSTRUMENT_VA(this, pid);
78
79 m_opaque_sp->SetProcessID(pid);
80}
81
84
85 return m_opaque_sp->GetResumeCount();
86}
87
89 LLDB_INSTRUMENT_VA(this, c);
90
91 m_opaque_sp->SetResumeCount(c);
92}
93
96
97 return ConstString(m_opaque_sp->GetProcessPluginName()).GetCString();
98}
99
100void SBAttachInfo::SetProcessPluginName(const char *plugin_name) {
101 LLDB_INSTRUMENT_VA(this, plugin_name);
102
103 return m_opaque_sp->SetProcessPluginName(plugin_name);
104}
105
106void SBAttachInfo::SetExecutable(const char *path) {
107 LLDB_INSTRUMENT_VA(this, path);
108
109 if (path && path[0])
110 m_opaque_sp->GetExecutableFile().SetFile(path, FileSpec::Style::native);
111 else
112 m_opaque_sp->GetExecutableFile().Clear();
113}
114
116 LLDB_INSTRUMENT_VA(this, exe_file);
117
118 if (exe_file.IsValid())
119 m_opaque_sp->GetExecutableFile() = exe_file.ref();
120 else
121 m_opaque_sp->GetExecutableFile().Clear();
122}
123
125 LLDB_INSTRUMENT_VA(this);
126
127 return m_opaque_sp->GetWaitForLaunch();
128}
129
131 LLDB_INSTRUMENT_VA(this, b);
132
133 m_opaque_sp->SetWaitForLaunch(b);
134}
135
136void SBAttachInfo::SetWaitForLaunch(bool b, bool async) {
137 LLDB_INSTRUMENT_VA(this, b, async);
138
139 m_opaque_sp->SetWaitForLaunch(b);
140 m_opaque_sp->SetAsync(async);
141}
142
144 LLDB_INSTRUMENT_VA(this);
145
146 return m_opaque_sp->GetIgnoreExisting();
147}
148
150 LLDB_INSTRUMENT_VA(this, b);
151
152 m_opaque_sp->SetIgnoreExisting(b);
153}
154
156 LLDB_INSTRUMENT_VA(this);
157
158 return m_opaque_sp->GetUserID();
159}
160
162 LLDB_INSTRUMENT_VA(this);
163
164 return m_opaque_sp->GetGroupID();
165}
166
168 LLDB_INSTRUMENT_VA(this);
169
170 return m_opaque_sp->UserIDIsValid();
171}
172
174 LLDB_INSTRUMENT_VA(this);
175
176 return m_opaque_sp->GroupIDIsValid();
177}
178
179void SBAttachInfo::SetUserID(uint32_t uid) {
180 LLDB_INSTRUMENT_VA(this, uid);
181
182 m_opaque_sp->SetUserID(uid);
183}
184
185void SBAttachInfo::SetGroupID(uint32_t gid) {
186 LLDB_INSTRUMENT_VA(this, gid);
187
188 m_opaque_sp->SetGroupID(gid);
189}
190
192 LLDB_INSTRUMENT_VA(this);
193
194 return m_opaque_sp->GetEffectiveUserID();
195}
196
198 LLDB_INSTRUMENT_VA(this);
199
200 return m_opaque_sp->GetEffectiveGroupID();
201}
202
204 LLDB_INSTRUMENT_VA(this);
205
206 return m_opaque_sp->EffectiveUserIDIsValid();
207}
208
210 LLDB_INSTRUMENT_VA(this);
211
212 return m_opaque_sp->EffectiveGroupIDIsValid();
213}
214
216 LLDB_INSTRUMENT_VA(this, uid);
217
218 m_opaque_sp->SetEffectiveUserID(uid);
219}
220
222 LLDB_INSTRUMENT_VA(this, gid);
223
224 m_opaque_sp->SetEffectiveGroupID(gid);
225}
226
228 LLDB_INSTRUMENT_VA(this);
229
230 return m_opaque_sp->GetParentProcessID();
231}
232
234 LLDB_INSTRUMENT_VA(this, pid);
235
236 m_opaque_sp->SetParentProcessID(pid);
237}
238
240 LLDB_INSTRUMENT_VA(this);
241
242 return m_opaque_sp->ParentProcessIDIsValid();
243}
244
246 LLDB_INSTRUMENT_VA(this);
247
248 return SBListener(m_opaque_sp->GetListener());
249}
250
252 LLDB_INSTRUMENT_VA(this, listener);
253
254 m_opaque_sp->SetListener(listener.GetSP());
255}
256
258 LLDB_INSTRUMENT_VA(this);
259
260 lldb::ListenerSP shadow_sp = m_opaque_sp->GetShadowListener();
261 if (!shadow_sp)
262 return SBListener();
263 return SBListener(shadow_sp);
264}
265
267 LLDB_INSTRUMENT_VA(this, listener);
268
269 m_opaque_sp->SetShadowListener(listener.GetSP());
270}
271
273 LLDB_INSTRUMENT_VA(this);
274
275 ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();
276
277 if (!metadata_sp || !*metadata_sp)
278 return nullptr;
279
280 // Constify this string so that it is saved in the string pool. Otherwise it
281 // would be freed when this function goes out of scope.
282 ConstString class_name(metadata_sp->GetClassName().data());
283 return class_name.AsCString();
284}
285
286void SBAttachInfo::SetScriptedProcessClassName(const char *class_name) {
287 LLDB_INSTRUMENT_VA(this, class_name);
288
289 ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();
290
291 if (!metadata_sp)
292 metadata_sp = std::make_shared<ScriptedMetadata>(class_name, nullptr);
293 else
294 metadata_sp = std::make_shared<ScriptedMetadata>(class_name,
295 metadata_sp->GetArgsSP());
296
297 m_opaque_sp->SetScriptedMetadata(metadata_sp);
298}
299
301 LLDB_INSTRUMENT_VA(this);
302
303 ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();
304
305 SBStructuredData data;
306 if (!metadata_sp)
307 return data;
308
309 lldb_private::StructuredData::DictionarySP dict_sp = metadata_sp->GetArgsSP();
310 data.m_impl_up->SetObjectSP(dict_sp);
311
312 return data;
313}
314
316 LLDB_INSTRUMENT_VA(this, dict);
317
318 if (!dict.IsValid() || !dict.m_impl_up)
319 return;
320
321 StructuredData::ObjectSP obj_sp = dict.m_impl_up->GetObjectSP();
322
323 if (!obj_sp)
324 return;
325
327 std::make_shared<StructuredData::Dictionary>(obj_sp);
328 if (!dict_sp || dict_sp->GetType() == lldb::eStructuredDataTypeInvalid)
329 return;
330
331 ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();
332
333 if (!metadata_sp)
334 metadata_sp = std::make_shared<ScriptedMetadata>("", dict_sp);
335 else
336 metadata_sp = std::make_shared<ScriptedMetadata>(
337 metadata_sp->GetClassName(), dict_sp);
338
339 m_opaque_sp->SetScriptedMetadata(metadata_sp);
340}
#define LLDB_INSTRUMENT_VA(...)
uint32_t GetEffectiveUserID()
ProcessAttachInfoSP m_opaque_sp
Definition: SBAttachInfo.h:206
SBListener GetListener()
Get the listener that will be used to receive process events.
lldb::SBStructuredData GetScriptedProcessDictionary() const
void SetShadowListener(SBListener &listener)
Set the shadow listener that will receive public process events, additionally to the default process ...
void SetProcessPluginName(const char *plugin_name)
uint32_t GetResumeCount()
void SetGroupID(uint32_t gid)
void SetIgnoreExisting(bool b)
bool EffectiveGroupIDIsValid()
void SetEffectiveUserID(uint32_t uid)
void SetParentProcessID(lldb::pid_t pid)
lldb_private::ProcessAttachInfo & ref()
void SetListener(SBListener &listener)
Set the listener that will be used to receive process events.
lldb::pid_t GetParentProcessID()
void SetScriptedProcessDictionary(lldb::SBStructuredData dict)
const char * GetProcessPluginName()
void SetEffectiveGroupID(uint32_t gid)
void SetProcessID(lldb::pid_t pid)
void SetScriptedProcessClassName(const char *class_name)
void SetResumeCount(uint32_t c)
SBAttachInfo & operator=(const SBAttachInfo &rhs)
SBListener GetShadowListener()
Get the shadow listener that receive public process events, additionally to the default process event...
uint32_t GetEffectiveGroupID()
const char * GetScriptedProcessClassName() const
lldb::pid_t GetProcessID()
void SetWaitForLaunch(bool b)
Set attach by process name settings.
void SetUserID(uint32_t uid)
void SetExecutable(const char *path)
bool IsValid() const
Definition: SBFileSpec.cpp:76
const lldb_private::FileSpec & ref() const
Definition: SBFileSpec.cpp:162
lldb::ListenerSP GetSP()
Definition: SBListener.cpp:286
StructuredDataImplUP m_impl_up
A uniqued constant string class.
Definition: ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:188
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
A class that represents a running process on the host machine.
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ScriptedMetadata > ScriptedMetadataSP
Definition: lldb-forward.h:405
uint64_t pid_t
Definition: lldb-types.h:83
std::shared_ptr< lldb_private::Listener > ListenerSP
Definition: lldb-forward.h:366
@ eStructuredDataTypeInvalid