blob: 0c80fb65b759527faca15d40a7cafb7a2a8c2c99 [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
Ben Murdoch257744e2011-11-30 15:57:28 +000031#include "allocation.h"
32
Ben Murdochb8e0da22011-05-16 14:20:40 +010033//
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
43namespace v8 {
44namespace internal {
45
46#define CODE_TAGS_LIST(V) \
47 V(LOAD_IC) \
48 V(KEYED_LOAD_IC) \
49 V(STORE_IC) \
50 V(KEYED_STORE_IC) \
51 V(CALL_IC) \
52 V(CALL_INITIALIZE) \
53 V(CALL_PRE_MONOMORPHIC) \
54 V(CALL_NORMAL) \
55 V(CALL_MEGAMORPHIC) \
56 V(CALL_MISS) \
57 V(STUB) \
58 V(BUILTIN) \
59 V(SCRIPT) \
Steve Block1e0659c2011-05-24 12:43:12 +010060 V(EVAL) \
61 V(FUNCTION)
Ben Murdochb8e0da22011-05-16 14:20:40 +010062
63class GDBJITLineInfo : public Malloced {
64 public:
65 GDBJITLineInfo()
66 : pc_info_(10) { }
67
68 void SetPosition(intptr_t pc, int pos, bool is_statement) {
69 AddPCInfo(PCInfo(pc, pos, is_statement));
70 }
71
72 struct PCInfo {
73 PCInfo(intptr_t pc, int pos, bool is_statement)
74 : pc_(pc), pos_(pos), is_statement_(is_statement) { }
75
76 intptr_t pc_;
77 int pos_;
78 bool is_statement_;
79 };
80
81 List<PCInfo>* pc_info() {
82 return &pc_info_;
83 }
84
85 private:
86 void AddPCInfo(const PCInfo& pc_info) {
87 pc_info_.Add(pc_info);
88 }
89
90 List<PCInfo> pc_info_;
91};
92
93
94class GDBJITInterface: public AllStatic {
95 public:
96 enum CodeTag {
97#define V(x) x,
98 CODE_TAGS_LIST(V)
99#undef V
100 TAG_COUNT
101 };
102
103 static const char* Tag2String(CodeTag tag) {
104 switch (tag) {
105#define V(x) case x: return #x;
106 CODE_TAGS_LIST(V)
107#undef V
108 default:
109 return NULL;
110 }
111 }
112
113 static void AddCode(const char* name,
114 Code* code,
Steve Block1e0659c2011-05-24 12:43:12 +0100115 CodeTag tag,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100116 Script* script = NULL);
117
118 static void AddCode(Handle<String> name,
119 Handle<Script> script,
120 Handle<Code> code);
121
122 static void AddCode(CodeTag tag, String* name, Code* code);
123
124 static void AddCode(CodeTag tag, const char* name, Code* code);
125
126 static void AddCode(CodeTag tag, Code* code);
127
128 static void RemoveCode(Code* code);
129
130 static void RegisterDetailedLineInfo(Code* code, GDBJITLineInfo* line_info);
Ben Murdoch8b112d22011-06-08 16:22:53 +0100131
132 private:
133 static Mutex* mutex_;
Ben Murdochb8e0da22011-05-16 14:20:40 +0100134};
135
136#define GDBJIT(action) GDBJITInterface::action
137
138} } // namespace v8::internal
139#else
140#define GDBJIT(action) ((void) 0)
141#endif
142
143#endif