[Lldb-commits] [lldb] r211526 - Add API control of the signal disposition.

Todd Fiala todd.fiala at gmail.com
Mon Jun 23 12:30:50 PDT 2014


Author: tfiala
Date: Mon Jun 23 14:30:49 2014
New Revision: 211526

URL: http://llvm.org/viewvc/llvm-project?rev=211526&view=rev
Log:
Add API control of the signal disposition.

See http://reviews.llvm.org/D4221 for details.

This commit allows you to control the signals that lldb will suppress, stop or forward using the Python and C++ APIs.

Change by Russell Harmon.

Xcode build system changes (and any mistakes) by Todd Fiala.  Tested on MacOSX 10.9.3 and Xcode 6 beta.  (Xcode 5 is hitting the dependency checker crasher on all my systems).

Added:
    lldb/trunk/include/lldb/API/SBUnixSignals.h
    lldb/trunk/source/API/SBUnixSignals.cpp
Modified:
    lldb/trunk/include/lldb/API/SBDefines.h
    lldb/trunk/include/lldb/API/SBProcess.h
    lldb/trunk/include/lldb/lldb-defines.h
    lldb/trunk/include/lldb/lldb-forward.h
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/scripts/Python/build-swig-Python.sh
    lldb/trunk/scripts/Python/interface/SBProcess.i
    lldb/trunk/scripts/lldb.swig
    lldb/trunk/source/API/CMakeLists.txt
    lldb/trunk/source/API/SBProcess.cpp

Modified: lldb/trunk/include/lldb/API/SBDefines.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBDefines.h?rev=211526&r1=211525&r2=211526&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBDefines.h (original)
+++ lldb/trunk/include/lldb/API/SBDefines.h Mon Jun 23 14:30:49 2014
@@ -85,6 +85,7 @@ class LLDB_API SBTypeList;
 class LLDB_API SBValue;
 class LLDB_API SBValueList;
 class LLDB_API SBWatchpoint;
+class LLDB_API SBUnixSignals;
 
 }
 

Modified: lldb/trunk/include/lldb/API/SBProcess.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBProcess.h?rev=211526&r1=211525&r2=211526&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBProcess.h (original)
+++ lldb/trunk/include/lldb/API/SBProcess.h Mon Jun 23 14:30:49 2014
@@ -221,6 +221,9 @@ public:
     lldb::SBError
     Signal (int signal);
 
+    lldb::SBUnixSignals
+    GetUnixSignals();
+
     void
     SendAsyncInterrupt();
     

Added: lldb/trunk/include/lldb/API/SBUnixSignals.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBUnixSignals.h?rev=211526&view=auto
==============================================================================
--- lldb/trunk/include/lldb/API/SBUnixSignals.h (added)
+++ lldb/trunk/include/lldb/API/SBUnixSignals.h Mon Jun 23 14:30:49 2014
@@ -0,0 +1,84 @@
+//===-- SBUnixSignals.h -----------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_SBUnixSignals_h_
+#define LLDB_SBUnixSignals_h_
+
+#include "lldb/API/SBDefines.h"
+
+namespace lldb {
+
+class SBUnixSignals {
+public:
+    SBUnixSignals ();
+
+    SBUnixSignals (const lldb::SBUnixSignals &rhs);
+
+    ~SBUnixSignals();
+
+    const SBUnixSignals &
+    operator =(const lldb::SBUnixSignals &rhs);
+
+    void
+    Clear ();
+
+    bool
+    IsValid () const;
+
+    const char *
+    GetSignalAsCString (int32_t signo) const;
+
+    int32_t
+    GetSignalNumberFromName (const char *name) const;
+
+    bool
+    GetShouldSuppress (int32_t signo) const;
+
+    bool
+    SetShouldSuppress (int32_t signo,
+                       bool value);
+
+    bool
+    GetShouldStop (int32_t signo) const;
+
+    bool
+    SetShouldStop (int32_t signo,
+                   bool value);
+
+    bool
+    GetShouldNotify (int32_t signo) const;
+
+    bool
+    SetShouldNotify (int32_t signo, bool value);
+
+    int32_t
+    GetNumSignals () const;
+
+    int32_t
+    GetSignalAtIndex (int32_t index) const;
+
+protected:
+    friend class SBProcess;
+
+    SBUnixSignals (lldb::ProcessSP &process_sp);
+
+    lldb::ProcessSP
+    GetSP() const;
+
+    void
+    SetSP (const lldb::ProcessSP &process_sp);
+
+private:
+    lldb::ProcessWP m_opaque_wp;
+};
+
+
+} // namespace lldb
+
+#endif // LLDB_SBUnixSignals_h_

