Skip to content

[lldb] Improve isolation between Process plugins and OS plugins #125302

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
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lldb/source/Breakpoint/BreakpointSite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "lldb/Breakpoint/Breakpoint.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/Stream.h"

using namespace lldb;
Expand Down Expand Up @@ -161,6 +162,8 @@ BreakpointLocationSP BreakpointSite::GetConstituentAtIndex(size_t index) {

bool BreakpointSite::ValidForThisThread(Thread &thread) {
std::lock_guard<std::recursive_mutex> guard(m_constituents_mutex);
if (ThreadSP backed_thread = thread.GetBackedThread())
return m_constituents.ValidForThisThread(*backed_thread);
return m_constituents.ValidForThisThread(thread);
}

Expand Down
4 changes: 0 additions & 4 deletions lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1726,10 +1726,6 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo(

if (!thread_sp->StopInfoIsUpToDate()) {
thread_sp->SetStopInfo(StopInfoSP());
// If there's a memory thread backed by this thread, we need to use it to
// calculate StopInfo.
if (ThreadSP memory_thread_sp = thread_sp->GetBackedThread())
thread_sp = memory_thread_sp;

if (exc_type != 0) {
// For thread plan async interrupt, creating stop info on the
Expand Down
21 changes: 21 additions & 0 deletions lldb/unittests/OperatingSystem/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
add_lldb_unittest(ProcessGdbRemoteTests
GDBRemoteClientBaseTest.cpp
GDBRemoteCommunicationClientTest.cpp
GDBRemoteCommunicationServerLLGSTest.cpp
GDBRemoteCommunicationServerTest.cpp
GDBRemoteCommunicationTest.cpp
GDBRemoteTestUtils.cpp

LINK_LIBS
LLVMTestingSupport
lldbCore
lldbHost
lldbInterpreter
lldbPluginProcessUtility
lldbSymbol
lldbTarget
lldbValueObject

LINK_COMPONENTS
Support
)
59 changes: 59 additions & 0 deletions lldb/unittests/OperatingSystem/OperatingSystemPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//===-- OperatingSystemPlugin.h ---------------------------------------===//
//
// 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/Core/PluginManager.h"
#include "lldb/Target/OperatingSystem.h"
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadList.h"

/// An operating system plugin that does nothing: simply keeps the thread lists
/// as they are.
class OperatingSystemIdentityMap : public lldb_private::OperatingSystem {
public:
OperatingSystemIdentityMap(lldb_private::Process *process)
: OperatingSystem(process) {}

static OperatingSystem *CreateInstance(lldb_private::Process *process,
bool force) {
return new OperatingSystemIdentityMap(process);
}
static llvm::StringRef GetPluginNameStatic() { return "identity map"; }
static llvm::StringRef GetPluginDescriptionStatic() { return ""; }

static void Initialize() {
lldb_private::PluginManager::RegisterPlugin(GetPluginNameStatic(),
GetPluginDescriptionStatic(),
CreateInstance, nullptr);
}
static void Terminate() {
lldb_private::PluginManager::UnregisterPlugin(CreateInstance);
}
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }

// Simply adds the threads from real_thread_list into new_thread_list.
bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
lldb_private::ThreadList &real_thread_list,
lldb_private::ThreadList &new_thread_list) override {
for (const auto &real_thread : real_thread_list.Threads())
new_thread_list.AddThread(real_thread);
return true;
}

void ThreadWasSelected(lldb_private::Thread *thread) override {}

lldb::RegisterContextSP
CreateRegisterContextForThread(lldb_private::Thread *thread,
lldb::addr_t reg_data_addr) override {
return thread->GetRegisterContext();
}

lldb::StopInfoSP
CreateThreadStopReason(lldb_private::Thread *thread) override {
return thread->GetStopInfo();
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//===-- OperatingSystemPlugin.h ---------------------------------------===//
//
// 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 "OperatingSystemPlugin.h"
LLDB_PLUGIN_DEFINE(OperatingSystemIdentityMap)