1 // Copyright 2014, VIXL authors 2 // All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions are met: 6 // 7 // * Redistributions of source code must retain the above copyright notice, 8 // this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above copyright notice, 10 // this list of conditions and the following disclaimer in the documentation 11 // and/or other materials provided with the distribution. 12 // * Neither the name of ARM Limited nor the names of its contributors may be 13 // used to endorse or promote products derived from this software without 14 // specific prior written permission. 15 // 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND 17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 27 #ifdef VIXL_INCLUDE_SIMULATOR_AARCH64 28 29 #ifndef VIXL_AARCH64_DEBUGGER_AARCH64_H_ 30 #define VIXL_AARCH64_DEBUGGER_AARCH64_H_ 31 32 #include <cctype> 33 #include <cerrno> 34 #include <climits> 35 #include <vector> 36 37 #include "../globals-vixl.h" 38 #include "../utils-vixl.h" 39 40 #include "constants-aarch64.h" 41 #include "simulator-aarch64.h" 42 43 namespace vixl { 44 namespace aarch64 { 45 46 // Forward declarations. 47 class DebugCommand; 48 class Token; 49 class FormatToken; 50 51 class Debugger : public Simulator { 52 public: 53 explicit Debugger(Decoder* decoder, FILE* stream = stdout); 54 ~Debugger(); 55 56 virtual void Run() VIXL_OVERRIDE; 57 virtual void VisitException(const Instruction* instr) VIXL_OVERRIDE; 58 IsDebuggerActive()59 bool IsDebuggerActive() const { return debugger_active_; } ActivateDebugger()60 void ActivateDebugger() { debugger_active_ = true; } DeactivateDebugger()61 void DeactivateDebugger() { debugger_active_ = false; } 62 63 // Numbers of instructions to execute before the debugger shell is given 64 // back control. GetSteps()65 int64_t GetSteps() const { return steps_; } 66 VIXL_DEPRECATED("GetSteps", int64_t steps() const) { return GetSteps(); } 67 SetSteps(int64_t value)68 void SetSteps(int64_t value) { 69 VIXL_ASSERT(value >= 0); 70 steps_ = value; 71 } set_steps(int64_t value)72 VIXL_DEPRECATED("SetSteps", void set_steps(int64_t value)) { 73 return SetSteps(value); 74 } 75 76 void PrintInstructions(const void* address, 77 int64_t count = 1, 78 const char* prefix = ""); PrintNextInstruction()79 void PrintNextInstruction() { PrintInstructions(ReadPc(), 1, "Next: "); } 80 void PrintMemory(const uint8_t* address, 81 const FormatToken* format, 82 int64_t count = 1); 83 void PrintRegister(const Register& target_reg, 84 const char* name, 85 const FormatToken* format); 86 void PrintFPRegister(const FPRegister& target_fpreg, 87 const FormatToken* format); 88 89 private: 90 char* ReadCommandLine(const char* prompt, char* buffer, int length); 91 void RunDebuggerShell(); 92 void DoBreakpoint(const Instruction* instr); 93 94 bool debugger_active_; 95 int64_t steps_; 96 DebugCommand* last_command_; 97 PrintDisassembler* disasm_; 98 Decoder* printer_; 99 100 // Length of the biggest command line accepted by the debugger shell. 101 static const int kMaxDebugShellLine = 256; 102 }; 103 104 } // namespace aarch64 105 } // namespace vixl 106 107 #endif // VIXL_AARCH64_DEBUGGER_AARCH64_H_ 108 109 #endif // VIXL_INCLUDE_SIMULATOR_AARCH64 110