Skip to content

Commit ee23250

Browse files
committed
[lldb] Move UnixSignals creation into Platform plugins
The high level goal of this change is to remove lldbTarget's dependency on lldbPluginProcessUtility. The reason for this existing dependency is so that we can create the appropriate UnixSignals object based on an ArchSpec. Instead of using the ArchSpec, we can instead take advantage of the Platform associated with the current Target. This is accomplished by adding a new method to Platform, CreateUnixSignals, which will create the correct UnixSignals object for us. We then can use `Platform::GetUnixSignals` and rely on that to give us the correct signals as needed. Differential Revision: https://reviews.llvm.org/D146263
1 parent ff48a29 commit ee23250

37 files changed

+103
-57
lines changed

lldb/include/lldb/Target/Platform.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,12 @@ class Platform : public PluginInterface {
619619
return 1;
620620
}
621621

622-
virtual const lldb::UnixSignalsSP &GetRemoteUnixSignals();
622+
virtual lldb::UnixSignalsSP GetRemoteUnixSignals();
623623

624624
lldb::UnixSignalsSP GetUnixSignals();
625625

626+
virtual lldb::UnixSignalsSP CreateUnixSignals() = 0;
627+
626628
/// Locate a queue name given a thread's qaddr
627629
///
628630
/// On a system using libdispatch ("Grand Central Dispatch") style queues, a

