public:
explicit PositionsRecorder(Assembler* assembler)
: assembler_(assembler) {
-#ifdef ENABLE_GDB_JIT_INTERFACE
- gdbjit_lineinfo_ = NULL;
-#endif
jit_handler_data_ = NULL;
}
-#ifdef ENABLE_GDB_JIT_INTERFACE
- ~PositionsRecorder() {
- delete gdbjit_lineinfo_;
- }
-
- void StartGDBJITLineInfoRecording() {
- if (FLAG_gdbjit) {
- gdbjit_lineinfo_ = new GDBJITLineInfo();
- }
- }
-
- GDBJITLineInfo* DetachGDBJITLineInfo() {
- GDBJITLineInfo* lineinfo = gdbjit_lineinfo_;
- gdbjit_lineinfo_ = NULL; // To prevent deallocation in destructor.
- return lineinfo;
- }
-#endif
void AttachJITHandlerData(void* user_data) {
jit_handler_data_ = user_data;
}
private:
Assembler* assembler_;
PositionState state_;
-#ifdef ENABLE_GDB_JIT_INTERFACE
- GDBJITLineInfo* gdbjit_lineinfo_;
-#endif
// Currently jit_handler_data_ is used to store JITHandler-specific data
// over the lifetime of a PositionsRecorder
#endif // defined(__ELF)
+class LineInfo : public Malloced {
+ public:
+ LineInfo() : pc_info_(10) {}
+
+ void SetPosition(intptr_t pc, int pos, bool is_statement) {
+ AddPCInfo(PCInfo(pc, pos, is_statement));
+ }
+
+ struct PCInfo {
+ PCInfo(intptr_t pc, int pos, bool is_statement)
+ : pc_(pc), pos_(pos), is_statement_(is_statement) {}
+
+ intptr_t pc_;
+ int pos_;
+ bool is_statement_;
+ };
+
+ List<PCInfo>* pc_info() { return &pc_info_; }
+
+ private:
+ void AddPCInfo(const PCInfo& pc_info) { pc_info_.Add(pc_info); }
+
+ List<PCInfo> pc_info_;
+};
+
+
class CodeDescription BASE_EMBEDDED {
public:
#if V8_TARGET_ARCH_X64
};
#endif
- CodeDescription(const char* name,
- Code* code,
- Handle<Script> script,
- GDBJITLineInfo* lineinfo,
- GDBJITInterface::CodeTag tag,
+ CodeDescription(const char* name, Code* code, Handle<Script> script,
+ LineInfo* lineinfo, GDBJITInterface::CodeTag tag,
CompilationInfo* info)
: name_(name),
code_(code),
script_(script),
lineinfo_(lineinfo),
tag_(tag),
- info_(info) {
- }
+ info_(info) {}
const char* name() const {
return name_;
}
- GDBJITLineInfo* lineinfo() const {
- return lineinfo_;
- }
+ LineInfo* lineinfo() const { return lineinfo_; }
GDBJITInterface::CodeTag tag() const {
return tag_;
const char* name_;
Code* code_;
Handle<Script> script_;
- GDBJITLineInfo* lineinfo_;
+ LineInfo* lineinfo_;
GDBJITInterface::CodeTag tag_;
CompilationInfo* info_;
#if V8_TARGET_ARCH_X64
intptr_t line = 1;
bool is_statement = true;
- List<GDBJITLineInfo::PCInfo>* pc_info = desc_->lineinfo()->pc_info();
+ List<LineInfo::PCInfo>* pc_info = desc_->lineinfo()->pc_info();
pc_info->Sort(&ComparePCInfo);
int pc_info_length = pc_info->length();
for (int i = 0; i < pc_info_length; i++) {
- GDBJITLineInfo::PCInfo* info = &pc_info->at(i);
+ LineInfo::PCInfo* info = &pc_info->at(i);
ASSERT(info->pc_ >= pc);
// Reduce bloating in the debug line table by removing duplicate line
w->Write<uint8_t>(op);
}
- static int ComparePCInfo(const GDBJITLineInfo::PCInfo* a,
- const GDBJITLineInfo::PCInfo* b) {
+ static int ComparePCInfo(const LineInfo::PCInfo* a,
+ const LineInfo::PCInfo* b) {
if (a->pc_ == b->pc_) {
if (a->is_statement_ != b->is_statement_) {
return b->is_statement_ ? +1 : -1;
}
-static void* TagLineInfo(GDBJITLineInfo* ptr) {
+static void* TagLineInfo(LineInfo* ptr) {
return reinterpret_cast<void*>(
reinterpret_cast<intptr_t>(ptr) | kLineInfoTag);
}
-static GDBJITLineInfo* UntagLineInfo(void* ptr) {
- return reinterpret_cast<GDBJITLineInfo*>(
- reinterpret_cast<intptr_t>(ptr) & ~kLineInfoTag);
+static LineInfo* UntagLineInfo(void* ptr) {
+ return reinterpret_cast<LineInfo*>(reinterpret_cast<intptr_t>(ptr) &
+ ~kLineInfoTag);
}
HashMap::Entry* e = GetEntries()->Lookup(code, HashForCodeObject(code), true);
if (e->value != NULL && !IsLineInfoTagged(e->value)) return;
- GDBJITLineInfo* lineinfo = UntagLineInfo(e->value);
+ LineInfo* lineinfo = UntagLineInfo(e->value);
CodeDescription code_desc(name,
code,
script != NULL ? Handle<Script>(script)
}
-void GDBJITInterface::RegisterDetailedLineInfo(Code* code,
- GDBJITLineInfo* line_info) {
+static void RegisterDetailedLineInfo(Code* code, LineInfo* line_info) {
base::LockGuard<base::Mutex> lock_guard(mutex.Pointer());
ASSERT(!IsLineInfoTagged(line_info));
HashMap::Entry* e = GetEntries()->Lookup(code, HashForCodeObject(code), true);
}
+void GDBJITInterface::EventHandler(const v8::JitCodeEvent* event) {
+ if (!FLAG_gdbjit) return;
+ switch (event->type) {
+ case v8::JitCodeEvent::CODE_ADDED:
+ case v8::JitCodeEvent::CODE_MOVED:
+ case v8::JitCodeEvent::CODE_REMOVED:
+ break;
+ case v8::JitCodeEvent::CODE_ADD_LINE_POS_INFO: {
+ LineInfo* line_info = reinterpret_cast<LineInfo*>(event->user_data);
+ line_info->SetPosition(static_cast<intptr_t>(event->line_info.offset),
+ static_cast<int>(event->line_info.pos),
+ event->line_info.position_type ==
+ v8::JitCodeEvent::STATEMENT_POSITION);
+ break;
+ }
+ case v8::JitCodeEvent::CODE_START_LINE_INFO_RECORDING: {
+ v8::JitCodeEvent* mutable_event = const_cast<v8::JitCodeEvent*>(event);
+ mutable_event->user_data = new LineInfo();
+ break;
+ }
+ case v8::JitCodeEvent::CODE_END_LINE_INFO_RECORDING: {
+ LineInfo* line_info = reinterpret_cast<LineInfo*>(event->user_data);
+ Code* code = Code::GetCodeFromTargetAddress(
+ reinterpret_cast<Address>(event->code_start));
+ RegisterDetailedLineInfo(code, line_info);
+ break;
+ }
+ }
+}
+
+
} } // namespace v8::internal
#endif
V(EVAL) \
V(FUNCTION)
-class GDBJITLineInfo : public Malloced {
- public:
- GDBJITLineInfo()
- : pc_info_(10) { }
-
- void SetPosition(intptr_t pc, int pos, bool is_statement) {
- AddPCInfo(PCInfo(pc, pos, is_statement));
- }
-
- struct PCInfo {
- PCInfo(intptr_t pc, int pos, bool is_statement)
- : pc_(pc), pos_(pos), is_statement_(is_statement) { }
-
- intptr_t pc_;
- int pos_;
- bool is_statement_;
- };
-
- List<PCInfo>* pc_info() {
- return &pc_info_;
- }
-
- private:
- void AddPCInfo(const PCInfo& pc_info) {
- pc_info_.Add(pc_info);
- }
-
- List<PCInfo> pc_info_;
-};
-
-
class GDBJITInterface: public AllStatic {
public:
enum CodeTag {
}
}
+ // Main entry point into GDB JIT realized as a JitCodeEventHandler.
+ static void EventHandler(const v8::JitCodeEvent* event);
+
static void AddCode(const char* name,
Code* code,
CodeTag tag,
static void RemoveCode(Code* code);
static void RemoveCodeRange(Address start, Address end);
-
- static void RegisterDetailedLineInfo(Code* code, GDBJITLineInfo* line_info);
};
#define GDBJIT(action) GDBJITInterface::action