Modified: lldb/trunk/include/lldb/lldb-defines.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-defines.h?rev=211526&r1=211525&r2=211526&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-defines.h (original)
+++ lldb/trunk/include/lldb/lldb-defines.h Mon Jun 23 14:30:49 2014
@@ -24,6 +24,10 @@
     #define LLDB_API
 #endif
 
+#if !defined(INT32_MAX)
+    #define INT32_MAX 2147483647
+#endif
+
 #if !defined(UINT32_MAX)
     #define UINT32_MAX 4294967295U
 #endif

Modified: lldb/trunk/include/lldb/lldb-forward.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=211526&r1=211525&r2=211526&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-forward.h (original)
+++ lldb/trunk/include/lldb/lldb-forward.h Mon Jun 23 14:30:49 2014
@@ -249,6 +249,7 @@ class   TypeEnumMemberListImpl;
 class   TypeNameSpecifierImpl;
 class   TypePair;
 class   UUID;
+class   UnixSignals;
 class   Unwind;
 class   UnwindAssembly;
 class   UnwindPlan;

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=211526&r1=211525&r2=211526&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Mon Jun 23 14:30:49 2014
@@ -51,6 +51,8 @@
 /* End PBXAggregateTarget section */
 
 /* Begin PBXBuildFile section */
+		23059A101958B319007B8189 /* SBUnixSignals.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23059A0F1958B319007B8189 /* SBUnixSignals.cpp */; };
+		23059A121958B3B2007B8189 /* SBUnixSignals.h in Headers */ = {isa = PBXBuildFile; fileRef = 23059A111958B37B007B8189 /* SBUnixSignals.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		23EFE389193D1ABC00E54E54 /* SBTypeEnumMember.h in Headers */ = {isa = PBXBuildFile; fileRef = 23EFE388193D1ABC00E54E54 /* SBTypeEnumMember.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		23EFE38B193D1AEC00E54E54 /* SBTypeEnumMember.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23EFE38A193D1AEC00E54E54 /* SBTypeEnumMember.cpp */; };
 		260157C61885F51C00F875CF /* libpanel.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 260157C41885F4FF00F875CF /* libpanel.dylib */; };
@@ -871,6 +873,8 @@
 /* End PBXCopyFilesBuildPhase section */
 
 /* Begin PBXFileReference section */
+		23059A0F1958B319007B8189 /* SBUnixSignals.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBUnixSignals.cpp; path = source/API/SBUnixSignals.cpp; sourceTree = "<group>"; };
+		23059A111958B37B007B8189 /* SBUnixSignals.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SBUnixSignals.h; path = include/lldb/API/SBUnixSignals.h; sourceTree = "<group>"; };
 		2360092C193FB21500189DB1 /* MemoryRegionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MemoryRegionInfo.h; path = include/lldb/Target/MemoryRegionInfo.h; sourceTree = "<group>"; };
 		23EDE3371926AAD500F6A132 /* RegisterInfoInterface.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RegisterInfoInterface.h; path = Utility/RegisterInfoInterface.h; sourceTree = "<group>"; };
 		23EFE388193D1ABC00E54E54 /* SBTypeEnumMember.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SBTypeEnumMember.h; path = include/lldb/API/SBTypeEnumMember.h; sourceTree = "<group>"; };
@@ -2535,6 +2539,8 @@
 				9461568C14E35621003A195C /* SBTypeSummary.cpp */,
 				9461568914E355F2003A195C /* SBTypeSynthetic.h */,
 				9461568D14E35621003A195C /* SBTypeSynthetic.cpp */,
+				23059A111958B37B007B8189 /* SBUnixSignals.h */,
+				23059A0F1958B319007B8189 /* SBUnixSignals.cpp */,
 				9A19A6A51163BB7E00E0D453 /* SBValue.h */,
 				9A19A6AD1163BB9800E0D453 /* SBValue.cpp */,
 				9A357582116CFDEE00E8ED2F /* SBValueList.h */,
@@ -3998,6 +4004,7 @@
 				941BCC8014E48C4000BB969C /* SBTypeFormat.h in Headers */,
 				9475C18F14E5F858001BFC6D /* SBTypeNameSpecifier.h in Headers */,
 				941BCC8114E48C4000BB969C /* SBTypeSummary.h in Headers */,
+				23059A121958B3B2007B8189 /* SBUnixSignals.h in Headers */,
 				941BCC8214E48C4000BB969C /* SBTypeSynthetic.h in Headers */,
 				9A19A6AF1163BBB200E0D453 /* SBValue.h in Headers */,
 				9A357583116CFDEE00E8ED2F /* SBValueList.h in Headers */,
@@ -4477,6 +4484,7 @@
 				26C72C961243229A0068DC16 /* SBStream.cpp in Sources */,
 				9443B122140C18C40013457C /* SBData.cpp in Sources */,
 				4CF52AF8142829390051E832 /* SBFileSpecList.cpp in Sources */,
