Changeset 215642 in webkit for trunk/Source/JavaScriptCore/assembler/MacroAssemblerPrinter.cpp
- Timestamp:
- Apr 21, 2017, 2:42:24 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/assembler/MacroAssemblerPrinter.cpp
r215592 r215642 32 32 33 33 namespace JSC { 34 namespace Printer { 34 35 35 36 using CPUState = MacroAssembler::CPUState; … … 37 38 using FPRegisterID = MacroAssembler::FPRegisterID; 38 39 39 static void printIndent(int indentation)40 void printAllRegisters(PrintStream& out, Context& context) 40 41 { 41 for (; indentation > 0; indentation--) 42 dataLog(" "); 43 } 42 auto& cpu = context.probeContext.cpu; 43 unsigned charsToIndent = context.data.as<unsigned>(); 44 44 45 #define INDENT printIndent(indentation) 46 47 void printCPU(CPUState& cpu, int indentation) 48 { 49 INDENT, dataLog("cpu: {\n"); 50 printCPURegisters(cpu, indentation + 1); 51 INDENT, dataLog("}\n"); 52 } 45 auto indent = [&] () { 46 for (unsigned i = 0; i < charsToIndent; ++i) 47 out.print(" "); 48 }; 49 #define INDENT indent() 53 50 54 void printCPURegisters(CPUState& cpu, int indentation) 55 { 51 INDENT, out.print("cpu: {\n"); 52 56 53 #if USE(JSVALUE32_64) 57 54 #define INTPTR_HEX_VALUE_FORMAT "0x%08lx" … … 62 59 #define PRINT_GPREGISTER(_type, _regName) { \ 63 60 intptr_t value = reinterpret_cast<intptr_t>(cpu._regName); \ 64 INDENT, dataLogF("%6s: " INTPTR_HEX_VALUE_FORMAT " %ld\n", #_regName, value, value) ; \61 INDENT, out.printf(" %6s: " INTPTR_HEX_VALUE_FORMAT " %ld\n", #_regName, value, value) ; \ 65 62 } 66 63 FOR_EACH_CPU_GPREGISTER(PRINT_GPREGISTER) … … 72 69 uint64_t* u = reinterpret_cast<uint64_t*>(&cpu._regName); \ 73 70 double* d = reinterpret_cast<double*>(&cpu._regName); \ 74 INDENT, dataLogF("%6s: 0x%016llx %.13g\n", #_regName, *u, *d); \71 INDENT, out.printf(" %6s: 0x%016llx %.13g\n", #_regName, *u, *d); \ 75 72 } 76 73 FOR_EACH_CPU_FPREGISTER(PRINT_FPREGISTER) 77 74 #undef PRINT_FPREGISTER 75 76 INDENT, out.print("}\n"); 77 #undef INDENT 78 78 79 } 79 80 80 static void printPC(CPUState& cpu)81 void printPCRegister(PrintStream& out, Context& context) 81 82 { 82 union { 83 void* voidPtr; 84 intptr_t intptrValue; 85 } u; 83 auto cpu = context.probeContext.cpu; 84 void* value; 86 85 #if CPU(X86) || CPU(X86_64) 87 u.voidPtr= cpu.eip;86 value = cpu.eip; 88 87 #elif CPU(ARM_TRADITIONAL) || CPU(ARM_THUMB2) || CPU(ARM64) 89 u.voidPtr= cpu.pc;88 value = cpu.pc; 90 89 #else 91 90 #error "Unsupported CPU" 92 91 #endif 93 dataLogF("pc:<%p %ld>", u.voidPtr, u.intptrValue);92 out.printf("pc:<%p %ld>", value, bitwise_cast<intptr_t>(value)); 94 93 } 95 94 96 void printRegister (CPUState& cpu, RegisterID regID)95 void printRegisterID(PrintStream& out, Context& context) 97 96 { 97 RegisterID regID = context.data.as<RegisterID>(); 98 98 const char* name = CPUState::gprName(regID); 99 union { 100 void* voidPtr; 101 intptr_t intptrValue; 102 } u; 103 u.voidPtr = cpu.gpr(regID); 104 dataLogF("%s:<%p %ld>", name, u.voidPtr, u.intptrValue); 99 void* value = context.probeContext.gpr(regID); 100 out.printf("%s:<%p %ld>", name, value, bitwise_cast<intptr_t>(value)); 105 101 } 106 102 107 void print Register(CPUState& cpu, FPRegisterID regID)103 void printFPRegisterID(PrintStream& out, Context& context) 108 104 { 105 FPRegisterID regID = context.data.as<FPRegisterID>(); 109 106 const char* name = CPUState::fprName(regID); 110 union { 111 double doubleValue; 112 uint64_t uint64Value; 113 } u; 114 u.doubleValue = cpu.fpr(regID); 115 dataLogF("%s:<0x%016llx %.13g>", name, u.uint64Value, u.doubleValue); 107 double value = context.probeContext.fpr(regID); 108 out.printf("%s:<0x%016llx %.13g>", name, bitwise_cast<uint64_t>(value), value); 116 109 } 117 110 118 void print Memory(CPUState& cpu, const Memory& memory)111 void printAddress(PrintStream& out, Context& context) 119 112 { 113 MacroAssembler::Address address = context.data.as<MacroAssembler::Address>(); 114 RegisterID regID = address.base; 115 const char* name = CPUState::gprName(regID); 116 void* value = context.probeContext.gpr(regID); 117 out.printf("Address{base:%s:<%p %ld>, offset:<0x%x %d>", name, value, bitwise_cast<intptr_t>(value), address.offset, address.offset); 118 } 119 120 void printMemory(PrintStream& out, Context& context) 121 { 122 const Memory& memory = context.data.as<Memory>(); 123 120 124 uint8_t* ptr = nullptr; 121 125 switch (memory.addressType) { 122 126 case Memory::AddressType::Address: { 123 ptr = reinterpret_cast<uint8_t*>(c pu.gpr(memory.u.address.base));127 ptr = reinterpret_cast<uint8_t*>(context.probeContext.gpr(memory.u.address.base)); 124 128 ptr += memory.u.address.offset; 125 129 break; … … 134 138 if (memory.numBytes == sizeof(int8_t)) { 135 139 auto p = reinterpret_cast<int8_t*>(ptr); 136 dataLogF("%p:<0x%02x %d>", p, *p, *p);140 out.printf("%p:<0x%02x %d>", p, *p, *p); 137 141 return; 138 142 } 139 143 if (memory.numBytes == sizeof(int16_t)) { 140 144 auto p = reinterpret_cast<int16_t*>(ptr); 141 dataLogF("%p:<0x%04x %d>", p, *p, *p);145 out.printf("%p:<0x%04x %d>", p, *p, *p); 142 146 return; 143 147 } 144 148 if (memory.numBytes == sizeof(int32_t)) { 145 149 auto p = reinterpret_cast<int32_t*>(ptr); 146 dataLogF("%p:<0x%08x %d>", p, *p, *p);150 out.printf("%p:<0x%08x %d>", p, *p, *p); 147 151 return; 148 152 } 149 153 if (memory.numBytes == sizeof(int64_t)) { 150 154 auto p = reinterpret_cast<int64_t*>(ptr); 151 dataLogF("%p:<0x%016llx %lld>", p, *p, *p);155 out.printf("%p:<0x%016llx %lld>", p, *p, *p); 152 156 return; 153 157 } … … 159 163 for (size_t i = 0; i < numBytes; i++) { 160 164 if (!(i % 16)) 161 dataLogF("%p: ", &ptr[i]);165 out.printf("%p: ", &ptr[i]); 162 166 else if (!(i % 4)) 163 dataLog(" ");167 out.printf(" "); 164 168 165 dataLogF("%02x", ptr[i]);169 out.printf("%02x", ptr[i]); 166 170 167 171 if (i % 16 == 15) 168 dataLog("\n");172 out.print("\n"); 169 173 } 170 174 if (numBytes % 16 < 15) 171 dataLog("\n");175 out.print("\n"); 172 176 } 173 177 174 void MacroAssemblerPrinter::printCallback(ProbeContext* context)178 void printCallback(ProbeContext* probeContext) 175 179 { 176 typedef PrintArg Arg; 177 PrintArgsList& argsList = 178 *reinterpret_cast<PrintArgsList*>(context->arg); 179 for (size_t i = 0; i < argsList.size(); i++) { 180 auto& arg = argsList[i]; 181 switch (arg.type) { 182 case Arg::Type::AllRegisters: 183 printCPU(context->cpu, 1); 184 break; 185 case Arg::Type::PCRegister: 186 printPC(context->cpu); 187 break; 188 case Arg::Type::RegisterID: 189 printRegister(context->cpu, arg.u.gpRegisterID); 190 break; 191 case Arg::Type::FPRegisterID: 192 printRegister(context->cpu, arg.u.fpRegisterID); 193 break; 194 case Arg::Type::Memory: 195 printMemory(context->cpu, arg.u.memory); 196 break; 197 case Arg::Type::ConstCharPtr: 198 dataLog(arg.u.constCharPtr); 199 break; 200 case Arg::Type::ConstVoidPtr: 201 dataLogF("%p", arg.u.constVoidPtr); 202 break; 203 case Arg::Type::IntptrValue: 204 dataLog(arg.u.intptrValue); 205 break; 206 case Arg::Type::UintptrValue: 207 dataLog(arg.u.uintptrValue); 208 break; 209 } 180 auto& out = WTF::dataFile(); 181 PrintRecordList& list = *reinterpret_cast<PrintRecordList*>(probeContext->arg); 182 for (size_t i = 0; i < list.size(); i++) { 183 auto& record = list[i]; 184 Context context(*probeContext, record.data); 185 record.printer(out, context); 210 186 } 211 187 } 212 188 189 } // namespace Printer 213 190 } // namespace JSC 214 191
Note:
See TracChangeset
for help on using the changeset viewer.