2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
6 | Copyright (c) 1997-2010 The PHP Group |
7 +----------------------------------------------------------------------+
8 | This source file is subject to version 3.01 of the PHP license, |
9 | that is bundled with this package in the file LICENSE, and is |
10 | available through the world-wide-web at the following url: |
11 | http://www.php.net/license/3_01.txt |
12 | If you did not receive a copy of the PHP license and are unable to |
13 | obtain it through the world-wide-web, please send a note to |
14 | license@php.net so we can mail you a copy immediately. |
15 +----------------------------------------------------------------------+
18 #ifndef incl_HPHP_PC_FILTER_H_
19 #define incl_HPHP_PC_FILTER_H_
21 #include "hphp/runtime/vm/unit.h"
24 ////////////////////////////////////////////////////////////////////////////////
26 // Map which holds a set of PCs and supports reasonably fast addition and
27 // lookup. Used to decide if a given PC falls within an interesting area, e.g.,
28 // for breakpoints and stepping.
31 // Radix-tree implementation of pointer map
34 #define PTRMAP_PTR_SIZE (sizeof(void*) * 8)
35 #define PTRMAP_LEVEL_BITS 8LL
36 #define PTRMAP_LEVEL_ENTRIES (1LL << PTRMAP_LEVEL_BITS)
37 #define PTRMAP_LEVEL_MASK (PTRMAP_LEVEL_ENTRIES - 1LL)
41 static_assert(PTRMAP_PTR_SIZE
% PTRMAP_LEVEL_BITS
== 0,
42 "PTRMAP_PTR_SIZE must be a multiple of PTRMAP_LEVEL_BITS");
46 void setPointer(void* ptr
, void* val
);
47 void* getPointer(void* ptr
);
52 static PtrMapNode
* MakeNode();
60 // Filter function to exclude opcodes when adding ranges.
61 typedef std::function
<bool(Op
)> OpcodeFilter
;
63 // Add/remove offsets, either individually or by range. By default allow all
65 void addRanges(const Unit
* unit
, const OffsetRangeVec
& offsets
,
66 OpcodeFilter isOpcodeAllowed
= [] (Op
) { return true; });
67 void removeRanges(const Unit
* unit
, const OffsetRangeVec
& offsets
,
68 OpcodeFilter isOpcodeAllowed
= [] (Op
) { return true; });
69 void removeOffset(const Unit
* unit
, Offset offset
);
71 // Add/remove/check explicit PCs.
72 void addPC(const unsigned char* pc
) {
73 m_map
.setPointer((void*)pc
, (void*)pc
);
75 void removePC(const unsigned char* pc
) {
76 m_map
.setPointer((void*)pc
, nullptr);
78 bool checkPC(const unsigned char* pc
) {
79 return m_map
.getPointer((void*)pc
) == (void*)pc
;
87 ///////////////////////////////////////////////////////////////////////////////
90 #endif // incl_HPHP_PC_FILTER_H_