blob: 5d348b69a166afb14d0c9aff07c509703a2b85ad [file] [log] [blame]
Ben Murdochb8e0da22011-05-16 14:20:40 +01001// 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//
32// Basic implementation of GDB JIT Interface client.
33// GBD JIT Interface is supported in GDB 7.0 and above.
34// Currently on x64 and ia32 architectures and Linux OS are supported.
35//
36
37#ifdef ENABLE_GDB_JIT_INTERFACE
38#include "v8.h"
39#include "factory.h"
40
41namespace v8 {
42namespace internal {
43
44#define CODE_TAGS_LIST(V) \
45 V(LOAD_IC) \
46 V(KEYED_LOAD_IC) \
47 V(STORE_IC) \
48 V(KEYED_STORE_IC) \
49 V(CALL_IC) \
50 V(CALL_INITIALIZE) \
51 V(CALL_PRE_MONOMORPHIC) \
52 V(CALL_NORMAL) \
53 V(CALL_MEGAMORPHIC) \
54 V(CALL_MISS) \
55 V(STUB) \
56 V(BUILTIN) \
57 V(SCRIPT) \
58 V(EVAL)
59
60class GDBJITLineInfo : public Malloced {
61 public:
62 GDBJITLineInfo()
63 : pc_info_(10) { }
64
65 void SetPosition(intptr_t pc, int pos, bool is_statement) {
66 AddPCInfo(PCInfo(pc, pos, is_statement));
67 }
68
69 struct PCInfo {
70 PCInfo(intptr_t pc, int pos, bool is_statement)
71 : pc_(pc), pos_(pos), is_statement_(is_statement) { }
72
73 intptr_t pc_;
74 int pos_;
75 bool is_statement_;
76 };
77
78 List<PCInfo>* pc_info() {
79 return &pc_info_;
80 }
81
82 private:
83 void AddPCInfo(const PCInfo& pc_info) {
84 pc_info_.Add(pc_info);
85 }
86
87 List<PCInfo> pc_info_;
88};
89
90
91class GDBJITInterface: public AllStatic {
92 public:
93 enum CodeTag {
94#define V(x) x,
95 CODE_TAGS_LIST(V)
96#undef V
97 TAG_COUNT
98 };
99
100 static const char* Tag2String(CodeTag tag) {
101 switch (tag) {
102#define V(x) case x: return #x;
103 CODE_TAGS_LIST(V)
104#undef V
105 default:
106 return NULL;
107 }
108 }
109
110 static void AddCode(const char* name,
111 Code* code,
112 Script* script = NULL);
113
114 static void AddCode(Handle<String> name,
115 Handle<Script> script,
116 Handle<Code> code);
117
118 static void AddCode(CodeTag tag, String* name, Code* code);
119
120 static void AddCode(CodeTag tag, const char* name, Code* code);
121
122 static void AddCode(CodeTag tag, Code* code);
123
124 static void RemoveCode(Code* code);
125
126 static void RegisterDetailedLineInfo(Code* code, GDBJITLineInfo* line_info);
127};
128
129#define GDBJIT(action) GDBJITInterface::action
130
131} } // namespace v8::internal
132#else
133#define GDBJIT(action) ((void) 0)
134#endif
135
136#endif