@@ -233,7 +233,6 @@ struct DAP {
233233 // / @}
234234
235235 ExceptionBreakpoint *GetExceptionBreakpoint (const std::string &filter);
236- ExceptionBreakpoint *GetExceptionBreakpoint (const lldb::break_id_t bp_id);
237236
238237 // / Redirect stdout and stderr fo the IDE's console output.
239238 // /
@@ -392,11 +391,20 @@ struct DAP {
392391
393392 void SetThreadFormat (llvm::StringRef format);
394393
394+ // Check to see if we have hit the <BreakpointType> breakpoint and return the
395+ // last breakpoint. but only do so if all breakpoints that were hit are of
396+ // <BreakpointType>.
397+ // Caller uses this to set the reason accordingly. i.e. If all the breakpoints
398+ // are exception breakpoints then reason is 'exception'; if all the
399+ // breakpoints are function breakpoints then reason is 'function breakpoint';
400+ // if all the breakpoints are instruction breakpoints then reason =
401+ // 'instruction breakpoint'; if there are combination of one more breakpoints,
402+ // then the reason will be 'breakpoint'.
395403 template <typename BreakpointType>
396404 BreakpointType *GetBreakpointFromStopReason (lldb::SBThread &thread) {
397- // Check to see if have hit the <BreakpointType> breakpoint and change the
398- // reason accordingly, but only do so if all breakpoints that were
399- // hit are of <BreakpointType>.
405+ // Check to see if we have hit the <BreakpointType> breakpoint and change
406+ // the reason accordingly, but only do so if all breakpoints that were hit
407+ // are of <BreakpointType>.
400408 const auto num = thread.GetStopReasonDataCount ();
401409 BreakpointType *bp = nullptr ;
402410 for (size_t i = 0 ; i < num; i += 2 ) {
@@ -416,47 +424,31 @@ struct DAP {
416424 template <>
417425 FunctionBreakpoint *
418426 GetBreakpoint<FunctionBreakpoint>(const lldb::break_id_t bp_id) {
419- for (auto &bp : function_breakpoints) {
420- if (bp.second .bp .GetID () == bp_id)
421- return &bp.second ;
422- }
423- return nullptr ;
427+ auto it = std::find_if (
428+ function_breakpoints.begin (), function_breakpoints.end (),
429+ [bp_id](const auto &bp) { return bp.second .bp .GetID () == bp_id; });
430+ return it != function_breakpoints.end () ? &it->second : nullptr ;
424431 }
425432
426433 template <>
427434 InstructionBreakpoint *
428435 GetBreakpoint<InstructionBreakpoint>(const lldb::break_id_t bp_id) {
429- for (auto &bp : instruction_breakpoints) {
430- if (bp.second .bp .GetID () == bp_id)
431- return &bp.second ;
432- }
433- return nullptr ;
436+ auto it = std::find_if (
437+ instruction_breakpoints.begin (), instruction_breakpoints.end (),
438+ [bp_id](const auto &bp) { return bp.second .bp .GetID () == bp_id; });
439+ return it != instruction_breakpoints.end () ? &it->second : nullptr ;
434440 }
435441
436442 template <>
437443 ExceptionBreakpoint *
438444 GetBreakpoint<ExceptionBreakpoint>(const lldb::break_id_t bp_id) {
439- // See comment in the other GetExceptionBreakpoint().
440445 PopulateExceptionBreakpoints ();
441446
442- for (auto &bp : *exception_breakpoints) {
443- if (bp.bp .GetID () == bp_id)
444- return &bp;
445- }
446- return nullptr ;
447+ auto it = std::find_if (
448+ exception_breakpoints->begin (), exception_breakpoints->end (),
449+ [bp_id](const auto &bp) { return bp.bp .GetID () == bp_id; });
450+ return it != exception_breakpoints->end () ? &*it : nullptr ;
447451 }
448-
449- FunctionBreakpoint *GetFunctionBPFromStopReason (lldb::SBThread &thread);
450-
451- FunctionBreakpoint *GetFunctionBreakPoint (const lldb::break_id_t bp_id);
452-
453- void WaitWorkerThreadsToExit ();
454-
455- private:
456- // Send the JSON in "json_str" to the "out" stream. Correctly send the
457- // "Content-Length:" field followed by the length, followed by the raw
458- // JSON bytes.
459- void SendJSON (const std::string &json_str);
460452};
461453
462454} // namespace lldb_dap
0 commit comments