Clean up VectorEffects::init
[hiphop-php.git] / hphp / runtime / vm / debugger_hook.h
blob898e6c414e13d2fa179b4d1b72e14f37df5e6426
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2013 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_DEBUGGER_HOOK_H_
18 #define incl_HPHP_DEBUGGER_HOOK_H_
20 #include "hphp/util/base.h"
21 #include "hphp/runtime/vm/unit.h"
22 #include <functional>
24 namespace HPHP {
25 namespace Eval{
26 class DebuggerProxy;
27 class PhpFile;
30 ///////////////////////////////////////////////////////////////////////////////
31 // This is a set of functions which are primarily called from the VM to notify
32 // the debugger about various events. Some of the implementations also interact
33 // with the VM to setup further notifications, though this is not the only place
34 // the debugger interacts directly with the VM.
36 namespace HPHP {
38 // "Hooks" called by the VM at various points during program execution while
39 // debugging to give the debugger a chance to act. The debugger may block
40 // execution indefinitely within one of these hooks.
41 void phpDebuggerOpcodeHook(const uchar* pc);
42 void phpDebuggerExceptionThrownHook(ObjectData* exception);
43 void phpDebuggerExceptionHandlerHook();
44 void phpDebuggerErrorHook(const std::string& message);
45 void phpDebuggerEvalHook(const Func* f);
46 void phpDebuggerFileLoadHook(Eval::PhpFile* efile);
47 class Class;
48 class Func;
49 void phpDebuggerDefClassHook(const Class* cls);
50 void phpDebuggerDefFuncHook(const Func* func);
52 void phpSetBreakPoints(Eval::DebuggerProxy* proxy);
54 // Add/remove breakpoints at a specific offset.
55 void phpAddBreakPoint(const Unit* unit, Offset offset);
56 void phpRemoveBreakPoint(const Unit* unit, Offset offset);
58 // Is this thread being debugged?
59 inline bool isDebuggerAttached() {
60 return ThreadInfo::s_threadInfo.getNoCheck()->
61 m_reqInjectionData.getDebugger();
64 #define DEBUGGER_ATTACHED_ONLY(code) do { \
65 if (isDebuggerAttached()) { \
66 code; \
67 } \
68 } while(0) \
70 // Is this process being debugged?
71 bool isDebuggerAttachedProcess();
73 // This flag ensures two things: first, that we stay in the interpreter and
74 // out of JIT code. Second, that phpDebuggerOpcodeHook will continue to allow
75 // debugger interrupts for every opcode executed (modulo filters.)
76 #define DEBUGGER_FORCE_INTR \
77 (ThreadInfo::s_threadInfo.getNoCheck()->m_reqInjectionData.getDebuggerIntr())
79 // Map which holds a set of PCs and supports reasonably fast addition and
80 // lookup. Used by the debugger to decide if a given PC falls within an
81 // interesting area, e.g., for breakpoints and stepping.
82 class PCFilter {
83 private:
84 // Radix-tree implementation of pointer map
85 struct PtrMapNode;
86 class PtrMap {
87 #define PTRMAP_PTR_SIZE (sizeof(void*) * 8)
88 #define PTRMAP_LEVEL_BITS 8LL
89 #define PTRMAP_LEVEL_ENTRIES (1LL << PTRMAP_LEVEL_BITS)
90 #define PTRMAP_LEVEL_MASK (PTRMAP_LEVEL_ENTRIES - 1LL)
92 public:
93 PtrMap() {
94 static_assert(PTRMAP_PTR_SIZE % PTRMAP_LEVEL_BITS == 0,
95 "PTRMAP_PTR_SIZE must be a multiple of PTRMAP_LEVEL_BITS");
96 m_root = MakeNode();
98 ~PtrMap();
99 void setPointer(void* ptr, void* val);
100 void* getPointer(void* ptr);
101 void clear();
103 private:
104 PtrMapNode* m_root;
105 static PtrMapNode* MakeNode();
108 PtrMap m_map;
110 public:
111 PCFilter() {}
113 // Filter function to exclude opcodes when adding ranges.
114 typedef std::function<bool(Op)> OpcodeFilter;
116 // Add/remove offsets, either individually or by range. By default allow all
117 // opcodes.
118 void addRanges(const Unit* unit, const OffsetRangeVec& offsets,
119 OpcodeFilter isOpcodeAllowed = [] (Op) { return true; });
120 void removeOffset(const Unit* unit, Offset offset);
122 // Add/remove/check explicit PCs.
123 void addPC(const uchar* pc) {
124 m_map.setPointer((void*)pc, (void*)pc);
126 void removePC(const uchar* pc) {
127 m_map.setPointer((void*)pc, nullptr);
129 bool checkPC(const uchar* pc) {
130 return m_map.getPointer((void*)pc) == (void*)pc;
133 void clear() {
134 m_map.clear();
138 } // namespace HPHP::VM
140 #endif /* incl_HPHP_DEBUGGER_HOOK_H_ */