<div dir="ltr">I poked around at this for a bit, and here's what I found.<div><br></div><div>1. The issue is probably a race condition. It only happens about 1/3 of the time on my machine.</div><div>2. SIGINT is definitely being suppressed by lldb. I added a singal handler for SIGINT which prints a message to main.cpp, and no such message is printed when the test is run.</div>
<div><br><div class="gmail_extra">Anyway, I added some debug logging information to the SBUnixSignals class, so I've attached a new patch below.</div><div class="gmail_extra"><div>--<br>Russell Harmon</div><div><br></div>
<div><div>From e66e124f06dfa17c5eb23636e3dccde4fa7738e8 Mon Sep 17 00:00:00 2001</div>
<div>From: Russell Harmon <<a href="mailto:russ@eatnumber1.com" target="_blank">russ@eatnumber1.com</a>></div><div>Date: Tue, 25 Jun 2013 01:02:31 -0700</div><div>Subject: [PATCH] Add the ability to control the signal disposition via the</div>
<div> API.</div><div><br></div><div>---</div><div> include/lldb/API/LLDB.h | 1 +</div><div> include/lldb/API/SBDefines.h | 1 +</div><div> include/lldb/API/SBProcess.h | 3 +</div>
<div> include/lldb/API/SBUnixSignals.h | 84 +++++++++++++</div><div> include/lldb/lldb-defines.h | 4 +</div><div> include/lldb/lldb-forward.h | 1 +</div><div> scripts/Python/build-swig-Python.sh | 6 +-</div>
<div> scripts/Python/interface/SBProcess.i | 3 +</div><div> scripts/Python/interface/SBUnixSignals.i | 74 ++++++++++++</div><div> scripts/lldb.swig | 5 +</div><div> source/API/CMakeLists.txt | 1 +</div>
<div> source/API/SBProcess.cpp | 14 +++</div><div> source/API/SBUnixSignals.cpp | 192 ++++++++++++++++++++++++++++++</div><div> test/python_api/signals/Makefile | 5 +</div><div> test/python_api/signals/TestSignalsAPI.py | 51 ++++++++</div>
<div> test/python_api/signals/main.cpp | 20 ++++</div><div> 16 files changed, 463 insertions(+), 2 deletions(-)</div><div> create mode 100644 include/lldb/API/SBUnixSignals.h</div><div> create mode 100644 scripts/Python/interface/SBUnixSignals.i</div>
<div> create mode 100644 source/API/SBUnixSignals.cpp</div><div> create mode 100644 test/python_api/signals/Makefile</div><div> create mode 100644 test/python_api/signals/TestSignalsAPI.py</div><div> create mode 100644 test/python_api/signals/main.cpp</div>
<div><br></div><div>diff --git a/include/lldb/API/LLDB.h b/include/lldb/API/LLDB.h</div><div>index 93bc3bc..4db60b0 100644</div><div>--- a/include/lldb/API/LLDB.h</div><div>+++ b/include/lldb/API/LLDB.h</div><div>@@ -50,5 +50,6 @@</div>
<div> #include "lldb/API/SBType.h"</div><div> #include "lldb/API/SBValue.h"</div><div> #include "lldb/API/SBValueList.h"</div><div>+#include "lldb/API/SBUnixSignals.h"</div><div> </div>
<div> #endif // LLDB_LLDB_h_</div><div>diff --git a/include/lldb/API/SBDefines.h b/include/lldb/API/SBDefines.h</div><div>index 2388c36..02742d3 100644</div><div>--- a/include/lldb/API/SBDefines.h</div><div>+++ b/include/lldb/API/SBDefines.h</div>
<div>@@ -76,6 +76,7 @@ class SBTypeList;</div><div> class SBValue;</div><div> class SBValueList;</div><div> class SBWatchpoint;</div><div>+class SBUnixSignals;</div><div> </div><div> }</div><div> </div><div>diff --git a/include/lldb/API/SBProcess.h b/include/lldb/API/SBProcess.h</div>
<div>index 784f362..a1e7353 100644</div><div>--- a/include/lldb/API/SBProcess.h</div><div>+++ b/include/lldb/API/SBProcess.h</div><div>@@ -211,6 +211,9 @@ public:</div><div> lldb::SBError</div><div> Signal (int signal);</div>
<div> </div><div>+ lldb::SBUnixSignals</div><div>+ GetUnixSignals();</div><div>+</div><div> void</div><div> SendAsyncInterrupt();</div><div> </div><div>diff --git a/include/lldb/API/SBUnixSignals.h b/include/lldb/API/SBUnixSignals.h</div>
<div>new file mode 100644</div><div>index 0000000..d95453a</div><div>--- /dev/null</div><div>+++ b/include/lldb/API/SBUnixSignals.h</div><div>@@ -0,0 +1,84 @@</div><div>+//===-- SBUnixSignals.h -----------------------------------------------*- C++ -*-===//</div>
<div>+//</div><div>+// The LLVM Compiler Infrastructure</div><div>+//</div><div>+// This file is distributed under the University of Illinois Open Source</div><div>+// License. See LICENSE.TXT for details.</div>
<div>+//</div><div>+//===----------------------------------------------------------------------===//</div><div>+</div><div>+#ifndef LLDB_SBUnixSignals_h_</div><div>+#define LLDB_SBUnixSignals_h_</div><div>+</div><div>+#include "lldb/API/SBDefines.h"</div>
<div>+</div><div>+namespace lldb {</div><div>+</div><div>+class SBUnixSignals {</div><div>+public:</div><div>+ SBUnixSignals ();</div><div>+</div><div>+ SBUnixSignals (const lldb::SBUnixSignals &rhs);</div><div>
+</div><div>+ ~SBUnixSignals();</div><div>+</div><div>+ const SBUnixSignals &</div><div>+ operator =(const lldb::SBUnixSignals &rhs);</div><div>+</div><div>+ void</div><div>+ Clear ();</div><div>+</div>
<div>+ bool</div><div>+ IsValid () const;</div><div>+</div><div>+ const char *</div><div>+ GetSignalAsCString (int32_t signo) const;</div><div>+</div><div>+ int32_t</div><div>+ GetSignalNumberFromName (const char *name) const;</div>
<div>+</div><div>+ bool</div><div>+ GetShouldSuppress (int32_t signo) const;</div><div>+</div><div>+ bool</div><div>+ SetShouldSuppress (int32_t signo,</div><div>+ bool value);</div><div>
+</div><div>+ bool</div><div>+ GetShouldStop (int32_t signo) const;</div><div>+</div><div>+ bool</div><div>+ SetShouldStop (int32_t signo,</div><div>+ bool value);</div><div>+</div><div>+ bool</div>
<div>+ GetShouldNotify (int32_t signo) const;</div><div>+</div><div>+ bool</div><div>+ SetShouldNotify (int32_t signo, bool value);</div><div>+</div><div>+ int32_t</div><div>+ GetNumSignals () const;</div>
<div>
+</div><div>+ int32_t</div><div>+ GetSignalAtIndex (int32_t index) const;</div><div>+</div><div>+protected:</div><div>+ friend class SBProcess;</div><div>+</div><div>+ SBUnixSignals (lldb_private::UnixSignals *unix_signals_ptr);</div>
<div>+</div><div>+ lldb_private::UnixSignals *</div><div>+ GetPtr() const;</div><div>+</div><div>+ void</div><div>+ SetPtr (lldb_private::UnixSignals *unix_signals_ptr);</div><div>+</div><div>+private:</div><div>
+ lldb_private::UnixSignals *m_opaque_ptr;</div><div>+};</div><div>+</div><div>+</div><div>+} // namespace lldb</div><div>+</div><div>+#endif // LLDB_SBUnixSignals_h_</div><div>diff --git a/include/lldb/lldb-defines.h b/include/lldb/lldb-defines.h</div>
<div>index 3318aa1..a42ba3c 100644</div><div>--- a/include/lldb/lldb-defines.h</div><div>+++ b/include/lldb/lldb-defines.h</div><div>@@ -12,6 +12,10 @@</div><div> </div><div> #include "lldb/lldb-types.h"</div><div>
</div><div>+#if !defined(INT32_MAX)</div><div>+ #define INT32_MAX 2147483647</div><div>+#endif</div><div>+</div><div> #if !defined(UINT32_MAX)</div><div> #define UINT32_MAX 4294967295U</div><div> #endif</div><div>
diff --git a/include/lldb/lldb-forward.h b/include/lldb/lldb-forward.h</div><div>index 84af8b6..077d537 100644</div><div>--- a/include/lldb/lldb-forward.h</div><div>+++ b/include/lldb/lldb-forward.h</div><div>@@ -232,6 +232,7 @@ class TypeListImpl;</div>
<div> class TypeMemberImpl;</div><div> class TypeNameSpecifierImpl;</div><div> class UUID;</div><div>+class UnixSignals;</div><div> class Unwind;</div><div> class UnwindAssembly;</div><div> class UnwindPlan;</div>
<div>diff --git a/scripts/Python/build-swig-Python.sh b/scripts/Python/build-swig-Python.sh</div><div>index 96c4b2b..4a111da 100755</div><div>--- a/scripts/Python/build-swig-Python.sh</div><div>+++ b/scripts/Python/build-swig-Python.sh</div>
<div>@@ -123,7 +123,8 @@ HEADER_FILES="${SRC_ROOT}/include/lldb/lldb.h"\</div><div> " ${SRC_ROOT}/include/lldb/API/SBTypeSynthetic.h"\</div><div> " ${SRC_ROOT}/include/lldb/API/SBValue.h"\</div>
<div> " ${SRC_ROOT}/include/lldb/API/SBValueList.h"\</div><div>-" ${SRC_ROOT}/include/lldb/API/SBWatchpoint.h"</div><div>+" ${SRC_ROOT}/include/lldb/API/SBWatchpoint.h"\</div><div>+" ${SRC_ROOT}/include/lldb/API/SBUnixSignals.h"</div>
<div> </div><div> INTERFACE_FILES="${SRC_ROOT}/scripts/Python/interface/SBAddress.i"\</div><div> " ${SRC_ROOT}/scripts/Python/interface/SBBlock.i"\</div><div>@@ -167,7 +168,8 @@ INTERFACE_FILES="${SRC_ROOT}/scripts/Python/interface/SBAddress.i"\</div>
<div> " ${SRC_ROOT}/scripts/Python/interface/SBTypeSynthetic.i"\</div><div> " ${SRC_ROOT}/scripts/Python/interface/SBValue.i"\</div><div> " ${SRC_ROOT}/scripts/Python/interface/SBValueList.i"\</div>
<div>-" ${SRC_ROOT}/scripts/Python/interface/SBWatchpoint.i"</div><div>+" ${SRC_ROOT}/scripts/Python/interface/SBWatchpoint.i"\</div><div>+" ${SRC_ROOT}/scripts/Python/interface/SBUnixSignals.i"</div>
<div> </div><div> if [ $Debug -eq 1 ]</div><div> then</div><div>diff --git a/scripts/Python/interface/SBProcess.i b/scripts/Python/interface/SBProcess.i</div><div>index 6f22d9a..7a03ac7 100644</div><div>--- a/scripts/Python/interface/SBProcess.i</div>
<div>+++ b/scripts/Python/interface/SBProcess.i</div><div>@@ -231,6 +231,9 @@ public:</div><div> lldb::SBError</div><div> Signal (int signal);</div><div> </div><div>+ lldb::SBUnixSignals</div><div>+ GetUnixSignals();</div>
<div>+</div><div> %feature("docstring", "</div><div> Returns a stop id that will increase every time the process executes. If</div><div> include_expression_stops is true, then stops caused by expression evaluation</div>
<div>diff --git a/scripts/Python/interface/SBUnixSignals.i b/scripts/Python/interface/SBUnixSignals.i</div><div>new file mode 100644</div><div>index 0000000..2bd537a</div><div>--- /dev/null</div><div>+++ b/scripts/Python/interface/SBUnixSignals.i</div>
<div>@@ -0,0 +1,74 @@</div><div>+//===-- SWIG Interface for SBProcess ----------------------------*- C++ -*-===//</div><div>+//</div><div>+// The LLVM Compiler Infrastructure</div><div>+//</div><div>+// This file is distributed under the University of Illinois Open Source</div>
<div>+// License. See LICENSE.TXT for details.</div><div>+//</div><div>+//===----------------------------------------------------------------------===//</div><div>+</div><div>+namespace lldb {</div><div>+</div><div>+%feature("docstring",</div>
<div>+"Allows you to manipulate LLDB's signal disposition"</div><div>+) SBUnixSignals;</div><div>+class SBUnixSignals</div><div>+{</div><div>+public:</div><div>+ SBUnixSignals ();</div><div>+</div><div>+ SBUnixSignals (const lldb::SBUnixSignals &rhs);</div>
<div>+</div><div>+ ~SBUnixSignals();</div><div>+</div><div>+ void</div><div>+ Clear ();</div><div>+</div><div>+ bool</div><div>+ IsValid () const;</div><div>+</div><div>+ const char *</div><div>+ GetSignalAsCString (int32_t signo) const;</div>
<div>+</div><div>+ int32_t</div><div>+ GetSignalNumberFromName (const char *name) const;</div><div>+</div><div>+ bool</div><div>+ GetShouldSuppress (int32_t signo) const;</div><div>+</div><div>+ bool</div>
<div>
+ SetShouldSuppress (int32_t signo,</div><div>+ bool value);</div><div>+</div><div>+ bool</div><div>+ GetShouldStop (int32_t signo) const;</div><div>+</div><div>+ bool</div><div>+ SetShouldStop (int32_t signo,</div>
<div>+ bool value);</div><div>+</div><div>+ bool</div><div>+ GetShouldNotify (int32_t signo) const;</div><div>+</div><div>+ bool</div><div>+ SetShouldNotify (int32_t signo, bool value);</div>
<div>+</div><div>+ int32_t</div><div>+ GetNumSignals () const;</div><div>+</div><div>+ int32_t</div><div>+ GetSignalAtIndex (int32_t index) const;</div><div>+</div><div>+ %pythoncode %{</div><div>+ def get_unix_signals_list(self):</div>
<div>+ signals = []</div><div>+ for idx in range(0, self.GetNumSignals()):</div><div>+ signals.append(self.GetSignalAtIndex(sig))</div><div>+ return signals</div><div>+</div>
<div>+ __swig_getmethods__["signals"] = get_unix_signals_list</div><div>+ if _newclass: threads = property(get_unix_signals_list, None, doc='''A read only property that returns a list() of valid signal numbers for this platform.''')</div>
<div>+ %}</div><div>+};</div><div>+</div><div>+} // namespace lldb</div><div>diff --git a/scripts/lldb.swig b/scripts/lldb.swig</div><div>index b813f51..0a9a8ca 100644</div><div>--- a/scripts/lldb.swig</div><div>+++ b/scripts/lldb.swig</div>
<div>@@ -98,6 +98,7 @@ import os</div><div> #include "lldb/API/SBValue.h"</div><div> #include "lldb/API/SBValueList.h"</div><div> #include "lldb/API/SBWatchpoint.h"</div><div>+#include "lldb/API/SBUnixSignals.h"</div>
<div> </div><div> #include "../scripts/Python/python-swigsafecast.swig"</div><div> </div><div>@@ -105,6 +106,9 @@ import os</div><div> </div><div> /* Various liblldb typedefs that SWIG needs to know about. */</div>
<div> #define __extension__ /* Undefine GCC keyword to make Swig happy when processing glibc's stdint.h. */</div><div>+/* The ISO C99 standard specifies that in C++ implementations limit macros such</div><div>+ as INT32_MAX should only be defined if __STDC_LIMIT_MACROS is. */</div>
<div>+#define __STDC_LIMIT_MACROS</div><div> %include "stdint.i"</div><div> %include "lldb/lldb-defines.h"</div><div> %include "lldb/lldb-enumerations.h"</div><div>@@ -161,6 +165,7 @@ import os</div>
<div> %include "./Python/interface/SBValue.i"</div><div> %include "./Python/interface/SBValueList.i"</div><div> %include "./Python/interface/SBWatchpoint.i"</div><div>+%include "./Python/interface/SBUnixSignals.i"</div>
<div> </div><div> %include "./Python/python-extensions.swig"</div><div> </div><div>diff --git a/source/API/CMakeLists.txt b/source/API/CMakeLists.txt</div><div>index 3580b74..937a4c2 100644</div><div>--- a/source/API/CMakeLists.txt</div>
<div>+++ b/source/API/CMakeLists.txt</div><div>@@ -47,4 +47,5 @@ add_lldb_library(lldbAPI</div><div> SBValue.cpp</div><div> SBValueList.cpp</div><div> SBWatchpoint.cpp</div><div>+ SBUnixSignals.cpp</div><div> )</div>
<div>diff --git a/source/API/SBProcess.cpp b/source/API/SBProcess.cpp</div><div>index 259eb5e..2486360 100644</div><div>--- a/source/API/SBProcess.cpp</div><div>+++ b/source/API/SBProcess.cpp</div><div>@@ -36,6 +36,7 @@</div>
<div> #include "lldb/API/SBThread.h"</div><div> #include "lldb/API/SBStream.h"</div><div> #include "lldb/API/SBStringList.h"</div><div>+#include "lldb/API/SBUnixSignals.h"</div><div>
</div><div> using namespace lldb;</div><div> using namespace lldb_private;</div><div>@@ -833,6 +834,19 @@ SBProcess::Signal (int signo)</div><div> return sb_error;</div><div> }</div><div> </div><div>+SBUnixSignals</div>
<div>+SBProcess::GetUnixSignals()</div><div>+{</div><div>+ SBUnixSignals sb_unix_signals;</div><div>+ ProcessSP process_sp(GetSP());</div><div>+ if (process_sp)</div><div>+ {</div><div>+ sb_unix_signals.SetPtr(&process_sp->GetUnixSignals());</div>
<div>+ }</div><div>+</div><div>+ return sb_unix_signals;</div><div>+}</div><div>+</div><div> void</div><div> SBProcess::SendAsyncInterrupt ()</div><div> {</div><div>diff --git a/source/API/SBUnixSignals.cpp b/source/API/SBUnixSignals.cpp</div>
<div>new file mode 100644</div><div>index 0000000..21c508d</div><div>--- /dev/null</div><div>+++ b/source/API/SBUnixSignals.cpp</div><div>@@ -0,0 +1,192 @@</div><div>+//===-- SBUnixSignals.cpp -------------------------------------------*- C++ -*-===//</div>
<div>+//</div><div>+// The LLVM Compiler Infrastructure</div><div>+//</div><div>+// This file is distributed under the University of Illinois Open Source</div><div>+// License. See LICENSE.TXT for details.</div>
<div>+//</div><div>+//===----------------------------------------------------------------------===//</div><div>+</div><div>+#include "lldb/lldb-defines.h"</div><div>+#include "lldb/Target/UnixSignals.h"</div>
<div>+#include "lldb/Core/Log.h"</div><div>+</div><div>+#include "lldb/API/SBUnixSignals.h"</div><div>+</div><div>+using namespace lldb;</div><div>+using namespace lldb_private;</div><div>+</div><div>
+SBUnixSignals::SBUnixSignals () :</div>
<div>+ m_opaque_ptr(NULL)</div><div>+{</div><div>+}</div><div>+</div><div>+SBUnixSignals::SBUnixSignals (const SBUnixSignals &rhs) :</div><div>+ m_opaque_ptr(rhs.m_opaque_ptr)</div><div>+{</div><div>+}</div><div>
+</div><div>+SBUnixSignals::SBUnixSignals (UnixSignals *unix_signals_ptr) :</div><div>+ m_opaque_ptr(unix_signals_ptr)</div><div>+{</div><div>+}</div><div>+</div><div>+const SBUnixSignals&</div><div>+SBUnixSignals::operator = (const SBUnixSignals& rhs)</div>
<div>+{</div><div>+ if (this != &rhs)</div><div>+ m_opaque_ptr = rhs.m_opaque_ptr;</div><div>+ return *this;</div><div>+}</div><div>+</div><div>+SBUnixSignals::~SBUnixSignals()</div><div>+{</div><div>+}</div>
<div>+</div><div>+UnixSignals *</div><div>+SBUnixSignals::GetPtr() const</div><div>+{</div><div>+ return m_opaque_ptr;</div><div>+}</div><div>+</div><div>+void</div><div>+SBUnixSignals::SetPtr (UnixSignals *unix_signals_ptr)</div>
<div>+{</div><div>+ m_opaque_ptr = unix_signals_ptr;</div><div>+}</div><div>+</div><div>+void</div><div>+SBUnixSignals::Clear ()</div><div>+{</div><div>+ m_opaque_ptr = NULL;</div><div>+}</div><div>+</div><div>+bool</div>
<div>+SBUnixSignals::IsValid() const</div><div>+{</div><div>+ return m_opaque_ptr != NULL;</div><div>+}</div><div>+</div><div>+const char *</div><div>+SBUnixSignals::GetSignalAsCString (int32_t signo) const</div><div>
+{</div>
<div>+ if (m_opaque_ptr) return m_opaque_ptr->GetSignalAsCString(signo);</div><div>+ return NULL;</div><div>+}</div><div>+</div><div>+int32_t</div><div>+SBUnixSignals::GetSignalNumberFromName (const char *name) const</div>
<div>+{</div><div>+ if (m_opaque_ptr) return m_opaque_ptr->GetSignalNumberFromName(name);</div><div>+ return -1;</div><div>+}</div><div>+</div><div>+bool</div><div>+SBUnixSignals::GetShouldSuppress (int32_t signo) const</div>
<div>+{</div><div>+ if (m_opaque_ptr) return m_opaque_ptr->GetShouldSuppress(signo);</div><div>+ return false;</div><div>+}</div><div>+</div><div>+bool</div><div>+SBUnixSignals::SetShouldSuppress (int32_t signo, bool value)</div>
<div>+{</div><div>+ Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));</div><div>+</div><div>+ if (log)</div><div>+ {</div><div>+ log->Printf ("SBUnixSignals(%p)::SetShouldSuppress (signo=%d, value=%d)",</div>
<div>+ m_opaque_ptr,</div><div>+ signo,</div><div>+ value);</div><div>+ }</div><div>+</div><div>+ if (m_opaque_ptr) return m_opaque_ptr->SetShouldSuppress(signo, value);</div>
<div>+ return false;</div><div>+}</div><div>+</div><div>+bool</div><div>+SBUnixSignals::GetShouldStop (int32_t signo) const</div><div>+{</div><div>+ if (m_opaque_ptr) return m_opaque_ptr->GetShouldStop(signo);</div>
<div>+ return false;</div><div>+}</div><div>+</div><div>+bool</div><div>+SBUnixSignals::SetShouldStop (int32_t signo, bool value)</div><div>+{</div><div>+ Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));</div>
<div>+</div><div>+ if (log)</div><div>+ {</div><div>+ log->Printf ("SBUnixSignals(%p)::SetShouldStop (signo=%d, value=%d)",</div><div>+ m_opaque_ptr,</div><div>+ signo,</div>
<div>+ value);</div><div>+ }</div><div>+</div><div>+ if (m_opaque_ptr) return m_opaque_ptr->SetShouldStop(signo, value);</div><div>+ return false;</div><div>+}</div><div>+</div><div>+bool</div>
<div>+SBUnixSignals::GetShouldNotify (int32_t signo) const</div><div>+{</div><div>+ if (m_opaque_ptr) return m_opaque_ptr->GetShouldNotify(signo);</div><div>+ return false;</div><div>+}</div><div>+</div><div>+bool</div>
<div>+SBUnixSignals::SetShouldNotify (int32_t signo, bool value)</div><div>+{</div><div>+ Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));</div><div>+</div><div>+ if (log)</div><div>+ {</div><div>
+ log->Printf ("SBUnixSignals(%p)::SetShouldNotify (signo=%d, value=%d)",</div><div>+ m_opaque_ptr,</div><div>+ signo,</div><div>+ value);</div>
<div>+ }</div><div>+</div><div>+ if (m_opaque_ptr) return m_opaque_ptr->SetShouldNotify(signo, value);</div><div>+ return false;</div><div>+}</div><div>+</div><div>+int32_t</div><div>+SBUnixSignals::GetNumSignals () const</div>
<div>+{</div><div>+ if (m_opaque_ptr)</div><div>+ {</div><div>+ int32_t num_signals = 0;</div><div>+ for (</div><div>+ int32_t signo = m_opaque_ptr->GetFirstSignalNumber();</div><div>+ signo != LLDB_INVALID_SIGNAL_NUMBER;</div>
<div>+ signo = m_opaque_ptr->GetNextSignalNumber(signo)</div><div>+ )</div><div>+ {</div><div>+ num_signals++;</div><div>+ }</div><div>+ return num_signals;</div><div>
+ }</div>
<div>+ return LLDB_INVALID_SIGNAL_NUMBER;</div><div>+}</div><div>+</div><div>+int32_t</div><div>+SBUnixSignals::GetSignalAtIndex (int32_t index) const</div><div>+{</div><div>+ if (m_opaque_ptr)</div><div>+ {</div>
<div>+ int32_t idx = 0;</div><div>+ for (</div><div>+ int32_t signo = m_opaque_ptr->GetFirstSignalNumber();</div><div>+ signo != LLDB_INVALID_SIGNAL_NUMBER;</div><div>+ signo = m_opaque_ptr->GetNextSignalNumber(signo)</div>
<div>+ )</div><div>+ {</div><div>+ if (index == idx) return signo;</div><div>+ idx++;</div><div>+ }</div><div>+ }</div><div>+ return LLDB_INVALID_SIGNAL_NUMBER;</div><div>
+}</div>
<div>diff --git a/test/python_api/signals/Makefile b/test/python_api/signals/Makefile</div><div>new file mode 100644</div><div>index 0000000..8a7102e</div><div>--- /dev/null</div><div>+++ b/test/python_api/signals/Makefile</div>
<div>@@ -0,0 +1,5 @@</div><div>+LEVEL = ../../make</div><div>+</div><div>+CXX_SOURCES := main.cpp</div><div>+</div><div>+include $(LEVEL)/Makefile.rules</div><div>diff --git a/test/python_api/signals/TestSignalsAPI.py b/test/python_api/signals/TestSignalsAPI.py</div>
<div>new file mode 100644</div><div>index 0000000..67f363a</div><div>--- /dev/null</div><div>+++ b/test/python_api/signals/TestSignalsAPI.py</div><div>@@ -0,0 +1,51 @@</div><div>+"""</div><div>+Test SBProcess APIs, including ReadMemory(), WriteMemory(), and others.</div>
<div>+"""</div><div>+</div><div>+import os, time</div><div>+import unittest2</div><div>+import lldb</div><div>+from lldbutil import get_stopped_thread, state_type_to_str</div><div>+from lldbtest import *</div>
<div>+</div><div>+class ProcessAPITestCase(TestBase):</div><div>+ mydir = os.path.join("python_api", "signals")</div><div>+</div><div>+ @python_api_test</div><div>+ def test_ignore_signal(self):</div>
<div>+ """Test Python SBUnixSignals.Suppress/Stop/Notify() API."""</div><div>+ self.buildDefault()</div><div>+ exe = os.path.join(os.getcwd(), "a.out")</div><div>
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)</div><div>+</div><div>+ target = self.dbg.CreateTarget(exe)</div><div>+ self.assertTrue(target, VALID_TARGET)</div><div>+</div><div>+ error = lldb.SBError()</div>
<div>+ event = lldb.SBEvent();</div><div>+ listener = lldb.SBListener("TestSignalsAPI Listener")</div><div>+ # Launch the process, and stop at the entry point.</div><div>+ process = target.Launch(listener, None, None,</div>
<div>+ None, None, None,</div><div>+ os.getcwd(), 0, True, error)</div><div>+ self.assertTrue(error.Success(), error.GetCString())</div><div>+</div><div>
+ while not event.IsValid() or not lldb.SBProcess.GetStateFromEvent(event) == lldb.eStateStopped:</div><div>+ self.assertTrue(listener.WaitForEvent(3, event), "Listener timeout")</div><div>+</div>
<div>+ unix_signals = process.GetUnixSignals()</div><div>+ sigint = unix_signals.GetSignalNumberFromName("SIGINT")</div><div>+ unix_signals.SetShouldSuppress(sigint, True)</div><div>+ unix_signals.SetShouldStop(sigint, False)</div>
<div>+ unix_signals.SetShouldNotify(sigint, False)</div><div>+</div><div>+ process.Continue()</div><div>+ self.assertTrue(process.state == lldb.eStateExited, "The process should have exited")</div>
<div>+ self.assertTrue(process.GetExitStatus() == 0, "The process should have returned 0")</div><div>+</div><div>+</div><div>+if __name__ == '__main__':</div><div>+ import atexit</div><div>+ lldb.SBDebugger.Initialize()</div>
<div>+ atexit.register(lambda: lldb.SBDebugger.Terminate())</div><div>+ unittest2.main()</div><div>diff --git a/test/python_api/signals/main.cpp b/test/python_api/signals/main.cpp</div><div>new file mode 100644</div>
<div>index 0000000..98f3e39</div><div>--- /dev/null</div><div>+++ b/test/python_api/signals/main.cpp</div><div>@@ -0,0 +1,20 @@</div><div>+//===-- main.c --------------------------------------------------*- C++ -*-===//</div>
<div>+//</div><div>+// The LLVM Compiler Infrastructure</div><div>+//</div><div>+// This file is distributed under the University of Illinois Open Source</div><div>+// License. See LICENSE.TXT for details.</div>
<div>+//</div><div>+//===----------------------------------------------------------------------===//</div><div>+#include <stdio.h></div><div>+#include <sys/types.h></div><div>+#include <unistd.h></div><div>
+#include <signal.h></div><div>+</div><div>+// This simple program is to test the lldb Python API related to process.</div><div>+</div><div>+int main (int argc, char const *argv[])</div><div>+{</div><div>+ kill(getpid(), SIGINT);</div>
<div>+ return 0;</div><div>+}</div><div>-- </div><div>1.8.1.3</div><div><br></div></div><br></div></div></div>