+				23059A101958B319007B8189 /* SBUnixSignals.cpp in Sources */,
 				26B82840142D020F002DBC64 /* SBSection.cpp in Sources */,
 				B2A58724143119D50092BFBA /* SBWatchpoint.cpp in Sources */,
 				263C4938178B50C40070F12D /* SBModuleSpec.cpp in Sources */,

Modified: lldb/trunk/scripts/Python/build-swig-Python.sh
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/build-swig-Python.sh?rev=211526&r1=211525&r2=211526&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/build-swig-Python.sh (original)
+++ lldb/trunk/scripts/Python/build-swig-Python.sh Mon Jun 23 14:30:49 2014
@@ -122,7 +122,8 @@ HEADER_FILES="${SRC_ROOT}/include/lldb/l
 " ${SRC_ROOT}/include/lldb/API/SBTypeSynthetic.h"\
 " ${SRC_ROOT}/include/lldb/API/SBValue.h"\
 " ${SRC_ROOT}/include/lldb/API/SBValueList.h"\
-" ${SRC_ROOT}/include/lldb/API/SBWatchpoint.h"
+" ${SRC_ROOT}/include/lldb/API/SBWatchpoint.h"\
+" ${SRC_ROOT}/include/lldb/API/SBUnixSignals.h"
 
 INTERFACE_FILES="${SRC_ROOT}/scripts/Python/interface/SBAddress.i"\
 " ${SRC_ROOT}/scripts/Python/interface/SBBlock.i"\
@@ -169,7 +170,8 @@ INTERFACE_FILES="${SRC_ROOT}/scripts/Pyt
 " ${SRC_ROOT}/scripts/Python/interface/SBTypeSynthetic.i"\
 " ${SRC_ROOT}/scripts/Python/interface/SBValue.i"\
 " ${SRC_ROOT}/scripts/Python/interface/SBValueList.i"\
-" ${SRC_ROOT}/scripts/Python/interface/SBWatchpoint.i"
+" ${SRC_ROOT}/scripts/Python/interface/SBWatchpoint.i"\
+" ${SRC_ROOT}/scripts/Python/interface/SBUnixSignals.i"
 
 if [ $Debug -eq 1 ]
 then

Modified: lldb/trunk/scripts/Python/interface/SBProcess.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBProcess.i?rev=211526&r1=211525&r2=211526&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBProcess.i (original)
+++ lldb/trunk/scripts/Python/interface/SBProcess.i Mon Jun 23 14:30:49 2014
@@ -240,6 +240,9 @@ public:
     lldb::SBError
     Signal (int signal);
 
+    lldb::SBUnixSignals
+    GetUnixSignals();
+
     %feature("docstring", "
     Returns a stop id that will increase every time the process executes.  If
     include_expression_stops is true, then stops caused by expression evaluation

Modified: lldb/trunk/scripts/lldb.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/lldb.swig?rev=211526&r1=211525&r2=211526&view=diff
==============================================================================
--- lldb/trunk/scripts/lldb.swig (original)
+++ lldb/trunk/scripts/lldb.swig Mon Jun 23 14:30:49 2014
@@ -102,6 +102,7 @@ import os
 #include "lldb/API/SBValue.h"
 #include "lldb/API/SBValueList.h"
 #include "lldb/API/SBWatchpoint.h"
+#include "lldb/API/SBUnixSignals.h"
 
 #include "../scripts/Python/python-swigsafecast.swig"
 
@@ -109,6 +110,9 @@ import os
 
 /* Various liblldb typedefs that SWIG needs to know about.  */
 #define __extension__ /* Undefine GCC keyword to make Swig happy when processing glibc's stdint.h. */
+/* The ISO C99 standard specifies that in C++ implementations limit macros such
+   as INT32_MAX should only be defined if __STDC_LIMIT_MACROS is. */
+#define __STDC_LIMIT_MACROS
 %include "stdint.i"
 %include "lldb/lldb-defines.h"
 %include "lldb/lldb-enumerations.h"
@@ -169,6 +173,7 @@ import os
 %include "./Python/interface/SBValue.i"
 %include "./Python/interface/SBValueList.i"
 %include "./Python/interface/SBWatchpoint.i"
+%include "./Python/interface/SBUnixSignals.i"
 
 %include "./Python/python-extensions.swig"
 

Modified: lldb/trunk/source/API/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/CMakeLists.txt?rev=211526&r1=211525&r2=211526&view=diff
==============================================================================
--- lldb/trunk/source/API/CMakeLists.txt (original)
+++ lldb/trunk/source/API/CMakeLists.txt Mon Jun 23 14:30:49 2014
@@ -51,4 +51,5 @@ add_lldb_library(lldbAPI
   SBValue.cpp
   SBValueList.cpp
   SBWatchpoint.cpp
+  SBUnixSignals.cpp
   )

Modified: lldb/trunk/source/API/SBProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBProcess.cpp?rev=211526&r1=211525&r2=211526&view=diff
==============================================================================
--- lldb/trunk/source/API/SBProcess.cpp (original)
+++ lldb/trunk/source/API/SBProcess.cpp Mon Jun 23 14:30:49 2014
@@ -40,6 +40,7 @@
 #include "lldb/API/SBThread.h"
 #include "lldb/API/SBStream.h"
 #include "lldb/API/SBStringList.h"
+#include "lldb/API/SBUnixSignals.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -893,6 +894,19 @@ SBProcess::Signal (int signo)
     return sb_error;
 }
 
