Skip to content

Commit 0bb1bbe

Browse files
committed
[lldb-dap] Support thread focused breakpoint mode for SourceBreakpoint
Summary: This diff mainly did 2 things to support the breakpoint mode in `SourceBreakpoint` - Return the `breakpointModes` in `Capabilities` - "Normal": this is an no-op, it will not change anything about source breakpoints - "threadFocused": this is the new mode we want to support for VSCode users; it will used the current "focused tid", which is usually the thread that users stopped on, or the specific thread that user selected to resume from. - Currently, the breakpoint modes only apply to `source` - Handle the mode in `setBreakpoints` request. - Only when the `mode` field comes back as `threadFocused` that we will set the bp's thread id to `dap.focus_tid` - Do nothing otherwise Test Plan: VSCode already supports such capabilities and UI showed up after lldb-dap return `breakpointModes` in its capabilities. {F1968843974} {F1968844047} {F1968844097} https://pxl.cl/62NFt And selecting the breakpoint mode `Thread Focused` will put a filter on the tid to the current stopped thread https://pxl.cl/62NFD The setBreakpoints request will send the `mode`; The setBreakpoint response will return the `tid` {F1968849686} Return empty `breakpointModes` if Single stopped event is turned off https://pxl.cl/658p3 NOTE: There's an issue with the UI updates, once the capabilities is registered with VSCode, it seems we cann> Tried using the `CapabilitiesEvent`, wasn't able to update the UI either. cc. @NBlake Reviewers: nblake, #lldb_team Reviewed By: nblake Subscribers: nblake, pdepetro, #lldb_team Differential Revision: https://phabricator.intern.facebook.com/D66549375 Differential Revision: https://phabricator.intern.facebook.com/D66835436 Tags: accept2ship
1 parent 1d4a63e commit 0bb1bbe

File tree

5 files changed

+80
-1
lines changed

5 files changed

+80
-1
lines changed

lldb/tools/lldb-dap/Breakpoint.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ protocol::Breakpoint Breakpoint::ToProtocolBreakpoint() {
8484
1;
8585
}
8686
}
87-
87+
// Return the tid if the breakpoint is set for a specific thread
88+
if (m_bp.GetThreadID() != LLDB_INVALID_THREAD_ID)
89+
breakpoint.threadId = m_bp.GetThreadID();
8890
breakpoint.source = std::move(source);
8991
}
9092

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,13 @@ protocol::Capabilities DAP::GetCapabilities() {
12241224
completion_characters.emplace_back("\t");
12251225
capabilities.completionTriggerCharacters = std::move(completion_characters);
12261226

1227+
// Only allow breakpoint mode if we set single_stoppped_event until
1228+
// we support user specified thread id, as it will affect the value
1229+
// of the dap.focus_tid
1230+
if (configuration.singleStoppedEvent) {
1231+
capabilities.breakpointModes = CreateBreakpointModes();
1232+
}
1233+
12271234
// Put in non-DAP specification lldb specific information.
12281235
capabilities.lldbExtVersion = debugger.GetVersionString();
12291236

@@ -1497,6 +1504,11 @@ std::vector<protocol::Breakpoint> DAP::SetSourceBreakpoints(
14971504

14981505
const auto [iv, inserted] =
14991506
existing_breakpoints.try_emplace(bp_pos, src_bp);
1507+
// Set thread id filter to focus_tid if the mode is "threadFocused"
1508+
const auto breakpoint_mode = bp.mode.value_or("");
1509+
if (breakpoint_mode == "threadFocused" &&
1510+
this->focus_tid != LLDB_INVALID_THREAD_ID)
1511+
iv->second.SetThreadID(this->focus_tid);
15001512
// We check if this breakpoint already exists to update it.
15011513
if (inserted) {
15021514
if (llvm::Error error = iv->second.SetBreakpoint(source)) {

lldb/tools/lldb-dap/JSONUtils.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,4 +1291,60 @@ std::string JSONToString(const llvm::json::Value &json) {
12911291
return data;
12921292
}
12931293

1294+
// "BreakpointMode": {
1295+
// "type": "object",
1296+
// "description": "A BreakpointMode is provided as a option when setting
1297+
// breakpoints on sources or instructions.",
1298+
// "properties": {
1299+
// "mode": {
1300+
// "type": "string",
1301+
// "description": "The internal ID of the mode. This value is passed
1302+
// to the setBreakpoints request."
1303+
// },
1304+
// "label": {
1305+
// "type": "string",
1306+
// "description": "The name of the breakpoint mode. This is shown in the UI."
1307+
// },
1308+
// "description": {
1309+
// "type": "string",
1310+
// "description": "An optional help text providing additional information about
1311+
// the breakpoint mode. This string is typically shown as a
1312+
// hover and can be translated."
1313+
// }
1314+
// "appliesTo": {
1315+
// "type": "array",
1316+
// "items": {
1317+
// "$ref": "#/definitions/BreakpointModeApplicability"
1318+
// },
1319+
// "description": "Describes one or more type of breakpoint this mode applies to."
1320+
// }
1321+
// },
1322+
// "required": [ "mode", "label", "appliesTo" ]
1323+
// }
1324+
1325+
std::vector<protocol::BreakpointMode> CreateBreakpointModes() {
1326+
std::vector<protocol::BreakpointMode> breakpointModes;
1327+
std::vector<protocol::BreakpointModeApplicability> appliesTo;
1328+
appliesTo.emplace_back(protocol::BreakpointModeApplicability::eBreakpointModeApplicabilitySource);
1329+
1330+
// Currently we support "Normal" and "Thread Focused" modes for source bp
1331+
// where "Normal" is no-op, and "Thread Focused" will add filter for tid
1332+
// using the builtin dap.focus_tid
1333+
protocol::BreakpointMode normal{
1334+
"normal", // mode
1335+
"Normal", // label
1336+
"Regular source breakpoint", // description
1337+
appliesTo,
1338+
};
1339+
protocol::BreakpointMode threadFocused{
1340+
"threadFocused", // mode
1341+
"Thread Focus", // label
1342+
"Breakpoint that will focus on the current selected thread.", // description
1343+
appliesTo,
1344+
};
1345+
breakpointModes.emplace_back(normal);
1346+
breakpointModes.emplace_back(threadFocused);
1347+
return breakpointModes;
1348+
}
1349+
12941350
} // namespace lldb_dap

lldb/tools/lldb-dap/JSONUtils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,13 @@ llvm::json::Object CreateInitializedEventObject(lldb::SBTarget &target);
464464
/// Convert a given JSON object to a string.
465465
std::string JSONToString(const llvm::json::Value &json);
466466

467+
/// Create a "breakpointModes" JSON object that contains supported
468+
/// modes
469+
///
470+
/// \return
471+
/// A JSON object with breakpoint modes
472+
std::vector<protocol::BreakpointMode> CreateBreakpointModes();
473+
467474
} // namespace lldb_dap
468475

469476
#endif

lldb/tools/lldb-dap/Protocol/ProtocolTypes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ struct Breakpoint {
560560
/// a breakpoint is verified or a specific reason is not known, the adapter
561561
/// should omit this property.
562562
std::optional<BreakpointReason> reason;
563+
// The tid is breakpoint is set for a specific thread.
564+
std::optional<lldb::tid_t> threadId;
563565
};
564566
bool fromJSON(const llvm::json::Value &, Breakpoint &, llvm::json::Path);
565567
llvm::json::Value toJSON(const Breakpoint &);

0 commit comments

Comments
 (0)