Skip to content

Commit 5f2b6b4

Browse files
royitaqikusmour
authored andcommitted
[DAP] Fix the missing exception breakpoints
Summary: In D59401005, `ResetDebuggerState()` was added as a part of the "reuse lldb-dap" change. The intention of the method is to reset any state related to the debugger, so that it will be a clean start for new debug sessions. However, clearing `exception_breakpoints` will cause exception breakpoints to disappear in VS Code for new debug sessions. See first video in "Test Plan" section. Here is why: The exception breakpoints are added into `exception_breakpoints` by `PopulateExceptionBreakpoints()`. This function has a `llvm::call_once` - it will only execute once during the whole lifetime of the process. Clearing `exception_breakpoints` at the end of the 1st debug session means that any 2nd+ sessions will see an empty list. See diff comment. The following properties are true: 1. In a single debug session, the list of `ExceptionBreakpoint` objects (and the `SBBreakpoint` objects within) remain the same. This ensures consistency within the session when the list of exception breakpoints are interacted. 2. When reusing lldb-dap, the list is cleared between sessions and is repopulated the first time `PopulateExceptionBreakpoints()` is called in each session. This differs from before the diff, where 2nd+ sessions don't repopulate the list. This fixes the bug. Test Plan: By debugging a c++ toy program and observe the existence of the exception breakpoints in VS Code Local. **Before the change:** Exception breakpoints exist for the 1st debug session, but disappears for 2nd+ sessions. https://pxl.cl/6CBK7 **After the change:** Exception breakpoints exist for all debug sessions. https://pxl.cl/6CBKl **Test fails __before__ the change:** ``` 1516 ROYDEBUG BEGIN OF 1 ... 1518 ROYDEBUG END OF 1 1519 ROYDEBUG BEGIN OF 2 ... 3096 AssertionError: False is not true : verify we got "C++ Throw" ``` Look at this diff's V5 for where the "ROYDEBUG" print statements are in the test. This verifies that the verification failed during the 2nd debug session. See full test output: P1742862144 **Test passes __after__ the change:** ``` [[email protected] ~/llvm-sand/build/Debug/fbcode-x86_64/toolchain]$ bin/llvm-lit -sv /home/royshi/llvm-sand/external/llvm-project/lldb/test/API/tools/lldb-dap/reuseDAP/TestDAP_reuseAdapter.py Testing Time: 5.12s Total Discovered Tests: 1 Passed: 1 (100.00%) [[email protected] ~/llvm-sand/build/Debug/fbcode-x86_64/toolchain]$ ``` Reviewers: jeffreytan, #lldb_team Reviewed By: jeffreytan Subscribers: davidayoung, mavitale, jalalonde, #lldb_team Differential Revision: https://phabricator.intern.facebook.com/D69966150 Tasks: T214613938
1 parent a29980c commit 5f2b6b4

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

lldb/test/API/tools/lldb-dap/reuseDAP/TestDAP_reuseAdapter.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,34 @@ def test_basic_reuse(self):
3737
breakpoint_ids = self.set_source_breakpoints(source, [breakpoint2_line])
3838
self.continue_to_breakpoints(breakpoint_ids)
3939
self.dap_server.request_disconnect()
40+
41+
@skipIfWindows
42+
def test_exception_breakopints(self):
43+
"""
44+
Test reuse lldb-dap works across debug sessions.
45+
"""
46+
program = self.getBuildArtifact("a.out")
47+
48+
# Keep lldb-dap alive for 10 minutes.
49+
dapKeepAliveTimeInMS = 10 * 1000 * 60
50+
self.build_and_launch(program, disconnectAutomatically=False, keepAliveTimeout=dapKeepAliveTimeInMS)
51+
52+
response = self.dap_server.request_setExceptionBreakpoints(
53+
filters=["cpp_throw", "cpp_catch"]
54+
)
55+
self.assertTrue(response)
56+
self.assertTrue(response["success"])
57+
self.continue_to_exception_breakpoint("C++ Throw")
58+
self.dap_server.request_disconnect()
59+
60+
# Second debug session by reusing lldb-dap.
61+
self.create_debug_adapter(reuseDapServer=True)
62+
self.launch(program)
63+
64+
response = self.dap_server.request_setExceptionBreakpoints(
65+
filters=["cpp_throw", "cpp_catch"],
66+
)
67+
self.assertTrue(response)
68+
self.assertTrue(response["success"])
69+
self.continue_to_exception_breakpoint("C++ Throw")
70+
self.dap_server.request_disconnect()
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33
#include <unistd.h>
4+
#include <stdexcept>
45

56
int main(int argc, char const *argv[], char const *envp[]) {
67
for (int i = 0; i < argc; ++i)
@@ -10,6 +11,7 @@ int main(int argc, char const *argv[], char const *envp[]) {
1011
char *cwd = getcwd(NULL, 0);
1112
printf("cwd = \"%s\"\n", cwd); // breakpoint 1
1213
free(cwd);
13-
cwd = NULL;
14-
return 0; // breakpoint 2
14+
cwd = NULL; // breakpoint 2
15+
throw new std::runtime_error("This is a C++ exception");
16+
return 0;
1517
}

0 commit comments

Comments
 (0)