1//===-- SetExceptionBreakpointsRequestHandler.cpp -------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "DAP.h"
10#include "EventHelper.h"
11#include "Protocol/ProtocolRequests.h"
12#include "RequestHandler.h"
13#include <set>
14
15using namespace llvm;
16using namespace lldb_dap::protocol;
17
18namespace lldb_dap {
19
20/// The request configures the debugger’s response to thrown exceptions. Each of
21/// the `filters`, `filterOptions`, and `exceptionOptions` in the request are
22/// independent configurations to a debug adapter indicating a kind of exception
23/// to catch. An exception thrown in a program should result in a `stopped`
24/// event from the debug adapter (with reason `exception`) if any of the
25/// configured filters match.
26///
27/// Clients should only call this request if the corresponding capability
28/// `exceptionBreakpointFilters` returns one or more filters.
29Expected<SetExceptionBreakpointsResponseBody>
30SetExceptionBreakpointsRequestHandler::Run(
31 const SetExceptionBreakpointsArguments &arguments) const {
32 // Keep a list of any exception breakpoint filter names that weren't set
33 // so we can clear any exception breakpoints if needed.
34 std::set<StringRef> unset_filters;
35 for (const auto &bp : dap.exception_breakpoints)
36 unset_filters.insert(x: bp.GetFilter());
37
38 SetExceptionBreakpointsResponseBody body;
39 for (const auto &filter : arguments.filters) {
40 auto *exc_bp = dap.GetExceptionBreakpoint(filter);
41 if (!exc_bp)
42 continue;
43
44 body.breakpoints.push_back(x: exc_bp->SetBreakpoint());
45 unset_filters.erase(x: filter);
46 }
47 for (const auto &filterOptions : arguments.filterOptions) {
48 auto *exc_bp = dap.GetExceptionBreakpoint(filter: filterOptions.filterId);
49 if (!exc_bp)
50 continue;
51
52 body.breakpoints.push_back(x: exc_bp->SetBreakpoint(filterOptions.condition));
53 unset_filters.erase(x: filterOptions.filterId);
54 }
55
56 // Clear any unset filters.
57 for (const auto &filter : unset_filters) {
58 auto *exc_bp = dap.GetExceptionBreakpoint(filter);
59 if (!exc_bp)
60 continue;
61
62 exc_bp->ClearBreakpoint();
63 }
64
65 return body;
66}
67
68} // namespace lldb_dap
69

source code of lldb/tools/lldb-dap/Handler/SetExceptionBreakpointsRequestHandler.cpp