1 // Copyright 2014, ARM Limited 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 28 29 #ifndef VIXL_A64_DEBUGGER_A64_H_ 30 #define VIXL_A64_DEBUGGER_A64_H_ 31 32 #include <ctype.h> 33 #include <limits.h> 34 #include <errno.h> 35 #include <vector> 36 37 #include "vixl/globals.h" 38 #include "vixl/utils.h" 39 #include "vixl/a64/constants-a64.h" 40 #include "vixl/a64/simulator-a64.h" 41 42 namespace vixl { 43 44 // Flags that represent the debugger state. 45 enum DebugParameters { 46 DBG_INACTIVE = 0, 47 DBG_ACTIVE = 1 << 0, // The debugger is active. 48 DBG_BREAK = 1 << 1 // The debugger is at a breakpoint. 49 }; 50 51 // Forward declarations. 52 class DebugCommand; 53 class Token; 54 class FormatToken; 55 56 class Debugger : public Simulator { 57 public: 58 explicit Debugger(Decoder* decoder, FILE* stream = stdout); 59 ~Debugger(); 60 61 virtual void Run(); 62 virtual void VisitException(const Instruction* instr); 63 64 int debug_parameters() const { return debug_parameters_; } 65 void set_debug_parameters(int parameters) { 66 debug_parameters_ = parameters; 67 68 update_pending_request(); 69 } 70 71 // Numbers of instructions to execute before the debugger shell is given 72 // back control. 73 int64_t steps() const { return steps_; } 74 void set_steps(int64_t value) { 75 VIXL_ASSERT(value > 1); 76 steps_ = value; 77 } 78 79 bool IsDebuggerRunning() const { 80 return (debug_parameters_ & DBG_ACTIVE) != 0; 81 } 82 83 bool pending_request() const { return pending_request_; } 84 void update_pending_request() { 85 pending_request_ = IsDebuggerRunning(); 86 } 87 88 void PrintInstructions(const void* address, int64_t count = 1); 89 void PrintMemory(const uint8_t* address, 90 const FormatToken* format, 91 int64_t count = 1); 92 void PrintRegister(const Register& target_reg, 93 const char* name, 94 const FormatToken* format); 95 void PrintFPRegister(const FPRegister& target_fpreg, 96 const FormatToken* format); 97 98 private: 99 char* ReadCommandLine(const char* prompt, char* buffer, int length); 100 void RunDebuggerShell(); 101 void DoBreakpoint(const Instruction* instr); 102 103 int debug_parameters_; 104 bool pending_request_; 105 int64_t steps_; 106 DebugCommand* last_command_; 107 PrintDisassembler* disasm_; 108 Decoder* printer_; 109 110 // Length of the biggest command line accepted by the debugger shell. 111 static const int kMaxDebugShellLine = 256; 112 }; 113 114 } // namespace vixl 115 116 #endif // VIXL_A64_DEBUGGER_A64_H_ 117 118 #endif // VIXL_INCLUDE_SIMULATOR 119