101263c6cSJonas Devlieghere //===-- BreakpointBase.cpp --------------------------------------*- C++ -*-===// 201263c6cSJonas Devlieghere // 301263c6cSJonas Devlieghere // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 401263c6cSJonas Devlieghere // See https://llvm.org/LICENSE.txt for license information. 501263c6cSJonas Devlieghere // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 601263c6cSJonas Devlieghere // 701263c6cSJonas Devlieghere //===----------------------------------------------------------------------===// 801263c6cSJonas Devlieghere 901263c6cSJonas Devlieghere #include "BreakpointBase.h" 1009c258efSAdrian Vogelsgesang #include "JSONUtils.h" 11*b99d4112SJohn Harrison #include "llvm/ADT/StringRef.h" 1201263c6cSJonas Devlieghere 1301263c6cSJonas Devlieghere using namespace lldb_dap; 1401263c6cSJonas Devlieghere 15*b99d4112SJohn Harrison BreakpointBase::BreakpointBase(DAP &d, const llvm::json::Object &obj) 16*b99d4112SJohn Harrison : dap(d), condition(std::string(GetString(obj, "condition"))), 17d58c128bSZequan Wu hitCondition(std::string(GetString(obj, "hitCondition"))) {} 1801263c6cSJonas Devlieghere 1901263c6cSJonas Devlieghere void BreakpointBase::UpdateBreakpoint(const BreakpointBase &request_bp) { 2001263c6cSJonas Devlieghere if (condition != request_bp.condition) { 2101263c6cSJonas Devlieghere condition = request_bp.condition; 2201263c6cSJonas Devlieghere SetCondition(); 2301263c6cSJonas Devlieghere } 2401263c6cSJonas Devlieghere if (hitCondition != request_bp.hitCondition) { 2501263c6cSJonas Devlieghere hitCondition = request_bp.hitCondition; 2601263c6cSJonas Devlieghere SetHitCondition(); 2701263c6cSJonas Devlieghere } 2801263c6cSJonas Devlieghere } 2901263c6cSJonas Devlieghere 3001263c6cSJonas Devlieghere const char *BreakpointBase::GetBreakpointLabel() { 3101263c6cSJonas Devlieghere // Breakpoints in LLDB can have names added to them which are kind of like 3201263c6cSJonas Devlieghere // labels or categories. All breakpoints that are set through the IDE UI get 3301263c6cSJonas Devlieghere // sent through the various DAP set*Breakpoint packets, and these 3401263c6cSJonas Devlieghere // breakpoints will be labeled with this name so if breakpoint update events 3501263c6cSJonas Devlieghere // come in for breakpoints that the IDE doesn't know about, like if a 3601263c6cSJonas Devlieghere // breakpoint is set manually using the debugger console, we won't report any 3701263c6cSJonas Devlieghere // updates on them and confused the IDE. This function gets called by all of 3801263c6cSJonas Devlieghere // the breakpoint classes after they set breakpoints to mark a breakpoint as 3901263c6cSJonas Devlieghere // a UI breakpoint. We can later check a lldb::SBBreakpoint object that comes 4001263c6cSJonas Devlieghere // in via LLDB breakpoint changed events and check the breakpoint by calling 4101263c6cSJonas Devlieghere // "bool lldb::SBBreakpoint::MatchesName(const char *)" to check if a 4201263c6cSJonas Devlieghere // breakpoint in one of the UI breakpoints that we should report changes for. 4301263c6cSJonas Devlieghere return "dap"; 4401263c6cSJonas Devlieghere } 45