lldb/include/lldb/Target/UnixSignals.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace lldb_private {
2222

2323
class UnixSignals {
2424
public:
25-
static lldb::UnixSignalsSP Create(const ArchSpec &arch);
2625
static lldb::UnixSignalsSP CreateForHost();
2726

2827
// Constructors and Destructors

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ add_lldb_library(lldbPluginAppleObjCRuntime PLUGIN
1919
lldbUtility
2020
lldbPluginExpressionParserClang
2121
lldbPluginCPPRuntime
22+
lldbPluginProcessUtility
2223
lldbPluginTypeSystemClang
2324
CLANG_LIBS
2425
clangAST

lldb/source/Plugins/Platform/FreeBSD/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_lldb_library(lldbPluginPlatformFreeBSD PLUGIN
2+
FreeBSDSignals.cpp
23
PlatformFreeBSD.cpp
34

45
LINK_LIBS

lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "PlatformFreeBSD.h"
10+
#include "FreeBSDSignals.h"
1011
#include "lldb/Host/Config.h"
1112

1213
#include <cstdio>
@@ -282,3 +283,7 @@ CompilerType PlatformFreeBSD::GetSiginfoType(const llvm::Triple &triple) {
282283
ast->CompleteTagDeclarationDefinition(siginfo_type);
283284
return siginfo_type;
284285
}
286+
287+
lldb::UnixSignalsSP PlatformFreeBSD::CreateUnixSignals() {
288+
return std::make_shared<FreeBSDSignals>();
289+
}

lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class PlatformFreeBSD : public PlatformPOSIX {
5959

6060
std::vector<ArchSpec> m_supported_architectures;
6161

62+
lldb::UnixSignalsSP CreateUnixSignals() override;
63+
6264
private:
6365
std::mutex m_mutex;
6466
std::shared_ptr<TypeSystemClang> m_type_system;

lldb/source/Plugins/Platform/Linux/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_lldb_library(lldbPluginPlatformLinux PLUGIN
2+
LinuxSignals.cpp
23
PlatformLinux.cpp
34

45
LINK_LIBS

lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "PlatformLinux.h"
10+
#include "LinuxSignals.h"
1011
#include "lldb/Host/Config.h"
1112

1213
#include <cstdio>
@@ -480,3 +481,7 @@ CompilerType PlatformLinux::GetSiginfoType(const llvm::Triple &triple) {
480481
ast->CompleteTagDeclarationDefinition(siginfo_type);
481482
return siginfo_type;
482483
}
484+
485+
lldb::UnixSignalsSP PlatformLinux::CreateUnixSignals() {
486+
return std::make_shared<LinuxSignals>();
487+
}

lldb/source/Plugins/Platform/Linux/PlatformLinux.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class PlatformLinux : public PlatformPOSIX {
6464

6565
std::vector<ArchSpec> m_supported_architectures;
6666

67+
lldb::UnixSignalsSP CreateUnixSignals() override;
68+
6769
private:
6870
std::mutex m_mutex;
6971
std::shared_ptr<TypeSystemClang> m_type_system;

lldb/source/Plugins/Platform/NetBSD/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_lldb_library(lldbPluginPlatformNetBSD PLUGIN
2+
NetBSDSignals.cpp
23
PlatformNetBSD.cpp
34

45
LINK_LIBS

lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "PlatformNetBSD.h"
10+
#include "NetBSDSignals.h"
1011
#include "lldb/Host/Config.h"
1112

1213
#include <cstdio>
@@ -348,3 +349,7 @@ CompilerType PlatformNetBSD::GetSiginfoType(const llvm::Triple &triple) {
348349
ast->CompleteTagDeclarationDefinition(siginfo_type);
349350
return siginfo_type;
350351
}
352+
353+
lldb::UnixSignalsSP PlatformNetBSD::CreateUnixSignals() {
354+
return std::make_shared<NetBSDSignals>();
355+
}

lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class PlatformNetBSD : public PlatformPOSIX {
6161

6262
std::vector<ArchSpec> m_supported_architectures;
6363

64+
lldb::UnixSignalsSP CreateUnixSignals() override;
65+
6466
private:
6567
std::mutex m_mutex;
6668
std::shared_ptr<TypeSystemClang> m_type_system;

lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "lldb/Target/ExecutionContext.h"
2828
#include "lldb/Target/Process.h"
2929
#include "lldb/Target/Thread.h"
30+
#include "lldb/Target/UnixSignals.h"
3031
#include "lldb/Utility/DataBufferHeap.h"
3132
#include "lldb/Utility/FileSpec.h"
3233
#include "lldb/Utility/LLDBLog.h"
@@ -294,9 +295,13 @@ std::string PlatformPOSIX::GetPlatformSpecificConnectionInformation() {
294295
return "";
295296
}
296297

297-
const lldb::UnixSignalsSP &PlatformPOSIX::GetRemoteUnixSignals() {
298-
if (IsRemote() && m_remote_platform_sp)
299-
return m_remote_platform_sp->GetRemoteUnixSignals();
298+
lldb::UnixSignalsSP PlatformPOSIX::GetRemoteUnixSignals() {
299+
if (IsRemote() && m_remote_platform_sp) {
300+
if (auto unix_signals_sp = m_remote_platform_sp->GetRemoteUnixSignals())
301+
return unix_signals_sp;
302+
}
303+
if (auto unix_signals_sp = CreateUnixSignals())
304+
return unix_signals_sp;
300305
return Platform::GetRemoteUnixSignals();
301306
}
302307

@@ -989,3 +994,7 @@ ConstString PlatformPOSIX::GetFullNameForDylib(ConstString basename) {
989994
stream.Printf("lib%s.so", basename.GetCString());
990995
return ConstString(stream.GetString());
991996
}
997+
998+
lldb::UnixSignalsSP PlatformPOSIX::CreateUnixSignals() {
999+
return std::make_shared<UnixSignals>();
1000+
}

lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class PlatformPOSIX : public lldb_private::RemoteAwarePlatform {
3535
GetFile(const lldb_private::FileSpec &source,
3636
const lldb_private::FileSpec &destination) override;
3737

38-
const lldb::UnixSignalsSP &GetRemoteUnixSignals() override;
38+
lldb::UnixSignalsSP GetRemoteUnixSignals() override;
3939

4040
lldb::ProcessSP Attach(lldb_private::ProcessAttachInfo &attach_info,
4141
lldb_private::Debugger &debugger,
@@ -69,6 +69,8 @@ class PlatformPOSIX : public lldb_private::RemoteAwarePlatform {
6969

7070
lldb_private::ConstString GetFullNameForDylib(lldb_private::ConstString basename) override;
7171

72+
lldb::UnixSignalsSP CreateUnixSignals() override;
73+
7274
protected:
7375
std::unique_ptr<lldb_private::OptionGroupPlatformRSync>
7476
m_option_group_platform_rsync;

lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ class PlatformQemuUser : public Platform {
6969
arch, addr, length, prot, flags, fd, offset);
7070
}
7171

72+
lldb::UnixSignalsSP CreateUnixSignals() override {
73+
// PlatformQemuUser shouldn't create its own UnixSignals. It should defer to
74+
// other platforms.
75+
return lldb::UnixSignalsSP();
76+
}
77+
7278
private:
7379
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
7480
static void DebuggerInitialize(Debugger &debugger);

lldb/source/Plugins/Platform/Windows/PlatformWindows.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ class PlatformWindows : public RemoteAwarePlatform {
8282

8383
std::vector<ArchSpec> m_supported_architectures;
8484

85+
lldb::UnixSignalsSP CreateUnixSignals() override {
86+
return lldb::UnixSignalsSP();
87+
}
88+
8589
private:
8690
std::unique_ptr<lldb_private::UtilityFunction>
8791
MakeLoadImageUtilityFunction(lldb_private::ExecutionContext &context,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
add_lldb_library(lldbPluginPlatformGDB PLUGIN
2+
GDBRemoteSignals.cpp
23
PlatformRemoteGDBServer.cpp
34

45
LINK_LIBS
56
lldbBreakpoint
67
lldbCore
78
lldbHost
89
lldbTarget
9-
lldbPluginProcessUtility
1010
lldbPluginProcessGDBRemote
1111
)

lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "PlatformRemoteGDBServer.h"
10+
#include "GDBRemoteSignals.h"
1011
#include "lldb/Host/Config.h"
1112

1213
#include "lldb/Breakpoint/BreakpointLocation.h"
@@ -31,7 +32,6 @@
3132
#include "lldb/Utility/UriParser.h"
3233
#include "llvm/Support/FormatAdapters.h"
3334

34-
#include "Plugins/Process/Utility/GDBRemoteSignals.h"
3535
#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
3636
#include <optional>
3737

@@ -680,17 +680,13 @@ void PlatformRemoteGDBServer::CalculateTrapHandlerSymbolNames() {
680680
m_trap_handlers.push_back(ConstString("_sigtramp"));
681681
}
682682

683-
const UnixSignalsSP &PlatformRemoteGDBServer::GetRemoteUnixSignals() {
683+
UnixSignalsSP PlatformRemoteGDBServer::GetRemoteUnixSignals() {
684684
if (!IsConnected())
685-
return Platform::GetRemoteUnixSignals();
685+
return UnixSignalsSP();
686686

687687
if (m_remote_signals_sp)
688688
return m_remote_signals_sp;
689689

690-
// If packet not implemented or JSON failed to parse, we'll guess the signal
691-
// set based on the remote architecture.
692-
m_remote_signals_sp = UnixSignals::Create(GetRemoteSystemArchitecture());
693-
694690
StringExtractorGDBRemote response;
695691
auto result =
696692
m_gdb_client_up->SendPacketAndWaitForResponse("jSignalsInfo", response);

lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <optional>
1414
#include <string>
1515

16-
#include "Plugins/Process/Utility/GDBRemoteSignals.h"
1716
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h"
1817
#include "lldb/Target/Platform.h"
1918

@@ -146,14 +145,19 @@ class PlatformRemoteGDBServer : public Platform, private UserIDResolver {
146145

147146
void CalculateTrapHandlerSymbolNames() override;
148147

149-
const lldb::UnixSignalsSP &GetRemoteUnixSignals() override;
148+
lldb::UnixSignalsSP GetRemoteUnixSignals() override;
150149

151150
size_t ConnectToWaitingProcesses(lldb_private::Debugger &debugger,
152151
lldb_private::Status &error) override;
153152

154153
virtual size_t
155154
GetPendingGdbServerList(std::vector<std::string> &connection_urls);
156155

156+
lldb::UnixSignalsSP CreateUnixSignals() override {
157+
// PlatformRemoteGDBServer should defer to other platforms.
158+
return lldb::UnixSignalsSP();
159+
}
160+
157161
protected:
158162
std::unique_ptr<process_gdb_remote::GDBRemoteCommunicationClient>
159163
m_gdb_client_up;

lldb/source/Plugins/Process/Utility/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
add_lldb_library(lldbPluginProcessUtility
22
AuxVector.cpp
3-
FreeBSDSignals.cpp
4-
GDBRemoteSignals.cpp
53
HistoryThread.cpp
64
HistoryUnwind.cpp
75
InferiorCallPOSIX.cpp
86
LinuxProcMaps.cpp
9-
LinuxSignals.cpp
107
MemoryTagManagerAArch64MTE.cpp
118
NativeProcessSoftwareSingleStep.cpp
129
NativeRegisterContextDBReg_arm64.cpp
1310
NativeRegisterContextDBReg_x86.cpp
1411
NativeRegisterContextRegisterInfo.cpp
15-
NetBSDSignals.cpp
1612
RegisterContext_x86.cpp
1713
RegisterContextDarwin_arm.cpp
1814
RegisterContextDarwin_arm64.cpp

lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "lldb/Target/ABI.h"
1919
#include "lldb/Target/DynamicLoader.h"
2020
#include "lldb/Target/MemoryRegionInfo.h"
21+
#include "lldb/Target/Platform.h"
2122
#include "lldb/Target/Target.h"
2223
#include "lldb/Target/UnixSignals.h"
2324
#include "lldb/Utility/DataBufferHeap.h"
@@ -223,9 +224,10 @@ Status ProcessElfCore::DoLoadCore() {
223224
ArchSpec target_arch = GetTarget().GetArchitecture();
224225
ArchSpec core_arch(m_core_module_sp->GetArchitecture());
225226
target_arch.MergeFrom(core_arch);
226-
GetTarget().SetArchitecture(target_arch);
227-
228-
SetUnixSignals(UnixSignals::Create(GetArchitecture()));
227+
GetTarget().SetArchitecture(target_arch, /* set_platform = */ true);
228+
229+
if (auto platform_sp = GetTarget().GetPlatform())
230+
SetUnixSignals(platform_sp->GetUnixSignals());
229231

230232
// Ensure we found at least one thread that was stopped on a signal.
231233
bool siginfo_signal_found = false;

lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474

7575
#include "GDBRemoteRegisterContext.h"
7676
#include "GDBRemoteRegisterFallback.h"
77-
#include "Plugins/Process/Utility/GDBRemoteSignals.h"
77+
#include "Plugins/Platform/gdb-server/GDBRemoteSignals.h"
7878
#include "Plugins/Process/Utility/InferiorCallPOSIX.h"
7979
#include "Plugins/Process/Utility/StopInfoMachException.h"
8080
#include "ProcessGDBRemote.h"
@@ -967,15 +967,13 @@ void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) {
967967
MapSupportedStructuredDataPlugins(*supported_packets);
968968

969969
// If connected to LLDB ("native-signals+"), use signal defs for
970-
// the remote platform. If connected to GDB, just use the standard set.
971-
if (!m_gdb_comm.UsesNativeSignals()) {
970+
// the remote platform (assuming it's available). If connected to GDB, just
971+
// use the standard set.
972+
auto platform_sp = GetTarget().GetPlatform();
973+
if (!platform_sp || !m_gdb_comm.UsesNativeSignals())
972974
SetUnixSignals(std::make_shared<GDBRemoteSignals>());
973-
} else {
974-
PlatformSP platform_sp = GetTarget().GetPlatform();
975-
if (platform_sp && platform_sp->IsConnected())
976-
SetUnixSignals(platform_sp->GetUnixSignals());
977-
else
978-
SetUnixSignals(UnixSignals::Create(GetTarget().GetArchitecture()));
975+
else {
976+
SetUnixSignals(platform_sp->GetUnixSignals());
979977
}
980978
}
981979

lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,14 @@ Status ProcessMinidump::DoLoadCore() {
206206
arch.GetArchitectureName());
207207
return error;
208208
}
209-
GetTarget().SetArchitecture(arch, true /*set_platform*/);
209+
GetTarget().SetArchitecture(arch, /*set_platform = */ true);
210210

211211
m_thread_list = m_minidump_parser->GetThreads();
212212
m_active_exception = m_minidump_parser->GetExceptionStream();
213213

214-
SetUnixSignals(UnixSignals::Create(GetArchitecture()));
214+
auto platform_sp = GetTarget().GetPlatform();
215+
if (platform_sp)
216+
SetUnixSignals(platform_sp->GetUnixSignals());
215217

216218
ReadModuleList();
217219
if (ModuleSP module = GetTarget().GetExecutableModule())

lldb/source/Target/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ add_lldb_library(lldbTarget
8585
lldbInterpreter
8686
lldbSymbol
8787
lldbUtility
88-
lldbPluginProcessUtility
8988

9089
LINK_COMPONENTS
9190
Support

lldb/source/Target/Platform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@ FileSpec Platform::GetModuleCacheRoot() {
16721672

16731673
const char *Platform::GetCacheHostname() { return GetHostname(); }
16741674

1675-
const UnixSignalsSP &Platform::GetRemoteUnixSignals() {
1675+
UnixSignalsSP Platform::GetRemoteUnixSignals() {
16761676
static const auto s_default_unix_signals_sp = std::make_shared<UnixSignals>();
16771677
return s_default_unix_signals_sp;
16781678
}

0 commit comments

Comments
 (0)