chaoren updated this revision to Diff 29418.
chaoren added a comment.

- UnixSignals::Reset should be virtual.


http://reviews.llvm.org/D11094

Files:
  include/lldb/API/SBPlatform.h
  include/lldb/API/SBUnixSignals.h
  include/lldb/Core/StructuredData.h
  include/lldb/Host/Host.h
  include/lldb/Target/Platform.h
  include/lldb/Target/Process.h
  include/lldb/Target/UnixSignals.h
  include/lldb/lldb-forward.h
  include/lldb/lldb-private-forward.h
  scripts/interface/SBPlatform.i
  source/API/SBPlatform.cpp
  source/API/SBProcess.cpp
  source/API/SBThread.cpp
  source/API/SBUnixSignals.cpp
  source/Commands/CommandObjectProcess.cpp
  source/Host/common/Host.cpp
  source/Host/freebsd/Host.cpp
  source/Host/linux/Host.cpp
  source/Plugins/Platform/Linux/PlatformLinux.cpp
  source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
  source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
  source/Plugins/Process/Linux/NativeProcessLinux.cpp
  source/Plugins/Process/Utility/CMakeLists.txt
  source/Plugins/Process/Utility/FreeBSDSignals.cpp
  source/Plugins/Process/Utility/FreeBSDSignals.h
  source/Plugins/Process/Utility/GDBRemoteSignals.cpp
  source/Plugins/Process/Utility/GDBRemoteSignals.h
  source/Plugins/Process/Utility/LinuxSignals.cpp
  source/Plugins/Process/Utility/LinuxSignals.h
  source/Plugins/Process/Utility/MipsLinuxSignals.cpp
  source/Plugins/Process/Utility/MipsLinuxSignals.h
  source/Plugins/Process/elf-core/ProcessElfCore.cpp
  source/Plugins/Process/elf-core/ProcessElfCore.h
  source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
  source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h
  source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
  source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
  source/Target/Platform.cpp
  source/Target/Process.cpp
  source/Target/StopInfo.cpp
  source/Target/UnixSignals.cpp
  source/Utility/StringExtractorGDBRemote.cpp
  source/Utility/StringExtractorGDBRemote.h
  test/lldbutil.py

Index: test/lldbutil.py
===================================================================
--- test/lldbutil.py
+++ test/lldbutil.py
@@ -934,35 +934,9 @@
 
 def get_signal_number(signal_name):
     platform = lldb.remote_platform
-    if platform:
-        if platform.GetName() == 'remote-linux':
-            command = lldb.SBPlatformShellCommand('kill -l %d' % signal_name)
-            if platform.Run(command).Success() and command.GetStatus() == 0:
-                try:
-                    return int(command.GetOutput())
-                except ValueError:
-                    pass
-        elif platform.GetName() == 'remote-android':
-            for signal_number in range(1, 65):
-                command = lldb.SBPlatformShellCommand('kill -l %d' % signal_number)
-                if platform.Run(command).Fail() or command.GetStatus() != 0:
-                    continue
-                output = command.GetOutput().strip().upper()
-                if not output.startswith('SIG'):
-                    output = 'SIG' + output
-                if output == signal_name:
-                    return signal_number
-    if lldb.debugger:
-        for target_index in range(lldb.debugger.GetNumTargets()):
-            target = lldb.debugger.GetTargetAtIndex(target_index)
-            if not target.IsValid():
-                continue
-            process = target.GetProcess()
-            if not process.IsValid():
-                continue
-            signals = process.GetUnixSignals()
-            if not signals.IsValid():
-                continue
+    if platform and platform.IsValid():
+        signals = platform.GetUnixSignals()
+        if signals.IsValid():
             signal_number = signals.GetSignalNumberFromName(signal_name)
             if signal_number > 0:
                 return signal_number
Index: source/Utility/StringExtractorGDBRemote.h
===================================================================
--- source/Utility/StringExtractorGDBRemote.h
+++ source/Utility/StringExtractorGDBRemote.h
@@ -118,6 +118,8 @@
         eServerPacketType_qWatchpointSupportInfoSupported,
         eServerPacketType_qXfer_auxv_read,
 
+        eServerPacketType_jSignalsInfo,
+
         eServerPacketType_vAttach,
         eServerPacketType_vAttachWait,
         eServerPacketType_vAttachOrWait,
Index: source/Utility/StringExtractorGDBRemote.cpp
===================================================================
--- source/Utility/StringExtractorGDBRemote.cpp
+++ source/Utility/StringExtractorGDBRemote.cpp
@@ -82,7 +82,7 @@
 
     case 'A':
         return eServerPacketType_A;
-            
+
     case 'Q':
 
         switch (packet_cstr[1])
@@ -122,7 +122,7 @@
             break;
         }
         break;
-            
+
     case 'q':
         switch (packet_cstr[1])
         {
@@ -219,6 +219,10 @@
             break;
         }
         break;
+
+    case 'j':
+        if (PACKET_MATCHES("jSignalInfo")) return eServerPacketType_jSignalsInfo;
+
     case 'v':
             if (PACKET_STARTS_WITH("vFile:"))
             {
Index: source/Target/UnixSignals.cpp
===================================================================
--- source/Target/UnixSignals.cpp
+++ source/Target/UnixSignals.cpp
@@ -291,3 +291,17 @@
         return SetShouldNotify (signo, value);
     return false;
 }
+
+int32_t
+UnixSignals::GetNumSignals() const
+{
+    return m_signals.size();
+}
+
+int32_t
+UnixSignals::GetSignalAtIndex(int32_t index) const
+{
+    auto it = m_signals.begin();
+    std::advance(it, index);
+    return it->first;
+}
Index: source/Target/StopInfo.cpp
===================================================================
--- source/Target/StopInfo.cpp
+++ source/Target/StopInfo.cpp
@@ -891,16 +891,16 @@
     {
         ThreadSP thread_sp (m_thread_wp.lock());
         if (thread_sp)
-            return thread_sp->GetProcess()->GetUnixSignals().GetShouldStop (m_value);
+            return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value);
         return false;
     }
 
     virtual bool
     ShouldStop (Event *event_ptr)
     {
         ThreadSP thread_sp (m_thread_wp.lock());
         if (thread_sp)
-            return thread_sp->GetProcess()->GetUnixSignals().GetShouldStop (m_value);
+            return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value);
         return false;
     }
     
@@ -912,13 +912,13 @@
         ThreadSP thread_sp (m_thread_wp.lock());
         if (thread_sp)
         {
-            bool should_notify = thread_sp->GetProcess()->GetUnixSignals().GetShouldNotify (m_value);
+            bool should_notify = thread_sp->GetProcess()->GetUnixSignals()->GetShouldNotify(m_value);
             if (should_notify)
             {
                 StreamString strm;
                 strm.Printf ("thread %d received signal: %s",
                              thread_sp->GetIndexID(),
-                             thread_sp->GetProcess()->GetUnixSignals().GetSignalAsCString (m_value));
+                             thread_sp->GetProcess()->GetUnixSignals()->GetSignalAsCString(m_value));
                 Process::ProcessEventData::AddRestartedReason(event_ptr, strm.GetData());
             }
             return should_notify;
@@ -933,7 +933,7 @@
         ThreadSP thread_sp (m_thread_wp.lock());
         if (thread_sp)
         {
-            if (thread_sp->GetProcess()->GetUnixSignals().GetShouldSuppress(m_value) == false)
+            if (thread_sp->GetProcess()->GetUnixSignals()->GetShouldSuppress(m_value) == false)
                 thread_sp->SetResumeSignal(m_value);
         }
     }
