Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / v8 / src / gdb-jit.h
1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 //     * Redistributions of source code must retain the above copyright
7 //       notice, this list of conditions and the following disclaimer.
8 //     * Redistributions in binary form must reproduce the above
9 //       copyright notice, this list of conditions and the following
10 //       disclaimer in the documentation and/or other materials provided
11 //       with the distribution.
12 //     * Neither the name of Google Inc. nor the names of its
13 //       contributors may be used to endorse or promote products derived
14 //       from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #ifndef V8_GDB_JIT_H_
29 #define V8_GDB_JIT_H_
30
31 #include "allocation.h"
32
33 //
34 // Basic implementation of GDB JIT Interface client.
35 // GBD JIT Interface is supported in GDB 7.0 and above.
36 // Currently on x64 and ia32 architectures and Linux OS are supported.
37 //
38
39 #ifdef ENABLE_GDB_JIT_INTERFACE
40 #include "v8.h"
41 #include "factory.h"
42
43 namespace v8 {
44 namespace internal {
45
46 class CompilationInfo;
47
48 #define CODE_TAGS_LIST(V)                       \
49   V(LOAD_IC)                                    \
50   V(KEYED_LOAD_IC)                              \
51   V(STORE_IC)                                   \
52   V(KEYED_STORE_IC)                             \
53   V(STUB)                                       \
54   V(BUILTIN)                                    \
55   V(SCRIPT)                                     \
56   V(EVAL)                                       \
57   V(FUNCTION)
58
59 class GDBJITLineInfo : public Malloced {
60  public:
61   GDBJITLineInfo()
62       : pc_info_(10) { }
63
64   void SetPosition(intptr_t pc, int pos, bool is_statement) {
65     AddPCInfo(PCInfo(pc, pos, is_statement));
66   }
67
68   struct PCInfo {
69     PCInfo(intptr_t pc, int pos, bool is_statement)
70         : pc_(pc), pos_(pos), is_statement_(is_statement) { }
71
72     intptr_t pc_;
73     int pos_;
74     bool is_statement_;
75   };
76
77   List<PCInfo>* pc_info() {
78     return &pc_info_;
79   }
80
81  private:
82   void AddPCInfo(const PCInfo& pc_info) {
83     pc_info_.Add(pc_info);
84   }
85
86   List<PCInfo> pc_info_;
87 };
88
89
90 class GDBJITInterface: public AllStatic {
91  public:
92   enum CodeTag {
93 #define V(x) x,
94     CODE_TAGS_LIST(V)
95 #undef V
96     TAG_COUNT
97   };
98
99   static const char* Tag2String(CodeTag tag) {
100     switch (tag) {
101 #define V(x) case x: return #x;
102       CODE_TAGS_LIST(V)
103 #undef V
104       default:
105         return NULL;
106     }
107   }
108
109   static void AddCode(const char* name,
110                       Code* code,
111                       CodeTag tag,
112                       Script* script,
113                       CompilationInfo* info);
114
115   static void AddCode(Handle<Name> name,
116                       Handle<Script> script,
117                       Handle<Code> code,
118                       CompilationInfo* info);
119
120   static void AddCode(CodeTag tag, Name* name, Code* code);
121
122   static void AddCode(CodeTag tag, const char* name, Code* code);
123
124   static void AddCode(CodeTag tag, Code* code);
125
126   static void RemoveCode(Code* code);
127
128   static void RemoveCodeRange(Address start, Address end);
129
130   static void RegisterDetailedLineInfo(Code* code, GDBJITLineInfo* line_info);
131 };
132
133 #define GDBJIT(action) GDBJITInterface::action
134
135 } }   // namespace v8::internal
136 #else
137 #define GDBJIT(action) ((void) 0)
138 #endif
139
140 #endif