+SBUnixSignals
+SBProcess::GetUnixSignals()
+{
+    SBUnixSignals sb_unix_signals;
+    ProcessSP process_sp(GetSP());
+    if (process_sp)
+    {
+        sb_unix_signals.SetSP(process_sp);
+    }
+
+    return sb_unix_signals;
+}
+
 void
 SBProcess::SendAsyncInterrupt ()
 {

Added: lldb/trunk/source/API/SBUnixSignals.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBUnixSignals.cpp?rev=211526&view=auto
==============================================================================
--- lldb/trunk/source/API/SBUnixSignals.cpp (added)
+++ lldb/trunk/source/API/SBUnixSignals.cpp Mon Jun 23 14:30:49 2014
@@ -0,0 +1,199 @@
+//===-- SBUnixSignals.cpp -------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/lldb-defines.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/UnixSignals.h"
+#include "lldb/Core/Log.h"
+
+#include "lldb/API/SBUnixSignals.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+SBUnixSignals::SBUnixSignals ()
+{}
+
+SBUnixSignals::SBUnixSignals (const SBUnixSignals &rhs) :
+    m_opaque_wp(rhs.m_opaque_wp)
+{
+}
+
+SBUnixSignals::SBUnixSignals (ProcessSP &process_sp) :
+    m_opaque_wp(process_sp)
+{
+}
+
+const SBUnixSignals&
+SBUnixSignals::operator = (const SBUnixSignals& rhs)
+{
+    if (this != &rhs)
+        m_opaque_wp = rhs.m_opaque_wp;
+    return *this;
+}
+
+SBUnixSignals::~SBUnixSignals()
+{
+}
+
+ProcessSP
+SBUnixSignals::GetSP() const
+{
+    return m_opaque_wp.lock();
+}
+
+void
+SBUnixSignals::SetSP (const ProcessSP &process_sp)
+{
+    m_opaque_wp = process_sp;
+}
+
+void
+SBUnixSignals::Clear ()
+{
+    m_opaque_wp.reset();
+}
+
+bool
+SBUnixSignals::IsValid() const
+{
+    return (bool) GetSP();
+}
+
+const char *
+SBUnixSignals::GetSignalAsCString (int32_t signo) const
+{
+    ProcessSP process_sp(GetSP());
+    if (process_sp) return process_sp->GetUnixSignals().GetSignalAsCString(signo);
+    return NULL;
+}
+
+int32_t
+SBUnixSignals::GetSignalNumberFromName (const char *name) const
+{
+    ProcessSP process_sp(GetSP());
+    if (process_sp) return process_sp->GetUnixSignals().GetSignalNumberFromName(name);
+    return -1;
+}
+
+bool
+SBUnixSignals::GetShouldSuppress (int32_t signo) const
+{
+    ProcessSP process_sp(GetSP());
+    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());
+
+    if (log)
+    {
+        log->Printf ("SBUnixSignals(%p)::SetShouldSuppress (signo=%d, value=%d)",
+                     static_cast<void*>(process_sp.get()),
+                     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);
+    return false;
+}
+
+bool
+SBUnixSignals::SetShouldStop (int32_t signo, bool value)
+{
+    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+    ProcessSP process_sp(GetSP());
+
+    if (log)
+    {
+        log->Printf ("SBUnixSignals(%p)::SetShouldStop (signo=%d, value=%d)",
+                     static_cast<void*>(process_sp.get()),
+                     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);
+    return false;
+}
+
+bool
+SBUnixSignals::SetShouldNotify (int32_t signo, bool value)
+{
+    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+    ProcessSP process_sp(GetSP());
+
+    if (log)
+    {
+        log->Printf ("SBUnixSignals(%p)::SetShouldNotify (signo=%d, value=%d)",
+                     static_cast<void*>(process_sp.get()),
+                     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;
+}
+
+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++;
+        }
+    }
+    return LLDB_INVALID_SIGNAL_NUMBER;
+}





More information about the lldb-commits mailing list