@@ -947,7 +947,7 @@
             if (thread_sp)
             {
                 StreamString strm;
-                const char *signal_name = thread_sp->GetProcess()->GetUnixSignals().GetSignalAsCString (m_value);
+                const char *signal_name = thread_sp->GetProcess()->GetUnixSignals()->GetSignalAsCString(m_value);
                 if (signal_name)
                     strm.Printf("signal %s", signal_name);
                 else
Index: source/Target/Process.cpp
===================================================================
--- source/Target/Process.cpp
+++ source/Target/Process.cpp
@@ -693,13 +693,6 @@
 // Process constructor
 //----------------------------------------------------------------------
 Process::Process(Target &target, Listener &listener) :
-    Process(target, listener, Host::GetUnixSignals ())
-{
-    // This constructor just delegates to the full Process constructor,
-    // defaulting to using the Host's UnixSignals.
-}
-
-Process::Process(Target &target, Listener &listener, const UnixSignalsSP &unix_signals_sp) :
     ProcessProperties (this),
     UserID (LLDB_INVALID_PROCESS_ID),
     Broadcaster (&(target.GetDebugger()), Process::GetStaticBroadcasterClass().AsCString()),
@@ -729,7 +722,6 @@
     m_listener (listener),
     m_breakpoint_site_list (),
     m_dynamic_checkers_ap (),
-    m_unix_signals_sp (unix_signals_sp),
     m_abi_sp (),
     m_process_input_reader (),
     m_stdio_communication ("process.stdio"),
@@ -762,9 +754,6 @@
     if (log)
         log->Printf ("%p Process::Process()", static_cast<void*>(this));
 
-    if (!m_unix_signals_sp)
-        m_unix_signals_sp.reset (new UnixSignals ());
-
     SetEventName (eBroadcastBitStateChanged, "state-changed");
     SetEventName (eBroadcastBitInterrupt, "interrupt");
     SetEventName (eBroadcastBitSTDOUT, "stdout-available");
@@ -790,8 +779,6 @@
                                                      eBroadcastInternalStateControlStop |
                                                      eBroadcastInternalStateControlPause |
                                                      eBroadcastInternalStateControlResume);
-    // We need something valid here, even if just the default UnixSignalsSP.
-    assert (m_unix_signals_sp && "null m_unix_signals_sp after initialization");
 }
 
 //----------------------------------------------------------------------
@@ -1164,7 +1151,7 @@
                                     // signal.  We have to have had another reason for stopping here, and
                                     // the user doesn't want to see this thread.
                                     uint64_t signo = thread->GetStopInfo()->GetValue();
-                                    if (process_sp->GetUnixSignals().GetShouldStop(signo))
+                                    if (process_sp->GetUnixSignals()->GetShouldStop(signo))
                                     {
                                         if (!other_thread)
                                             other_thread = thread;
@@ -1523,7 +1510,7 @@
             {
                 const char *signal_cstr = NULL;
                 if (signo)
-                    signal_cstr = process_sp->GetUnixSignals().GetSignalAsCString (signo);
+                    signal_cstr = process_sp->GetUnixSignals()->GetSignalAsCString(signo);
 
                 process_sp->SetExitStatus (exit_status, signal_cstr);
             }
@@ -4094,18 +4081,10 @@
     return error;
 }
 
-void
-Process::SetUnixSignals (const UnixSignalsSP &signals_sp)
-{
-    assert (signals_sp && "null signals_sp");
-    m_unix_signals_sp = signals_sp;
-}
-
-UnixSignals &
-Process::GetUnixSignals ()
+const UnixSignalsSP &
+Process::GetUnixSignals()
 {
-    assert (m_unix_signals_sp && "null m_unix_signals_sp");
-    return *m_unix_signals_sp;
+    return Host::GetUnixSignals();
 }
 
 lldb::ByteOrder
Index: source/Target/Platform.cpp
===================================================================
--- source/Target/Platform.cpp
+++ source/Target/Platform.cpp
@@ -1930,3 +1930,9 @@
 {
     return GetHostname ();
 }
+
+const UnixSignalsSP &
+Platform::GetUnixSignals()
+{
+    return Host::GetUnixSignals();
+}
Index: source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
+++ source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
@@ -215,14 +215,14 @@
             break;
 
         case eStateRunning:
-            if (gdb_process->GetUnixSignals().SignalIsValid (signo))
+            if (gdb_process->GetUnixSignals()->SignalIsValid(signo))
                 gdb_process->m_continue_C_tids.push_back(std::make_pair(tid, signo));
             else
                 gdb_process->m_continue_c_tids.push_back(tid);
             break;
 
         case eStateStepping:
-            if (gdb_process->GetUnixSignals().SignalIsValid (signo))
+            if (gdb_process->GetUnixSignals()->SignalIsValid(signo))
                 gdb_process->m_continue_S_tids.push_back(std::make_pair(tid, signo));
             else
                 gdb_process->m_continue_s_tids.push_back(tid);
Index: source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
===================================================================
--- source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -247,6 +247,9 @@
     void
     ModulesDidLoad (ModuleList &module_list) override;
 
+    const lldb::UnixSignalsSP &
+    GetUnixSignals() override;
+
 protected:
     friend class ThreadGDBRemote;
     friend class GDBRemoteCommunicationClient;
Index: source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -61,14 +61,12 @@
 #include "lldb/Target/TargetList.h"
 #include "lldb/Target/ThreadPlanCallFunction.h"
 #include "lldb/Target/SystemRuntime.h"
+#include "lldb/Target/UnixSignals.h"
 #include "lldb/Utility/PseudoTerminal.h"
 
 // Project includes
 #include "lldb/Host/Host.h"
-#include "Plugins/Process/Utility/FreeBSDSignals.h"
 #include "Plugins/Process/Utility/InferiorCallPOSIX.h"
-#include "Plugins/Process/Utility/LinuxSignals.h"
-#include "Plugins/Process/Utility/MipsLinuxSignals.h"
 #include "Plugins/Process/Utility/StopInfoMachException.h"
 #include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h"
 #include "Utility/StringExtractorGDBRemote.h"
@@ -823,42 +821,6 @@
     if (log)
         log->Printf ("ProcessGDBRemote::%s pid %" PRIu64 ": normalized target architecture triple: %s", __FUNCTION__, GetID (), GetTarget ().GetArchitecture ().GetTriple ().getTriple ().c_str ());
 
-    // Set the Unix signals properly for the target.
-    // FIXME Add a gdb-remote packet to discover dynamically.
-    if (error.Success ())
-    {
-        const ArchSpec arch_spec = m_gdb_comm.GetHostArchitecture();
-        if (arch_spec.IsValid ())
-        {
-            if (log)
-                log->Printf ("ProcessGDBRemote::%s pid %" PRIu64 ": determining unix signals type based on architecture %s, triple %s", __FUNCTION__, GetID (), arch_spec.GetArchitectureName () ? arch_spec.GetArchitectureName () : "<null>", arch_spec.GetTriple ().getTriple ().c_str ());
-
-            switch (arch_spec.GetTriple ().getOS ())
-            {
-            case llvm::Triple::Linux:
-                if (arch_spec.GetTriple ().getArch () == llvm::Triple::mips64 || arch_spec.GetTriple ().getArch () == llvm::Triple::mips64el)
-                    SetUnixSignals (UnixSignalsSP (new process_linux::MipsLinuxSignals ()));
-                else
-                    SetUnixSignals (UnixSignalsSP (new process_linux::LinuxSignals ()));
-                if (log)
-                    log->Printf ("ProcessGDBRemote::%s using Linux unix signals type for pid %" PRIu64, __FUNCTION__, GetID ());
-                break;
-            case llvm::Triple::OpenBSD:
-            case llvm::Triple::FreeBSD:
-            case llvm::Triple::NetBSD:
-                SetUnixSignals (UnixSignalsSP (new FreeBSDSignals ()));
-                if (log)
-                    log->Printf ("ProcessGDBRemote::%s using *BSD unix signals type for pid %" PRIu64, __FUNCTION__, GetID ());
-                break;
-            default:
-                SetUnixSignals (UnixSignalsSP (new UnixSignals ()));
-                if (log)
-                    log->Printf ("ProcessGDBRemote::%s using generic unix signals type for pid %" PRIu64, __FUNCTION__, GetID ());
-                break;
-            }
-        }
-    }
-
     return error;
 }
 
