Hmm, so there's two possibilities:

  1.  SIGINT is not being suppressed by LLDB and instead is causing an abrupt 
termination of the inferior, and the exit code is correctly reported.
  2.  LLDB is incorrectly parsing the exit code of the subprocess.

Not sure how to narrow down what's happening here — if you can figure out 
what's going on, even if you don't have a fix, I recommend checking in the 
test. If it still isn't passing and is breaking some buildbots, maybe mark it 
with an @expectedFailureLinux and a corresponding comment pointing to an open 
llvm.org/bugs ticket.


Thanks for implementing tests for this feature Russel!

Cheers,
Dan

From: Russell Harmon <[email protected]<mailto:[email protected]>>
Date: Friday, 5 July, 2013 1:10 PM
To: Daniel Malea <[email protected]<mailto:[email protected]>>
Cc: "[email protected]<mailto:[email protected]>" 
<[email protected]<mailto:[email protected]>>, 
"[email protected]<mailto:[email protected]>" 
<[email protected]<mailto:[email protected]>>
Subject: Re: [lldb-dev] Ignoring Signals via the API

That was super helpful, I didn't know about -t. I've got one (hopefully last) 
issue with the test in that I believe I must be using the 
SBProcess.GetExitStatus() API incorrectly, as it always returns -1 for me. If 
that returned 0 when the debugee exited normally, the test would be finished. 
Thoughts?

--
Russell Harmon
>From 1d777a4c1433c6e5b889f0363b25e3fecb9ecb1b Mon Sep 17 00:00:00 2001
From: Russell Harmon <[email protected]<mailto:[email protected]>>
Date: Mon, 1 Jul 2013 10:15:14 -0700
Subject: [PATCH 2/2] Add a unit test for SBUnixSignals

---
 test/python_api/signals/Makefile          |  5 +++
 test/python_api/signals/TestSignalsAPI.py | 51 +++++++++++++++++++++++++++++++
 test/python_api/signals/main.cpp          | 19 ++++++++++++
 3 files changed, 75 insertions(+)
 create mode 100644 test/python_api/signals/Makefile
 create mode 100644 test/python_api/signals/TestSignalsAPI.py
 create mode 100644 test/python_api/signals/main.cpp

diff --git a/test/python_api/signals/Makefile b/test/python_api/signals/Makefile
new file mode 100644
index 0000000..8a7102e
--- /dev/null
+++ b/test/python_api/signals/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
diff --git a/test/python_api/signals/TestSignalsAPI.py 
b/test/python_api/signals/TestSignalsAPI.py
new file mode 100644
index 0000000..67f363a
--- /dev/null
+++ b/test/python_api/signals/TestSignalsAPI.py
@@ -0,0 +1,51 @@
+"""
+Test SBProcess APIs, including ReadMemory(), WriteMemory(), and others.
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbutil import get_stopped_thread, state_type_to_str
+from lldbtest import *
+
+class ProcessAPITestCase(TestBase):
+    mydir = os.path.join("python_api", "signals")
+
+    @python_api_test
+    def test_ignore_signal(self):
+        """Test Python SBUnixSignals.Suppress/Stop/Notify() API."""
+        self.buildDefault()
+        exe = os.path.join(os.getcwd(), "a.out")
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        target = self.dbg.CreateTarget(exe)
+        self.assertTrue(target, VALID_TARGET)
+
+        error = lldb.SBError()
+        event = lldb.SBEvent();
+        listener = lldb.SBListener("TestSignalsAPI Listener")
+        # Launch the process, and stop at the entry point.
+        process = target.Launch(listener, None, None,
+                                None, None, None,
+                                os.getcwd(), 0, True, error)
+        self.assertTrue(error.Success(), error.GetCString())
+
+        while not event.IsValid() or not 
lldb.SBProcess.GetStateFromEvent(event) == lldb.eStateStopped:
+            self.assertTrue(listener.WaitForEvent(3, event), "Listener 
timeout")
+
+        unix_signals = process.GetUnixSignals()
+        sigint = unix_signals.GetSignalNumberFromName("SIGINT")
+        unix_signals.SetShouldSuppress(sigint, True)
+        unix_signals.SetShouldStop(sigint, False)
+        unix_signals.SetShouldNotify(sigint, False)
+
+        process.Continue()
+        self.assertTrue(process.state == lldb.eStateExited, "The process 
should have exited")
+        self.assertTrue(process.GetExitStatus() == 0, "The process should have 
returned 0")
+
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()
diff --git a/test/python_api/signals/main.cpp b/test/python_api/signals/main.cpp
new file mode 100644
index 0000000..a4e1201
--- /dev/null
+++ b/test/python_api/signals/main.cpp
@@ -0,0 +1,19 @@
+//===-- main.c --------------------------------------------------*- C++ 
-*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include <stdio.h>
+#include <unistd.h>
+#include <signal.h>
+
+// This simple program is to test the lldb Python API related to process.
+
+int main (int argc, char const *argv[])
+{
+    kill(getpid(), SIGINT); // Set break point at this line.
+    return 0;
+}
--
1.8.1.3

_______________________________________________
lldb-dev mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev

Reply via email to