Refactor Unix signals.

Summary:
- Consolidate Unix signals selection in UnixSignals.
- Make Unix signals available from platform.
- Add jSignalsInfo packet to retrieve Unix signals from remote platform.
- Get a copy of the platform signal for each remote process.
- Update SB API for signals.
- Update signal utility in test suite.

Reviewers: ovyalov, clayborg

Subscribers: chaoren, jingham, labath, emaste, tberghammer, lldb-commits

Differential Revision: http://reviews.llvm.org/D11094

llvm-svn: 242101
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
index f5e5d76..1205049 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -19,6 +19,7 @@
 // Other libraries and framework includes
 #include "lldb/Core/Log.h"
 #include "lldb/Core/StreamString.h"
+#include "lldb/Core/StructuredData.h"
 #include "lldb/Host/Config.h"
 #include "lldb/Host/ConnectionFileDescriptor.h"
 #include "lldb/Host/Host.h"
@@ -26,6 +27,7 @@
 #include "lldb/Target/FileAction.h"
 #include "lldb/Target/Platform.h"
 #include "lldb/Target/Process.h"
+#include "lldb/Target/UnixSignals.h"
 
 // Project includes
 #include "Utility/StringExtractorGDBRemote.h"
@@ -54,6 +56,8 @@
                                   &GDBRemoteCommunicationServerPlatform::Handle_qProcessInfo);
     RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_QSetWorkingDir,
                                   &GDBRemoteCommunicationServerPlatform::Handle_QSetWorkingDir);
+    RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_jSignalsInfo,
+                                  &GDBRemoteCommunicationServerPlatform::Handle_jSignalsInfo);
 
     RegisterPacketHandler(StringExtractorGDBRemote::eServerPacketType_interrupt,
                           [this](StringExtractorGDBRemote packet,
@@ -251,6 +255,35 @@
     return SendPacketNoLock (response.GetData(), response.GetSize());
 }
 
+GDBRemoteCommunication::PacketResult
+GDBRemoteCommunicationServerPlatform::Handle_jSignalsInfo(StringExtractorGDBRemote &packet)
+{
+    StructuredData::Array signal_array;
+
+    const auto &signals = Host::GetUnixSignals();
+    for (auto signo = signals->GetFirstSignalNumber();
+         signo != LLDB_INVALID_SIGNAL_NUMBER;
+         signo = signals->GetNextSignalNumber(signo))
+    {
+        auto dictionary = std::make_shared<StructuredData::Dictionary>();
+
+        dictionary->AddIntegerItem("signo", signo);
+        dictionary->AddStringItem("name", signals->GetSignalAsCString(signo));
+
+        bool suppress, stop, notify;
+        signals->GetSignalInfo(signo, suppress, stop, notify);
+        dictionary->AddBooleanItem("suppress", suppress);
+        dictionary->AddBooleanItem("stop", stop);
+        dictionary->AddBooleanItem("notify", notify);
+
+        signal_array.Push(dictionary);
+    }
+
+    StreamString response;
+    signal_array.Dump(response);
+    return SendPacketNoLock(response.GetData(), response.GetSize());
+}
+
 bool
 GDBRemoteCommunicationServerPlatform::DebugserverProcessReaped (lldb::pid_t pid)
 {