OLD | NEW |
---|---|
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 13 matching lines...) Expand all Loading... | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifdef ENABLE_GDB_JIT_INTERFACE | 28 #ifdef ENABLE_GDB_JIT_INTERFACE |
29 #include "v8.h" | 29 #include "v8.h" |
30 #include "gdb-jit.h" | 30 #include "gdb-jit.h" |
31 | 31 |
32 #include "bootstrapper.h" | 32 #include "bootstrapper.h" |
33 #include "compiler.h" | 33 #include "compiler.h" |
34 #include "frames-inl.h" | |
34 #include "global-handles.h" | 35 #include "global-handles.h" |
35 #include "messages.h" | 36 #include "messages.h" |
36 #include "platform.h" | 37 #include "platform.h" |
37 #include "natives.h" | 38 #include "natives.h" |
38 #include "scopeinfo.h" | 39 #include "scopeinfo.h" |
40 #include "scopes.h" | |
39 | 41 |
40 namespace v8 { | 42 namespace v8 { |
41 namespace internal { | 43 namespace internal { |
42 | 44 |
43 #ifdef __APPLE__ | 45 #ifdef __APPLE__ |
44 #define __MACH_O | 46 #define __MACH_O |
45 class MachO; | 47 class MachO; |
46 class MachOSection; | 48 class MachOSection; |
47 typedef MachO DebugObject; | 49 typedef MachO DebugObject; |
48 typedef MachOSection DebugSection; | 50 typedef MachOSection DebugSection; |
49 #else | 51 #else |
50 #define __ELF | 52 #define __ELF |
51 class ELF; | 53 class ELF; |
52 class ELFSection; | 54 class ELFSection; |
53 typedef ELF DebugObject; | 55 typedef ELF DebugObject; |
54 typedef ELFSection DebugSection; | 56 typedef ELFSection DebugSection; |
55 #endif | 57 #endif |
56 | 58 |
57 class Writer BASE_EMBEDDED { | 59 class Writer BASE_EMBEDDED { |
58 public: | 60 public: |
59 explicit Writer(DebugObject* debug_object) | 61 Writer(DebugObject* debug_object, Zone* zone) |
60 : debug_object_(debug_object), | 62 : zone_(zone), |
63 debug_object_(debug_object), | |
61 position_(0), | 64 position_(0), |
62 capacity_(1024), | 65 capacity_(1024), |
63 buffer_(reinterpret_cast<byte*>(malloc(capacity_))) { | 66 buffer_(reinterpret_cast<byte*>(malloc(capacity_))) { |
64 } | 67 } |
65 | 68 |
66 ~Writer() { | 69 ~Writer() { |
67 free(buffer_); | 70 free(buffer_); |
68 } | 71 } |
69 | 72 |
70 uintptr_t position() const { | 73 uintptr_t position() const { |
71 return position_; | 74 return position_; |
72 } | 75 } |
73 | 76 |
77 Zone* zone() { | |
78 return zone_; | |
79 } | |
80 | |
74 template<typename T> | 81 template<typename T> |
75 class Slot { | 82 class Slot { |
76 public: | 83 public: |
77 Slot(Writer* w, uintptr_t offset) : w_(w), offset_(offset) { } | 84 Slot(Writer* w, uintptr_t offset) : w_(w), offset_(offset) { } |
78 | 85 |
79 T* operator-> () { | 86 T* operator-> () { |
80 return w_->RawSlotAt<T>(offset_); | 87 return w_->RawSlotAt<T>(offset_); |
81 } | 88 } |
82 | 89 |
83 void set(const T& value) { | 90 void set(const T& value) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 | 179 |
173 private: | 180 private: |
174 template<typename T> friend class Slot; | 181 template<typename T> friend class Slot; |
175 | 182 |
176 template<typename T> | 183 template<typename T> |
177 T* RawSlotAt(uintptr_t offset) { | 184 T* RawSlotAt(uintptr_t offset) { |
178 ASSERT(offset < capacity_ && offset + sizeof(T) <= capacity_); | 185 ASSERT(offset < capacity_ && offset + sizeof(T) <= capacity_); |
179 return reinterpret_cast<T*>(&buffer_[offset]); | 186 return reinterpret_cast<T*>(&buffer_[offset]); |
180 } | 187 } |
181 | 188 |
189 Zone* zone_; | |
182 DebugObject* debug_object_; | 190 DebugObject* debug_object_; |
183 uintptr_t position_; | 191 uintptr_t position_; |
184 uintptr_t capacity_; | 192 uintptr_t capacity_; |
185 byte* buffer_; | 193 byte* buffer_; |
186 }; | 194 }; |
187 | 195 |
188 class StringTable; | 196 class StringTable; |
189 | 197 |
190 template<typename THeader> | 198 template<typename THeader> |
191 class DebugSectionBase : public ZoneObject { | 199 class DebugSectionBase : public ZoneObject { |
192 public: | 200 public: |
193 virtual ~DebugSectionBase() { } | 201 virtual ~DebugSectionBase() { } |
194 | 202 |
195 virtual void WriteBody(Writer::Slot<THeader> header, Writer* writer) { | 203 virtual void WriteHeadersAndBody(Writer::Slot<THeader> header, |
204 Writer* writer) { | |
196 uintptr_t start = writer->position(); | 205 uintptr_t start = writer->position(); |
197 if (WriteBody(writer)) { | 206 if (WriteBody(writer)) { |
198 uintptr_t end = writer->position(); | 207 uintptr_t end = writer->position(); |
199 header->offset = start; | 208 header->offset = start; |
200 #if defined(__MACH_O) | 209 #if defined(__MACH_O) |
201 header->addr = 0; | 210 header->addr = 0; |
202 #endif | 211 #endif |
203 header->size = end - start; | 212 header->size = end - start; |
204 } | 213 } |
205 } | 214 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 INDEX_ABSOLUTE = 0xfff1 | 340 INDEX_ABSOLUTE = 0xfff1 |
332 }; | 341 }; |
333 | 342 |
334 ELFSection(const char* name, Type type, uintptr_t align) | 343 ELFSection(const char* name, Type type, uintptr_t align) |
335 : name_(name), type_(type), align_(align) { } | 344 : name_(name), type_(type), align_(align) { } |
336 | 345 |
337 virtual ~ELFSection() { } | 346 virtual ~ELFSection() { } |
338 | 347 |
339 void PopulateHeader(Writer::Slot<Header> header, StringTable* strtab); | 348 void PopulateHeader(Writer::Slot<Header> header, StringTable* strtab); |
340 | 349 |
341 virtual void WriteBody(Writer::Slot<Header> header, Writer* w) { | 350 virtual void WriteHeadersAndBody(Writer::Slot<Header> header, Writer* w) { |
342 uintptr_t start = w->position(); | 351 uintptr_t start = w->position(); |
343 if (WriteBody(w)) { | 352 if (WriteBody(w)) { |
344 uintptr_t end = w->position(); | 353 uintptr_t end = w->position(); |
345 header->offset = start; | 354 header->offset = start; |
346 header->size = end - start; | 355 header->size = end - start; |
347 } | 356 } |
348 } | 357 } |
349 | 358 |
350 virtual bool WriteBody(Writer* w) { | 359 virtual bool WriteBody(Writer* w) { |
351 return false; | 360 return false; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 offset_ = writer_->position(); | 464 offset_ = writer_->position(); |
456 | 465 |
457 // First entry in the string table should be an empty string. | 466 // First entry in the string table should be an empty string. |
458 WriteString(""); | 467 WriteString(""); |
459 } | 468 } |
460 | 469 |
461 void DetachWriter() { | 470 void DetachWriter() { |
462 writer_ = NULL; | 471 writer_ = NULL; |
463 } | 472 } |
464 | 473 |
465 virtual void WriteBody(Writer::Slot<Header> header, Writer* w) { | 474 virtual void WriteHeadersAndBody(Writer::Slot<Header> header, Writer* w) { |
466 ASSERT(writer_ == NULL); | 475 ASSERT(writer_ == NULL); |
467 header->offset = offset_; | 476 header->offset = offset_; |
468 header->size = size_; | 477 header->size = size_; |
469 } | 478 } |
470 | 479 |
471 private: | 480 private: |
472 void WriteString(const char* str) { | 481 void WriteString(const char* str) { |
473 uintptr_t written = 0; | 482 uintptr_t written = 0; |
474 do { | 483 do { |
475 writer_->Write(*str); | 484 writer_->Write(*str); |
(...skipping 15 matching lines...) Expand all Loading... | |
491 header->type = type_; | 500 header->type = type_; |
492 header->alignment = align_; | 501 header->alignment = align_; |
493 PopulateHeader(header); | 502 PopulateHeader(header); |
494 } | 503 } |
495 #endif // defined(__ELF) | 504 #endif // defined(__ELF) |
496 | 505 |
497 | 506 |
498 #if defined(__MACH_O) | 507 #if defined(__MACH_O) |
499 class MachO BASE_EMBEDDED { | 508 class MachO BASE_EMBEDDED { |
500 public: | 509 public: |
501 MachO() : sections_(6) { } | 510 explicit MachO(Zone* zone) : sections_(6, zone) { } |
502 | 511 |
503 uint32_t AddSection(MachOSection* section) { | 512 uint32_t AddSection(MachOSection* section, Zone* zone) { |
504 sections_.Add(section); | 513 sections_.Add(section, zone); |
505 return sections_.length() - 1; | 514 return sections_.length() - 1; |
506 } | 515 } |
507 | 516 |
508 void Write(Writer* w, uintptr_t code_start, uintptr_t code_size) { | 517 void Write(Writer* w, uintptr_t code_start, uintptr_t code_size) { |
509 Writer::Slot<MachOHeader> header = WriteHeader(w); | 518 Writer::Slot<MachOHeader> header = WriteHeader(w); |
510 uintptr_t load_command_start = w->position(); | 519 uintptr_t load_command_start = w->position(); |
511 Writer::Slot<MachOSegmentCommand> cmd = WriteSegmentCommand(w, | 520 Writer::Slot<MachOSegmentCommand> cmd = WriteSegmentCommand(w, |
512 code_start, | 521 code_start, |
513 code_size); | 522 code_size); |
514 WriteSections(w, cmd, header, load_command_start); | 523 WriteSections(w, cmd, header, load_command_start); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 void WriteSections(Writer* w, | 615 void WriteSections(Writer* w, |
607 Writer::Slot<MachOSegmentCommand> cmd, | 616 Writer::Slot<MachOSegmentCommand> cmd, |
608 Writer::Slot<MachOHeader> header, | 617 Writer::Slot<MachOHeader> header, |
609 uintptr_t load_command_start) { | 618 uintptr_t load_command_start) { |
610 Writer::Slot<MachOSection::Header> headers = | 619 Writer::Slot<MachOSection::Header> headers = |
611 w->CreateSlotsHere<MachOSection::Header>(sections_.length()); | 620 w->CreateSlotsHere<MachOSection::Header>(sections_.length()); |
612 cmd->fileoff = w->position(); | 621 cmd->fileoff = w->position(); |
613 header->sizeofcmds = w->position() - load_command_start; | 622 header->sizeofcmds = w->position() - load_command_start; |
614 for (int section = 0; section < sections_.length(); ++section) { | 623 for (int section = 0; section < sections_.length(); ++section) { |
615 sections_[section]->PopulateHeader(headers.at(section)); | 624 sections_[section]->PopulateHeader(headers.at(section)); |
616 sections_[section]->WriteBody(headers.at(section), w); | 625 sections_[section]->WriteHeadersAndBody(headers.at(section), w); |
617 } | 626 } |
618 cmd->filesize = w->position() - (uintptr_t)cmd->fileoff; | 627 cmd->filesize = w->position() - (uintptr_t)cmd->fileoff; |
619 } | 628 } |
620 | 629 |
621 | 630 |
622 ZoneList<MachOSection*> sections_; | 631 ZoneList<MachOSection*> sections_; |
623 }; | 632 }; |
624 #endif // defined(__MACH_O) | 633 #endif // defined(__MACH_O) |
625 | 634 |
626 | 635 |
627 #if defined(__ELF) | 636 #if defined(__ELF) |
628 class ELF BASE_EMBEDDED { | 637 class ELF BASE_EMBEDDED { |
629 public: | 638 public: |
630 ELF() : sections_(6) { | 639 explicit ELF(Zone* zone) : sections_(6, zone) { |
631 sections_.Add(new ELFSection("", ELFSection::TYPE_NULL, 0)); | 640 sections_.Add(new(zone) ELFSection("", ELFSection::TYPE_NULL, 0), zone); |
632 sections_.Add(new StringTable(".shstrtab")); | 641 sections_.Add(new(zone) StringTable(".shstrtab"), zone); |
633 } | 642 } |
634 | 643 |
635 void Write(Writer* w) { | 644 void Write(Writer* w) { |
636 WriteHeader(w); | 645 WriteHeader(w); |
637 WriteSectionTable(w); | 646 WriteSectionTable(w); |
638 WriteSections(w); | 647 WriteSections(w); |
639 } | 648 } |
640 | 649 |
641 ELFSection* SectionAt(uint32_t index) { | 650 ELFSection* SectionAt(uint32_t index) { |
642 return sections_[index]; | 651 return sections_[index]; |
643 } | 652 } |
644 | 653 |
645 uint32_t AddSection(ELFSection* section) { | 654 uint32_t AddSection(ELFSection* section, Zone* zone) { |
646 sections_.Add(section); | 655 sections_.Add(section, zone); |
647 section->set_index(sections_.length() - 1); | 656 section->set_index(sections_.length() - 1); |
648 return sections_.length() - 1; | 657 return sections_.length() - 1; |
649 } | 658 } |
650 | 659 |
651 private: | 660 private: |
652 struct ELFHeader { | 661 struct ELFHeader { |
653 uint8_t ident[16]; | 662 uint8_t ident[16]; |
654 uint16_t type; | 663 uint16_t type; |
655 uint16_t machine; | 664 uint16_t machine; |
656 uint32_t version; | 665 uint32_t version; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
730 return sizeof(ELFHeader) + sizeof(ELFSection::Header) * section_index; | 739 return sizeof(ELFHeader) + sizeof(ELFSection::Header) * section_index; |
731 } | 740 } |
732 | 741 |
733 void WriteSections(Writer* w) { | 742 void WriteSections(Writer* w) { |
734 Writer::Slot<ELFSection::Header> headers = | 743 Writer::Slot<ELFSection::Header> headers = |
735 w->SlotAt<ELFSection::Header>(sizeof(ELFHeader)); | 744 w->SlotAt<ELFSection::Header>(sizeof(ELFHeader)); |
736 | 745 |
737 for (int i = 0, length = sections_.length(); | 746 for (int i = 0, length = sections_.length(); |
738 i < length; | 747 i < length; |
739 i++) { | 748 i++) { |
740 sections_[i]->WriteBody(headers.at(i), w); | 749 sections_[i]->WriteHeadersAndBody(headers.at(i), w); |
741 } | 750 } |
742 } | 751 } |
743 | 752 |
744 ZoneList<ELFSection*> sections_; | 753 ZoneList<ELFSection*> sections_; |
745 }; | 754 }; |
746 | 755 |
747 | 756 |
748 class ELFSymbol BASE_EMBEDDED { | 757 class ELFSymbol BASE_EMBEDDED { |
749 public: | 758 public: |
750 enum Type { | 759 enum Type { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
845 uintptr_t value; | 854 uintptr_t value; |
846 uintptr_t size; | 855 uintptr_t size; |
847 uint8_t info; | 856 uint8_t info; |
848 uint8_t other; | 857 uint8_t other; |
849 uint16_t section; | 858 uint16_t section; |
850 }; | 859 }; |
851 | 860 |
852 | 861 |
853 class ELFSymbolTable : public ELFSection { | 862 class ELFSymbolTable : public ELFSection { |
854 public: | 863 public: |
855 explicit ELFSymbolTable(const char* name) | 864 explicit ELFSymbolTable(const char* name, Zone* zone) |
856 : ELFSection(name, TYPE_SYMTAB, sizeof(uintptr_t)), | 865 : ELFSection(name, TYPE_SYMTAB, sizeof(uintptr_t)), |
857 locals_(1), | 866 locals_(1, zone), |
858 globals_(1) { | 867 globals_(1, zone) { |
859 } | 868 } |
860 | 869 |
861 virtual void WriteBody(Writer::Slot<Header> header, Writer* w) { | 870 virtual void WriteHeadersAndBody(Writer::Slot<Header> header, Writer* w) { |
862 w->Align(header->alignment); | 871 w->Align(header->alignment); |
863 int total_symbols = locals_.length() + globals_.length() + 1; | 872 int total_symbols = locals_.length() + globals_.length() + 1; |
864 header->offset = w->position(); | 873 header->offset = w->position(); |
865 | 874 |
866 Writer::Slot<ELFSymbol::SerializedLayout> symbols = | 875 Writer::Slot<ELFSymbol::SerializedLayout> symbols = |
867 w->CreateSlotsHere<ELFSymbol::SerializedLayout>(total_symbols); | 876 w->CreateSlotsHere<ELFSymbol::SerializedLayout>(total_symbols); |
868 | 877 |
869 header->size = w->position() - header->offset; | 878 header->size = w->position() - header->offset; |
870 | 879 |
871 // String table for this symbol table should follow it in the section table. | 880 // String table for this symbol table should follow it in the section table. |
872 StringTable* strtab = | 881 StringTable* strtab = |
873 static_cast<StringTable*>(w->debug_object()->SectionAt(index() + 1)); | 882 static_cast<StringTable*>(w->debug_object()->SectionAt(index() + 1)); |
874 strtab->AttachWriter(w); | 883 strtab->AttachWriter(w); |
875 symbols.at(0).set(ELFSymbol::SerializedLayout(0, | 884 symbols.at(0).set(ELFSymbol::SerializedLayout(0, |
876 0, | 885 0, |
877 0, | 886 0, |
878 ELFSymbol::BIND_LOCAL, | 887 ELFSymbol::BIND_LOCAL, |
879 ELFSymbol::TYPE_NOTYPE, | 888 ELFSymbol::TYPE_NOTYPE, |
880 0)); | 889 0)); |
881 WriteSymbolsList(&locals_, symbols.at(1), strtab); | 890 WriteSymbolsList(&locals_, symbols.at(1), strtab); |
882 WriteSymbolsList(&globals_, symbols.at(locals_.length() + 1), strtab); | 891 WriteSymbolsList(&globals_, symbols.at(locals_.length() + 1), strtab); |
883 strtab->DetachWriter(); | 892 strtab->DetachWriter(); |
884 } | 893 } |
885 | 894 |
886 void Add(const ELFSymbol& symbol) { | 895 void Add(const ELFSymbol& symbol, Zone* zone) { |
887 if (symbol.binding() == ELFSymbol::BIND_LOCAL) { | 896 if (symbol.binding() == ELFSymbol::BIND_LOCAL) { |
888 locals_.Add(symbol); | 897 locals_.Add(symbol, zone); |
889 } else { | 898 } else { |
890 globals_.Add(symbol); | 899 globals_.Add(symbol, zone); |
891 } | 900 } |
892 } | 901 } |
893 | 902 |
894 protected: | 903 protected: |
895 virtual void PopulateHeader(Writer::Slot<Header> header) { | 904 virtual void PopulateHeader(Writer::Slot<Header> header) { |
896 ELFSection::PopulateHeader(header); | 905 ELFSection::PopulateHeader(header); |
897 // We are assuming that string table will follow symbol table. | 906 // We are assuming that string table will follow symbol table. |
898 header->link = index() + 1; | 907 header->link = index() + 1; |
899 header->info = locals_.length() + 1; | 908 header->info = locals_.length() + 1; |
900 header->entry_size = sizeof(ELFSymbol::SerializedLayout); | 909 header->entry_size = sizeof(ELFSymbol::SerializedLayout); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1011 GDBJITInterface::CodeTag tag_; | 1020 GDBJITInterface::CodeTag tag_; |
1012 CompilationInfo* info_; | 1021 CompilationInfo* info_; |
1013 #ifdef V8_TARGET_ARCH_X64 | 1022 #ifdef V8_TARGET_ARCH_X64 |
1014 uintptr_t stack_state_start_addresses_[STACK_STATE_MAX]; | 1023 uintptr_t stack_state_start_addresses_[STACK_STATE_MAX]; |
1015 #endif | 1024 #endif |
1016 }; | 1025 }; |
1017 | 1026 |
1018 #if defined(__ELF) | 1027 #if defined(__ELF) |
1019 static void CreateSymbolsTable(CodeDescription* desc, | 1028 static void CreateSymbolsTable(CodeDescription* desc, |
1020 ELF* elf, | 1029 ELF* elf, |
1021 int text_section_index) { | 1030 int text_section_index, |
1022 ELFSymbolTable* symtab = new ELFSymbolTable(".symtab"); | 1031 Zone* zone) { |
1023 StringTable* strtab = new StringTable(".strtab"); | 1032 ELFSymbolTable* symtab = new(zone) ELFSymbolTable(".symtab", zone); |
1033 StringTable* strtab = new(zone) StringTable(".strtab"); | |
1024 | 1034 |
1025 // Symbol table should be followed by the linked string table. | 1035 // Symbol table should be followed by the linked string table. |
1026 elf->AddSection(symtab); | 1036 elf->AddSection(symtab, zone); |
1027 elf->AddSection(strtab); | 1037 elf->AddSection(strtab, zone); |
1028 | 1038 |
1029 symtab->Add(ELFSymbol("V8 Code", | 1039 symtab->Add(ELFSymbol("V8 Code", |
1030 0, | 1040 0, |
1031 0, | 1041 0, |
1032 ELFSymbol::BIND_LOCAL, | 1042 ELFSymbol::BIND_LOCAL, |
1033 ELFSymbol::TYPE_FILE, | 1043 ELFSymbol::TYPE_FILE, |
1034 ELFSection::INDEX_ABSOLUTE)); | 1044 ELFSection::INDEX_ABSOLUTE), |
1045 zone); | |
1035 | 1046 |
1036 symtab->Add(ELFSymbol(desc->name(), | 1047 symtab->Add(ELFSymbol(desc->name(), |
1037 0, | 1048 0, |
1038 desc->CodeSize(), | 1049 desc->CodeSize(), |
1039 ELFSymbol::BIND_GLOBAL, | 1050 ELFSymbol::BIND_GLOBAL, |
1040 ELFSymbol::TYPE_FUNC, | 1051 ELFSymbol::TYPE_FUNC, |
1041 text_section_index)); | 1052 text_section_index), |
1053 zone); | |
1042 } | 1054 } |
1043 #endif // defined(__ELF) | 1055 #endif // defined(__ELF) |
1044 | 1056 |
1045 | 1057 |
1046 class DebugInfoSection : public DebugSection { | 1058 class DebugInfoSection : public DebugSection { |
1047 public: | 1059 public: |
1048 explicit DebugInfoSection(CodeDescription* desc) | 1060 explicit DebugInfoSection(CodeDescription* desc) |
1049 #if defined(__ELF) | 1061 #if defined(__ELF) |
1050 : ELFSection(".debug_info", TYPE_PROGBITS, 1), | 1062 : ELFSection(".debug_info", TYPE_PROGBITS, 1), |
1051 #else | 1063 #else |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1088 w->Write<intptr_t>(desc_->CodeStart() + desc_->CodeSize()); | 1100 w->Write<intptr_t>(desc_->CodeStart() + desc_->CodeSize()); |
1089 w->Write<uint32_t>(0); | 1101 w->Write<uint32_t>(0); |
1090 | 1102 |
1091 uint32_t ty_offset = static_cast<uint32_t>(w->position() - cu_start); | 1103 uint32_t ty_offset = static_cast<uint32_t>(w->position() - cu_start); |
1092 w->WriteULEB128(3); | 1104 w->WriteULEB128(3); |
1093 w->Write<uint8_t>(kPointerSize); | 1105 w->Write<uint8_t>(kPointerSize); |
1094 w->WriteString("v8value"); | 1106 w->WriteString("v8value"); |
1095 | 1107 |
1096 if (desc_->IsInfoAvailable()) { | 1108 if (desc_->IsInfoAvailable()) { |
1097 CompilationInfo* info = desc_->info(); | 1109 CompilationInfo* info = desc_->info(); |
1098 ScopeInfo<FreeStoreAllocationPolicy> scope_info(info->scope()); | 1110 Scope* scope = info->scope(); |
1099 w->WriteULEB128(2); | 1111 w->WriteULEB128(2); |
1100 w->WriteString(desc_->name()); | 1112 w->WriteString(desc_->name()); |
1101 w->Write<intptr_t>(desc_->CodeStart()); | 1113 w->Write<intptr_t>(desc_->CodeStart()); |
1102 w->Write<intptr_t>(desc_->CodeStart() + desc_->CodeSize()); | 1114 w->Write<intptr_t>(desc_->CodeStart() + desc_->CodeSize()); |
1103 Writer::Slot<uint32_t> fb_block_size = w->CreateSlotHere<uint32_t>(); | 1115 Writer::Slot<uint32_t> fb_block_size = w->CreateSlotHere<uint32_t>(); |
1104 uintptr_t fb_block_start = w->position(); | 1116 uintptr_t fb_block_start = w->position(); |
1105 #if defined(V8_TARGET_ARCH_IA32) | 1117 #if defined(V8_TARGET_ARCH_IA32) |
1106 w->Write<uint8_t>(DW_OP_reg5); // The frame pointer's here on ia32 | 1118 w->Write<uint8_t>(DW_OP_reg5); // The frame pointer's here on ia32 |
1107 #elif defined(V8_TARGET_ARCH_X64) | 1119 #elif defined(V8_TARGET_ARCH_X64) |
1108 w->Write<uint8_t>(DW_OP_reg6); // and here on x64. | 1120 w->Write<uint8_t>(DW_OP_reg6); // and here on x64. |
1109 #else | 1121 #else |
1110 #error Unsupported target architecture. | 1122 #error Unsupported target architecture. |
1111 #endif | 1123 #endif |
1112 fb_block_size.set(static_cast<uint32_t>(w->position() - fb_block_start)); | 1124 fb_block_size.set(static_cast<uint32_t>(w->position() - fb_block_start)); |
1113 | 1125 |
1114 int params = scope_info.number_of_parameters(); | 1126 ZoneList<Variable*> stack_locals(0, w->zone()); |
1115 int slots = scope_info.number_of_stack_slots(); | 1127 ZoneList<Variable*> context_locals(0, w->zone()); |
1116 int context_slots = scope_info.number_of_context_slots(); | 1128 scope->CollectStackAndContextLocals(&stack_locals, &context_locals); |
1129 | |
1130 int params = scope->num_parameters(); | |
1131 int slots = scope->num_stack_slots(); | |
1132 int context_slots = scope->num_heap_slots(); | |
1117 // The real slot ID is internal_slots + context_slot_id. | 1133 // The real slot ID is internal_slots + context_slot_id. |
1118 int internal_slots = Context::MIN_CONTEXT_SLOTS; | 1134 int internal_slots = Context::MIN_CONTEXT_SLOTS; |
1119 int locals = scope_info.LocalCount(); | 1135 int locals = stack_locals.length(); |
1120 int current_abbreviation = 4; | 1136 int current_abbreviation = 4; |
1121 | 1137 |
1122 for (int param = 0; param < params; ++param) { | 1138 for (int param = 0; param < params; ++param) { |
1123 w->WriteULEB128(current_abbreviation++); | 1139 w->WriteULEB128(current_abbreviation++); |
1124 w->WriteString( | 1140 w->WriteString( |
1125 *scope_info.ParameterName(param)->ToCString(DISALLOW_NULLS)); | 1141 *scope->parameter(param)->name()->ToCString(DISALLOW_NULLS)); |
1126 w->Write<uint32_t>(ty_offset); | 1142 w->Write<uint32_t>(ty_offset); |
1127 Writer::Slot<uint32_t> block_size = w->CreateSlotHere<uint32_t>(); | 1143 Writer::Slot<uint32_t> block_size = w->CreateSlotHere<uint32_t>(); |
1128 uintptr_t block_start = w->position(); | 1144 uintptr_t block_start = w->position(); |
1129 w->Write<uint8_t>(DW_OP_fbreg); | 1145 w->Write<uint8_t>(DW_OP_fbreg); |
1130 w->WriteSLEB128( | 1146 w->WriteSLEB128( |
1131 JavaScriptFrameConstants::kLastParameterOffset + | 1147 JavaScriptFrameConstants::kLastParameterOffset + |
1132 kPointerSize * (params - param - 1)); | 1148 kPointerSize * (params - param - 1)); |
1133 block_size.set(static_cast<uint32_t>(w->position() - block_start)); | 1149 block_size.set(static_cast<uint32_t>(w->position() - block_start)); |
1134 } | 1150 } |
1135 | 1151 |
(...skipping 27 matching lines...) Expand all Loading... | |
1163 ++context_slot) { | 1179 ++context_slot) { |
1164 w->WriteULEB128(current_abbreviation++); | 1180 w->WriteULEB128(current_abbreviation++); |
1165 builder.Reset(); | 1181 builder.Reset(); |
1166 builder.AddFormatted("context_slot%d", context_slot + internal_slots); | 1182 builder.AddFormatted("context_slot%d", context_slot + internal_slots); |
1167 w->WriteString(builder.Finalize()); | 1183 w->WriteString(builder.Finalize()); |
1168 } | 1184 } |
1169 | 1185 |
1170 for (int local = 0; local < locals; ++local) { | 1186 for (int local = 0; local < locals; ++local) { |
1171 w->WriteULEB128(current_abbreviation++); | 1187 w->WriteULEB128(current_abbreviation++); |
1172 w->WriteString( | 1188 w->WriteString( |
1173 *scope_info.LocalName(local)->ToCString(DISALLOW_NULLS)); | 1189 *stack_locals[local]->name()->ToCString(DISALLOW_NULLS)); |
1174 w->Write<uint32_t>(ty_offset); | 1190 w->Write<uint32_t>(ty_offset); |
1175 Writer::Slot<uint32_t> block_size = w->CreateSlotHere<uint32_t>(); | 1191 Writer::Slot<uint32_t> block_size = w->CreateSlotHere<uint32_t>(); |
1176 uintptr_t block_start = w->position(); | 1192 uintptr_t block_start = w->position(); |
1177 w->Write<uint8_t>(DW_OP_fbreg); | 1193 w->Write<uint8_t>(DW_OP_fbreg); |
1178 w->WriteSLEB128( | 1194 w->WriteSLEB128( |
1179 JavaScriptFrameConstants::kLocal0Offset - | 1195 JavaScriptFrameConstants::kLocal0Offset - |
1180 kPointerSize * local); | 1196 kPointerSize * local); |
1181 block_size.set(static_cast<uint32_t>(w->position() - block_start)); | 1197 block_size.set(static_cast<uint32_t>(w->position() - block_start)); |
1182 } | 1198 } |
1183 | 1199 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1300 w->WriteULEB128(DW_FORM_ADDR); | 1316 w->WriteULEB128(DW_FORM_ADDR); |
1301 w->WriteULEB128(DW_AT_HIGH_PC); | 1317 w->WriteULEB128(DW_AT_HIGH_PC); |
1302 w->WriteULEB128(DW_FORM_ADDR); | 1318 w->WriteULEB128(DW_FORM_ADDR); |
1303 w->WriteULEB128(DW_AT_STMT_LIST); | 1319 w->WriteULEB128(DW_AT_STMT_LIST); |
1304 w->WriteULEB128(DW_FORM_DATA4); | 1320 w->WriteULEB128(DW_FORM_DATA4); |
1305 w->WriteULEB128(0); | 1321 w->WriteULEB128(0); |
1306 w->WriteULEB128(0); | 1322 w->WriteULEB128(0); |
1307 | 1323 |
1308 if (extra_info) { | 1324 if (extra_info) { |
1309 CompilationInfo* info = desc_->info(); | 1325 CompilationInfo* info = desc_->info(); |
1310 ScopeInfo<FreeStoreAllocationPolicy> scope_info(info->scope()); | 1326 Scope* scope = info->scope(); |
1311 int params = scope_info.number_of_parameters(); | 1327 |
1312 int slots = scope_info.number_of_stack_slots(); | 1328 ZoneList<Variable*> stack_locals(0, w->zone()); |
1313 int context_slots = scope_info.number_of_context_slots(); | 1329 ZoneList<Variable*> context_locals(0, w->zone()); |
1330 scope->CollectStackAndContextLocals(&stack_locals, &context_locals); | |
1331 | |
1332 int params = scope->num_parameters(); | |
1333 int slots = scope->num_stack_slots(); | |
1334 int context_slots = scope->num_heap_slots(); | |
1314 // The real slot ID is internal_slots + context_slot_id. | 1335 // The real slot ID is internal_slots + context_slot_id. |
1315 int internal_slots = Context::MIN_CONTEXT_SLOTS; | 1336 int internal_slots = Context::MIN_CONTEXT_SLOTS; |
1316 int locals = scope_info.LocalCount(); | 1337 int locals = stack_locals.length(); |
1317 int total_children = | 1338 int total_children = |
1318 params + slots + context_slots + internal_slots + locals + 2; | 1339 params + slots + context_slots + internal_slots + locals + 2; |
1319 | 1340 |
1320 // The extra duplication below seems to be necessary to keep | 1341 // The extra duplication below seems to be necessary to keep |
1321 // gdb from getting upset on OSX. | 1342 // gdb from getting upset on OSX. |
1322 w->WriteULEB128(current_abbreviation++); // Abbreviation code. | 1343 w->WriteULEB128(current_abbreviation++); // Abbreviation code. |
1323 w->WriteULEB128(DW_TAG_SUBPROGRAM); | 1344 w->WriteULEB128(DW_TAG_SUBPROGRAM); |
1324 w->Write<uint8_t>( | 1345 w->Write<uint8_t>( |
1325 total_children != 0 ? DW_CHILDREN_YES : DW_CHILDREN_NO); | 1346 total_children != 0 ? DW_CHILDREN_YES : DW_CHILDREN_NO); |
1326 w->WriteULEB128(DW_AT_NAME); | 1347 w->WriteULEB128(DW_AT_NAME); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1411 DW_LNS_NEGATE_STMT = 6 | 1432 DW_LNS_NEGATE_STMT = 6 |
1412 }; | 1433 }; |
1413 | 1434 |
1414 // DWARF2 standard, figure 35. | 1435 // DWARF2 standard, figure 35. |
1415 enum DWARF2ExtendedOpcode { | 1436 enum DWARF2ExtendedOpcode { |
1416 DW_LNE_END_SEQUENCE = 1, | 1437 DW_LNE_END_SEQUENCE = 1, |
1417 DW_LNE_SET_ADDRESS = 2, | 1438 DW_LNE_SET_ADDRESS = 2, |
1418 DW_LNE_DEFINE_FILE = 3 | 1439 DW_LNE_DEFINE_FILE = 3 |
1419 }; | 1440 }; |
1420 | 1441 |
1421 bool WriteBody(Writer* w) { | 1442 virtual bool WriteBody(Writer* w) { |
1422 // Write prologue. | 1443 // Write prologue. |
1423 Writer::Slot<uint32_t> total_length = w->CreateSlotHere<uint32_t>(); | 1444 Writer::Slot<uint32_t> total_length = w->CreateSlotHere<uint32_t>(); |
1424 uintptr_t start = w->position(); | 1445 uintptr_t start = w->position(); |
1425 | 1446 |
1426 // Used for special opcodes | 1447 // Used for special opcodes |
1427 const int8_t line_base = 1; | 1448 const int8_t line_base = 1; |
1428 const uint8_t line_range = 7; | 1449 const uint8_t line_range = 7; |
1429 const int8_t max_line_incr = (line_base + line_range - 1); | 1450 const int8_t max_line_incr = (line_base + line_range - 1); |
1430 const uint8_t opcode_base = DW_LNS_NEGATE_STMT + 1; | 1451 const uint8_t opcode_base = DW_LNS_NEGATE_STMT + 1; |
1431 | 1452 |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1772 | 1793 |
1773 bool UnwindInfoSection::WriteBody(Writer* w) { | 1794 bool UnwindInfoSection::WriteBody(Writer* w) { |
1774 uint32_t cie_position = WriteCIE(w); | 1795 uint32_t cie_position = WriteCIE(w); |
1775 WriteFDE(w, cie_position); | 1796 WriteFDE(w, cie_position); |
1776 return true; | 1797 return true; |
1777 } | 1798 } |
1778 | 1799 |
1779 | 1800 |
1780 #endif // V8_TARGET_ARCH_X64 | 1801 #endif // V8_TARGET_ARCH_X64 |
1781 | 1802 |
1782 static void CreateDWARFSections(CodeDescription* desc, DebugObject* obj) { | 1803 static void CreateDWARFSections(CodeDescription* desc, |
1804 DebugObject* obj, | |
1805 Zone* zone) { | |
1783 if (desc->IsLineInfoAvailable()) { | 1806 if (desc->IsLineInfoAvailable()) { |
1784 obj->AddSection(new DebugInfoSection(desc)); | 1807 obj->AddSection(new(zone) DebugInfoSection(desc), zone); |
1785 obj->AddSection(new DebugAbbrevSection(desc)); | 1808 obj->AddSection(new(zone) DebugAbbrevSection(desc), zone); |
1786 obj->AddSection(new DebugLineSection(desc)); | 1809 obj->AddSection(new(zone) DebugLineSection(desc), zone); |
1787 } | 1810 } |
1788 #ifdef V8_TARGET_ARCH_X64 | 1811 #ifdef V8_TARGET_ARCH_X64 |
1789 obj->AddSection(new UnwindInfoSection(desc)); | 1812 obj->AddSection(new(zone) UnwindInfoSection(desc), zone); |
1790 #endif | 1813 #endif |
1791 } | 1814 } |
1792 | 1815 |
1793 | 1816 |
1794 // ------------------------------------------------------------------- | 1817 // ------------------------------------------------------------------- |
1795 // Binary GDB JIT Interface as described in | 1818 // Binary GDB JIT Interface as described in |
1796 // http://sourceware.org/gdb/onlinedocs/gdb/Declarations.html | 1819 // http://sourceware.org/gdb/onlinedocs/gdb/Declarations.html |
1797 extern "C" { | 1820 extern "C" { |
1798 typedef enum { | 1821 typedef enum { |
1799 JIT_NOACTION = 0, | 1822 JIT_NOACTION = 0, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1897 if (entry->next_ != NULL) { | 1920 if (entry->next_ != NULL) { |
1898 entry->next_->prev_ = entry->prev_; | 1921 entry->next_->prev_ = entry->prev_; |
1899 } | 1922 } |
1900 | 1923 |
1901 __jit_debug_descriptor.relevant_entry_ = entry; | 1924 __jit_debug_descriptor.relevant_entry_ = entry; |
1902 __jit_debug_descriptor.action_flag_ = JIT_UNREGISTER_FN; | 1925 __jit_debug_descriptor.action_flag_ = JIT_UNREGISTER_FN; |
1903 __jit_debug_register_code(); | 1926 __jit_debug_register_code(); |
1904 } | 1927 } |
1905 | 1928 |
1906 | 1929 |
1907 static JITCodeEntry* CreateELFObject(CodeDescription* desc) { | 1930 static JITCodeEntry* CreateELFObject(CodeDescription* desc, Zone* zone) { |
1908 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); | |
1909 #ifdef __MACH_O | 1931 #ifdef __MACH_O |
1910 MachO mach_o; | 1932 MachO mach_o(zone); |
1911 Writer w(&mach_o); | 1933 Writer w(&mach_o, zone); |
1912 | 1934 |
1913 mach_o.AddSection(new MachOTextSection(kCodeAlignment, | 1935 MachOTextSection* section = new(zone) MachOTextSection(kCodeAlignment, |
1914 desc->CodeStart(), | 1936 desc->CodeStart(), |
1915 desc->CodeSize())); | 1937 desc->CodeSize()); |
1938 mach_o.AddSection(section, zone); | |
1916 | 1939 |
1917 CreateDWARFSections(desc, &mach_o); | 1940 CreateDWARFSections(desc, &mach_o, zone); |
1918 | 1941 |
1919 mach_o.Write(&w, desc->CodeStart(), desc->CodeSize()); | 1942 mach_o.Write(&w, desc->CodeStart(), desc->CodeSize()); |
1920 #else | 1943 #else |
1921 ELF elf; | 1944 ELF elf(zone); |
1922 Writer w(&elf); | 1945 Writer w(&elf, zone); |
1923 | 1946 |
1924 int text_section_index = elf.AddSection( | 1947 FullHeaderELFSection* section = |
1925 new FullHeaderELFSection(".text", | 1948 new(zone) FullHeaderELFSection(".text", |
1926 ELFSection::TYPE_NOBITS, | 1949 ELFSection::TYPE_NOBITS, |
1927 kCodeAlignment, | 1950 kCodeAlignment, |
1928 desc->CodeStart(), | 1951 desc->CodeStart(), |
1929 0, | 1952 0, |
1930 desc->CodeSize(), | 1953 desc->CodeSize(), |
1931 ELFSection::FLAG_ALLOC | ELFSection::FLAG_EXEC)); | 1954 ELFSection::FLAG_ALLOC | |
1955 ELFSection::FLAG_EXEC); | |
1956 int text_section_index = elf.AddSection(section, zone); | |
1932 | 1957 |
1933 CreateSymbolsTable(desc, &elf, text_section_index); | 1958 CreateSymbolsTable(desc, &elf, text_section_index, zone); |
1934 | 1959 |
1935 CreateDWARFSections(desc, &elf); | 1960 CreateDWARFSections(desc, &elf, zone); |
1936 | 1961 |
1937 elf.Write(&w); | 1962 elf.Write(&w); |
1938 #endif | 1963 #endif |
1939 | 1964 |
1940 return CreateCodeEntry(w.buffer(), w.position()); | 1965 return CreateCodeEntry(w.buffer(), w.position()); |
1941 } | 1966 } |
1942 | 1967 |
1943 | 1968 |
1944 static bool SameCodeObjects(void* key1, void* key2) { | 1969 static bool SameCodeObjects(void* key1, void* key2) { |
1945 return key1 == key2; | 1970 return key1 == key2; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2060 lineinfo, | 2085 lineinfo, |
2061 tag, | 2086 tag, |
2062 info); | 2087 info); |
2063 | 2088 |
2064 if (!FLAG_gdbjit_full && !code_desc.IsLineInfoAvailable()) { | 2089 if (!FLAG_gdbjit_full && !code_desc.IsLineInfoAvailable()) { |
2065 delete lineinfo; | 2090 delete lineinfo; |
2066 GetEntries()->Remove(code, HashForCodeObject(code)); | 2091 GetEntries()->Remove(code, HashForCodeObject(code)); |
2067 return; | 2092 return; |
2068 } | 2093 } |
2069 | 2094 |
2095 Zone* zone = Isolate::Current()->runtime_zone(); | |
noordhuis
2012/08/17 01:28:39
I suspect that it's better to create a new zone an
| |
2096 ZoneScope zone_scope(zone, DELETE_ON_EXIT); | |
2097 | |
2070 AddUnwindInfo(&code_desc); | 2098 AddUnwindInfo(&code_desc); |
2071 JITCodeEntry* entry = CreateELFObject(&code_desc); | 2099 JITCodeEntry* entry = CreateELFObject(&code_desc, zone); |
2072 ASSERT(!IsLineInfoTagged(entry)); | 2100 ASSERT(!IsLineInfoTagged(entry)); |
2073 | 2101 |
2074 delete lineinfo; | 2102 delete lineinfo; |
2075 e->value = entry; | 2103 e->value = entry; |
2076 | 2104 |
2077 const char* name_hint = NULL; | 2105 const char* name_hint = NULL; |
2078 bool should_dump = false; | 2106 bool should_dump = false; |
2079 if (FLAG_gdbjit_dump) { | 2107 if (FLAG_gdbjit_dump) { |
2080 if (strlen(FLAG_gdbjit_dump_filter) == 0) { | 2108 if (strlen(FLAG_gdbjit_dump_filter) == 0) { |
2081 name_hint = name; | 2109 name_hint = name; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2150 ScopedLock lock(mutex.Pointer()); | 2178 ScopedLock lock(mutex.Pointer()); |
2151 ASSERT(!IsLineInfoTagged(line_info)); | 2179 ASSERT(!IsLineInfoTagged(line_info)); |
2152 HashMap::Entry* e = GetEntries()->Lookup(code, HashForCodeObject(code), true); | 2180 HashMap::Entry* e = GetEntries()->Lookup(code, HashForCodeObject(code), true); |
2153 ASSERT(e->value == NULL); | 2181 ASSERT(e->value == NULL); |
2154 e->value = TagLineInfo(line_info); | 2182 e->value = TagLineInfo(line_info); |
2155 } | 2183 } |
2156 | 2184 |
2157 | 2185 |
2158 } } // namespace v8::internal | 2186 } } // namespace v8::internal |
2159 #endif | 2187 #endif |
OLD | NEW |