@@ -3524,7 +3486,7 @@
                 char error_str[1024];
                 if (signo)
                 {
-                    const char *signal_cstr = process->GetUnixSignals().GetSignalAsCString (signo);
+                    const char *signal_cstr = process->GetUnixSignals()->GetSignalAsCString(signo);
                     if (signal_cstr)
                         ::snprintf (error_str, sizeof (error_str), DEBUGSERVER_BASENAME " died with signal %s", signal_cstr);
                     else
@@ -5010,3 +4972,9 @@
         m_command_sp.reset (new CommandObjectMultiwordProcessGDBRemote (GetTarget().GetDebugger().GetCommandInterpreter()));
     return m_command_sp.get();
 }
+
+const UnixSignalsSP &
+ProcessGDBRemote::GetUnixSignals()
+{
+    return GetTarget().GetPlatform()->GetUnixSignals();
+}
Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h
===================================================================
--- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h
+++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h
@@ -79,6 +79,9 @@
     PacketResult
     Handle_qC (StringExtractorGDBRemote &packet);
 
+    PacketResult
+    Handle_jSignalsInfo(StringExtractorGDBRemote &packet);
+
 private:
     bool
     DebugserverProcessReaped (lldb::pid_t pid);
Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -19,13 +19,15 @@
 // 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"
 #include "lldb/Host/StringConvert.h"
 #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,34 @@
     return SendPacketNoLock (response.GetData(), response.GetSize());
 }
 
+GDBRemoteCommunication::PacketResult
+GDBRemoteCommunicationServerPlatform::Handle_jSignalsInfo(StringExtractorGDBRemote &packet)
+{
+    StructuredData::Array signal_array;
+
+    for (auto signo = Host::GetUnixSignals()->GetFirstSignalNumber();
+         signo != LLDB_INVALID_SIGNAL_NUMBER;
+         signo = Host::GetUnixSignals()->GetNextSignalNumber(signo))
+    {
+        auto dictionary = std::make_shared<StructuredData::Dictionary>();
+
+        dictionary->AddIntegerItem("signo", signo);
+        dictionary->AddStringItem("name", Host::GetUnixSignals()->GetSignalAsCString(signo));
+
+        bool suppress, stop, notify;
+        Host::GetUnixSignals()->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)
 {
Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -1037,8 +1037,8 @@
     // may change if we are interrupted and we continue after an async packet...
     std::string continue_packet(payload, packet_length);
 
-    const auto sigstop_signo = process->GetUnixSignals().GetSignalNumberFromName("SIGSTOP");
-    const auto sigint_signo = process->GetUnixSignals().GetSignalNumberFromName("SIGINT");
+    const auto sigstop_signo = process->GetUnixSignals()->GetSignalNumberFromName("SIGSTOP");
+    const auto sigint_signo = process->GetUnixSignals()->GetSignalNumberFromName("SIGINT");
 
     bool got_async_packet = false;
     
Index: source/Plugins/Process/elf-core/ProcessElfCore.h
===================================================================
--- source/Plugins/Process/elf-core/ProcessElfCore.h
+++ source/Plugins/Process/elf-core/ProcessElfCore.h
@@ -110,6 +110,9 @@
     const lldb::DataBufferSP
     GetAuxvData() override;
 
+    const lldb::UnixSignalsSP &
+    GetUnixSignals() override;
+
 protected:
     void
     Clear ( );
Index: source/Plugins/Process/elf-core/ProcessElfCore.cpp
===================================================================
--- source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -23,14 +23,11 @@
 #include "lldb/Core/Log.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Target/DynamicLoader.h"
-#include "lldb/Target/UnixSignals.h"
 
 #include "llvm/Support/ELF.h"
 
 #include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
 #include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h"
-#include "Plugins/Process/Utility/FreeBSDSignals.h"
-#include "Plugins/Process/Utility/LinuxSignals.h"
 
 // Project includes
 #include "ProcessElfCore.h"
@@ -237,24 +234,6 @@
     if (arch.IsValid())
         m_target.SetArchitecture(arch);
 
-    switch (m_os)
-    {
-        case llvm::Triple::FreeBSD:
-        {
-            static UnixSignalsSP s_freebsd_signals_sp(new FreeBSDSignals ());
-            SetUnixSignals(s_freebsd_signals_sp);
-            break;
-        }
-        case llvm::Triple::Linux:
-        {
-            static UnixSignalsSP s_linux_signals_sp(new process_linux::LinuxSignals ());
-            SetUnixSignals(s_linux_signals_sp);
-            break;
-        }
-        default:
-            break;
-    }
-
     return error;
 }
 
@@ -369,9 +348,6 @@
 {
     m_thread_list.Clear();
     m_os = llvm::Triple::UnknownOS;
-
-    static UnixSignalsSP s_default_unix_signals_sp(new UnixSignals());
-    SetUnixSignals(s_default_unix_signals_sp);
 }
 
 void
@@ -612,3 +588,9 @@
     lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(start, len));
     return buffer;
 }
+
+const lldb::UnixSignalsSP &
+ProcessElfCore::GetUnixSignals()
+{
+    return Host::GetUnixSignals(GetArchitecture());
+}
Index: source/Plugins/Process/Utility/MipsLinuxSignals.h
===================================================================
--- source/Plugins/Process/Utility/MipsLinuxSignals.h
+++ source/Plugins/Process/Utility/MipsLinuxSignals.h
@@ -17,21 +17,19 @@
 #include "lldb/Target/UnixSignals.h"
 
 namespace lldb_private {
-namespace process_linux {
 
-    /// Linux specific set of Unix signals.
-    class MipsLinuxSignals
-        : public lldb_private::UnixSignals
-    {
-    public:
-        MipsLinuxSignals();
+/// Linux specific set of Unix signals.
+class MipsLinuxSignals
+    : public lldb_private::UnixSignals
+{
+public:
+    MipsLinuxSignals();
 
-    private:
-        void
-        Reset();
-    };
+private:
+    void
+    Reset() override;
+};
 
 } // namespace lldb_private
-} // namespace process_linux
 
-#endif
+#endif // liblldb_MipsLinuxSignals_H_
Index: source/Plugins/Process/Utility/MipsLinuxSignals.cpp
===================================================================
--- source/Plugins/Process/Utility/MipsLinuxSignals.cpp
+++ source/Plugins/Process/Utility/MipsLinuxSignals.cpp
@@ -12,7 +12,7 @@
 // Project includes
 #include "MipsLinuxSignals.h"
 
-using namespace lldb_private::process_linux;
+using namespace lldb_private;
 
 MipsLinuxSignals::MipsLinuxSignals()
     : UnixSignals()
Index: source/Plugins/Process/Utility/LinuxSignals.cpp
===================================================================
--- source/Plugins/Process/Utility/LinuxSignals.cpp
+++ source/Plugins/Process/Utility/LinuxSignals.cpp
@@ -12,7 +12,7 @@
 // Project includes
 #include "LinuxSignals.h"
 
-using namespace lldb_private::process_linux;
+using namespace lldb_private;
 
 LinuxSignals::LinuxSignals()
     : UnixSignals()
Index: source/Plugins/Process/Utility/LinuxSignals.h
===================================================================
--- source/Plugins/Process/Utility/LinuxSignals.h
+++ source/Plugins/Process/Utility/LinuxSignals.h
@@ -17,21 +17,19 @@
 #include "lldb/Target/UnixSignals.h"
 
 namespace lldb_private {
-namespace process_linux {
 
-    /// Linux specific set of Unix signals.
-    class LinuxSignals
-        : public lldb_private::UnixSignals
-    {
-    public:
-        LinuxSignals();
+/// Linux specific set of Unix signals.
+class LinuxSignals
+    : public lldb_private::UnixSignals
+{
+public:
+    LinuxSignals();
 
-    private:
-        void
-        Reset();
-    };
+private:
+    void
+    Reset() override;
+};
 
 } // namespace lldb_private
-} // namespace process_linux
 
