Skip to content

Commit e949d2e

Browse files
committed
Make breakpoint stop reason more accurate
1 parent a6463f4 commit e949d2e

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def verify_breakpoint_hit(self, breakpoint_ids):
8686
if (
8787
body["reason"] != "breakpoint"
8888
and body["reason"] != "instruction breakpoint"
89+
and body["reason"] != "function breakpoint"
8990
):
9091
continue
9192
if "description" not in body:
@@ -100,7 +101,7 @@ def verify_breakpoint_hit(self, breakpoint_ids):
100101
# location.
101102
description = body["description"]
102103
for breakpoint_id in breakpoint_ids:
103-
match_desc = "breakpoint %s." % (breakpoint_id)
104+
match_desc = "%s %s." % (body["reason"], breakpoint_id)
104105
if match_desc in description:
105106
return
106107
self.assertTrue(False, "breakpoint not hit")

lldb/tools/lldb-dap/DAP.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,32 @@ DAP::GetInstructionBPFromStopReason(lldb::SBThread &thread) {
10741074
return inst_bp;
10751075
}
10761076

1077+
FunctionBreakpoint *DAP::GetFunctionBPFromStopReason(lldb::SBThread &thread) {
1078+
const auto num = thread.GetStopReasonDataCount();
1079+
FunctionBreakpoint *func_bp = nullptr;
1080+
for (size_t i = 0; i < num; i += 2) {
1081+
// thread.GetStopReasonDataAtIndex(i) will return the bp ID and
1082+
// thread.GetStopReasonDataAtIndex(i+1) will return the location
1083+
// within that breakpoint. We only care about the bp ID so we can
1084+
// see if this is an function breakpoint that is getting hit.
1085+
lldb::break_id_t bp_id = thread.GetStopReasonDataAtIndex(i);
1086+
func_bp = GetFunctionBreakPoint(bp_id);
1087+
// If any breakpoint is not an function breakpoint, then stop and
1088+
// report this as a normal breakpoint
1089+
if (func_bp == nullptr)
1090+
return nullptr;
1091+
}
1092+
return func_bp;
1093+
}
1094+
1095+
FunctionBreakpoint *DAP::GetFunctionBreakPoint(const lldb::break_id_t bp_id) {
1096+
for (auto &bp : function_breakpoints) {
1097+
if (bp.second.bp.GetID() == bp_id)
1098+
return &bp.second;
1099+
}
1100+
return nullptr;
1101+
}
1102+
10771103
lldb::SBValueList *Variables::GetTopLevelScope(int64_t variablesReference) {
10781104
switch (variablesReference) {
10791105
case VARREF_LOCALS:

lldb/tools/lldb-dap/DAP.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,21 @@ struct Variables {
125125

126126
struct StartDebuggingRequestHandler : public lldb::SBCommandPluginInterface {
127127
DAP &dap;
128-
explicit StartDebuggingRequestHandler(DAP &d) : dap(d) {};
128+
explicit StartDebuggingRequestHandler(DAP &d) : dap(d){};
129129
bool DoExecute(lldb::SBDebugger debugger, char **command,
130130
lldb::SBCommandReturnObject &result) override;
131131
};
132132

133133
struct ReplModeRequestHandler : public lldb::SBCommandPluginInterface {
134134
DAP &dap;
135-
explicit ReplModeRequestHandler(DAP &d) : dap(d) {};
135+
explicit ReplModeRequestHandler(DAP &d) : dap(d){};
136136
bool DoExecute(lldb::SBDebugger debugger, char **command,
137137
lldb::SBCommandReturnObject &result) override;
138138
};
139139

140140
struct SendEventRequestHandler : public lldb::SBCommandPluginInterface {
141141
DAP &dap;
142-
explicit SendEventRequestHandler(DAP &d) : dap(d) {};
142+
explicit SendEventRequestHandler(DAP &d) : dap(d){};
143143
bool DoExecute(lldb::SBDebugger debugger, char **command,
144144
lldb::SBCommandReturnObject &result) override;
145145
};
@@ -392,9 +392,11 @@ struct DAP {
392392

393393
void SetThreadFormat(llvm::StringRef format);
394394

395-
InstructionBreakpoint *GetInstructionBreakpoint(const lldb::break_id_t bp_id);
396-
397-
InstructionBreakpoint *GetInstructionBPFromStopReason(lldb::SBThread &thread);
395+
private:
396+
// Send the JSON in "json_str" to the "out" stream. Correctly send the
397+
// "Content-Length:" field followed by the length, followed by the raw
398+
// JSON bytes.
399+
void SendJSON(const std::string &json_str);
398400
};
399401

400402
} // namespace lldb_dap

lldb/tools/lldb-dap/JSONUtils.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -967,17 +967,23 @@ llvm::json::Value CreateThreadStopped(DAP &dap, lldb::SBThread &thread,
967967
body.try_emplace("reason", "exception");
968968
EmplaceSafeString(body, "description", exc_bp->label);
969969
} else {
970+
std::string reason = "breakpoint";
970971
InstructionBreakpoint *inst_bp =
971972
dap.GetInstructionBPFromStopReason(thread);
972973
if (inst_bp) {
973-
body.try_emplace("reason", "instruction breakpoint");
974+
reason = "instruction breakpoint";
974975
} else {
975-
body.try_emplace("reason", "breakpoint");
976+
FunctionBreakpoint *function_bp =
977+
dap.GetFunctionBPFromStopReason(thread);
978+
if (function_bp) {
979+
reason = "function breakpoint";
980+
}
976981
}
982+
body.try_emplace("reason", reason);
977983
lldb::break_id_t bp_id = thread.GetStopReasonDataAtIndex(0);
978984
lldb::break_id_t bp_loc_id = thread.GetStopReasonDataAtIndex(1);
979985
std::string desc_str =
980-
llvm::formatv("breakpoint {0}.{1}", bp_id, bp_loc_id);
986+
llvm::formatv("{0} {1}.{2}", reason, bp_id, bp_loc_id);
981987
body.try_emplace("hitBreakpointIds",
982988
llvm::json::Array{llvm::json::Value(bp_id)});
983989
EmplaceSafeString(body, "description", desc_str);

0 commit comments

Comments
 (0)