Skip to content

Commit 450be6e

Browse files
committed
[lldb] Expose SBPlatform::GetAllProcesses to the SB API
Add the ability to list all processes through the SB API. rdar://116188959
1 parent 19141c4 commit 450be6e

File tree

15 files changed

+244
-1
lines changed

15 files changed

+244
-1
lines changed

lldb/bindings/headers.swig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "lldb/API/SBPlatform.h"
4747
#include "lldb/API/SBProcess.h"
4848
#include "lldb/API/SBProcessInfo.h"
49+
#include "lldb/API/SBProcessInfoList.h"
4950
#include "lldb/API/SBQueue.h"
5051
#include "lldb/API/SBQueueItem.h"
5152
#include "lldb/API/SBReproducer.h"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
%extend lldb::SBProcessInfoList {
2+
#ifdef SWIGPYTHON
3+
%pythoncode%{
4+
def __len__(self):
5+
'''Return the number of process info in a lldb.SBProcessInfoListExtensions object.'''
6+
return self.GetSize()
7+
8+
def __iter__(self):
9+
'''Iterate over all the process info in a lldb.SBProcessInfoListExtensions object.'''
10+
return lldb_iter(self, 'GetSize', 'GetProcessInfoAtIndex')
11+
%}
12+
#endif
13+
}

lldb/bindings/interfaces.swig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
%include "lldb/API/SBPlatform.h"
123123
%include "lldb/API/SBProcess.h"
124124
%include "lldb/API/SBProcessInfo.h"
125+
%include "lldb/API/SBProcessInfoList.h"
125126
%include "lldb/API/SBQueue.h"
126127
%include "lldb/API/SBQueueItem.h"
127128
%include "lldb/API/SBReproducer.h"
@@ -184,6 +185,7 @@
184185
%include "./interface/SBModuleSpecExtensions.i"
185186
%include "./interface/SBModuleSpecListExtensions.i"
186187
%include "./interface/SBProcessExtensions.i"
188+
%include "./interface/SBProcessInfoListExtensions.i"
187189
%include "./interface/SBQueueItemExtensions.i"
188190
%include "./interface/SBScriptObjectExtensions.i"
189191
%include "./interface/SBSectionExtensions.i"

lldb/include/lldb/API/LLDB.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "lldb/API/SBPlatform.h"
5050
#include "lldb/API/SBProcess.h"
5151
#include "lldb/API/SBProcessInfo.h"
52+
#include "lldb/API/SBProcessInfoList.h"
5253
#include "lldb/API/SBQueue.h"
5354
#include "lldb/API/SBQueueItem.h"
5455
#include "lldb/API/SBReproducer.h"

lldb/include/lldb/API/SBDefines.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class LLDB_API SBPlatformConnectOptions;
9090
class LLDB_API SBPlatformShellCommand;
9191
class LLDB_API SBProcess;
9292
class LLDB_API SBProcessInfo;
93+
class LLDB_API SBProcessInfoList;
9394
class LLDB_API SBQueue;
9495
class LLDB_API SBQueueItem;
9596
class LLDB_API SBReplayOptions;

lldb/include/lldb/API/SBPlatform.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111

1212
#include "lldb/API/SBDefines.h"
1313
#include "lldb/API/SBProcess.h"
14+
#include "lldb/API/SBProcessInfoList.h"
1415

1516
#include <functional>
1617

1718
struct PlatformConnectOptions;
1819
struct PlatformShellCommand;
20+
class ProcessInstanceInfoMatch;
1921

2022
namespace lldb {
2123

@@ -154,6 +156,8 @@ class LLDB_API SBPlatform {
154156
SBProcess Attach(SBAttachInfo &attach_info, const SBDebugger &debugger,
155157
SBTarget &target, SBError &error);
156158

159+
SBProcessInfoList GetAllProcesses(SBError &error);
160+
157161
SBError Kill(const lldb::pid_t pid);
158162

159163
SBError

lldb/include/lldb/API/SBProcessInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class LLDB_API SBProcessInfo {
5555

5656
private:
5757
friend class SBProcess;
58+
friend class SBProcessInfoList;
5859

5960
lldb_private::ProcessInstanceInfo &ref();
6061

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//===-- SBProcessInfoList.h -------------------------------------*- C++ -*-===//
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+
9+
#ifndef LLDB_API_SBPROCESSINSTANCEINFOLIST_H
10+
#define LLDB_API_SBPROCESSINSTANCEINFOLIST_H
11+
12+
#include "lldb/API/SBDefines.h"
13+
14+
#include <memory>
15+
16+
namespace lldb_private {
17+
class ProcessInfoList;
18+
} // namespace lldb_private
19+
20+
namespace lldb {
21+
22+
class LLDB_API SBProcessInfoList {
23+
public:
24+
SBProcessInfoList();
25+
~SBProcessInfoList();
26+
27+
SBProcessInfoList(const lldb::SBProcessInfoList &rhs);
28+
29+
const lldb::SBProcessInfoList &operator=(const lldb::SBProcessInfoList &rhs);
30+
31+
uint32_t GetSize() const;
32+
33+
bool GetProcessInfoAtIndex(uint32_t idx, SBProcessInfo &info);
34+
35+
void Clear();
36+
37+
private:
38+
friend SBPlatform;
39+
40+
SBProcessInfoList(const lldb_private::ProcessInfoList &impl);
41+
std::unique_ptr<lldb_private::ProcessInfoList> m_opaque_up;
42+
};
43+
44+
} // namespace lldb
45+
46+
#endif // LLDB_API_SBPROCESSINSTANCEINFOLIST_H

lldb/include/lldb/Target/Platform.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ class Platform : public PluginInterface {
407407
virtual uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info,
408408
ProcessInstanceInfoList &proc_infos);
409409

410+
ProcessInstanceInfoList GetAllProcesses();
411+
410412
virtual bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info);
411413

412414
// Set a breakpoint on all functions that can end up creating a thread for
@@ -883,7 +885,7 @@ class Platform : public PluginInterface {
883885
}
884886

885887
virtual CompilerType GetSiginfoType(const llvm::Triple &triple);
886-
888+
887889
virtual Args GetExtraStartupCommands();
888890

889891
typedef std::function<Status(const ModuleSpec &module_spec,

lldb/include/lldb/Utility/ProcessInfo.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,26 @@ class ProcessInstanceInfo : public ProcessInfo {
187187

188188
typedef std::vector<ProcessInstanceInfo> ProcessInstanceInfoList;
189189

190+
class ProcessInfoList {
191+
public:
192+
ProcessInfoList(const ProcessInstanceInfoList &list) : m_list(list) {}
193+
194+
uint32_t GetSize() const { return m_list.size(); }
195+
196+
bool GetProcessInfoAtIndex(uint32_t idx, ProcessInstanceInfo &info) {
197+
if (idx < m_list.size()) {
198+
info = m_list[idx];
199+
return true;
200+
}
201+
return false;
202+
}
203+
204+
void Clear() { return m_list.clear(); }
205+
206+
private:
207+
ProcessInstanceInfoList m_list;
208+
};
209+
190210
// ProcessInstanceInfoMatch
191211
//
192212
// A class to help matching one ProcessInstanceInfo to another.

0 commit comments

Comments
 (0)