2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2017-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_VSDEBUG_BREAKPOINT_MGR_H_
18 #define incl_HPHP_VSDEBUG_BREAKPOINT_MGR_H_
20 #include "hphp/runtime/ext/vsdebug/break_mode.h"
21 #include "hphp/runtime/ext/vsdebug/command.h"
22 #include "hphp/runtime/ext/vsdebug/debugger.h"
25 #include <unordered_map>
26 #include <unordered_set>
32 struct ClientPreferences
;
40 // Represents the resolved location of an installed breakpoint. This may
41 // differ from the request location due to source mapping and line calibration.
42 struct ResolvedLocation
{
55 const std::string path
,
56 const std::string condition
,
57 const std::string hitCondition
60 void updateConditions(std::string condition
, std::string hitCondition
);
63 const BreakpointType m_type
;
66 const std::string m_path
;
68 ResolvedLocation m_resolvedLocation
;
71 std::string
getCondition() const { return m_condition
; }
72 std::string
getHitCondition() { return m_hitCondition
; }
74 void cacheConditionUnit(request_id_t requestId
, HPHP::Unit
* unit
) {
75 m_unitCache
.emplace(requestId
, unit
);
78 HPHP::Unit
* getCachedConditionUnit(request_id_t requestId
) {
79 auto it
= m_unitCache
.find(requestId
);
80 return it
== m_unitCache
.end() ? nullptr : it
->second
;
83 void clearCachedConditionUnit(request_id_t requestId
) {
84 auto it
= m_unitCache
.find(requestId
);
85 if (it
!= m_unitCache
.end()) {
86 m_unitCache
.erase(it
);
92 // Evaluation condition for a conditional breakpoint.
93 std::string m_condition
;
95 // Hit condition, specified separately in the protocol. This is used for
96 // comparison to the number of times the breakpoint has been hit.
97 std::string m_hitCondition
;
99 // Cache of compilation units for breakpoint conditions, per request
101 std::unordered_map
<request_id_t
, HPHP::Unit
*> m_unitCache
;
104 struct ExceptionBreakpointSettings
{
105 ExceptionBreakMode m_breakMode
{ExceptionBreakMode::BreakNone
};
106 const std::vector
<std::string
> m_filters
;
109 struct BreakpointManager
{
110 BreakpointManager(Debugger
* debugger
);
111 ~BreakpointManager();
113 void setExceptionBreakMode(ExceptionBreakMode mode
);
114 ExceptionBreakMode
getExceptionBreakMode() const;
116 void onBreakpointResolved(
122 const std::string
& path
125 void onBreakpointHit(int id
);
127 bool isBreakpointResolved(int id
) const;
132 const std::string
& path
,
133 const std::string
& condition
,
134 const std::string
& hitCondition
137 void removeBreakpoint(int id
);
139 Breakpoint
* getBreakpointById(int id
);
141 const std::unordered_set
<int> getAllBreakpointIds() const;
143 const std::unordered_set
<int> getBreakpointIdsByFile(
144 const std::string
& sourcePath
147 bool isBreakConditionSatisified(
152 void onRequestShutdown(request_id_t requestId
);
156 static constexpr char* ReasonNew
= "new";
157 static constexpr char* ReasonChanged
= "changed";
158 static constexpr char* ReasonRemoved
= "removed";
160 void sendBreakpointEvent(int breakpointId
, const char* reason
);
165 const std::string
& condition
168 // Helper to honor client's lines start at 0 or 1 preference.
169 static int adjustLineNumber(
170 const ClientPreferences
& preferences
,
175 ExceptionBreakpointSettings m_exceptionSettings
;
177 // The authoratative list of the current breakpoints set by the client.
178 std::unordered_map
<int, Breakpoint
> m_breakpoints
;
180 // Map of source file name to list of breakpoints in that file.
181 std::unordered_map
<std::string
, std::unordered_set
<int>> m_sourceBreakpoints
;
183 // Verified breakpoints. A breakpoint is verified if at least one request
184 // has resolved it in a compilation unit since it was set. This is a bit odd
185 // compared to most debuggers, because each request loads its own Hack/PHP
186 // code and needs to resolve the bp itself. Clients consuming the protocol
187 // expect a single resolved notification to mean the bp is valid for the whole
189 std::unordered_set
<int> m_resolvedBreakpoints
;
191 Debugger
* m_debugger
;
197 #endif //incl_HPHP_VSDEBUG_BREAKPOINT_MGR_H_