-#endif
+#endif // liblldb_LinuxSignals_H_
Index: source/Plugins/Process/Utility/GDBRemoteSignals.h
===================================================================
--- source/Plugins/Process/Utility/GDBRemoteSignals.h
+++ source/Plugins/Process/Utility/GDBRemoteSignals.h
@@ -1,37 +1,35 @@
-//===-- LinuxSignals.h ------------------------------------------*- C++ -*-===//
+//===-- GDBRemoteSignals.h --------------------------------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
 // This file is distributed under the University of Illinois Open Source
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef liblldb_LinuxSignals_H_
-#define liblldb_LinuxSignals_H_
+#ifndef liblldb_GDBRemoteSignals_H_
+#define liblldb_GDBRemoteSignals_H_
 
 // C Includes
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
 #include "lldb/Target/UnixSignals.h"
 
 namespace lldb_private {
-namespace process_linux {
 
-    /// Linux specific set of Unix signals.
-    class LinuxSignals
-        : public lldb_private::UnixSignals
-    {
-    public:
-        LinuxSignals();
+/// Empty set of Unix signals to be filled by PlatformRemoteGDBServer
+class GDBRemoteSignals
+    : public lldb_private::UnixSignals
+{
+public:
+    GDBRemoteSignals();
 
-    private:
-        void
-        Reset();
-    };
+private:
+    void
+    Reset() override;
+};
 
 } // namespace lldb_private
-} // namespace process_linux
 
-#endif
+#endif // liblldb_GDBRemoteSignals_H_
Index: source/Plugins/Process/Utility/GDBRemoteSignals.cpp
===================================================================
--- /dev/null
+++ source/Plugins/Process/Utility/GDBRemoteSignals.cpp
@@ -0,0 +1,27 @@
+//===-- GDBRemoteSignals.cpp ------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "GDBRemoteSignals.h"
+
+using namespace lldb_private;
+
+GDBRemoteSignals::GDBRemoteSignals()
+    : UnixSignals()
+{
+    Reset();
+}
+
+void
+GDBRemoteSignals::Reset()
+{
+    m_signals.clear();
+}
Index: source/Plugins/Process/Utility/FreeBSDSignals.h
===================================================================
--- source/Plugins/Process/Utility/FreeBSDSignals.h
+++ source/Plugins/Process/Utility/FreeBSDSignals.h
@@ -13,6 +13,8 @@
 // Project includes
 #include "lldb/Target/UnixSignals.h"
 
+namespace lldb_private {
+
 /// FreeBSD specific set of Unix signals.
 class FreeBSDSignals
     : public lldb_private::UnixSignals
@@ -22,7 +24,9 @@
 
 private:
     void
-    Reset();
+    Reset() override;
 };
 
+} // namespace lldb_private
+
 #endif // liblldb_FreeBSDSignals_H_
Index: source/Plugins/Process/Utility/FreeBSDSignals.cpp
===================================================================
--- source/Plugins/Process/Utility/FreeBSDSignals.cpp
+++ source/Plugins/Process/Utility/FreeBSDSignals.cpp
@@ -13,6 +13,8 @@
 // Project includes
 #include "FreeBSDSignals.h"
 
