summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/functionalities/signal/handle-segv
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2015-10-28 17:43:26 +0000
committerZachary Turner <zturner@google.com>2015-10-28 17:43:26 +0000
commitc432c8f856e0bd84de980a9d9bb2d31b06fa95b1 (patch)
tree4efa528e074a6e2df782345e4cd97f5d85d038c4 /lldb/packages/Python/lldbsuite/test/functionalities/signal/handle-segv
parenta8a3bd210086b50242903ed95048fe5e53897878 (diff)
downloadbcm5719-llvm-c432c8f856e0bd84de980a9d9bb2d31b06fa95b1.tar.gz
bcm5719-llvm-c432c8f856e0bd84de980a9d9bb2d31b06fa95b1.zip
Move lldb/test to lldb/packages/Python/lldbsuite/test.
This is the conclusion of an effort to get LLDB's Python code structured into a bona-fide Python package. This has a number of benefits, but most notably the ability to more easily share Python code between different but related pieces of LLDB's Python infrastructure (for example, `scripts` can now share code with `test`). llvm-svn: 251532
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/functionalities/signal/handle-segv')
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/signal/handle-segv/Makefile5
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/signal/handle-segv/TestHandleSegv.py43
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/signal/handle-segv/main.c58
3 files changed, 106 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/signal/handle-segv/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/signal/handle-segv/Makefile
new file mode 100644
index 00000000000..b09a579159d
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/signal/handle-segv/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/signal/handle-segv/TestHandleSegv.py b/lldb/packages/Python/lldbsuite/test/functionalities/signal/handle-segv/TestHandleSegv.py
new file mode 100644
index 00000000000..c60656a3c60
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/signal/handle-segv/TestHandleSegv.py
@@ -0,0 +1,43 @@
+"""Test that we can debug inferiors that handle SIGSEGV by themselves"""
+
+from __future__ import print_function
+
+import use_lldb_suite
+
+import os
+import lldb
+from lldbtest import *
+import lldbutil
+import re
+
+
+class HandleSegvTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @skipIfWindows # signals do not exist on Windows
+ @skipIfDarwin
+ @expectedFailureFreeBSD("llvm.org/pr23699 SIGSEGV is reported as exception, not signal")
+ def test_inferior_handle_sigsegv(self):
+ self.build()
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # launch
+ process = target.LaunchSimple(None, None, self.get_process_working_directory())
+ self.assertTrue(process, PROCESS_IS_VALID)
+ self.assertEqual(process.GetState(), lldb.eStateStopped)
+ signo = process.GetUnixSignals().GetSignalNumberFromName("SIGSEGV")
+
+ thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonSignal)
+ self.assertTrue(thread and thread.IsValid(), "Thread should be stopped due to a signal")
+ self.assertTrue(thread.GetStopReasonDataCount() >= 1, "There was data in the event.")
+ self.assertEqual(thread.GetStopReasonDataAtIndex(0), signo, "The stop signal was SIGSEGV")
+
+ # Continue until we exit.
+ process.Continue()
+ self.assertEqual(process.GetState(), lldb.eStateExited)
+ self.assertEqual(process.GetExitStatus(), 0)
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/signal/handle-segv/main.c b/lldb/packages/Python/lldbsuite/test/functionalities/signal/handle-segv/main.c
new file mode 100644
index 00000000000..27d9b8e500a
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/signal/handle-segv/main.c
@@ -0,0 +1,58 @@
+#include <sys/mman.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+
+enum {
+ kMmapSize = 0x1000,
+ kMagicValue = 47,
+};
+
+void *address;
+volatile sig_atomic_t signaled = 0;
+
+void handler(int sig)
+{
+ signaled = 1;
+ if (munmap(address, kMmapSize) != 0)
+ {
+ perror("munmap");
+ _exit(5);
+ }
+
+ void* newaddr = mmap(address, kMmapSize, PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_FIXED | MAP_PRIVATE, -1, 0);
+ if (newaddr != address)
+ {
+ fprintf(stderr, "Newly mmaped address (%p) does not equal old address (%p).\n",
+ newaddr, address);
+ _exit(6);
+ }
+ *(int*)newaddr = kMagicValue;
+}
+
+int main()
+{
+ if (signal(SIGSEGV, handler) == SIG_ERR)
+ {
+ perror("signal");
+ return 1;
+ }
+
+ address = mmap(NULL, kMmapSize, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
+ if (address == MAP_FAILED)
+ {
+ perror("mmap");
+ return 2;
+ }
+
+ // This should first trigger a segfault. Our handler will make the memory readable and write
+ // the magic value into memory.
+ if (*(int*)address != kMagicValue)
+ return 3;
+
+ if (! signaled)
+ return 4;
+
+ return 0;
+}
OpenPOWER on IntegriCloud