-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[lldb] Expose SBPlatform::GetAllProcesses to the SB API #68378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JDevlieghere
merged 1 commit into
llvm:main
from
JDevlieghere:jdevlieghere/SBPlatformGetAllProcesses
Oct 6, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.