+using namespace lldb_private;
+
 FreeBSDSignals::FreeBSDSignals()
     : UnixSignals()
 {
Index: source/Plugins/Process/Utility/CMakeLists.txt
===================================================================
--- source/Plugins/Process/Utility/CMakeLists.txt
+++ source/Plugins/Process/Utility/CMakeLists.txt
@@ -5,6 +5,7 @@
 add_lldb_library(lldbPluginProcessUtility
   DynamicRegisterInfo.cpp
   FreeBSDSignals.cpp
+  GDBRemoteSignals.cpp
   HistoryThread.cpp
   HistoryUnwind.cpp
   InferiorCallPOSIX.cpp
Index: source/Plugins/Process/Linux/NativeProcessLinux.cpp
===================================================================
--- source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -43,7 +43,6 @@
 #include "lldb/Utility/StringExtractor.h"
 
 #include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
-#include "Plugins/Process/Utility/LinuxSignals.h"
 #include "NativeThreadLinux.h"
 #include "ProcFileReader.h"
 #include "Procfs.h"
@@ -113,13 +112,6 @@
 
 namespace
 {
-    const UnixSignals&
-    GetUnixSignals ()
-    {
-        static process_linux::LinuxSignals signals;
-        return signals;
-    }
-
     Error
     ResolveProcessArchitecture (lldb::pid_t pid, Platform &platform, ArchSpec &arch)
     {
@@ -1987,7 +1979,7 @@
         if (log)
             log->Printf ("NativeProcessLinux::%s() received signal %s (%d) with code %s, (siginfo pid = %d (%s), waitpid pid = %" PRIu64 ")",
                             __FUNCTION__,
-                            GetUnixSignals ().GetSignalAsCString (signo),
+                            Host::GetSignalAsCString(signo),
                             signo,
                             (info->si_code == SI_TKILL ? "SI_TKILL" : "SI_USER"),
                             info->si_pid,
@@ -2062,7 +2054,7 @@
                     // Retrieve the signal name if the thread was stopped by a signal.
                     int stop_signo = 0;
                     const bool stopped_by_signal = linux_thread_sp->IsStopped (&stop_signo);
-                    const char *signal_name = stopped_by_signal ? GetUnixSignals ().GetSignalAsCString (stop_signo) : "<not stopped by signal>";
+                    const char *signal_name = stopped_by_signal ? Host::GetSignalAsCString(stop_signo) : "<not stopped by signal>";
                     if (!signal_name)
                         signal_name = "<no-signal-name>";
 
@@ -2083,7 +2075,7 @@
     }
 
     if (log)
-        log->Printf ("NativeProcessLinux::%s() received signal %s", __FUNCTION__, GetUnixSignals ().GetSignalAsCString (signo));
+        log->Printf ("NativeProcessLinux::%s() received signal %s", __FUNCTION__, Host::GetSignalAsCString(signo));
 
     // This thread is stopped.
     ThreadDidStop (pid, false);
@@ -2428,8 +2420,8 @@
 
     Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
     if (log)
-        log->Printf ("NativeProcessLinux::%s: sending signal %d (%s) to pid %" PRIu64, 
-                __FUNCTION__, signo,  GetUnixSignals ().GetSignalAsCString (signo), GetID ());
+        log->Printf ("NativeProcessLinux::%s: sending signal %d (%s) to pid %" PRIu64,
+                __FUNCTION__, signo, Host::GetSignalAsCString(signo), GetID());
 
     if (kill(GetID(), signo))
         error.SetErrorToErrno();
@@ -3176,7 +3168,7 @@
 
     if (log)
         log->Printf ("NativeProcessLinux::%s() resuming thread = %"  PRIu64 " with signal %s", __FUNCTION__, tid,
-                                 GetUnixSignals().GetSignalAsCString (signo));
+                                 Host::GetSignalAsCString(signo));
 
 
 
Index: source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
===================================================================
--- source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
+++ source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
@@ -18,6 +18,7 @@
 // Project includes
 #include "lldb/Target/Platform.h"
 #include "../../Process/gdb-remote/GDBRemoteCommunicationClient.h"
+#include "Plugins/Process/Utility/GDBRemoteSignals.h"
 
 namespace lldb_private {
 namespace platform_gdb_server {
@@ -213,12 +214,17 @@
     void
     CalculateTrapHandlerSymbolNames () override;
 
+    const lldb::UnixSignalsSP &
+    GetUnixSignals() override;
+
 protected:
     process_gdb_remote::GDBRemoteCommunicationClient m_gdb_client;
     std::string m_platform_description; // After we connect we can get a more complete description of what we are connected to
     std::string m_platform_scheme;
     std::string m_platform_hostname;
 
+    lldb::UnixSignalsSP m_remote_signals_sp;
+
     // Launch the lldb-gdbserver on the remote host and return the port it is listening on or 0 on
     // failure. Subclasses should override this method if they want to do extra actions before or
     // after launching the lldb-gdbserver.
@@ -228,6 +234,9 @@
     virtual bool
     KillSpawnedProcess (lldb::pid_t pid);
 
+    void
+    GetRemoteSignals(bool force);
+
 private:
     DISALLOW_COPY_AND_ASSIGN (PlatformRemoteGDBServer);
 
Index: source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
===================================================================
--- source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -29,9 +29,12 @@
 #include "lldb/Host/StringConvert.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
+#include "lldb/Utility/LLDBAssert.h"
 
 #include "Utility/UriParser.h"
 
+#include "Plugins/Process/Utility/GDBRemoteSignals.h"
+
 using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::platform_gdb_server;
@@ -413,6 +416,7 @@
 {
     Error error;
     m_gdb_client.Disconnect(&error);
+    m_remote_signals_sp.reset();
     return error;
 }
 
@@ -871,6 +875,104 @@
 
 void
 PlatformRemoteGDBServer::CalculateTrapHandlerSymbolNames ()
-{   
+{
     m_trap_handlers.push_back (ConstString ("_sigtramp"));
 }
+
+void
+PlatformRemoteGDBServer::GetRemoteSignals(bool force)
+{
+    if (!force && m_remote_signals_sp)
+        return;
+
+    // If packet not implemented or JSON failed to parse,
+    // we'll guess the signal set based on the remote architecture.
+    m_remote_signals_sp = Host::GetUnixSignals(GetRemoteSystemArchitecture());
+
+    const char packet[] = "jSignalsInfo";
+    StringExtractorGDBRemote response;
+    auto result = m_gdb_client.SendPacketAndWaitForResponse(
+            packet, strlen(packet), response, false);
+
+    if (result != decltype(result)::Success ||
+            response.GetResponseType() != response.eResponse)
+        return;
+
+    auto object_sp = StructuredData::ParseJSON(response.GetStringRef());
+    if (!object_sp || !object_sp->IsValid())
+        return;
+
+    auto array_sp = object_sp->GetAsArray();
+    if (!array_sp || !array_sp->IsValid())
+        return;
+
+    auto remote_signals_sp = std::make_shared<lldb_private::GDBRemoteSignals>();
+
+    bool done = array_sp->ForEach(
+        [&remote_signals_sp](StructuredData::Object *object) -> bool
+        {
+            if (!object || !object->IsValid())
+                return false;
+
+            auto dict = object->GetAsDictionary();
+            if (!dict || !dict->IsValid())
+                return false;
+
+            // Signal number and signal name are required.
+            int signo;
+            if (!dict->GetValueForKeyAsInteger("signo", signo))
+                return false;
+
+            std::string name;
+            if (!dict->GetValueForKeyAsString("name", name))
+                return false;
+
+            // We can live without short_name, description, etc.
+            std::string short_name{""};
+            auto object_sp = dict->GetValueForKey("short_name");
+            if (object_sp && object_sp->IsValid())
+                short_name = object_sp->GetStringValue();
+
+            bool suppress{false};
+            object_sp = dict->GetValueForKey("suppress");
+            if (object_sp && object_sp->IsValid())
+                suppress = object_sp->GetBooleanValue();
+
+            bool stop{false};
+            object_sp = dict->GetValueForKey("stop");
+            if (object_sp && object_sp->IsValid())
+                stop = object_sp->GetBooleanValue();
+
+            bool notify{false};
+            object_sp = dict->GetValueForKey("notify");
+            if (object_sp && object_sp->IsValid())
+                notify = object_sp->GetBooleanValue();
+
+            std::string description{""};
+            object_sp = dict->GetValueForKey("description");
+            if (object_sp && object_sp->IsValid())
+                description = object_sp->GetStringValue();
+
+            remote_signals_sp->AddSignal(signo,
+                                         name.c_str(),
+                                         short_name.c_str(),
+                                         suppress, stop, notify,
+                                         description.c_str());
+            return true;
+        });
+
+    if (done)
+        m_remote_signals_sp = std::move(remote_signals_sp);
+}
+
+const UnixSignalsSP &
+PlatformRemoteGDBServer::GetUnixSignals()
+{
+    if (IsConnected())
+    {
+        // Get the signals through jSignalsInfo if we haven't already.
+        GetRemoteSignals(false);
+        return m_remote_signals_sp;
+    }
+    return Host::GetUnixSignals(GetRemoteSystemArchitecture());
+}
Index: source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
===================================================================
--- source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -785,9 +785,6 @@
 
             if (process_sp)
             {
-                // Set UnixSignals appropriately.
-                process_sp->SetUnixSignals (Host::GetUnixSignals ());
-
                 auto listener_sp = attach_info.GetHijackListener();
                 if (listener_sp == nullptr)
                 {
Index: source/Plugins/Platform/Linux/PlatformLinux.cpp
===================================================================
--- source/Plugins/Platform/Linux/PlatformLinux.cpp
+++ source/Plugins/Platform/Linux/PlatformLinux.cpp
@@ -754,9 +754,6 @@
             log->Printf ("PlatformLinux::%s successfully created process", __FUNCTION__);
     }
 
-    // Set the unix signals properly.
-    process_sp->SetUnixSignals (Host::GetUnixSignals ());
-
     // Adjust launch for a hijacker.
     ListenerSP listener_sp;
     if (!launch_info.GetHijackListener ())
Index: source/Host/linux/Host.cpp
===================================================================
--- source/Host/linux/Host.cpp
+++ source/Host/linux/Host.cpp
@@ -36,8 +36,7 @@
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "Plugins/Process/Linux/ProcFileReader.h"
-#include "Plugins/Process/Utility/LinuxSignals.h"
-#include "Plugins/Process/Utility/MipsLinuxSignals.h"
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -390,26 +389,6 @@
     return i;
 }
 
-// TODO: Generalize this with a function Host::GetSignals() as discussed at http://reviews.llvm.org/D10180 
-const lldb_private::UnixSignalsSP&
-Host::GetUnixSignals ()
-{
-    ArchSpec target_arch = HostInfoBase::GetArchitecture();
-    if(target_arch.GetTriple ().getArch () == llvm::Triple::mips64 ||
-       target_arch.GetTriple ().getArch () == llvm::Triple::mips64el ||
-       target_arch.GetTriple ().getArch () == llvm::Triple::mips ||
-       target_arch.GetTriple ().getArch () == llvm::Triple::mipsel) {
-        static const lldb_private::UnixSignalsSP s_unix_signals_sp (new process_linux::MipsLinuxSignals ());
-        return s_unix_signals_sp;
-    }
-    else
-    {
-        static const lldb_private::UnixSignalsSP s_unix_signals_sp (new process_linux::LinuxSignals ());
-        return s_unix_signals_sp;
-    }
-
-}
-
 Error
 Host::ShellExpandArguments (ProcessLaunchInfo &launch_info)
 {
Index: source/Host/freebsd/Host.cpp
===================================================================
--- source/Host/freebsd/Host.cpp
+++ source/Host/freebsd/Host.cpp
@@ -40,8 +40,6 @@
 #include "lldb/Utility/CleanUp.h"
 #include "lldb/Utility/NameMatches.h"
 
-#include "Plugins/Process/Utility/FreeBSDSignals.h"
-
 #include "llvm/Support/Host.h"
 
 extern "C" {
@@ -277,13 +275,6 @@
    return buf_sp;
 }
 
-const UnixSignalsSP&
-Host::GetUnixSignals ()
-{
-    static const lldb_private::UnixSignalsSP s_unix_signals_sp (new FreeBSDSignals ());
-    return s_unix_signals_sp;
-}
-
 Error
 Host::ShellExpandArguments (ProcessLaunchInfo &launch_info)
 {
Index: source/Host/common/Host.cpp
===================================================================
--- source/Host/common/Host.cpp
+++ source/Host/common/Host.cpp
@@ -62,6 +62,10 @@
 #include "lldb/Utility/CleanUp.h"
 #include "llvm/ADT/SmallString.h"
 
+#include "Plugins/Process/Utility/FreeBSDSignals.h"
+#include "Plugins/Process/Utility/LinuxSignals.h"
+#include "Plugins/Process/Utility/MipsLinuxSignals.h"
+
 #if defined(_WIN32)
 #include "lldb/Host/windows/ProcessLauncherWindows.h"
 #elif defined(__ANDROID__) || defined(__ANDROID_NDK__)
@@ -1070,13 +1074,42 @@
 
 #endif
 
-#if !defined (__linux__) && !defined (__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined (__NetBSD__)
-
-const lldb_private::UnixSignalsSP&
-Host::GetUnixSignals ()
+const UnixSignalsSP &
+Host::GetUnixSignals(const ArchSpec &arch)
 {
-    static UnixSignalsSP s_unix_signals_sp (new UnixSignals ());
-    return s_unix_signals_sp;
+    const auto &triple = arch.GetTriple();
+    switch (triple.getOS())
+    {
+        case llvm::Triple::Linux:
+        {
+            switch (triple.getArch())
+            {
+                case llvm::Triple::mips:
+                case llvm::Triple::mipsel:
+                case llvm::Triple::mips64:
+                case llvm::Triple::mips64el:
+                {
+                    static const UnixSignalsSP s_unix_signals_sp{std::make_shared<MipsLinuxSignals>()};
+                    return s_unix_signals_sp;
+                }
+                default:
+                {
+                    static const UnixSignalsSP s_unix_signals_sp{std::make_shared<LinuxSignals>()};
+                    return s_unix_signals_sp;
+                }
+            }
+        }
+        case llvm::Triple::FreeBSD:
+        case llvm::Triple::OpenBSD:
+        case llvm::Triple::NetBSD:
+        {
+            static const UnixSignalsSP s_unix_signals_sp{std::make_shared<FreeBSDSignals>()};
+            return s_unix_signals_sp;
+        }
+        default:
+        {
+            static const UnixSignalsSP s_unix_signals_sp{std::make_shared<UnixSignals>()};
+            return s_unix_signals_sp;
+        }
+    }
 }
-
-#endif
Index: source/Commands/CommandObjectProcess.cpp
===================================================================
--- source/Commands/CommandObjectProcess.cpp
+++ source/Commands/CommandObjectProcess.cpp
@@ -1337,7 +1337,7 @@
             if (::isxdigit (signal_name[0]))
                 signo = StringConvert::ToSInt32(signal_name, LLDB_INVALID_SIGNAL_NUMBER, 0);
             else
-                signo = process->GetUnixSignals().GetSignalNumberFromName (signal_name);
+                signo = process->GetUnixSignals()->GetSignalNumberFromName(signal_name);
             
             if (signo == LLDB_INVALID_SIGNAL_NUMBER)
             {
@@ -1734,14 +1734,14 @@
     }  
 
     void
-    PrintSignal (Stream &str, int32_t signo, const char *sig_name, UnixSignals &signals)
+    PrintSignal(Stream &str, int32_t signo, const char *sig_name, UnixSignalsSP signals)
     {
         bool stop;
         bool suppress;
         bool notify;
 
         str.Printf ("%-11s  ", sig_name);
-        if (signals.GetSignalInfo (signo, suppress, stop, notify))
+        if (signals->GetSignalInfo(signo, suppress, stop, notify))
         {
             bool pass = !suppress;
             str.Printf ("%s  %s  %s", 
@@ -1753,27 +1753,27 @@
     }
 
     void
-    PrintSignalInformation (Stream &str, Args &signal_args, int num_valid_signals, UnixSignals &signals)
+    PrintSignalInformation(Stream &str, Args &signal_args, int num_valid_signals, UnixSignalsSP signals)
     {
         PrintSignalHeader (str);
 
         if (num_valid_signals > 0)
         {
             size_t num_args = signal_args.GetArgumentCount();
             for (size_t i = 0; i < num_args; ++i)
             {
-                int32_t signo = signals.GetSignalNumberFromName (signal_args.GetArgumentAtIndex (i));
+                int32_t signo = signals->GetSignalNumberFromName(signal_args.GetArgumentAtIndex(i));
                 if (signo != LLDB_INVALID_SIGNAL_NUMBER)
                     PrintSignal (str, signo, signal_args.GetArgumentAtIndex (i), signals);
             }
         }
         else // Print info for ALL signals
         {
-            int32_t signo = signals.GetFirstSignalNumber(); 
+            int32_t signo = signals->GetFirstSignalNumber();
             while (signo != LLDB_INVALID_SIGNAL_NUMBER)
             {
-                PrintSignal (str, signo, signals.GetSignalAsCString (signo), signals);
-                signo = signals.GetNextSignalNumber (signo);
+                PrintSignal(str, signo, signals->GetSignalAsCString(signo), signals);
+                signo = signals->GetNextSignalNumber(signo);
             }
         }
     }
@@ -1830,27 +1830,27 @@
         }
 
         size_t num_args = signal_args.GetArgumentCount();
-        UnixSignals &signals = process_sp->GetUnixSignals();
+        UnixSignalsSP signals = process_sp->GetUnixSignals();
         int num_signals_set = 0;
 
         if (num_args > 0)
         {
             for (size_t i = 0; i < num_args; ++i)
             {
-                int32_t signo = signals.GetSignalNumberFromName (signal_args.GetArgumentAtIndex (i));
+                int32_t signo = signals->GetSignalNumberFromName(signal_args.GetArgumentAtIndex(i));
                 if (signo != LLDB_INVALID_SIGNAL_NUMBER)
                 {
                     // Casting the actions as bools here should be okay, because VerifyCommandOptionValue guarantees
                     // the value is either 0 or 1.
                     if (stop_action != -1)
-                        signals.SetShouldStop (signo, (bool) stop_action);
+                        signals->SetShouldStop(signo, stop_action);
                     if (pass_action != -1)
                     {
-                        bool suppress = ! ((bool) pass_action);
-                        signals.SetShouldSuppress (signo, suppress);
+                        bool suppress = !pass_action;
+                        signals->SetShouldSuppress(signo, suppress);
                     }
                     if (notify_action != -1)
-                        signals.SetShouldNotify (signo, (bool) notify_action);
+                        signals->SetShouldNotify(signo, notify_action);
                     ++num_signals_set;
                 }
                 else
@@ -1866,19 +1866,19 @@
             {
                 if (m_interpreter.Confirm ("Do you really want to update all the signals?", false))
                 {
-                    int32_t signo = signals.GetFirstSignalNumber();
+                    int32_t signo = signals->GetFirstSignalNumber();
                     while (signo != LLDB_INVALID_SIGNAL_NUMBER)
                     {
                         if (notify_action != -1)
-                            signals.SetShouldNotify (signo, (bool) notify_action);
+                            signals->SetShouldNotify(signo, notify_action);
                         if (stop_action != -1)
-                            signals.SetShouldStop (signo, (bool) stop_action);
+                            signals->SetShouldStop(signo, stop_action);
                         if (pass_action != -1)
                         {
-                            bool suppress = ! ((bool) pass_action);
-                            signals.SetShouldSuppress (signo, suppress);
+                            bool suppress = !pass_action;
+                            signals->SetShouldSuppress(signo, suppress);
                         }
-                        signo = signals.GetNextSignalNumber (signo);
+                        signo = signals->GetNextSignalNumber(signo);
                     }
                 }
             }
Index: source/API/SBUnixSignals.cpp
===================================================================
--- source/API/SBUnixSignals.cpp
+++ source/API/SBUnixSignals.cpp
@@ -9,6 +9,7 @@
 
 #include "lldb/lldb-defines.h"
 #include "lldb/Target/Process.h"
+#include "lldb/Target/Platform.h"
 #include "lldb/Target/UnixSignals.h"
 #include "lldb/Core/Log.h"
 
@@ -20,81 +21,88 @@
 SBUnixSignals::SBUnixSignals ()
 {}
 
-SBUnixSignals::SBUnixSignals (const SBUnixSignals &rhs) :
-    m_opaque_wp(rhs.m_opaque_wp)
+SBUnixSignals::SBUnixSignals(const SBUnixSignals &rhs) :
+    m_opaque_sp{rhs.m_opaque_sp}, m_process_wp{rhs.m_process_wp}
 {
 }
 
-SBUnixSignals::SBUnixSignals (ProcessSP &process_sp) :
-    m_opaque_wp(process_sp)
+SBUnixSignals::SBUnixSignals(const ProcessSP &process_sp) :
+    m_opaque_sp{process_sp->GetUnixSignals()}, m_process_wp{process_sp}
+{
+}
+
+SBUnixSignals::SBUnixSignals(const PlatformSP &platform_sp) :
+    m_opaque_sp{platform_sp->GetUnixSignals()}, m_process_wp{}
 {
 }
 
 const SBUnixSignals&
 SBUnixSignals::operator = (const SBUnixSignals& rhs)
 {
     if (this != &rhs)
-        m_opaque_wp = rhs.m_opaque_wp;
+    {
+        m_opaque_sp = rhs.m_opaque_sp;
+        m_process_wp = rhs.m_process_wp;
+    }
     return *this;
 }
 
 SBUnixSignals::~SBUnixSignals()
 {
 }
 
 ProcessSP
-SBUnixSignals::GetSP() const
-{
-    return m_opaque_wp.lock();
-}
-
-void
-SBUnixSignals::SetSP (const ProcessSP &process_sp)
+SBUnixSignals::GetProcess() const
 {
-    m_opaque_wp = process_sp;
+    return m_process_wp.lock();
 }
 
 void
 SBUnixSignals::Clear ()
 {
-    m_opaque_wp.reset();
+    m_opaque_sp.reset();
+    m_process_wp.reset();
 }
 
 bool
 SBUnixSignals::IsValid() const
 {
-    return (bool) GetSP();
+    return m_opaque_sp.get();
 }
 
 const char *
-SBUnixSignals::GetSignalAsCString (int32_t signo) const
+SBUnixSignals::GetSignalAsCString(int32_t signo) const
 {
-    ProcessSP process_sp(GetSP());
-    if (process_sp) return process_sp->GetUnixSignals().GetSignalAsCString(signo);
-    return NULL;
+    if (m_opaque_sp)
+        return m_opaque_sp->GetSignalAsCString(signo);
+
+    return nullptr;
 }
 
 int32_t
 SBUnixSignals::GetSignalNumberFromName (const char *name) const
 {
-    ProcessSP process_sp(GetSP());
-    if (process_sp) return process_sp->GetUnixSignals().GetSignalNumberFromName(name);
-    return -1;
+    if (m_opaque_sp)
+        return m_opaque_sp->GetSignalNumberFromName(name);
+
+    return LLDB_INVALID_SIGNAL_NUMBER;
 }
 
 bool
 SBUnixSignals::GetShouldSuppress (int32_t signo) const
 {
-    ProcessSP process_sp(GetSP());
-    if (process_sp) return process_sp->GetUnixSignals().GetShouldSuppress(signo);
+    ProcessSP process_sp(GetProcess());
+    if (process_sp)
+        return process_sp->GetUnixSignals()->GetShouldSuppress(signo);
+
     return false;
 }
 
 bool
 SBUnixSignals::SetShouldSuppress (int32_t signo, bool value)
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-    ProcessSP process_sp(GetSP());
+    ProcessSP process_sp(GetProcess());
 
     if (log)
     {
@@ -104,23 +112,27 @@
                      value);
     }
 
-    if (process_sp) return process_sp->GetUnixSignals().SetShouldSuppress(signo, value);
+    if (process_sp)
+        return process_sp->GetUnixSignals()->SetShouldSuppress(signo, value);
+
     return false;
 }
 
 bool
 SBUnixSignals::GetShouldStop (int32_t signo) const
 {
-    ProcessSP process_sp(GetSP());
-    if (process_sp) return process_sp->GetUnixSignals().GetShouldStop(signo);
+    ProcessSP process_sp(GetProcess());
+    if (process_sp)
+        return process_sp->GetUnixSignals()->GetShouldStop(signo);
+
     return false;
 }
 
 bool
 SBUnixSignals::SetShouldStop (int32_t signo, bool value)
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-    ProcessSP process_sp(GetSP());
+    ProcessSP process_sp(GetProcess());
 
     if (log)
     {
@@ -130,23 +142,27 @@
                      value);
     }
 
-    if (process_sp) return process_sp->GetUnixSignals().SetShouldStop(signo, value);
+    if (process_sp)
+        return process_sp->GetUnixSignals()->SetShouldStop(signo, value);
+
     return false;
 }
 
 bool
 SBUnixSignals::GetShouldNotify (int32_t signo) const
 {
-    ProcessSP process_sp(GetSP());
-    if (process_sp) return process_sp->GetUnixSignals().GetShouldNotify(signo);
+    ProcessSP process_sp(GetProcess());
+    if (process_sp)
+        return process_sp->GetUnixSignals()->GetShouldNotify(signo);
+
     return false;
 }
 
 bool
 SBUnixSignals::SetShouldNotify (int32_t signo, bool value)
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-    ProcessSP process_sp(GetSP());
+    ProcessSP process_sp(GetProcess());
 
     if (log)
     {
@@ -156,44 +172,26 @@
                      value);
     }
 
-    if (process_sp) return process_sp->GetUnixSignals().SetShouldNotify(signo, value);
+    if (process_sp)
+        return process_sp->GetUnixSignals()->SetShouldNotify(signo, value);
+
     return false;
 }
 
 int32_t
 SBUnixSignals::GetNumSignals () const
 {
-    if (auto process_sp = GetSP())
-    {
-        // only valid while we hold process_sp
-        UnixSignals *unix_signals_ptr = &process_sp->GetUnixSignals();
-        int32_t num_signals = 0;
-        for (int32_t signo = unix_signals_ptr->GetFirstSignalNumber();
-             signo != LLDB_INVALID_SIGNAL_NUMBER;
-             signo = unix_signals_ptr->GetNextSignalNumber(signo))
-        {
-            num_signals++;
-        }
-        return num_signals;
-    }
-    return LLDB_INVALID_SIGNAL_NUMBER;
+    if (m_opaque_sp)
+        return m_opaque_sp->GetNumSignals();
+
+    return -1;
 }
 
 int32_t
 SBUnixSignals::GetSignalAtIndex (int32_t index) const
 {
-    if (auto process_sp = GetSP())
-    {
-        // only valid while we hold process_sp
-        UnixSignals *unix_signals_ptr = &process_sp->GetUnixSignals();
-        int32_t idx = 0;
-        for (int32_t signo = unix_signals_ptr->GetFirstSignalNumber();
-             signo != LLDB_INVALID_SIGNAL_NUMBER;
-             signo = unix_signals_ptr->GetNextSignalNumber(signo))
-        {
-            if (index == idx) return signo;
-            idx++;
-        }
-    }
+    if (m_opaque_sp)
+        return m_opaque_sp->GetSignalAtIndex(index);
+
     return LLDB_INVALID_SIGNAL_NUMBER;
 }
Index: source/API/SBThread.cpp
===================================================================
--- source/API/SBThread.cpp
+++ source/API/SBThread.cpp
@@ -392,7 +392,7 @@
 
                     case eStopReasonSignal:
                         {
-                            stop_desc = exe_ctx.GetProcessPtr()->GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
+                            stop_desc = exe_ctx.GetProcessPtr()->GetUnixSignals()->GetSignalAsCString(stop_info_sp->GetValue());
                             if (stop_desc == NULL || stop_desc[0] == '\0')
                             {
                                 static char signal_desc[] = "signal";
Index: source/API/SBProcess.cpp
===================================================================
--- source/API/SBProcess.cpp
+++ source/API/SBProcess.cpp
@@ -912,14 +912,11 @@
 SBUnixSignals
 SBProcess::GetUnixSignals()
 {
-    SBUnixSignals sb_unix_signals;
-    ProcessSP process_sp(GetSP());
+    ProcessSP process_sp{GetSP()};
     if (process_sp)
-    {
-        sb_unix_signals.SetSP(process_sp);
-    }
+        return SBUnixSignals{process_sp};
 
-    return sb_unix_signals;
+    return {};
 }
 
 void
Index: source/API/SBPlatform.cpp
===================================================================
--- source/API/SBPlatform.cpp
+++ source/API/SBPlatform.cpp
@@ -11,6 +11,7 @@
 #include "lldb/API/SBError.h"
 #include "lldb/API/SBFileSpec.h"
 #include "lldb/API/SBLaunchInfo.h"
+#include "lldb/API/SBUnixSignals.h"
 #include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/Error.h"
 #include "lldb/Host/File.h"
@@ -638,3 +639,12 @@
     
 }
 
+SBUnixSignals
+SBPlatform::GetUnixSignals() const
+{
+    PlatformSP platform_sp{GetSP()};
+    if (platform_sp)
+        return SBUnixSignals{platform_sp};
+
+    return {};
+}
Index: scripts/interface/SBPlatform.i
===================================================================
--- scripts/interface/SBPlatform.i
+++ scripts/interface/SBPlatform.i
@@ -188,6 +188,9 @@
     lldb::SBError
     SetFilePermissions (const char *path, uint32_t file_permissions);
 
+    lldb::SBUnixSignals
+    GetUnixSignals();
+
 };
 
 } // namespace lldb
Index: include/lldb/lldb-private-forward.h
===================================================================
--- include/lldb/lldb-private-forward.h
+++ include/lldb/lldb-private-forward.h
@@ -34,7 +34,6 @@
     typedef std::weak_ptr<lldb_private::NativeProcessProtocol> NativeProcessProtocolWP;
     typedef std::shared_ptr<lldb_private::NativeRegisterContext> NativeRegisterContextSP;
     typedef std::shared_ptr<lldb_private::NativeThreadProtocol> NativeThreadProtocolSP;
-    typedef std::shared_ptr<lldb_private::UnixSignals> UnixSignalsSP;
 }
 
 #endif // #if defined(__cplusplus)
Index: include/lldb/lldb-forward.h
===================================================================
--- include/lldb/lldb-forward.h
+++ include/lldb/lldb-forward.h
@@ -423,6 +423,7 @@
 #ifndef LLDB_DISABLE_PYTHON
     typedef std::shared_ptr<lldb_private::ScriptedSyntheticChildren> ScriptedSyntheticChildrenSP;
 #endif
+    typedef std::shared_ptr<lldb_private::UnixSignals> UnixSignalsSP;
     typedef std::shared_ptr<lldb_private::UnwindAssembly> UnwindAssemblySP;
     typedef std::shared_ptr<lldb_private::UnwindPlan> UnwindPlanSP;
     typedef lldb_private::SharingPtr<lldb_private::ValueObject> ValueObjectSP;
Index: include/lldb/Target/UnixSignals.h
===================================================================
--- include/lldb/Target/UnixSignals.h
+++ include/lldb/Target/UnixSignals.h
@@ -89,6 +89,12 @@
     int32_t
     GetNextSignalNumber (int32_t current_signal) const;
 
+    int32_t
+    GetNumSignals() const;
+
+    int32_t
+    GetSignalAtIndex(int32_t index) const;
+
     // We assume that the elements of this object are constant once it is constructed,
     // since a process should never need to add or remove symbols as it runs.  So don't
     // call these functions anywhere but the constructor of your subclass of UnixSignals or in
@@ -130,7 +136,7 @@
         ~Signal () {}
     };
 
-    void
+    virtual void
     Reset ();
 
     typedef std::map <int32_t, Signal> collection;
Index: include/lldb/Target/Process.h
===================================================================
--- include/lldb/Target/Process.h
+++ include/lldb/Target/Process.h
@@ -941,17 +941,10 @@
 
     //------------------------------------------------------------------
     /// Construct with a shared pointer to a target, and the Process listener.
-    /// Uses the Host UnixSignalsSP by default.
     //------------------------------------------------------------------
     Process(Target &target, Listener &listener);
 
     //------------------------------------------------------------------
-    /// Construct with a shared pointer to a target, the Process listener,
-    /// and the appropriate UnixSignalsSP for the process.
-    //------------------------------------------------------------------
-    Process(Target &target, Listener &listener, const UnixSignalsSP &unix_signals_sp);
-
-    //------------------------------------------------------------------
     /// Destructor.
     ///
     /// The destructor is virtual since this class is designed to be
@@ -1400,11 +1393,8 @@
     Error
     Signal (int signal);
 
-    void
-    SetUnixSignals (const UnixSignalsSP &signals_sp);
-
-    UnixSignals &
-    GetUnixSignals ();
+    virtual const lldb::UnixSignalsSP &
+    GetUnixSignals();
 
     //==================================================================
     // Plug-in Process Control Overrides
@@ -3205,7 +3195,6 @@
     lldb::DynamicCheckerFunctionsUP m_dynamic_checkers_ap; ///< The functions used by the expression parser to validate data that expressions use.
     lldb::OperatingSystemUP     m_os_ap;
     lldb::SystemRuntimeUP       m_system_runtime_ap;
-    UnixSignalsSP               m_unix_signals_sp;         /// This is the current signal set for this process.
     lldb::ABISP                 m_abi_sp;
     lldb::IOHandlerSP           m_process_input_reader;
     Communication               m_stdio_communication;
Index: include/lldb/Target/Platform.h
===================================================================
--- include/lldb/Target/Platform.h
+++ include/lldb/Target/Platform.h
@@ -863,6 +863,9 @@
             return 1;
         }
 
+        virtual const lldb::UnixSignalsSP &
+        GetUnixSignals();
+
         //------------------------------------------------------------------
         /// Locate a queue name given a thread's qaddr
         ///
Index: include/lldb/Host/Host.h
===================================================================
--- include/lldb/Host/Host.h
+++ include/lldb/Host/Host.h
@@ -21,6 +21,7 @@
 #include "lldb/Core/StringList.h"
 #include "lldb/Host/File.h"
 #include "lldb/Host/FileSpec.h"
+#include "lldb/Host/HostInfo.h"
 #include "lldb/Host/HostThread.h"
 
 namespace lldb_private {
@@ -244,8 +245,8 @@
 #endif // !defined(__ANDROID__) && !defined(__ANDROID_NDK__)
 #endif // defined (__APPLE__) || defined (__linux__) || defined (__FreeBSD__) || defined (__GLIBC__) || defined(__NetBSD__)
 
-    static const lldb_private::UnixSignalsSP&
-    GetUnixSignals ();
+    static const lldb::UnixSignalsSP &
+    GetUnixSignals(const ArchSpec &arch = HostInfo::GetArchitecture());
 
     static Error
     LaunchProcess (ProcessLaunchInfo &launch_info);
Index: include/lldb/Core/StructuredData.h
===================================================================
--- include/lldb/Core/StructuredData.h
+++ include/lldb/Core/StructuredData.h
@@ -238,14 +238,15 @@
         {
         }
 
-        void
+        bool
         ForEach (std::function <bool(Object* object)> const &foreach_callback) const
         {
             for (const auto &object_sp : m_items)
             {
                 if (foreach_callback(object_sp.get()) == false)
-                    break;
+                    return false;
             }
+            return true;
         }
 
 
Index: include/lldb/API/SBUnixSignals.h
===================================================================
--- include/lldb/API/SBUnixSignals.h
+++ include/lldb/API/SBUnixSignals.h
@@ -65,17 +65,17 @@
 
 protected:
     friend class SBProcess;
+    SBUnixSignals(const lldb::ProcessSP &process_sp);
 
-    SBUnixSignals (lldb::ProcessSP &process_sp);
+    friend class SBPlatform;
+    SBUnixSignals(const lldb::PlatformSP &platform_sp);
 
     lldb::ProcessSP
-    GetSP() const;
-
-    void
-    SetSP (const lldb::ProcessSP &process_sp);
+    GetProcess() const;
 
 private:
-    lldb::ProcessWP m_opaque_wp;
+    lldb::UnixSignalsSP m_opaque_sp;
+    lldb::ProcessWP m_process_wp;
 };
 
 
Index: include/lldb/API/SBPlatform.h
===================================================================
--- include/lldb/API/SBPlatform.h
+++ include/lldb/API/SBPlatform.h
@@ -189,6 +189,9 @@
         SBError
         SetFilePermissions (const char *path, uint32_t file_permissions);
 
+        SBUnixSignals
+        GetUnixSignals() const;
+
     protected:
         
         friend class SBDebugger;
_______________________________________________
lldb-commits mailing list
lldb-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits

Reply via email to