| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdarg.h> | 5 #include <stdarg.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #if V8_TARGET_ARCH_S390 | 9 #if V8_TARGET_ARCH_S390 |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // SScanF not being implemented in a platform independent way through | 29 // SScanF not being implemented in a platform independent way through |
| 30 // ::v8::internal::OS in the same way as SNPrintF is that the | 30 // ::v8::internal::OS in the same way as SNPrintF is that the |
| 31 // Windows C Run-Time Library does not provide vsscanf. | 31 // Windows C Run-Time Library does not provide vsscanf. |
| 32 #define SScanF sscanf // NOLINT | 32 #define SScanF sscanf // NOLINT |
| 33 | 33 |
| 34 // The S390Debugger class is used by the simulator while debugging simulated | 34 // The S390Debugger class is used by the simulator while debugging simulated |
| 35 // z/Architecture code. | 35 // z/Architecture code. |
| 36 class S390Debugger { | 36 class S390Debugger { |
| 37 public: | 37 public: |
| 38 explicit S390Debugger(Simulator* sim) : sim_(sim) {} | 38 explicit S390Debugger(Simulator* sim) : sim_(sim) {} |
| 39 ~S390Debugger(); | |
| 40 | 39 |
| 41 void Stop(Instruction* instr); | 40 void Stop(Instruction* instr); |
| 42 void Debug(); | 41 void Debug(); |
| 43 | 42 |
| 44 private: | 43 private: |
| 45 #if V8_TARGET_LITTLE_ENDIAN | 44 #if V8_TARGET_LITTLE_ENDIAN |
| 46 static const Instr kBreakpointInstr = (0x0000FFB2); // TRAP4 0000 | 45 static const Instr kBreakpointInstr = (0x0000FFB2); // TRAP4 0000 |
| 47 static const Instr kNopInstr = (0x00160016); // OR r0, r0 x2 | 46 static const Instr kNopInstr = (0x00160016); // OR r0, r0 x2 |
| 48 #else | 47 #else |
| 49 static const Instr kBreakpointInstr = (0xB2FF0000); // TRAP4 0000 | 48 static const Instr kBreakpointInstr = (0xB2FF0000); // TRAP4 0000 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 62 // Set or delete a breakpoint. Returns true if successful. | 61 // Set or delete a breakpoint. Returns true if successful. |
| 63 bool SetBreakpoint(Instruction* break_pc); | 62 bool SetBreakpoint(Instruction* break_pc); |
| 64 bool DeleteBreakpoint(Instruction* break_pc); | 63 bool DeleteBreakpoint(Instruction* break_pc); |
| 65 | 64 |
| 66 // Undo and redo all breakpoints. This is needed to bracket disassembly and | 65 // Undo and redo all breakpoints. This is needed to bracket disassembly and |
| 67 // execution to skip past breakpoints when run from the debugger. | 66 // execution to skip past breakpoints when run from the debugger. |
| 68 void UndoBreakpoints(); | 67 void UndoBreakpoints(); |
| 69 void RedoBreakpoints(); | 68 void RedoBreakpoints(); |
| 70 }; | 69 }; |
| 71 | 70 |
| 72 S390Debugger::~S390Debugger() {} | |
| 73 | |
| 74 #ifdef GENERATED_CODE_COVERAGE | |
| 75 static FILE* coverage_log = NULL; | |
| 76 | |
| 77 static void InitializeCoverage() { | |
| 78 char* file_name = getenv("V8_GENERATED_CODE_COVERAGE_LOG"); | |
| 79 if (file_name != NULL) { | |
| 80 coverage_log = fopen(file_name, "aw+"); | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 void S390Debugger::Stop(Instruction* instr) { | |
| 85 // Get the stop code. | |
| 86 uint32_t code = instr->SvcValue() & kStopCodeMask; | |
| 87 // Retrieve the encoded address, which comes just after this stop. | |
| 88 char** msg_address = | |
| 89 reinterpret_cast<char**>(sim_->get_pc() + sizeof(FourByteInstr)); | |
| 90 char* msg = *msg_address; | |
| 91 DCHECK(msg != NULL); | |
| 92 | |
| 93 // Update this stop description. | |
| 94 if (isWatchedStop(code) && !watched_stops_[code].desc) { | |
| 95 watched_stops_[code].desc = msg; | |
| 96 } | |
| 97 | |
| 98 if (strlen(msg) > 0) { | |
| 99 if (coverage_log != NULL) { | |
| 100 fprintf(coverage_log, "%s\n", msg); | |
| 101 fflush(coverage_log); | |
| 102 } | |
| 103 // Overwrite the instruction and address with nops. | |
| 104 instr->SetInstructionBits(kNopInstr); | |
| 105 reinterpret_cast<Instruction*>(msg_address)->SetInstructionBits(kNopInstr); | |
| 106 } | |
| 107 sim_->set_pc(sim_->get_pc() + sizeof(FourByteInstr) + kPointerSize); | |
| 108 } | |
| 109 | |
| 110 #else // ndef GENERATED_CODE_COVERAGE | |
| 111 | |
| 112 static void InitializeCoverage() {} | |
| 113 | |
| 114 void S390Debugger::Stop(Instruction* instr) { | 71 void S390Debugger::Stop(Instruction* instr) { |
| 115 // Get the stop code. | 72 // Get the stop code. |
| 116 // use of kStopCodeMask not right on PowerPC | 73 // use of kStopCodeMask not right on PowerPC |
| 117 uint32_t code = instr->SvcValue() & kStopCodeMask; | 74 uint32_t code = instr->SvcValue() & kStopCodeMask; |
| 118 // Retrieve the encoded address, which comes just after this stop. | 75 // Retrieve the encoded address, which comes just after this stop. |
| 119 char* msg = *reinterpret_cast<char**>(sim_->get_pc() + sizeof(FourByteInstr)); | 76 char* msg = *reinterpret_cast<char**>(sim_->get_pc() + sizeof(FourByteInstr)); |
| 120 // Update this stop description. | 77 // Update this stop description. |
| 121 if (sim_->isWatchedStop(code) && !sim_->watched_stops_[code].desc) { | 78 if (sim_->isWatchedStop(code) && !sim_->watched_stops_[code].desc) { |
| 122 sim_->watched_stops_[code].desc = msg; | 79 sim_->watched_stops_[code].desc = msg; |
| 123 } | 80 } |
| 124 // Print the stop message and code if it is not the default code. | 81 // Print the stop message and code if it is not the default code. |
| 125 if (code != kMaxStopCode) { | 82 if (code != kMaxStopCode) { |
| 126 PrintF("Simulator hit stop %u: %s\n", code, msg); | 83 PrintF("Simulator hit stop %u: %s\n", code, msg); |
| 127 } else { | 84 } else { |
| 128 PrintF("Simulator hit %s\n", msg); | 85 PrintF("Simulator hit %s\n", msg); |
| 129 } | 86 } |
| 130 sim_->set_pc(sim_->get_pc() + sizeof(FourByteInstr) + kPointerSize); | 87 sim_->set_pc(sim_->get_pc() + sizeof(FourByteInstr) + kPointerSize); |
| 131 Debug(); | 88 Debug(); |
| 132 } | 89 } |
| 133 #endif | |
| 134 | 90 |
| 135 intptr_t S390Debugger::GetRegisterValue(int regnum) { | 91 intptr_t S390Debugger::GetRegisterValue(int regnum) { |
| 136 return sim_->get_register(regnum); | 92 return sim_->get_register(regnum); |
| 137 } | 93 } |
| 138 | 94 |
| 139 double S390Debugger::GetRegisterPairDoubleValue(int regnum) { | 95 double S390Debugger::GetRegisterPairDoubleValue(int regnum) { |
| 140 return sim_->get_double_from_register_pair(regnum); | 96 return sim_->get_double_from_register_pair(regnum); |
| 141 } | 97 } |
| 142 | 98 |
| 143 double S390Debugger::GetFPDoubleRegisterValue(int regnum) { | 99 double S390Debugger::GetFPDoubleRegisterValue(int regnum) { |
| (...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1548 // Initializing FP registers. | 1504 // Initializing FP registers. |
| 1549 for (int i = 0; i < kNumFPRs; i++) { | 1505 for (int i = 0; i < kNumFPRs; i++) { |
| 1550 fp_registers_[i] = 0.0; | 1506 fp_registers_[i] = 0.0; |
| 1551 } | 1507 } |
| 1552 | 1508 |
| 1553 // The sp is initialized to point to the bottom (high address) of the | 1509 // The sp is initialized to point to the bottom (high address) of the |
| 1554 // allocated stack area. To be safe in potential stack underflows we leave | 1510 // allocated stack area. To be safe in potential stack underflows we leave |
| 1555 // some buffer below. | 1511 // some buffer below. |
| 1556 registers_[sp] = | 1512 registers_[sp] = |
| 1557 reinterpret_cast<intptr_t>(stack_) + stack_size - stack_protection_size_; | 1513 reinterpret_cast<intptr_t>(stack_) + stack_size - stack_protection_size_; |
| 1558 InitializeCoverage(); | |
| 1559 | 1514 |
| 1560 last_debugger_input_ = NULL; | 1515 last_debugger_input_ = NULL; |
| 1561 } | 1516 } |
| 1562 | 1517 |
| 1563 Simulator::~Simulator() { free(stack_); } | 1518 Simulator::~Simulator() { free(stack_); } |
| 1564 | 1519 |
| 1565 // When the generated code calls an external reference we need to catch that in | 1520 // When the generated code calls an external reference we need to catch that in |
| 1566 // the simulator. The external reference will be a function compiled for the | 1521 // the simulator. The external reference will be a function compiled for the |
| 1567 // host architecture. We need to call that function instead of trying to | 1522 // host architecture. We need to call that function instead of trying to |
| 1568 // execute it with the simulator. We do that by redirecting the external | 1523 // execute it with the simulator. We do that by redirecting the external |
| (...skipping 10996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12565 return 0; | 12520 return 0; |
| 12566 } | 12521 } |
| 12567 | 12522 |
| 12568 #undef EVALUATE | 12523 #undef EVALUATE |
| 12569 | 12524 |
| 12570 } // namespace internal | 12525 } // namespace internal |
| 12571 } // namespace v8 | 12526 } // namespace v8 |
| 12572 | 12527 |
| 12573 #endif // USE_SIMULATOR | 12528 #endif // USE_SIMULATOR |
| 12574 #endif // V8_TARGET_ARCH_S390 | 12529 #endif // V8_TARGET_ARCH_S390 |
| OLD | NEW |