tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Debugger-vixl.h (3988B)


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