Add support for HHBC ops with 5 immediates
[hiphop-php.git] / hphp / runtime / ext / vsdebug / breakpoint.h
blobfc66246075d17d4f90f87c0f37b65c0632fb24b7
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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"
24 #include <string>
25 #include <unordered_map>
26 #include <unordered_set>
27 #include <vector>
29 namespace HPHP {
30 namespace VSDEBUG {
32 struct ClientPreferences;
33 struct RequestInfo;
35 enum BreakpointType {
36 Source,
37 Function
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 {
43 int m_startLine;
44 int m_endLine;
45 int m_startCol;
46 int m_endCol;
47 std::string m_path;
50 struct Breakpoint {
51 Breakpoint(
52 int id,
53 int line,
54 int column,
55 const std::string path,
56 const std::string condition,
57 const std::string hitCondition
60 void updateConditions(std::string condition, std::string hitCondition);
62 const int m_id;
63 const BreakpointType m_type;
64 const int m_line;
65 const int m_column;
66 const std::string m_path;
68 ResolvedLocation m_resolvedLocation;
69 int m_hitCount;
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);
90 private:
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
100 // thread.
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(
117 int id,
118 int startLine,
119 int endLine,
120 int startColumn,
121 int endColumn,
122 const std::string& path
125 void onBreakpointHit(int id);
127 bool isBreakpointResolved(int id) const;
129 int addBreakpoint(
130 int line,
131 int column,
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
145 ) const;
147 bool isBreakConditionSatisified(
148 RequestInfo* ri,
149 Breakpoint* bp
152 void onRequestShutdown(request_id_t requestId);
154 private:
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);
162 void sendBpError(
163 int bpId,
164 const char* error,
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,
171 int line,
172 bool column
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
188 // program...
189 std::unordered_set<int> m_resolvedBreakpoints;
191 Debugger* m_debugger;
197 #endif //incl_HPHP_VSDEBUG_BREAKPOINT_MGR_H_