Optional Two-phase heap tracing
[hiphop-php.git] / hphp / util / disasm.h
blob5246febdbf441faf57a19225edc69600103c8e13
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-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 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_UTIL_DISASM_H_
17 #define incl_HPHP_UTIL_DISASM_H_
19 #ifdef HAVE_LIBXED
20 extern "C" {
21 #include <xed-interface.h>
23 #endif // HAVE_LIBXED
25 #include <ostream>
27 namespace HPHP {
29 struct Disasm {
30 struct Options {
31 Options()
32 : m_indentLevel(0)
33 , m_printEncoding(false)
34 , m_relativeOffset(false)
35 , m_addresses(true)
36 , m_forceAttSyntax(false)
39 Options& indent(int i) {
40 m_indentLevel = i;
41 return *this;
44 Options& printEncoding(bool pe) {
45 m_printEncoding = pe;
46 return *this;
49 Options& relativeOffset(bool re) {
50 m_relativeOffset = re;
51 return *this;
54 Options& color(std::string c) {
55 m_color = std::move(c);
56 return *this;
59 Options& addresses(bool b) {
60 m_addresses = b;
61 return *this;
64 Options& forceAttSyntax(bool b) {
65 m_forceAttSyntax = b;
66 return *this;
69 int m_indentLevel;
70 bool m_printEncoding;
71 bool m_relativeOffset;
72 bool m_addresses;
73 bool m_forceAttSyntax;
74 std::string m_color;
77 /* Create a Disasm object. indentLevel spaces will be put at the beginning of
78 * each line of disassembly. If printEncoding is true, the raw hex bytes of
79 * the instructions will also be in the output. */
80 explicit Disasm(const Options& opts = Options());
82 Disasm(const Disasm&) = delete;
83 Disasm& operator=(const Disasm&) = delete;
85 /* Disassemble instructions. start should be the first byte of the region to
86 * disassemble and end should be the first byte past the region to
87 * disassemble. */
88 void disasm(std::ostream& out, uint8_t* start, uint8_t* end);
90 static void ExcludedAddressRange(void* low, size_t len);
91 private:
92 #ifdef HAVE_LIBXED
93 xed_state_t m_xedState;
94 #endif // HAVE_LIBXED
95 const Options m_opts;
98 } // namespace HPHP
100 #endif