2 +----------------------------------------------------------------------+
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 +----------------------------------------------------------------------+
20 #include "hphp/runtime/vm/jit/translator.h"
21 #include "hphp/util/eh-frame.h"
23 #include <folly/Optional.h>
28 namespace HPHP
{ namespace Debug
{
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*
58 #define LIBDWARF_CALLBACK_NAME_TYPE char*
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
);
67 TCRange() : m_start(nullptr), m_end(nullptr), m_isAcold(false) {
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
) {
76 m_isAcold
= r
.m_isAcold
;
81 bool isValid() const {
82 assertx(bool(m_start
) == bool(m_end
));
83 assertx(!m_start
|| m_start
< m_end
);
84 assertx(!m_start
|| (m_end
- m_start
) < (1ll << 32));
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 assertx(newEnd
>= m_end
);
99 void V() const { assertx(isValid()); }
107 void byte(uint8_t c
);
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
);
119 std::vector
<uint8_t> m_buf
;
125 LineEntry(TCRange r
, int l
) : range(r
), lineNumber(l
) {}
130 struct FunctionInfo
{
136 std::vector
<LineEntry
> m_lineTable
;
137 std::vector
<std::string
> m_namedLocals
;
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
; }
150 std::vector
<FunctionInfo
*> m_functions
;
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
;
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.
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
,