diff options
| author | Todd Fiala <todd.fiala@gmail.com> | 2014-08-12 17:02:07 +0000 |
|---|---|---|
| committer | Todd Fiala <todd.fiala@gmail.com> | 2014-08-12 17:02:07 +0000 |
| commit | 58a2f6692bc3d140d2308549f5c0b96e72c0a034 (patch) | |
| tree | 15889695196839cd13e19b4ff87c4ac017855896 /lldb/test/tools | |
| parent | 09d84addb77e7ddf6a430ea79174ec123e9d3581 (diff) | |
| download | bcm5719-llvm-58a2f6692bc3d140d2308549f5c0b96e72c0a034.tar.gz bcm5719-llvm-58a2f6692bc3d140d2308549f5c0b96e72c0a034.zip | |
llgs: corrected Linux signal reception notification for SIGABRT, SIGSEGV and their ilk.
Added llgs/debugserver gdb-remote tests around SIGABRT and SIGSEGV signal reception
notification. Found a few bugs in exception signal handling in Linux llgs. Fixed those.
llvm-svn: 215458
Diffstat (limited to 'lldb/test/tools')
5 files changed, 146 insertions, 5 deletions
diff --git a/lldb/test/tools/lldb-gdbserver/gdbremote_testcase.py b/lldb/test/tools/lldb-gdbserver/gdbremote_testcase.py index 15aca47d046..afc03c8e367 100644 --- a/lldb/test/tools/lldb-gdbserver/gdbremote_testcase.py +++ b/lldb/test/tools/lldb-gdbserver/gdbremote_testcase.py @@ -284,11 +284,12 @@ class GdbRemoteTestCaseBase(TestBase): raise Exception("failed to create a socket to the launched debug monitor after %d tries" % attempts) - def launch_process_for_attach(self,inferior_args=None, sleep_seconds=3): + def launch_process_for_attach(self,inferior_args=None, sleep_seconds=3, exe_path=None): # We're going to start a child process that the debug monitor stub can later attach to. # This process needs to be started so that it just hangs around for a while. We'll # have it sleep. - exe_path = os.path.abspath("a.out") + if not exe_path: + exe_path = os.path.abspath("a.out") args = [exe_path] if inferior_args: @@ -298,7 +299,7 @@ class GdbRemoteTestCaseBase(TestBase): return subprocess.Popen(args) - def prep_debug_monitor_and_inferior(self, inferior_args=None, inferior_sleep_seconds=3): + def prep_debug_monitor_and_inferior(self, inferior_args=None, inferior_sleep_seconds=3, inferior_exe_path=None): """Prep the debug monitor, the inferior, and the expected packet stream. Handle the separate cases of using the debug monitor in attach-to-inferior mode @@ -323,7 +324,7 @@ class GdbRemoteTestCaseBase(TestBase): if self._inferior_startup == self._STARTUP_ATTACH or self._inferior_startup == self._STARTUP_ATTACH_MANUALLY: # Launch the process that we'll use as the inferior. - inferior = self.launch_process_for_attach(inferior_args=inferior_args, sleep_seconds=inferior_sleep_seconds) + inferior = self.launch_process_for_attach(inferior_args=inferior_args, sleep_seconds=inferior_sleep_seconds, exe_path=inferior_exe_path) self.assertIsNotNone(inferior) self.assertTrue(inferior.pid > 0) if self._inferior_startup == self._STARTUP_ATTACH: @@ -336,7 +337,9 @@ class GdbRemoteTestCaseBase(TestBase): if self._inferior_startup == self._STARTUP_LAUNCH: # Build launch args - launch_args = [os.path.abspath('a.out')] + if not inferior_exe_path: + inferior_exe_path = os.path.abspath("a.out") + launch_args = [inferior_exe_path] if inferior_args: launch_args.extend(inferior_args) diff --git a/lldb/test/tools/lldb-gdbserver/inferior-crash/Makefile b/lldb/test/tools/lldb-gdbserver/inferior-crash/Makefile new file mode 100644 index 00000000000..93052df3111 --- /dev/null +++ b/lldb/test/tools/lldb-gdbserver/inferior-crash/Makefile @@ -0,0 +1,8 @@ +LEVEL = ../../../make + +CFLAGS_EXTRAS := -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS -std=c++11 +# LD_EXTRAS := -lpthread +CXX_SOURCES := main.cpp +MAKE_DSYM :=NO + +include $(LEVEL)/Makefile.rules diff --git a/lldb/test/tools/lldb-gdbserver/inferior-crash/TestGdbRemoteAbort.py b/lldb/test/tools/lldb-gdbserver/inferior-crash/TestGdbRemoteAbort.py new file mode 100644 index 00000000000..1d1f73f35f6 --- /dev/null +++ b/lldb/test/tools/lldb-gdbserver/inferior-crash/TestGdbRemoteAbort.py @@ -0,0 +1,45 @@ +import unittest2 + +# Add the directory above ours to the python library path since we +# will import from there. +import os.path +import sys +sys.path.append(os.path.join(os.path.dirname(__file__), "..")) + +import gdbremote_testcase +import signal +from lldbtest import * + +class TestGdbRemoteAbort(gdbremote_testcase.GdbRemoteTestCaseBase): + mydir = TestBase.compute_mydir(__file__) + + def inferior_abort_received(self): + procs = self.prep_debug_monitor_and_inferior(inferior_args=["abort"]) + self.assertIsNotNone(procs) + + self.test_sequence.add_log_lines([ + "read packet: $vCont;c#00", + {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2}).*#[0-9a-fA-F]{2}$", "capture":{ 1:"hex_exit_code"} }, + ], True) + + context = self.expect_gdbremote_sequence() + self.assertIsNotNone(context) + + hex_exit_code = context.get("hex_exit_code") + self.assertIsNotNone(hex_exit_code) + self.assertEquals(int(hex_exit_code, 16), signal.SIGABRT) + + @debugserver_test + @dsym_test + def test_inferior_abort_received_debugserver_dsym(self): + self.init_debugserver_test() + self.buildDsym() + self.inferior_abort_received() + + @llgs_test + @dwarf_test + def test_inferior_abort_received_llgs_dwarf(self): + self.init_llgs_test() + self.buildDwarf() + self.inferior_abort_received() + diff --git a/lldb/test/tools/lldb-gdbserver/inferior-crash/TestGdbRemoteSegFault.py b/lldb/test/tools/lldb-gdbserver/inferior-crash/TestGdbRemoteSegFault.py new file mode 100644 index 00000000000..d1dafdb384f --- /dev/null +++ b/lldb/test/tools/lldb-gdbserver/inferior-crash/TestGdbRemoteSegFault.py @@ -0,0 +1,46 @@ +import unittest2 + +# Add the directory above ours to the python library path since we +# will import from there. +import os.path +import sys +sys.path.append(os.path.join(os.path.dirname(__file__), "..")) + +import gdbremote_testcase +# import signal +from lldbtest import * + +class TestGdbRemoteSegFault(gdbremote_testcase.GdbRemoteTestCaseBase): + mydir = TestBase.compute_mydir(__file__) + + GDB_REMOTE_STOP_CODE_BAD_ACCESS = 0x91 + + def inferior_seg_fault_received(self): + procs = self.prep_debug_monitor_and_inferior(inferior_args=["segfault"]) + self.assertIsNotNone(procs) + + self.test_sequence.add_log_lines([ + "read packet: $vCont;c#00", + {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2}).*#[0-9a-fA-F]{2}$", "capture":{ 1:"hex_exit_code"} }, + ], True) + + context = self.expect_gdbremote_sequence() + self.assertIsNotNone(context) + + hex_exit_code = context.get("hex_exit_code") + self.assertIsNotNone(hex_exit_code) + self.assertEquals(int(hex_exit_code, 16), self.GDB_REMOTE_STOP_CODE_BAD_ACCESS) + + @debugserver_test + @dsym_test + def test_inferior_seg_fault_received_debugserver_dsym(self): + self.init_debugserver_test() + self.buildDsym() + self.inferior_seg_fault_received() + + @llgs_test + @dwarf_test + def test_inferior_seg_fault_received_llgs_dwarf(self): + self.init_llgs_test() + self.buildDwarf() + self.inferior_seg_fault_received() diff --git a/lldb/test/tools/lldb-gdbserver/inferior-crash/main.cpp b/lldb/test/tools/lldb-gdbserver/inferior-crash/main.cpp new file mode 100644 index 00000000000..69d60071aa4 --- /dev/null +++ b/lldb/test/tools/lldb-gdbserver/inferior-crash/main.cpp @@ -0,0 +1,39 @@ +#include <cstdlib> +#include <cstring> +#include <iostream> + +namespace +{ + const char *const SEGFAULT_COMMAND = "segfault"; + const char *const ABORT_COMMAND = "abort"; +} + +int main (int argc, char **argv) +{ + if (argc < 2) + { + std::cout << "expected at least one command provided on the command line" << std::endl; + } + + // Process command line args. + for (int i = 1; i < argc; ++i) + { + const char *const command = argv[i]; + if (std::strstr (command, SEGFAULT_COMMAND)) + { + // Perform a null pointer access. + int *const null_int_ptr = nullptr; + *null_int_ptr = 0xDEAD; + } + else if (std::strstr (command, ABORT_COMMAND)) + { + std::abort(); + } + else + { + std::cout << "Unsupported command: " << command << std::endl; + } + } + + return 0; +} |

