codemod 2010-2016 to 2010-present
[hiphop-php.git] / hphp / runtime / vm / debug / dwarf.h
blob41b6991c138e07288283f369834ac7ea504ce565
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 +----------------------------------------------------------------------+
17 #ifndef HPHP_DWARF_H_
18 #define HPHP_DWARF_H_
20 #include "hphp/runtime/vm/jit/translator.h"
21 #include "hphp/util/eh-frame.h"
23 #include <folly/Optional.h>
25 #include <string>
26 #include <vector>
28 namespace HPHP { namespace Debug {
30 using jit::TCA;
32 typedef enum {
33 RAX,
34 RDX,
35 RCX,
36 RBX,
37 RSI,
38 RDI,
39 RBP,
40 RSP,
41 R8,
42 R9,
43 R10,
44 R11,
45 R12,
46 R13,
47 R14,
48 R15,
49 RIP
50 } x86_64_regnum_t;
52 const int DWARF_CODE_ALIGN = 1;
53 const int DWARF_DATA_ALIGN = 8;
55 #if (defined(FACEBOOK) || defined(LIBDWARF_CONST_NAME))
56 #define LIBDWARF_CALLBACK_NAME_TYPE const char*
57 #else
58 #define LIBDWARF_CALLBACK_NAME_TYPE char*
59 #endif
61 extern int g_dwarfCallback(
62 LIBDWARF_CALLBACK_NAME_TYPE name, int size, Dwarf_Unsigned type,
63 Dwarf_Unsigned flags, Dwarf_Unsigned link, Dwarf_Unsigned info,
64 Dwarf_Unsigned *sect_name_index, Dwarf_Ptr handle, int *error);
66 struct TCRange {
67 TCRange() : m_start(nullptr), m_end(nullptr), m_isAcold(false) {
68 assert(!isValid());
70 TCRange(const TCA start, const TCA end, bool isAcold) :
71 m_start(start), m_end(end), m_isAcold(isAcold) { V(); }
73 TCRange& operator=(const TCRange& r) {
74 m_start = r.m_start;
75 m_end = r.m_end;
76 m_isAcold = r.m_isAcold;
77 V();
78 return *this;
81 bool isValid() const {
82 assert(bool(m_start) == bool(m_end));
83 assert(!m_start || m_start < m_end);
84 assert(!m_start || (m_end - m_start) < (1ll << 32));
85 return bool(m_start);
87 bool isAcold() const { return m_isAcold; }
88 TCA begin() const { V(); return m_start; }
89 TCA end() const { V(); return m_end; };
90 uint32_t size() const { V(); return m_end - m_start; }
92 void extend(const TCA newEnd) {
93 assert(newEnd >= m_end);
94 m_end = newEnd;
95 V();
98 private:
99 void V() const { assert(isValid()); }
101 private:
102 TCA m_start, m_end;
103 bool m_isAcold;
106 struct DwarfBuf {
107 void byte(uint8_t c);
109 void clear();
110 int size();
111 uint8_t *getBuf();
112 void print();
114 void dwarf_cfa_def_cfa(uint8_t reg, uint8_t offset);
115 void dwarf_cfa_same_value(uint8_t reg);
116 void dwarf_cfa_offset_extended_sf(uint8_t reg, int8_t offset);
118 private:
119 std::vector<uint8_t> m_buf;
122 struct LineEntry {
123 TCRange range;
124 int lineNumber;
125 LineEntry(TCRange r, int l) : range(r), lineNumber(l) {}
128 struct DwarfChunk;
130 struct FunctionInfo {
131 std::string name;
132 const char *file;
133 TCRange range;
134 bool exit;
135 bool m_perfSynced;
136 std::vector<LineEntry> m_lineTable;
137 std::vector<std::string> m_namedLocals;
138 DwarfChunk* m_chunk;
139 FunctionInfo() : m_chunk(nullptr) { }
140 FunctionInfo(TCRange r, bool ex)
141 : range(r), exit(ex), m_perfSynced(false),
142 m_namedLocals(std::vector<std::string>()), m_chunk(nullptr) {}
143 void setPerfSynced() { m_perfSynced = true; }
144 void clearPerfSynced() { m_perfSynced = false; }
145 bool perfSynced() const { return m_perfSynced; }
148 struct DwarfChunk {
149 DwarfBuf m_buf;
150 std::vector<FunctionInfo *> m_functions;
151 char *m_symfile;
152 bool m_synced;
153 DwarfChunk() : m_symfile(nullptr), m_synced(false) {}
154 void setSynced() { m_synced = true; }
155 void clearSynced() { m_synced = false; }
156 bool isSynced() const { return m_synced; }
159 typedef std::map<TCA, FunctionInfo* > FuncDB;
160 typedef std::vector<FunctionInfo* > FuncPtrDB;
162 struct DwarfInfo {
163 typedef std::map<TCA, jit::TransRec> TransDB;
165 std::vector<DwarfChunk*> m_dwarfChunks;
166 /* Array of chunks indexed by lg(#functions in chunk) + 1.
167 * i.e. m_dwarfChunk[i] = pointer to chunk with
168 * 2^(i-1) * RuntimeOption::EvalGdbSyncChunks functions, or NULL if
169 * there is no such chunk. The first chunk m_dwarfChunks[0] is special in
170 * that it can be partially full. All other chunks are completely full.
172 FuncDB m_functions;
174 const char *lookupFile(const Unit *unit);
175 void addLineEntries(TCRange range, const Unit *unit,
176 PC instr, FunctionInfo* f);
177 void transferFuncs(DwarfChunk* from, DwarfChunk* to);
178 void compactChunks();
179 DwarfChunk* addTracelet(TCRange range,
180 folly::Optional<std::string> name,
181 const Func* func,
182 PC instr,
183 bool exit,
184 bool inPrologue);
185 void syncChunks();
190 #endif