summaryrefslogtreecommitdiff
path: root/lldb/test/API/tools/lldb-dap/exception/objc/TestDAP_exception_objc.py
blob: ddedf7a6de8c6c5ccdc31c2fa251057878f28a0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Test exception behavior in DAP with obj-c throw.
"""

from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
import lldbdap_testcase


class TestDAP_exception_objc(lldbdap_testcase.DAPTestCaseBase):
    @skipUnlessDarwin
    def test_stopped_description(self):
        """
        Test that exception description is shown correctly in stopped event.
        """
        program = self.getBuildArtifact("a.out")
        self.build_and_launch(program)
        self.dap_server.request_continue()
        self.assertTrue(self.verify_stop_exception_info("signal SIGABRT"))
        exception_info = self.get_exceptionInfo()
        self.assertEqual(exception_info["breakMode"], "always")
        self.assertEqual(exception_info["description"], "signal SIGABRT")
        self.assertEqual(exception_info["exceptionId"], "signal")
        exception_details = exception_info["details"]
        self.assertRegex(exception_details["message"], "SomeReason")
        self.assertRegex(exception_details["stackTrace"], "main.m")

    @skipUnlessDarwin
    def test_break_on_throw_and_catch(self):
        """
        Test that breakpoints on exceptions work as expected.
        """
        program = self.getBuildArtifact("a.out")
        self.build_and_launch(program)

        response = self.dap_server.request_setExceptionBreakpoints(
            filter_options=[
                {
                    "filterId": "objc_throw",
                    "condition": '[[((NSException *)$arg1) name] isEqual:@"ThrownException"]',
                },
            ]
        )
        if response:
            self.assertTrue(response["success"])

        self.continue_to_exception_breakpoint("Objective-C Throw")

        # FIXME: Catching objc exceptions do not appear to be working.
        # Xcode appears to set a breakpoint on '__cxa_begin_catch' for objc
        # catch, which is different than
        # SBTarget::BreakpointCreateForException(eLanguageObjectiveC, /*catch_bp=*/true, /*throw_bp=*/false);
        # self.continue_to_exception_breakpoint("Objective-C Catch")

        self.do_continue()

        self.assertTrue(self.verify_stop_exception_info("signal SIGABRT"))
        exception_info = self.get_exceptionInfo()
        self.assertEqual(exception_info["breakMode"], "always")
        self.assertEqual(exception_info["description"], "signal SIGABRT")
        self.assertEqual(exception_info["exceptionId"], "signal")
        exception_details = exception_info["details"]
        self.assertRegex(exception_details["message"], "SomeReason")
        self.assertRegex(exception_details["stackTrace"], "main.m")