summaryrefslogtreecommitdiff
path: root/deps/v8/src/gdb-jit.cc
diff options
context:
space:
mode:
authorRefael Ackermann <refack@gmail.com>2014-09-29 13:20:04 +0400
committerFedor Indutny <fedor@indutny.com>2014-10-08 15:35:57 +0400
commit939278ac059b44439d41aab12bf552c8ae3c52d0 (patch)
tree86c586915a96d308b1b04de679a8ae293caf3e41 /deps/v8/src/gdb-jit.cc
parent4412a71d76a0fa002f627ec21d2337e089da6764 (diff)
downloadnode-new-939278ac059b44439d41aab12bf552c8ae3c52d0.tar.gz
deps: update v8 to 3.28.73
Reviewed-By: Fedor Indutny <fedor@indutny.com> PR-URL: https://github.com/joyent/node/pull/8476
Diffstat (limited to 'deps/v8/src/gdb-jit.cc')
-rw-r--r--deps/v8/src/gdb-jit.cc274
1 files changed, 153 insertions, 121 deletions
diff --git a/deps/v8/src/gdb-jit.cc b/deps/v8/src/gdb-jit.cc
index f2861c15f3..c9a57b5fa0 100644
--- a/deps/v8/src/gdb-jit.cc
+++ b/deps/v8/src/gdb-jit.cc
@@ -3,18 +3,19 @@
// found in the LICENSE file.
#ifdef ENABLE_GDB_JIT_INTERFACE
-#include "v8.h"
-#include "gdb-jit.h"
-
-#include "bootstrapper.h"
-#include "compiler.h"
-#include "frames.h"
-#include "frames-inl.h"
-#include "global-handles.h"
-#include "messages.h"
-#include "natives.h"
-#include "platform.h"
-#include "scopes.h"
+#include "src/v8.h"
+
+#include "src/base/platform/platform.h"
+#include "src/bootstrapper.h"
+#include "src/compiler.h"
+#include "src/frames-inl.h"
+#include "src/frames.h"
+#include "src/gdb-jit.h"
+#include "src/global-handles.h"
+#include "src/messages.h"
+#include "src/natives.h"
+#include "src/ostreams.h"
+#include "src/scopes.h"
namespace v8 {
namespace internal {
@@ -114,7 +115,7 @@ class Writer BASE_EMBEDDED {
if (delta == 0) return;
uintptr_t padding = align - delta;
Ensure(position_ += padding);
- ASSERT((position_ % align) == 0);
+ DCHECK((position_ % align) == 0);
}
void WriteULEB128(uintptr_t value) {
@@ -154,7 +155,7 @@ class Writer BASE_EMBEDDED {
template<typename T>
T* RawSlotAt(uintptr_t offset) {
- ASSERT(offset < capacity_ && offset + sizeof(T) <= capacity_);
+ DCHECK(offset < capacity_ && offset + sizeof(T) <= capacity_);
return reinterpret_cast<T*>(&buffer_[offset]);
}
@@ -194,7 +195,7 @@ class DebugSectionBase : public ZoneObject {
struct MachOSectionHeader {
char sectname[16];
char segname[16];
-#if V8_TARGET_ARCH_IA32
+#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87
uint32_t addr;
uint32_t size;
#else
@@ -230,7 +231,7 @@ class MachOSection : public DebugSectionBase<MachOSectionHeader> {
align_(align),
flags_(flags) {
if (align_ != 0) {
- ASSERT(IsPowerOf2(align));
+ DCHECK(IsPowerOf2(align));
align_ = WhichPowerOf2(align_);
}
}
@@ -249,8 +250,8 @@ class MachOSection : public DebugSectionBase<MachOSectionHeader> {
header->reserved2 = 0;
memset(header->sectname, 0, sizeof(header->sectname));
memset(header->segname, 0, sizeof(header->segname));
- ASSERT(strlen(name_) < sizeof(header->sectname));
- ASSERT(strlen(segment_) < sizeof(header->segname));
+ DCHECK(strlen(name_) < sizeof(header->sectname));
+ DCHECK(strlen(segment_) < sizeof(header->segname));
strncpy(header->sectname, name_, sizeof(header->sectname));
strncpy(header->segname, segment_, sizeof(header->segname));
}
@@ -442,7 +443,7 @@ class ELFStringTable : public ELFSection {
}
virtual void WriteBody(Writer::Slot<Header> header, Writer* w) {
- ASSERT(writer_ == NULL);
+ DCHECK(writer_ == NULL);
header->offset = offset_;
header->size = size_;
}
@@ -511,7 +512,7 @@ class MachO BASE_EMBEDDED {
uint32_t cmd;
uint32_t cmdsize;
char segname[16];
-#if V8_TARGET_ARCH_IA32
+#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87
uint32_t vmaddr;
uint32_t vmsize;
uint32_t fileoff;
@@ -535,9 +536,9 @@ class MachO BASE_EMBEDDED {
Writer::Slot<MachOHeader> WriteHeader(Writer* w) {
- ASSERT(w->position() == 0);
+ DCHECK(w->position() == 0);
Writer::Slot<MachOHeader> header = w->CreateSlotHere<MachOHeader>();
-#if V8_TARGET_ARCH_IA32
+#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87
header->magic = 0xFEEDFACEu;
header->cputype = 7; // i386
header->cpusubtype = 3; // CPU_SUBTYPE_I386_ALL
@@ -562,7 +563,7 @@ class MachO BASE_EMBEDDED {
uintptr_t code_size) {
Writer::Slot<MachOSegmentCommand> cmd =
w->CreateSlotHere<MachOSegmentCommand>();
-#if V8_TARGET_ARCH_IA32
+#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87
cmd->cmd = LC_SEGMENT_32;
#else
cmd->cmd = LC_SEGMENT_64;
@@ -647,20 +648,21 @@ class ELF BASE_EMBEDDED {
void WriteHeader(Writer* w) {
- ASSERT(w->position() == 0);
+ DCHECK(w->position() == 0);
Writer::Slot<ELFHeader> header = w->CreateSlotHere<ELFHeader>();
-#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_ARM
+#if (V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X87 || \
+ (V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT))
const uint8_t ident[16] =
{ 0x7f, 'E', 'L', 'F', 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-#elif V8_TARGET_ARCH_X64
+#elif V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_64_BIT
const uint8_t ident[16] =
{ 0x7f, 'E', 'L', 'F', 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0};
#else
#error Unsupported target architecture.
#endif
- OS::MemCopy(header->ident, ident, 16);
+ memcpy(header->ident, ident, 16);
header->type = 1;
-#if V8_TARGET_ARCH_IA32
+#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87
header->machine = 3;
#elif V8_TARGET_ARCH_X64
// Processor identification value for x64 is 62 as defined in
@@ -689,7 +691,7 @@ class ELF BASE_EMBEDDED {
void WriteSectionTable(Writer* w) {
// Section headers table immediately follows file header.
- ASSERT(w->position() == sizeof(ELFHeader));
+ DCHECK(w->position() == sizeof(ELFHeader));
Writer::Slot<ELFSection::Header> headers =
w->CreateSlotsHere<ELFSection::Header>(sections_.length());
@@ -762,7 +764,8 @@ class ELFSymbol BASE_EMBEDDED {
Binding binding() const {
return static_cast<Binding>(info >> 4);
}
-#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_ARM
+#if (V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X87 || \
+ (V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT))
struct SerializedLayout {
SerializedLayout(uint32_t name,
uintptr_t value,
@@ -785,7 +788,7 @@ class ELFSymbol BASE_EMBEDDED {
uint8_t other;
uint16_t section;
};
-#elif V8_TARGET_ARCH_X64
+#elif V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_64_BIT
struct SerializedLayout {
SerializedLayout(uint32_t name,
uintptr_t value,
@@ -897,6 +900,32 @@ class ELFSymbolTable : public ELFSection {
#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
@@ -908,27 +937,21 @@ class CodeDescription BASE_EMBEDDED {
};
#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_;
@@ -964,12 +987,12 @@ class CodeDescription BASE_EMBEDDED {
#if V8_TARGET_ARCH_X64
uintptr_t GetStackStateStartAddress(StackState state) const {
- ASSERT(state < STACK_STATE_MAX);
+ DCHECK(state < STACK_STATE_MAX);
return stack_state_start_addresses_[state];
}
void SetStackStateStartAddress(StackState state, uintptr_t addr) {
- ASSERT(state < STACK_STATE_MAX);
+ DCHECK(state < STACK_STATE_MAX);
stack_state_start_addresses_[state] = addr;
}
#endif
@@ -987,7 +1010,7 @@ class CodeDescription BASE_EMBEDDED {
const char* name_;
Code* code_;
Handle<Script> script_;
- GDBJITLineInfo* lineinfo_;
+ LineInfo* lineinfo_;
GDBJITInterface::CodeTag tag_;
CompilationInfo* info_;
#if V8_TARGET_ARCH_X64
@@ -1084,7 +1107,7 @@ class DebugInfoSection : public DebugSection {
w->Write<intptr_t>(desc_->CodeStart() + desc_->CodeSize());
Writer::Slot<uint32_t> fb_block_size = w->CreateSlotHere<uint32_t>();
uintptr_t fb_block_start = w->position();
-#if V8_TARGET_ARCH_IA32
+#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87
w->Write<uint8_t>(DW_OP_reg5); // The frame pointer's here on ia32
#elif V8_TARGET_ARCH_X64
w->Write<uint8_t>(DW_OP_reg6); // and here on x64.
@@ -1092,6 +1115,8 @@ class DebugInfoSection : public DebugSection {
UNIMPLEMENTED();
#elif V8_TARGET_ARCH_MIPS
UNIMPLEMENTED();
+#elif V8_TARGET_ARCH_MIPS64
+ UNIMPLEMENTED();
#else
#error Unsupported target architecture.
#endif
@@ -1130,11 +1155,11 @@ class DebugInfoSection : public DebugSection {
}
// See contexts.h for more information.
- ASSERT(Context::MIN_CONTEXT_SLOTS == 4);
- ASSERT(Context::CLOSURE_INDEX == 0);
- ASSERT(Context::PREVIOUS_INDEX == 1);
- ASSERT(Context::EXTENSION_INDEX == 2);
- ASSERT(Context::GLOBAL_OBJECT_INDEX == 3);
+ DCHECK(Context::MIN_CONTEXT_SLOTS == 4);
+ DCHECK(Context::CLOSURE_INDEX == 0);
+ DCHECK(Context::PREVIOUS_INDEX == 1);
+ DCHECK(Context::EXTENSION_INDEX == 2);
+ DCHECK(Context::GLOBAL_OBJECT_INDEX == 3);
w->WriteULEB128(current_abbreviation++);
w->WriteString(".closure");
w->WriteULEB128(current_abbreviation++);
@@ -1282,7 +1307,7 @@ class DebugAbbrevSection : public DebugSection {
bool WriteBodyInternal(Writer* w) {
int current_abbreviation = 1;
bool extra_info = desc_->IsInfoAvailable();
- ASSERT(desc_->IsLineInfoAvailable());
+ DCHECK(desc_->IsLineInfoAvailable());
w->WriteULEB128(current_abbreviation++);
w->WriteULEB128(DW_TAG_COMPILE_UNIT);
w->Write<uint8_t>(extra_info ? DW_CHILDREN_YES : DW_CHILDREN_NO);
@@ -1447,13 +1472,13 @@ class DebugLineSection : public DebugSection {
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);
- ASSERT(info->pc_ >= pc);
+ LineInfo::PCInfo* info = &pc_info->at(i);
+ DCHECK(info->pc_ >= pc);
// Reduce bloating in the debug line table by removing duplicate line
// entries (per DWARF2 standard).
@@ -1523,8 +1548,8 @@ class DebugLineSection : public DebugSection {
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;
@@ -1623,7 +1648,7 @@ void UnwindInfoSection::WriteLength(Writer* w,
}
}
- ASSERT((w->position() - initial_position) % kPointerSize == 0);
+ DCHECK((w->position() - initial_position) % kPointerSize == 0);
length_slot->set(w->position() - initial_position);
}
@@ -1819,8 +1844,9 @@ extern "C" {
#ifdef OBJECT_PRINT
void __gdb_print_v8_object(Object* object) {
- object->Print();
- PrintF(stdout, "\n");
+ OFStream os(stdout);
+ object->Print(os);
+ os << flush;
}
#endif
}
@@ -1833,7 +1859,7 @@ static JITCodeEntry* CreateCodeEntry(Address symfile_addr,
entry->symfile_addr_ = reinterpret_cast<Address>(entry + 1);
entry->symfile_size_ = symfile_size;
- OS::MemCopy(entry->symfile_addr_, symfile_addr, symfile_size);
+ MemCopy(entry->symfile_addr_, symfile_addr, symfile_size);
entry->prev_ = entry->next_ = NULL;
@@ -1857,12 +1883,12 @@ static void RegisterCodeEntry(JITCodeEntry* entry,
static const char* kObjFileExt = ".o";
char file_name[64];
- OS::SNPrintF(Vector<char>(file_name, kMaxFileNameSize),
- "%s%s%d%s",
- kElfFilePrefix,
- (name_hint != NULL) ? name_hint : "",
- file_num++,
- kObjFileExt);
+ SNPrintF(Vector<char>(file_name, kMaxFileNameSize),
+ "%s%s%d%s",
+ kElfFilePrefix,
+ (name_hint != NULL) ? name_hint : "",
+ file_num++,
+ kObjFileExt);
WriteBytes(file_name, entry->symfile_addr_, entry->symfile_size_);
}
#endif
@@ -1962,15 +1988,15 @@ static bool IsLineInfoTagged(void* ptr) {
}
-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);
}
@@ -2030,7 +2056,7 @@ static void AddUnwindInfo(CodeDescription* desc) {
}
-static LazyMutex mutex = LAZY_MUTEX_INITIALIZER;
+static base::LazyMutex mutex = LAZY_MUTEX_INITIALIZER;
void GDBJITInterface::AddCode(const char* name,
@@ -2038,15 +2064,13 @@ void GDBJITInterface::AddCode(const char* name,
GDBJITInterface::CodeTag tag,
Script* script,
CompilationInfo* info) {
- if (!FLAG_gdbjit) return;
-
- LockGuard<Mutex> lock_guard(mutex.Pointer());
+ base::LockGuard<base::Mutex> lock_guard(mutex.Pointer());
DisallowHeapAllocation no_gc;
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)
@@ -2064,7 +2088,7 @@ void GDBJITInterface::AddCode(const char* name,
AddUnwindInfo(&code_desc);
Isolate* isolate = code->GetIsolate();
JITCodeEntry* entry = CreateELFObject(&code_desc, isolate);
- ASSERT(!IsLineInfoTagged(entry));
+ DCHECK(!IsLineInfoTagged(entry));
delete lineinfo;
e->value = entry;
@@ -2084,49 +2108,10 @@ void GDBJITInterface::AddCode(const char* name,
}
-void GDBJITInterface::AddCode(GDBJITInterface::CodeTag tag,
- const char* name,
- Code* code) {
- if (!FLAG_gdbjit) return;
-
- EmbeddedVector<char, 256> buffer;
- StringBuilder builder(buffer.start(), buffer.length());
-
- builder.AddString(Tag2String(tag));
- if ((name != NULL) && (*name != '\0')) {
- builder.AddString(": ");
- builder.AddString(name);
- } else {
- builder.AddFormatted(": code object %p", static_cast<void*>(code));
- }
-
- AddCode(builder.Finalize(), code, tag, NULL, NULL);
-}
-
-
-void GDBJITInterface::AddCode(GDBJITInterface::CodeTag tag,
- Name* name,
- Code* code) {
- if (!FLAG_gdbjit) return;
- if (name != NULL && name->IsString()) {
- AddCode(tag, String::cast(name)->ToCString(DISALLOW_NULLS).get(), code);
- } else {
- AddCode(tag, "", code);
- }
-}
-
-
-void GDBJITInterface::AddCode(GDBJITInterface::CodeTag tag, Code* code) {
- if (!FLAG_gdbjit) return;
-
- AddCode(tag, "", code);
-}
-
-
void GDBJITInterface::RemoveCode(Code* code) {
if (!FLAG_gdbjit) return;
- LockGuard<Mutex> lock_guard(mutex.Pointer());
+ base::LockGuard<base::Mutex> lock_guard(mutex.Pointer());
HashMap::Entry* e = GetEntries()->Lookup(code,
HashForCodeObject(code),
false);
@@ -2162,15 +2147,62 @@ void GDBJITInterface::RemoveCodeRange(Address start, Address end) {
}
-void GDBJITInterface::RegisterDetailedLineInfo(Code* code,
- GDBJITLineInfo* line_info) {
- LockGuard<Mutex> lock_guard(mutex.Pointer());
- ASSERT(!IsLineInfoTagged(line_info));
+static void RegisterDetailedLineInfo(Code* code, LineInfo* line_info) {
+ base::LockGuard<base::Mutex> lock_guard(mutex.Pointer());
+ DCHECK(!IsLineInfoTagged(line_info));
HashMap::Entry* e = GetEntries()->Lookup(code, HashForCodeObject(code), true);
- ASSERT(e->value == NULL);
+ DCHECK(e->value == NULL);
e->value = TagLineInfo(line_info);
}
+void GDBJITInterface::EventHandler(const v8::JitCodeEvent* event) {
+ if (!FLAG_gdbjit) return;
+ switch (event->type) {
+ case v8::JitCodeEvent::CODE_ADDED: {
+ Code* code = Code::GetCodeFromTargetAddress(
+ reinterpret_cast<Address>(event->code_start));
+ if (code->kind() == Code::OPTIMIZED_FUNCTION ||
+ code->kind() == Code::FUNCTION) {
+ break;
+ }
+ EmbeddedVector<char, 256> buffer;
+ StringBuilder builder(buffer.start(), buffer.length());
+ builder.AddSubstring(event->name.str, static_cast<int>(event->name.len));
+ AddCode(builder.Finalize(), code, NON_FUNCTION, NULL, NULL);
+ break;
+ }
+ case v8::JitCodeEvent::CODE_MOVED:
+ break;
+ case v8::JitCodeEvent::CODE_REMOVED: {
+ Code* code = Code::GetCodeFromTargetAddress(
+ reinterpret_cast<Address>(event->code_start));
+ RemoveCode(code);
+ 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