forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lldb] Expose SBPlatform::GetAllProcesses to the SB API (llvm#68378)
Add the ability to list all processes through the SB API. rdar://116188959
- Loading branch information
1 parent
70368ea
commit 8f378ff
Showing
15 changed files
with
244 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
%extend lldb::SBProcessInfoList { | ||
#ifdef SWIGPYTHON | ||
%pythoncode%{ | ||
def __len__(self): | ||
'''Return the number of process info in a lldb.SBProcessInfoListExtensions object.''' | ||
return self.GetSize() | ||
|
||
def __iter__(self): | ||
'''Iterate over all the process info in a lldb.SBProcessInfoListExtensions object.''' | ||
return lldb_iter(self, 'GetSize', 'GetProcessInfoAtIndex') | ||
%} | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//===-- SBProcessInfoList.h -------------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLDB_API_SBPROCESSINSTANCEINFOLIST_H | ||
#define LLDB_API_SBPROCESSINSTANCEINFOLIST_H | ||
|
||
#include "lldb/API/SBDefines.h" | ||
|
||
#include <memory> | ||
|
||
namespace lldb_private { | ||
class ProcessInfoList; | ||
} // namespace lldb_private | ||
|
||
namespace lldb { | ||
|
||
class LLDB_API SBProcessInfoList { | ||
public: | ||
SBProcessInfoList(); | ||
~SBProcessInfoList(); | ||
|
||
SBProcessInfoList(const lldb::SBProcessInfoList &rhs); | ||
|
||
const lldb::SBProcessInfoList &operator=(const lldb::SBProcessInfoList &rhs); | ||
|
||
uint32_t GetSize() const; | ||
|
||
bool GetProcessInfoAtIndex(uint32_t idx, SBProcessInfo &info); | ||
|
||
void Clear(); | ||
|
||
private: | ||
friend SBPlatform; | ||
|
||
SBProcessInfoList(const lldb_private::ProcessInfoList &impl); | ||
std::unique_ptr<lldb_private::ProcessInfoList> m_opaque_up; | ||
}; | ||
|
||
} // namespace lldb | ||
|
||
#endif // LLDB_API_SBPROCESSINSTANCEINFOLIST_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
//===-- SBProcessInfoList.cpp ---------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "lldb/API/SBProcessInfoList.h" | ||
#include "lldb/API/SBProcessInfo.h" | ||
#include "lldb/Utility/Instrumentation.h" | ||
#include "lldb/Utility/ProcessInfo.h" | ||
|
||
#include "Utils.h" | ||
|
||
using namespace lldb; | ||
using namespace lldb_private; | ||
|
||
SBProcessInfoList::SBProcessInfoList() = default; | ||
|
||
SBProcessInfoList::~SBProcessInfoList() = default; | ||
|
||
SBProcessInfoList::SBProcessInfoList(const ProcessInfoList &impl) | ||
: m_opaque_up(std::make_unique<ProcessInfoList>(impl)) { | ||
LLDB_INSTRUMENT_VA(this, impl); | ||
} | ||
|
||
SBProcessInfoList::SBProcessInfoList(const lldb::SBProcessInfoList &rhs) { | ||
|
||
LLDB_INSTRUMENT_VA(this, rhs); | ||
|
||
m_opaque_up = clone(rhs.m_opaque_up); | ||
} | ||
|
||
const lldb::SBProcessInfoList & | ||
SBProcessInfoList::operator=(const lldb::SBProcessInfoList &rhs) { | ||
|
||
LLDB_INSTRUMENT_VA(this, rhs); | ||
|
||
if (this != &rhs) | ||
m_opaque_up = clone(rhs.m_opaque_up); | ||
return *this; | ||
} | ||
|
||
uint32_t SBProcessInfoList::GetSize() const { | ||
LLDB_INSTRUMENT_VA(this); | ||
|
||
if (m_opaque_up) | ||
return m_opaque_up->GetSize(); | ||
|
||
return 0; | ||
} | ||
|
||
void SBProcessInfoList::Clear() { | ||
LLDB_INSTRUMENT_VA(this); | ||
|
||
if (m_opaque_up) | ||
m_opaque_up->Clear(); | ||
} | ||
|
||
bool SBProcessInfoList::GetProcessInfoAtIndex(uint32_t idx, | ||
SBProcessInfo &info) { | ||
LLDB_INSTRUMENT_VA(this, idx, info); | ||
|
||
if (m_opaque_up) { | ||
lldb_private::ProcessInstanceInfo process_instance_info; | ||
if (m_opaque_up->GetProcessInfoAtIndex(idx, process_instance_info)) { | ||
info.SetProcessInfo(process_instance_info); | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
lldb/test/API/functionalities/gdb_remote_client/TestPlatformListProcesses.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import lldb | ||
from lldbsuite.test.lldbtest import * | ||
from lldbsuite.test.decorators import * | ||
from lldbsuite.test.gdbclientutils import * | ||
from lldbsuite.test.lldbgdbclient import GDBRemoteTestBase | ||
|
||
|
||
class TestPlatformListProcesses(GDBRemoteTestBase): | ||
@skipIfRemote | ||
@skipIfWindows | ||
def test_get_all_processes(self): | ||
"""Test listing processes""" | ||
|
||
class MyPlatformResponder(MockGDBServerResponder): | ||
def __init__(self): | ||
MockGDBServerResponder.__init__(self) | ||
self.done = False | ||
|
||
def qfProcessInfo(self, packet): | ||
return "pid:95117;name:666f6f;" | ||
|
||
def qsProcessInfo(self): | ||
if not self.done: | ||
self.done = True | ||
return "pid:95126;name:666f6f;" | ||
return "E10" | ||
|
||
self.server.responder = MyPlatformResponder() | ||
|
||
error = lldb.SBError() | ||
platform = lldb.SBPlatform("remote-linux") | ||
self.dbg.SetSelectedPlatform(platform) | ||
|
||
error = platform.ConnectRemote( | ||
lldb.SBPlatformConnectOptions(self.server.get_connect_url()) | ||
) | ||
self.assertSuccess(error) | ||
self.assertTrue(platform.IsConnected()) | ||
|
||
processes = platform.GetAllProcesses(error) | ||
self.assertSuccess(error) | ||
self.assertEqual(processes.GetSize(), 2) | ||
self.assertEqual(len(processes), 2) | ||
|
||
process_info = lldb.SBProcessInfo() | ||
processes.GetProcessInfoAtIndex(0, process_info) | ||
self.assertEqual(process_info.GetProcessID(), 95117) | ||
self.assertEqual(process_info.GetName(), "foo") | ||
|
||
processes.GetProcessInfoAtIndex(1, process_info) | ||
self.assertEqual(process_info.GetProcessID(), 95126) | ||
self.assertEqual(process_info.GetName(), "foo") | ||
|
||
platform.DisconnectRemote() |